SinFP3.pm

filter: Statementstmt 85.4% 194 / 227 Branchbran 20.0% 4 / 20 Conditioncond 11.1% 2 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 95.0% 57 / 60 Podpod 100% 6 / 6 totaltotal 76.6% 263 / 343 CC 22 SCAR 32.2
CC
22
Cov
75%
computeLengths
156.0
unpack
7.5
getLength
6.0
CRAP 24.9
« SinFP3/Tlv.pm ↑ Summary
1 #
2 # $Id: SinFP3.pm 9 2012-11-22 19:13:54Z gomor $
3 #
4 package Net::Frame::Layer::SinFP3;
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '1.01';
9  
10 3 ▶use base qw(Net::Frame::Layer Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our %EXPORT_TAGS = (
13 consts => [qw(
14 NF_SINFP3_VERSION1
15 NF_SINFP3_FLAG_FULL
16 NF_SINFP3_FLAG_TRUSTED
17 NF_SINFP3_FLAG_IPVERSION
18 NF_SINFP3_FLAG_SYSTEMCLASS
19 NF_SINFP3_FLAG_VENDOR
20 NF_SINFP3_FLAG_OS
21 NF_SINFP3_FLAG_OSVERSION
22 NF_SINFP3_FLAG_OSVERSIONFAMILY
23 NF_SINFP3_FLAG_MATCHTYPE
24 NF_SINFP3_FLAG_MATCHMASK
25 NF_SINFP3_FLAG_MATCHSCORE
26 NF_SINFP3_FLAG_P1SIG
27 NF_SINFP3_FLAG_P2SIG
28 NF_SINFP3_FLAG_P3SIG
29 NF_SINFP3_TYPE_REQUESTACTIVE
30 NF_SINFP3_TYPE_REQUESTPASSIVE
31 NF_SINFP3_TYPE_RESPONSEACTIVE
32 NF_SINFP3_TYPE_RESPONSEPASSIVE
33 NF_SINFP3_TLV_TYPE_FRAMEPROTOCOL
34 NF_SINFP3_TLV_TYPE_FRAMEPASSIVE
35 NF_SINFP3_TLV_TYPE_FRAMEACTIVEP1
36 NF_SINFP3_TLV_TYPE_FRAMEACTIVEP2
37 NF_SINFP3_TLV_TYPE_FRAMEACTIVEP3
38 NF_SINFP3_TLV_TYPE_FRAMEACTIVEP1R
39 NF_SINFP3_TLV_TYPE_FRAMEACTIVEP2R
40 NF_SINFP3_TLV_TYPE_FRAMEACTIVEP3R
41 NF_SINFP3_TLV_TYPE_TRUSTED
42 NF_SINFP3_TLV_TYPE_IPVERSION
43 NF_SINFP3_TLV_TYPE_SYSTEMCLASS
44 NF_SINFP3_TLV_TYPE_VENDOR
45 NF_SINFP3_TLV_TYPE_OS
46 NF_SINFP3_TLV_TYPE_OSVERSION
47 NF_SINFP3_TLV_TYPE_OSVERSIONFAMILY
48 NF_SINFP3_TLV_TYPE_MATCHTYPE
49 NF_SINFP3_TLV_TYPE_MATCHMASK
50 NF_SINFP3_TLV_TYPE_MATCHSCORE
51 NF_SINFP3_TLV_TYPE_P1SIG
52 NF_SINFP3_TLV_TYPE_P2SIG
53 NF_SINFP3_TLV_TYPE_P3SIG
54 NF_SINFP3_TLV_VALUE_ETH
55 NF_SINFP3_TLV_VALUE_IPv4
56 NF_SINFP3_TLV_VALUE_IPv6
57 NF_SINFP3_TLV_VALUE_TCP
58 NF_SINFP3_CODE_SUCCESSUNKNOWN
59 NF_SINFP3_CODE_SUCCESSRESULT
60 NF_SINFP3_CODE_BADVERSION
61 NF_SINFP3_CODE_BADTYPE
62 NF_SINFP3_CODE_BADTLVCOUNT
63 NF_SINFP3_CODE_BADTLV
64 )],
65 );
66 our @EXPORT_OK = (
67 3 @{$EXPORT_TAGS{consts}},
68 );
69  
70 3 ▶use constant NF_SINFP3_VERSION1 => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 3 ▶use constant NF_SINFP3_FLAG_FULL => 0x0000;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 3 ▶use constant NF_SINFP3_FLAG_TRUSTED => 0x0001;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 3 ▶use constant NF_SINFP3_FLAG_IPVERSION => 0x0002;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 3 ▶use constant NF_SINFP3_FLAG_SYSTEMCLASS => 0x0004;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 3 ▶use constant NF_SINFP3_FLAG_VENDOR => 0x0008;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 3 ▶use constant NF_SINFP3_FLAG_OS => 0x0010;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 3 ▶use constant NF_SINFP3_FLAG_OSVERSION => 0x0020;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 3 ▶use constant NF_SINFP3_FLAG_OSVERSIONFAMILY => 0x0040;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 3 ▶use constant NF_SINFP3_FLAG_MATCHTYPE => 0x0080;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 3 ▶use constant NF_SINFP3_FLAG_MATCHMASK => 0x0100;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 3 ▶use constant NF_SINFP3_FLAG_MATCHSCORE => 0x0200;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 3 ▶use constant NF_SINFP3_FLAG_P1SIG => 0x0400;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 3 ▶use constant NF_SINFP3_FLAG_P2SIG => 0x0800;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 3 ▶use constant NF_SINFP3_FLAG_P3SIG => 0x1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 3 ▶use constant NF_SINFP3_TYPE_REQUESTACTIVE => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 3 ▶use constant NF_SINFP3_TYPE_REQUESTPASSIVE => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 3 ▶use constant NF_SINFP3_TYPE_RESPONSEACTIVE => 0x03;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 3 ▶use constant NF_SINFP3_TYPE_RESPONSEPASSIVE => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEPROTOCOL => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEPASSIVE => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEACTIVEP1 => 0x03;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEACTIVEP2 => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEACTIVEP3 => 0x05;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEACTIVEP1R => 0x06;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEACTIVEP2R => 0x07;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 3 ▶use constant NF_SINFP3_TLV_TYPE_FRAMEACTIVEP3R => 0x08;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 3 ▶use constant NF_SINFP3_TLV_TYPE_P1SIG => 0x09;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 3 ▶use constant NF_SINFP3_TLV_TYPE_P2SIG => 0x0a;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 3 ▶use constant NF_SINFP3_TLV_TYPE_P3SIG => 0x0b;
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 3 ▶use constant NF_SINFP3_TLV_VALUE_ETH => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 3 ▶use constant NF_SINFP3_TLV_VALUE_IPv4 => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 3 ▶use constant NF_SINFP3_TLV_VALUE_IPv6 => 0x03;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 3 ▶use constant NF_SINFP3_TLV_VALUE_TCP => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 3 ▶use constant NF_SINFP3_TLV_TYPE_TRUSTED => 0x20;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 3 ▶use constant NF_SINFP3_TLV_TYPE_IPVERSION => 0x21;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 3 ▶use constant NF_SINFP3_TLV_TYPE_SYSTEMCLASS => 0x22;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 3 ▶use constant NF_SINFP3_TLV_TYPE_VENDOR => 0x23;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 3 ▶use constant NF_SINFP3_TLV_TYPE_OS => 0x24;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 3 ▶use constant NF_SINFP3_TLV_TYPE_OSVERSION => 0x25;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 3 ▶use constant NF_SINFP3_TLV_TYPE_OSVERSIONFAMILY => 0x26;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 3 ▶use constant NF_SINFP3_TLV_TYPE_MATCHTYPE => 0x27;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 3 ▶use constant NF_SINFP3_TLV_TYPE_MATCHMASK => 0x28;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 3 ▶use constant NF_SINFP3_TLV_TYPE_MATCHSCORE => 0x29;
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 3 ▶use constant NF_SINFP3_CODE_SUCCESSUNKNOWN => 0x00;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 3 ▶use constant NF_SINFP3_CODE_SUCCESSRESULT => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 3 ▶use constant NF_SINFP3_CODE_BADVERSION => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 3 ▶use constant NF_SINFP3_CODE_BADTYPE => 0x03;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 3 ▶use constant NF_SINFP3_CODE_BADTLVCOUNT => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 3 ▶use constant NF_SINFP3_CODE_BADTLV => 0x05;
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 3 our @AS = qw(
128 version
129 type
130 flags
131 code
132 tlvCount
133 length
134 );
135 3 our @AA = qw(
136 tlvList
137 );
138 3 __PACKAGE__->cgBuildIndices;
139 3 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
140 3 __PACKAGE__->cgBuildAccessorsArray (\@AA);
141  
142 3 ▶use Net::Frame::Layer::SinFP3::Tlv;
Subroutine BEGIN: called CC=1 SCAR=0.0
143  
144 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
145 1 my $self = shift->SUPER::new(
146 version => NF_SINFP3_VERSION1,
147 type => NF_SINFP3_TYPE_RESPONSEPASSIVE,
148 flags => NF_SINFP3_FLAG_FULL,
149 code => NF_SINFP3_CODE_SUCCESSRESULT,
150 tlvCount => 0,
151 length => 0,
152 tlvList => [],
153 @_,
154 );
155  
156 1 return $self;
157 }
158  
159 0 ▶sub getLength {
Subroutine getLength: not called CC=2 SCAR=17.9
Pod documented
160 0 my $self = shift;
161  
162 0 my $len = 8; # 8-byte header
163  
164 0 for my $tlv ($self->tlvList) {
165 0 $len += $tlv->getLength;
166 }
167  
168 0 return $len;
169 }
170  
171 1 ▶sub pack {
Subroutine pack: called CC=4 SCAR=16.9
Pod documented
172 1 my $self = shift;
173  
174 1 ▶ my $raw = $self->SUPER::pack('CCnCCn',
Branch: 1 branch
BranchTrueFalseTotal
my $raw = $self->SUPER::pack("CCnCCn", $self->version, $self->type, $self->flags, $self->code, $self->tlvCount, $self->length) or return 1 0 1
175 $self->version,
176 $self->type,
177 $self->flags,
178 $self->code,
179 $self->tlvCount,
180 $self->length,
181 ) or return;
182  
183 1 for my $tlv ($self->tlvList) {
184 0 ▶ $raw .= $tlv->pack or return;
Branch: 1 branch
BranchTrueFalseTotal
$raw .= $tlv->pack or return 0 0 0
185 }
186  
187 1 return $self->raw($raw);
188 }
189  
190 1 ▶sub unpack {
Subroutine unpack: called CC=6 SCAR=20.1
Pod documented
191 1 my $self = shift;
192  
193 1 ▶ my ($version, $type, $flags, $code, $tlvCount, $length, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCnCCn a*", $self->raw) or return 1 0 1
194 $self->SUPER::unpack('CCnCCn a*', $self->raw)
195 or return;
196  
197 1 $self->version($version);
198 1 $self->type($type);
199 1 $self->flags($flags);
200 1 $self->code($code);
201 1 $self->tlvCount($tlvCount);
202 1 $self->length($length);
203  
204 1 ▶ if (defined($payload) && length($payload) >= $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $payload and CORE::length $payload >= $length) 1 0 1
Condition33%1/3
defined $payload and CORE::length $payload >= $length
!ll&&!rl&&r
001
MC/DC0%0/2
defined $payload and CORE::length $payload >= $length
defined $payload CORE::length $payload >= $length
Truth table33%1/3
A and B
A= defined $payloadB= CORE::length $payload >= $length
ABresult
0X0
100
111
205 1 my $tlv = substr($payload, 0, $length);
206 1 $payload = substr($payload, $length);
207 1 my @tlvList = ();
208 1 ▶ while (defined($tlv) && length($tlv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tlv and CORE::length $tlv) 0 1 1
Condition33%1/3
defined $tlv and CORE::length $tlv
!ll&&!rl&&r
010
MC/DC0%0/2
defined $tlv and CORE::length $tlv
defined $tlv CORE::length $tlv
Truth table33%1/3
A and B
A= defined $tlvB= CORE::length $tlv
ABresult
0X0
100
111
209 0 my $new = Net::Frame::Layer::SinFP3::Tlv->new(
210 raw => $tlv,
211 )->unpack;
212 0 $tlv = $new->payload;
213 0 $new->payload(undef);
214 0 push @tlvList, $new;
215 }
216 1 $self->tlvList(\@tlvList);
217 }
218  
219 1 $self->payload($payload);
220  
221 1 return $self;
222 }
223  
224 0 ▶sub computeLengths {
Subroutine computeLengths: not called CC=12 SCAR=50.5
Pod documented
225 0 my $self = shift;
226  
227 0 my $tlvCount = 0;
228 # Request types, tlvCount is the total number of TLVs
229 0 ▶ if ($self->type == NF_SINFP3_TYPE_REQUESTACTIVE
Branch: 2 branches
BranchTrueFalseTotal
if ($self->type == 1 or $self->type == 2) { } 0 0 0
elsif ($self->type == 3 or $self->type == 4) { } 0 0 0
Condition0%0/3
$self->type == 1 or $self->type == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->type == 1 or $self->type == 2
$self->type == 1 $self->type == 2
Truth table0%0/3
A or B
A= $self->type == 1B= $self->type == 2
ABresult
1X1
011
000
230 || $self->type == NF_SINFP3_TYPE_REQUESTPASSIVE) {
231 0 $tlvCount = scalar($self->tlvList);
232 }
233 # Response types, tlvCount is the number of TLV per result
234 ▶ elsif ($self->type == NF_SINFP3_TYPE_RESPONSEACTIVE
Condition0%0/3
$self->type == 3 or $self->type == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->type == 3 or $self->type == 4
$self->type == 3 $self->type == 4
Truth table0%0/3
A or B
A= $self->type == 3B= $self->type == 4
ABresult
1X1
011
000
235 || $self->type == NF_SINFP3_TYPE_RESPONSEPASSIVE) {
236 0 ▶ if ($self->type == NF_SINFP3_TYPE_RESPONSEACTIVE && $self->flags == NF_SINFP3_FLAG_FULL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->type == 3 and $self->flags == 0) { } 0 0 0
elsif ($self->type == 4 and $self->flags == 0) { } 0 0 0
Condition0%0/3
$self->type == 3 and $self->flags == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->type == 3 and $self->flags == 0
$self->type == 3 $self->flags == 0
Truth table0%0/3
A and B
A= $self->type == 3B= $self->flags == 0
ABresult
0X0
100
111
237 0 $tlvCount = 13;
238 }
239 ▶ elsif ($self->type == NF_SINFP3_TYPE_RESPONSEPASSIVE && $self->flags == NF_SINFP3_FLAG_FULL) {
Condition0%0/3
$self->type == 4 and $self->flags == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->type == 4 and $self->flags == 0
$self->type == 4 $self->flags == 0
Truth table0%0/3
A and B
A= $self->type == 4B= $self->flags == 0
ABresult
0X0
100
111
240 0 $tlvCount = 11;
241 }
242 else {
243 0 for my $flag (
244 NF_SINFP3_FLAG_TRUSTED,
245 NF_SINFP3_FLAG_IPVERSION,
246 NF_SINFP3_FLAG_SYSTEMCLASS,
247 NF_SINFP3_FLAG_VENDOR,
248 NF_SINFP3_FLAG_OS,
249 NF_SINFP3_FLAG_OSVERSION,
250 NF_SINFP3_FLAG_OSVERSIONFAMILY,
251 NF_SINFP3_FLAG_MATCHTYPE,
252 NF_SINFP3_FLAG_MATCHMASK,
253 NF_SINFP3_FLAG_MATCHSCORE,
254 NF_SINFP3_FLAG_P1SIG,
255 NF_SINFP3_FLAG_P2SIG,
256 NF_SINFP3_FLAG_P3SIG,
257 ) {
258 0 ▶ if ($self->flags & $flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flags & $flag) 0 0 0
259 0 $tlvCount++;
260 }
261 }
262 }
263 }
264 0 $self->tlvCount($tlvCount);
265  
266 0 my $len = 0;
267 0 for my $tlv ($self->tlvList) {
268 0 $tlv->computeLengths;
269 0 $len += $tlv->getLength;
270 }
271 0 $self->length($len);
272  
273 0 return 1;
274 }
275  
276 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
277 0 my $self = shift;
278  
279 0 my $l = $self->layer;
280 0 my $buf = sprintf("$l: version:%d type:0x%02x flags:0x%04x\n".
281 "$l: code:0x%02x tlvCount:%d length:%d",
282 $self->version,
283 $self->type,
284 $self->flags,
285 $self->code,
286 $self->tlvCount,
287 $self->length,
288 );
289  
290 0 for my $tlv ($self->tlvList) {
291 0 $buf .= "\n".$tlv->print;
292 }
293  
294 0 return $buf;
295 }
296  
297 3 1;
298  
299 __END__
« SinFP3/Tlv.pm ↑ Summary