| 1 | # | ||||||||||
| 2 | # $Id: Hello.pm 73 2015-01-14 06:42:49Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::Layer::OSPF::Hello; | ||||||||||
| 5 | 15 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 15 | ▶ | use Net::Frame::Layer qw(:consts :subs); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 15 | our @ISA = qw(Net::Frame::Layer); | |||||||||
| 9 | |||||||||||
| 10 | 15 | our @AS = qw( | |||||||||
| 11 | networkMask | ||||||||||
| 12 | helloInterval | ||||||||||
| 13 | options | ||||||||||
| 14 | routerPri | ||||||||||
| 15 | routerDeadInterval | ||||||||||
| 16 | designatedRouter | ||||||||||
| 17 | backupDesignatedRouter | ||||||||||
| 18 | lls | ||||||||||
| 19 | ); | ||||||||||
| 20 | 15 | our @AA = qw( | |||||||||
| 21 | neighborList | ||||||||||
| 22 | ); | ||||||||||
| 23 | 15 | __PACKAGE__->cgBuildIndices; | |||||||||
| 24 | 15 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 25 | 15 | __PACKAGE__->cgBuildAccessorsArray (\@AA); | |||||||||
| 26 | |||||||||||
| 27 | 15 | ▶ | use Net::Frame::Layer::OSPF qw(:consts); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 30 | shift->SUPER::new( | ||||||||||
| 31 | 1 | networkMask => '255.255.255.0', | |||||||||
| 32 | helloInterval => 60, | ||||||||||
| 33 | options => 0, | ||||||||||
| 34 | routerPri => 0, | ||||||||||
| 35 | routerDeadInterval => 120, | ||||||||||
| 36 | designatedRouter => '0.0.0.0', | ||||||||||
| 37 | backupDesignatedRouter => '0.0.0.0', | ||||||||||
| 38 | neighborList => [], | ||||||||||
| 39 | @_, | ||||||||||
| 40 | ); | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub getLength { | ||||||||
|
Subroutine
getLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 44 | 0 | my $self = shift; | |||||||||
| 45 | 0 | my $len = 20; | |||||||||
| 46 | 0 | for ($self->neighborList) { | |||||||||
| 47 | 0 | $len += 4; | |||||||||
| 48 | } | ||||||||||
| 49 | 0 | $len; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | sub pack { | ||||||||
|
Subroutine
pack: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||
| 53 | 1 | my $self = shift; | |||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | my $raw = $self->SUPER::pack('a4nCCNa4a4', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | inetAton($self->networkMask), $self->helloInterval, $self->options, | ||||||||||
| 57 | $self->routerPri, $self->routerDeadInterval, | ||||||||||
| 58 | inetAton($self->designatedRouter), | ||||||||||
| 59 | inetAton($self->backupDesignatedRouter), | ||||||||||
| 60 | ) or return undef; | ||||||||||
| 61 | |||||||||||
| 62 | 1 | for ($self->neighborList) { | |||||||||
| 63 | 0 | ▶ | $raw .= $self->SUPER::pack('a4', inetAton($_)) or return undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 1 | $self->raw($raw); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | sub unpack { | ||||||||
|
Subroutine
unpack: called CC=5 SCAR=18.6
Pod
documented
| |||||||||||
| 70 | 1 | my $self = shift; | |||||||||
| 71 | |||||||||||
| 72 | 1 | ▶ | my ($netmask, $helloInt, $options, $pri, $deadInt, $desRouter, $backup, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | $payload) = $self->SUPER::unpack('a4nCCNa4a4 a*', $self->raw) | ||||||||||
| 74 | or return undef; | ||||||||||
| 75 | |||||||||||
| 76 | 1 | $self->networkMask(inetNtoa($netmask)); | |||||||||
| 77 | 1 | $self->helloInterval($helloInt); | |||||||||
| 78 | 1 | $self->options($options); | |||||||||
| 79 | 1 | $self->routerPri($pri); | |||||||||
| 80 | 1 | $self->routerDeadInterval($deadInt); | |||||||||
| 81 | 1 | $self->designatedRouter(inetNtoa($desRouter)); | |||||||||
| 82 | 1 | $self->backupDesignatedRouter(inetNtoa($backup)); | |||||||||
| 83 | |||||||||||
| 84 | 1 | my @neighborList = (); | |||||||||
| 85 | 1 | ▶ | if ($payload) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | ▶ | while ($payload) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | ▶ | my ($neighbor, $tail) = $self->SUPER::unpack('a4 a*', $payload) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | or return undef; | ||||||||||
| 89 | 0 | push @neighborList, inetNtoa($neighbor); | |||||||||
| 90 | 0 | $payload = $tail; | |||||||||
| 91 | } | ||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 1 | $self->neighborList(\@neighborList); | |||||||||
| 95 | |||||||||||
| 96 | 1 | $self->payload($payload); | |||||||||
| 97 | |||||||||||
| 98 | 1 | $self; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | sub print { | ||||||||
|
Subroutine
print: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 102 | 0 | my $self = shift; | |||||||||
| 103 | |||||||||||
| 104 | 0 | my $l = $self->layer; | |||||||||
| 105 | 0 | my $buf = sprintf | |||||||||
| 106 | "$l: networkMask:%s helloInterval:%d\n". | ||||||||||
| 107 | "$l: options:0x%02x routerPri:0x%02x routerDeadInterval:%d\n". | ||||||||||
| 108 | "$l: designatedRouter:%s backupDesignatedRouter:%s", | ||||||||||
| 109 | $self->networkMask, | ||||||||||
| 110 | $self->helloInterval, | ||||||||||
| 111 | $self->options, | ||||||||||
| 112 | $self->routerPri, | ||||||||||
| 113 | $self->routerDeadInterval, | ||||||||||
| 114 | $self->designatedRouter, | ||||||||||
| 115 | $self->backupDesignatedRouter, | ||||||||||
| 116 | ; | ||||||||||
| 117 | |||||||||||
| 118 | 0 | for ($self->neighborList) { | |||||||||
| 119 | 0 | $buf .= "\n$l: neighbor: $_"; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 0 | ▶ | if ($self->lls) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | $buf .= "\n".$self->lls->print; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 0 | $buf; | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | 15 | 1; | |||||||||
| 130 | |||||||||||
| 131 | __END__ | ||||||||||