OSPF/Lsa.pm

filter: Statementstmt 43.1% 41 / 95 Branchbran 14.7% 5 / 34 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 63.6% 7 / 11 Podpod 100% 7 / 7 totaltotal 37.8% 61 / 161 SCAR 49.9
CC
21
Cov
34%
unpack
51.2
computeChecksums
42.0
getLength
6.0
CRAP 147.5
« OSPF.pm ↑ Summary OSPF/DatabaseDesc.pm »
1 #
2 # $Id: Lsa.pm,v 1.9 2007/03/13 18:19:52 gomor Exp $
3 #
4 package Net::Frame::Layer::OSPF::Lsa;
5 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 our @ISA = qw(Net::Frame::Layer);
10  
11 15 our @AS = qw(
12 lsAge
13 options
14 lsType
15 linkStateId
16 advertisingRouter
17 lsSequenceNumber
18 lsChecksum
19 length
20 lsa
21 full
22 );
23 15 __PACKAGE__->cgBuildIndices;
24 15 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
25  
26 15 ▶use Net::Frame::Layer::OSPF qw(:consts);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 15 require Net::Frame::Layer::OSPF::Lsa::Opaque;
28 15 require Net::Frame::Layer::OSPF::Lsa::Router;
29 15 require Net::Frame::Layer::OSPF::Lsa::Network;
30 15 require Net::Frame::Layer::OSPF::Lsa::SummaryIp;
31  
32 sub new {
33 shift->SUPER::new(
34 1 ▶ lsAge => 30,
Subroutine new: called CC=1 SCAR=0.0
Pod documented
35 options => 0,
36 lsType => NF_OSPF_LSTYPE_ROUTER,
37 linkStateId => '0.0.0.0',
38 advertisingRouter => '0.0.0.0',
39 lsSequenceNumber => 0,
40 lsChecksum => 0,
41 length => NF_OSPF_LSA_HDR_LEN,
42 full => 1,
43 @_,
44 );
45 }
46  
47 # Lsa begins with standard 20 bytes header
48 sub getLength {
49 0 ▶ my $self = shift;
Subroutine getLength: not called CC=2 SCAR=17.9
Pod documented
50 0 my $len = NF_OSPF_LSA_HDR_LEN;
51 0 ▶ $len += $self->lsa->getLength if $self->lsa;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lsa 0 0 0
52 0 $len;
53 }
54  
55 sub computeLengths {
56 0 ▶ my $self = shift;
Subroutine computeLengths: not called CC=1 SCAR=6.9
Pod documented
57 0 my $len = $self->getLength;
58 0 $self->length($len);
59 }
60  
61 sub computeChecksums {
62 0 ▶ my $self = shift;
Subroutine computeChecksums: not called CC=6 SCAR=37.4
Pod documented
63  
64 0 $self->lsChecksum(0);
65 0 my $raw = $self->pack;
66 0 my $data = substr($raw, 2);
67 # We pad the data to the possibly fake length
68 0 my @chars = unpack('C*', $data.("0"x($self->length - length($data))));
69  
70 0 my $c0 = 0;
71 0 my $c1 = 0;
72 0 my $length = $self->length - 2;
73 0 my $MODX = 4102;
74 0 my ($sp, $ep, $p, $q);
75 0 $sp = 0;
76 0 ▶ for ($ep = $length; $sp < $ep; $sp = $q) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sp < $ep) 0 0 0
77 0 $q = $sp + $MODX;
78 0 ▶ if ($q > $ep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($q > $ep) 0 0 0
79 0 $q = $ep;
80 }
81 0 ▶ for ($p = $sp; $p < $q; $p++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $q) 0 0 0
82 0 $c0 += $chars[$p];
83 0 $c1 += $c0;
84 }
85 0 $c0 %= 255;
86 0 $c1 %= 255;
87 }
88 0 my $x = (($length - 15) * $c0 - $c1) % 255;
89 0 ▶ if ($x <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= 0) 0 0 0
90 0 $x += 255;
91 }
92 0 my $y = 510 - $c0 - $x;
93 0 ▶ if ($y > 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y > 255) 0 0 0
94 0 $y -= 255;
95 }
96  
97 0 $self->lsChecksum(($x << 8) + $y);
98 }
99  
100 sub pack {
101 1 ▶ my $self = shift;
Subroutine pack: called CC=3 SCAR=11.4
Pod documented
102  
103 1 ▶ my $raw = $self->SUPER::pack('nCCa4a4Nnn a*',
Branch: 1 branch
BranchTrueFalseTotal
my $raw = $self->SUPER::pack("nCCa4a4Nnn a*", $self->lsAge, $self->options, $self->lsType, inetAton($self->linkStateId), inetAton($self->advertisingRouter), $self->lsSequenceNumber, $self->lsChecksum, $self->length) or return undef 0 1 1
104 $self->lsAge, $self->options, $self->lsType, inetAton($self->linkStateId),
105 inetAton($self->advertisingRouter), $self->lsSequenceNumber,
106 $self->lsChecksum, $self->length,
107 ) or return undef;
108  
109 1 ▶ $raw .= $self->lsa->pack if $self->lsa;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lsa 0 1 1
110  
111 1 $self->raw($raw);
112 }
113  
114 sub unpack {
115 1 ▶ my $self = shift;
Subroutine unpack: called CC=12 SCAR=39.4
Pod documented
116  
117 1 ▶ my ($lsAge, $options, $lsType, $linkStateId, $advertisingRouter,
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("nCCa4a4Nnn a*", $self->raw) or return undef 0 1 1
118 $lsSequenceNumber, $lsChecksum, $length, $payload)
119 = $self->SUPER::unpack('nCCa4a4Nnn a*', $self->raw)
120 or return undef;
121  
122 1 $self->lsAge($lsAge);
123 1 $self->options($options);
124 1 $self->lsType($lsType);
125 1 $self->linkStateId(inetNtoa($linkStateId));
126 1 $self->advertisingRouter(inetNtoa($advertisingRouter));
127 1 $self->lsSequenceNumber($lsSequenceNumber);
128 1 $self->lsChecksum($lsChecksum);
129 1 $self->length($length);
130  
131 1 my $next;
132 1 ▶ if ($self->full && $payload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->full and $payload) 0 1 1
Condition33%1/3
$self->full and $payload
!ll&&!rl&&r
010
MC/DC0%0/2
$self->full and $payload
$self->full $payload
Truth table33%1/3
A and B
A= $self->fullB= $payload
ABresult
0X0
100
111
133 0 ▶ if ($lsType == NF_OSPF_LSTYPE_OPAQUELINKLOCAL
Branch: 4 branches
BranchTrueFalseTotal
if ($lsType == 10 or $lsType == 11 or $lsType == 12) { } 0 0 0
elsif ($lsType == 1) { } 0 0 0
elsif ($lsType == 2) { } 0 0 0
elsif ($lsType == 3) { } 0 0 0
Condition0%0/6
$lsType == 10 or $lsType == 11 or $lsType == 12
l!l&&r!l&&!r
000
$lsType == 10 or $lsType == 11
l!l&&r!l&&!r
000
MC/DC0%0/3
$lsType == 10 or $lsType == 11 or $lsType == 12
$lsType == 10 $lsType == 11 $lsType == 12
Truth table0%0/4
A or B or C
A= $lsType == 10B= $lsType == 11C= $lsType == 12
ABCresult
1XX1
01X1
0011
0000
134 || $lsType == NF_OSPF_LSTYPE_OPAQUEAREALOCAL
135 || $lsType == NF_OSPF_LSTYPE_OPAQUEDOMAIN) {
136 0 my $pLen = length($payload);
137 0 ▶ if ($length > $pLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $pLen) 0 0 0
138 0 my $oLen = $length - NF_OSPF_LSA_HDR_LEN;
139 0 my $opaque = substr($payload, 0, $oLen);
140 0 $next = Net::Frame::Layer::OSPF::Lsa::Opaque->new(raw => $opaque);
141 0 $payload = substr($payload, $oLen);
142 0 $next->payload($payload);
143 }
144 }
145 elsif ($lsType == NF_OSPF_LSTYPE_ROUTER) {
146 0 $next = Net::Frame::Layer::OSPF::Lsa::Router->new(raw => $payload);
147 }
148 elsif ($lsType == NF_OSPF_LSTYPE_NETWORK) {
149 0 $next = Net::Frame::Layer::OSPF::Lsa::Network->new(raw => $payload);
150 }
151 elsif ($lsType == NF_OSPF_LSTYPE_SUMMARYIP) {
152 0 $next = Net::Frame::Layer::OSPF::Lsa::SummaryIp->new(raw => $payload);
153 }
154 }
155  
156 1 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) 0 1 1
157 0 $next->unpack;
158 0 $self->lsa($next);
159 0 $payload = $next->payload;
160 }
161  
162 1 $self->payload($payload);
163  
164 1 $self;
165 }
166  
167 sub print {
168 0 ▶ my $self = shift;
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
169  
170 0 my $l = $self->layer;
171 0 my $buf = sprintf
172 "$l: lsAge:%d options:0x%02x lsType:0x%02x linkStateId:%s\n".
173 "$l: advertisingRouter:%s lsSequenceNumber:0x%08x\n".
174 "$l: lsChecksum:0x%04x length:%d",
175 $self->lsAge,
176 $self->options,
177 $self->lsType,
178 $self->linkStateId,
179 $self->advertisingRouter,
180 $self->lsSequenceNumber,
181 $self->lsChecksum,
182 $self->length,
183 ;
184  
185 0 ▶ if ($self->lsa) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lsa) 0 0 0
186 0 $buf .= "\n".$self->lsa->print;
187 }
188  
189 0 $buf;
190 }
191  
192 15 1;
193  
194 __END__
« OSPF.pm ↑ Summary OSPF/DatabaseDesc.pm »