blib/lib/Net/Frame/Layer/VRRP.pm

filter: Statementstmt 75.5% 99 / 131 Branchbran 19.2% 5 / 26 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 86.9% 20 / 23 Podpod 100% 8 / 8 totaltotal 65.5% 133 / 203 CC 23 SCAR 35.5
CC
23
Cov
63%
computeChecksums
132.0
computeLengths
12.0
getLength
6.0
CRAP 34.8
↑ Summary
1 #
2 # $Id: VRRP.pm 49 2009-05-31 13:15:34Z VinsWorldcom $
3 #
4 package Net::Frame::Layer::VRRP;
5 3 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '1.00';
8  
9 3 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 our @ISA = qw(Net::Frame::Layer Exporter);
12  
13 3 our %EXPORT_TAGS = (
14 consts => [qw(
15 NF_VRRP_ALLVRRPRTRS
16 NF_VRRP_ALLVRRPRTRS_MAC
17 NF_VRRP_VERSION
18 NF_VRRP_TYPE_ADVERT
19 NF_VRRP_PRIORITY_OWNER
20 NF_VRRP_PRIORITY_DEFAULT
21 NF_VRRP_PRIORITY_NOMASTER
22 NF_VRRP_AUTH_NO
23 NF_VRRP_AUTH_TEXT
24 NF_VRRP_AUTH_AH
25 )],
26 );
27 our @EXPORT_OK = (
28 3 @{$EXPORT_TAGS{consts}},
29 );
30  
31 3 ▶use constant NF_VRRP_ALLVRRPRTRS => '224.0.0.18';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶use constant NF_VRRP_ALLVRRPRTRS_MAC => '01:00:5e:00:00:12';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use constant NF_VRRP_VERSION => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use constant NF_VRRP_TYPE_ADVERT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use constant NF_VRRP_PRIORITY_OWNER => 255;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use constant NF_VRRP_PRIORITY_DEFAULT => 100;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use constant NF_VRRP_PRIORITY_NOMASTER => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶use constant NF_VRRP_AUTH_NO => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use constant NF_VRRP_AUTH_TEXT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use constant NF_VRRP_AUTH_AH => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 3 our @AS = qw(
43 version
44 type
45 vrId
46 priority
47 countIp
48 authType
49 interval
50 checksum
51 authentication
52 );
53 3 our @AA = qw(
54 ipAddresses
55 );
56 3 __PACKAGE__->cgBuildIndices;
57 3 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
58 3 __PACKAGE__->cgBuildAccessorsArray(\@AA);
59  
60 #no strict 'vars';
61  
62 3 ▶use Bit::Vector;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
65 shift->SUPER::new(
66 1 version => NF_VRRP_VERSION,
67 type => NF_VRRP_TYPE_ADVERT,
68 vrId => 1,
69 priority => NF_VRRP_PRIORITY_DEFAULT,
70 countIp => 1,
71 authType => NF_VRRP_AUTH_NO,
72 interval => 1,
73 checksum => 0,
74 ipAddresses => ['127.0.0.1'],
75 authentication => '',
76 @_,
77 );
78 }
79  
80 0 ▶sub getLength {
Subroutine getLength: not called CC=2 SCAR=17.9
Pod documented
81 0 my $self = shift;
82 0 my $len = 16;
83 0 $len += 4 for $self->ipAddresses;
84 0 return $len;
85 }
86  
87 1 ▶sub pack {
Subroutine pack: called CC=4 SCAR=14.0
Pod documented
88 1 my $self = shift;
89  
90 1 my $version = Bit::Vector->new_Dec(4, $self->version);
91 1 my $type = Bit::Vector->new_Dec(4, $self->type);
92 1 my $bvlist = $version->Concat_List($type);
93  
94 1 ▶ my $raw = $self->SUPER::pack('CCCCCCn',
Branch: 1 branch
BranchTrueFalseTotal
my $raw = $self->SUPER::pack("CCCCCCn", $bvlist->to_Dec, $self->vrId, $self->priority, $self->countIp, $self->authType, $self->interval, $self->checksum) or return 1 0 1
95 $bvlist->to_Dec,
96 $self->vrId,
97 $self->priority,
98 $self->countIp,
99 $self->authType,
100 $self->interval,
101 $self->checksum,
102 ) or return;
103  
104 1 for ($self->ipAddresses) {
105 1 $raw .= inetAton($_);
106 }
107
108 1 ▶ $raw .= $self->SUPER::pack('a8',
Branch: 1 branch
BranchTrueFalseTotal
$raw .= $self->SUPER::pack("a8", $self->authentication) or return 1 0 1
109 $self->authentication,
110 ) or return;
111  
112 1 return $self->raw($raw);
113 }
114  
115 1 ▶sub unpack {
Subroutine unpack: called CC=5 SCAR=16.2
Pod documented
116 1 my $self = shift;
117  
118 1 ▶ my ($bv, $vrId, $priority, $countIp, $authType,
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCCCCCn a*", $self->raw) or return 1 0 1
119 $interval, $checksum, $payload) =
120 $self->SUPER::unpack('CCCCCCn a*', $self->raw)
121 or return;
122  
123 1 my $bvlist = Bit::Vector->new_Dec(8, $bv);
124 1 $self->version ($bvlist->Chunk_Read(4, 4));
125 1 $self->type ($bvlist->Chunk_Read(4, 0));
126  
127 1 $self->vrId($vrId);
128 1 $self->priority($priority);
129 1 $self->countIp($countIp);
130 1 $self->authType($authType);
131 1 $self->interval($interval);
132 1 $self->checksum($checksum);
133  
134 1 my @ipAddresses = ();
135 1 for my $num (0..$countIp-1) {
136 1 ▶ if (defined($payload) && (length($payload) >= 4)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $payload and length $payload >= 4) 1 0 1
Condition33%1/3
defined $payload and length $payload >= 4
!ll&&!rl&&r
001
MC/DC0%0/2
defined $payload and length $payload >= 4
defined $payload length $payload >= 4
Truth table33%1/3
A and B
A= defined $payloadB= length $payload >= 4
ABresult
0X0
100
111
137 1 my $addr = unpack 'a4', $payload;
138 1 push @ipAddresses, inetNtoa($addr);
139 1 $payload = substr $payload, 4;
140 }
141 }
142 1 $self->ipAddresses(\@ipAddresses);
143  
144 1 my $authentication = unpack 'a8', $payload;
145 1 $payload = substr $payload, 8;
146  
147 1 $self->authentication($authentication);
148  
149 1 $self->payload($payload);
150  
151 1 return $self;
152 }
153  
154 0 ▶sub computeChecksums {
Subroutine computeChecksums: not called CC=11 SCAR=48.8
Pod documented
155 0 my $self = shift;
156 0 my ($layers) = @_;
157  
158 0 my $version = Bit::Vector->new_Dec(4, $self->version);
159 0 my $type = Bit::Vector->new_Dec(4, $self->type);
160 0 my $bvlist = $version->Concat_List($type);
161  
162 0 ▶ my $phpkt = $self->SUPER::pack('CCCCCCn',
Branch: 1 branch
BranchTrueFalseTotal
my $phpkt = $self->SUPER::pack("CCCCCCn", $bvlist->to_Dec, $self->vrId, $self->priority, $self->countIp, $self->authType, $self->interval, 0) or return 0 0 0
163 $bvlist->to_Dec,
164 $self->vrId,
165 $self->priority,
166 $self->countIp,
167 $self->authType,
168 $self->interval,
169 0,
170 ) or return;
171  
172 0 for ($self->ipAddresses) {
173 0 $phpkt .= inetAton($_);
174 }
175
176 0 ▶ $phpkt .= $self->SUPER::pack('a8',
Branch: 1 branch
BranchTrueFalseTotal
$phpkt .= $self->SUPER::pack("a8", $self->authentication) or return 0 0 0
177 $self->authentication,
178 ) or return;
179  
180 0 my $start = 0;
181 0 my $last = $self;
182 0 my $payload = '';
183 0 for my $l (@$layers) {
184 0 $last = $l;
185 0 ▶ if (! $start) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($start) 0 0 0
186 0 ▶ $start++ if $l->layer eq 'VRRP';
Branch: 1 branch
BranchTrueFalseTotal
if $l->layer eq "VRRP" 0 0 0
187 0 next;
188 }
189 0 $payload .= $l->pack;
190 }
191  
192 0 ▶ if (defined($last->payload) && length($last->payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last->payload and length $last->payload) 0 0 0
Condition0%0/3
defined $last->payload and length $last->payload
!ll&&!rl&&r
000
MC/DC0%0/2
defined $last->payload and length $last->payload
defined $last->payload length $last->payload
Truth table0%0/3
A and B
A= defined $last->payloadB= length $last->payload
ABresult
0X0
100
111
193 0 $payload .= $last->payload;
194 }
195  
196 0 ▶ if (length($payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $payload) 0 0 0
197 0 ▶ $phpkt .= $self->SUPER::pack('a*', $payload)
Branch: 1 branch
BranchTrueFalseTotal
$phpkt .= $self->SUPER::pack("a*", $payload) or return 0 0 0
198 or return;
199 }
200  
201 0 $self->checksum(inetChecksum($phpkt));
202  
203 0 return 1;
204 }
205  
206 1 ▶sub encapsulate {
Subroutine encapsulate: called CC=2 SCAR=7.1
Pod documented
207 1 my $self = shift;
208  
209 1 ▶ return $self->nextLayer if $self->nextLayer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nextLayer 0 1 1
210  
211 1 NF_LAYER_NONE;
212 }
213  
214 0 ▶sub computeLengths {
Subroutine computeLengths: not called CC=3 SCAR=24.8
Pod documented
215 0 my $self = shift;
216  
217 # Calculate countIp from ipAddresses array items
218 0 ▶ if (scalar($self->ipAddresses) && ($self->countIp == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $self->ipAddresses and $self->countIp == 0) 0 0 0
Condition0%0/3
scalar $self->ipAddresses and $self->countIp == 0
!ll&&!rl&&r
000
MC/DC0%0/2
scalar $self->ipAddresses and $self->countIp == 0
scalar $self->ipAddresses $self->countIp == 0
Truth table0%0/3
A and B
A= scalar $self->ipAddressesB= $self->countIp == 0
ABresult
0X0
100
111
219 0 $self->countIp(scalar($self->ipAddresses))
220 }
221  
222 0 return 1;
223 }
224  
225 1 ▶sub print {
Subroutine print: called CC=2 SCAR=6.9
Pod documented
226 1 my $self = shift;
227  
228 1 my $l = $self->layer;
229 1 my $buf = sprintf
230 "$l: version:%d type:%d vrId:%d priority:%d\n".
231 "$l: countIp:%d authType:%d interval:%d checksum:0x%04x",
232 $self->version, $self->type, $self->vrId, $self->priority,
233 $self->countIp, $self->authType, $self->interval, $self->checksum;
234  
235 1 for ($self->ipAddresses) {
236 1 $buf .= sprintf
237 "\n$l: ipAddresses:%s",
238 $_
239 }
240  
241 1 $buf .= sprintf
242 "\n$l: authentication:%s",
243 $self->authentication;
244  
245 1 return $buf;
246 }
247  
248 3 1;
249  
250 __END__
↑ Summary