| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # $Id: Network.pm,v 1.2 2007/03/13 18:20:07 gomor Exp $ | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | package Net::Frame::Layer::OSPF::Lsa::Network; | 
| 5 | 14 |  |  | 14 |  | 6472 | use strict; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 625 |  | 
| 6 | 14 |  |  | 14 |  | 78 | use warnings; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 495 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 14 |  |  | 14 |  | 1248 | use Net::Frame::Layer qw(:consts :subs); | 
|  | 14 |  |  |  |  | 115245 |  | 
|  | 14 |  |  |  |  | 5434 |  | 
| 9 |  |  |  |  |  |  | our @ISA = qw(Net::Frame::Layer); | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our @AS = qw( | 
| 12 |  |  |  |  |  |  | netmask | 
| 13 |  |  |  |  |  |  | ); | 
| 14 |  |  |  |  |  |  | our @AA = qw( | 
| 15 |  |  |  |  |  |  | routerList | 
| 16 |  |  |  |  |  |  | ); | 
| 17 |  |  |  |  |  |  | __PACKAGE__->cgBuildIndices; | 
| 18 |  |  |  |  |  |  | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | 
| 19 |  |  |  |  |  |  | __PACKAGE__->cgBuildAccessorsArray (\@AA); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 14 |  |  | 14 |  | 994 | use Net::Frame::Layer::OSPF qw(:consts); | 
|  | 14 |  |  |  |  | 33 |  | 
|  | 14 |  |  |  |  | 11110 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub new { | 
| 24 |  |  |  |  |  |  | shift->SUPER::new( | 
| 25 | 1 |  |  | 1 | 1 | 27 | netmask    => '255.255.255.0', | 
| 26 |  |  |  |  |  |  | routerList => [], | 
| 27 |  |  |  |  |  |  | @_, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub getLength { | 
| 32 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 33 | 0 |  |  |  |  | 0 | my $len = 4; | 
| 34 | 0 |  |  |  |  | 0 | $len += 4 for $self->routerList; | 
| 35 | 0 |  |  |  |  | 0 | $len; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub pack { | 
| 39 | 1 |  |  | 1 | 1 | 231 | my $self = shift; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 1 | 50 |  |  |  | 5 | my $raw = $self->SUPER::pack('a4', inetAton($self->netmask)) | 
| 42 |  |  |  |  |  |  | or return undef; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 1 |  |  |  |  | 71 | for ($self->routerList) { | 
| 45 | 0 | 0 |  |  |  | 0 | $raw .= $self->SUPER::pack('a4', inetAton($_)) | 
| 46 |  |  |  |  |  |  | or return undef; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 1 |  |  |  |  | 29 | $self->raw($raw); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub unpack { | 
| 53 | 1 |  |  | 1 | 1 | 17 | my $self = shift; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 1 | 50 |  |  |  | 5 | my ($netmask, $payload) = $self->SUPER::unpack('a4 a*', $self->raw) | 
| 56 |  |  |  |  |  |  | or return undef; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 1 |  |  |  |  | 36 | $self->netmask(inetNtoa($netmask)); | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 1 |  |  |  |  | 20 | my @routerList; | 
| 61 | 1 |  | 33 |  |  | 8 | while ($payload && length($payload) > 3) { | 
| 62 | 0 |  |  |  |  | 0 | my $ip; | 
| 63 | 0 | 0 |  |  |  | 0 | ($ip, $payload) = $self->SUPER::unpack('a4 a*', $payload) | 
| 64 |  |  |  |  |  |  | or return undef; | 
| 65 | 0 |  |  |  |  | 0 | push @routerList, inetNtoa($ip); | 
| 66 |  |  |  |  |  |  | } | 
| 67 | 1 |  |  |  |  | 5 | $self->routerList(\@routerList); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 1 |  |  |  |  | 16 | $self->payload($payload); | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 1 |  |  |  |  | 9 | $self; | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub print { | 
| 75 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 0 |  |  |  |  |  | my $l = $self->layer; | 
| 78 | 0 |  |  |  |  |  | my $buf = sprintf | 
| 79 |  |  |  |  |  |  | "$l: netmask:%s", | 
| 80 |  |  |  |  |  |  | $self->netmask, | 
| 81 |  |  |  |  |  |  | ; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 0 |  |  |  |  |  | for ($self->routerList) { | 
| 84 | 0 |  |  |  |  |  | $buf .= sprintf "\n$l: router: %s", $_; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 0 |  |  |  |  |  | $buf; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | 1; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | __END__ |