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