Packet/CDP.pm

filter: Statementstmt 15.3% 12 / 78 Branchbran 0.0% 0 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod n/a totaltotal 11.9% 16 / 134 CC 24 SCAR 43.4
CC
24
Cov
10%
pack
156.0
unpack
56.0
print
42.0
CRAP 76.8
↑ Summary Packet/Utils.pm »
1 #
2 # $Id: CDP.pm 2002 2015-02-15 16:50:35Z gomor $
3 #
4 package Net::Packet::CDP;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 require Net::Packet::Layer4;
9 our @ISA = qw(Net::Packet::Layer4);
10  
11 1 ▶use Net::Packet::Consts qw(:cdp :layer);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 require Net::Packet::CDP::TypeDeviceId;
13 require Net::Packet::CDP::TypeAddresses;
14 require Net::Packet::CDP::TypePortId;
15 require Net::Packet::CDP::TypeCapabilities;
16 require Net::Packet::CDP::TypeSoftwareVersion;
17  
18 our @AS = qw(
19 version
20 ttl
21 checksum
22 typeDeviceId
23 typeAddresses
24 typePortId
25 typeCapabilities
26 typeSoftwareVersion
27 );
28 __PACKAGE__->cgBuildIndices;
29 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
30  
31 1 ▶no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
34 shift->SUPER::new(
35 0 version => 2,
36 ttl => 180,
37 checksum => 0,
38 @_,
39 );
40 }
41  
42 0 ▶sub getLength { NP_CDP_HDR_LEN }
Subroutine getLength: not called CC=1 SCAR=6.9
43  
44 0 ▶sub pack {
Subroutine pack: not called CC=12 SCAR=50.5
45 0 my $self = shift;
46  
47 0 ▶ $self->[$__raw] = $self->SUPER::pack('CCn',
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] = $self->SUPER::pack("CCn", $self->[$__version], $self->[$__ttl], $self->[$__checksum]) or return undef 0 0 0
48 $self->[$__version],
49 $self->[$__ttl],
50 $self->[$__checksum],
51 ) or return undef;
52  
53 0 ▶ if ($self->[$__typeDeviceId]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeDeviceId]) 0 0 0
54 0 ▶ $self->[$__raw] .= $self->[$__typeDeviceId]->pack
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] .= $self->[$__typeDeviceId]->pack or return undef 0 0 0
55 or return undef;
56 }
57 0 ▶ if ($self->[$__typeAddresses]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeAddresses]) 0 0 0
58 0 ▶ $self->[$__raw] .= $self->[$__typeAddresses]->pack
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] .= $self->[$__typeAddresses]->pack or return undef 0 0 0
59 or return undef;
60 }
61 0 ▶ if ($self->[$__typePortId]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typePortId]) 0 0 0
62 0 ▶ $self->[$__raw] .= $self->[$__typePortId]->pack
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] .= $self->[$__typePortId]->pack or return undef 0 0 0
63 or return undef;
64 }
65 0 ▶ if ($self->[$__typeCapabilities]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeCapabilities]) 0 0 0
66 0 ▶ $self->[$__raw] .= $self->[$__typeCapabilities]->pack
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] .= $self->[$__typeCapabilities]->pack or return undef 0 0 0
67 or return undef;
68 }
69 0 ▶ if ($self->[$__typeSoftwareVersion]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeSoftwareVersion]) 0 0 0
70 0 ▶ $self->[$__raw] .= $self->[$__typeSoftwareVersion]->pack
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] .= $self->[$__typeSoftwareVersion]->pack or return undef 0 0 0
71 or return undef;
72 }
73  
74 0 1;
75 }
76  
77 0 ▶sub unpack {
Subroutine unpack: not called CC=7 SCAR=40.3
78 0 my $self = shift;
79  
80 0 ▶ my ($version, $ttl, $checksum, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCn a*", $self->[$__raw]) or return undef 0 0 0
81 $self->SUPER::unpack('CCn a*', $self->[$__raw])
82 or return undef;
83  
84 0 $self->[$__version] = $version;
85 0 $self->[$__ttl] = $ttl;
86 0 $self->[$__checksum] = $checksum;
87  
88 0 my $tail = CORE::unpack('H*', $payload);
89  
90 0 ▶ if ($tail =~ /^0001/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /^0001/) 0 0 0
91 0 my $type = Net::Packet::CDP::TypeDeviceId->new(raw => $payload);
92 0 $self->[$__typeDeviceId] = $type;
93 0 $payload = $type->payload;
94 0 $tail = CORE::unpack('H*', $payload);
95 }
96 0 ▶ if ($tail =~ /^0002/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /^0002/) 0 0 0
97 0 my $type = Net::Packet::CDP::TypeAddresses->new(raw => $payload);
98 0 $self->[$__typeAddresses] = $type;
99 0 $payload = $type->payload;
100 0 $tail = CORE::unpack('H*', $payload);
101 }
102 0 ▶ if ($tail =~ /^0003/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /^0003/) 0 0 0
103 0 my $type = Net::Packet::CDP::TypePortId->new(raw => $payload);
104 0 $self->[$__typePortId] = $type;
105 0 $payload = $type->payload;
106 0 $tail = CORE::unpack('H*', $payload);
107 }
108 0 ▶ if ($tail =~ /^0004/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /^0004/) 0 0 0
109 0 my $type = Net::Packet::CDP::TypeCapabilities->new(raw => $payload);
110 0 $self->[$__typeCapabilities] = $type;
111 0 $payload = $type->payload;
112 0 $tail = CORE::unpack('H*', $payload);
113 }
114 0 ▶ if ($tail =~ /^0005/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /^0005/) 0 0 0
115 0 my $type = Net::Packet::CDP::TypeSoftwareVersion->new(raw => $payload);
116 0 $self->[$__typeSoftwareVersion] = $type;
117 0 $payload = $type->payload;
118 0 $tail = CORE::unpack('H*', $payload);
119 }
120  
121 0 $self->[$__payload] = $payload;
122  
123 0 1;
124 }
125  
126 0 ▶sub encapsulate {
Subroutine encapsulate: not called CC=2 SCAR=17.9
127 0 my $types = {
128 NP_LAYER_NONE() => NP_LAYER_NONE(),
129 };
130  
131 0 ▶ $types->{NP_LAYER_NONE()} || NP_LAYER_UNKNOWN();
Branch: 1 branch
BranchTrueFalseTotal
$types->{"NONE"} or "UNKNOWN" 0 0 0
132 }
133  
134 0 ▶sub print {
Subroutine print: not called CC=6 SCAR=37.4
135 0 my $self = shift;
136  
137 0 my $buf = '';
138  
139 0 my $l = $self->layer;
140 0 my $i = $self->is;
141 0 $buf .= sprintf "$l:+$i: version:%d ttl:%d checksum:0x%04x",
142 $self->[$__version], $self->[$__ttl], $self->[$__checksum];
143  
144 0 ▶ if ($self->[$__typeDeviceId]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeDeviceId]) 0 0 0
145 0 $buf .= "\n".$self->[$__typeDeviceId]->print;
146 }
147 0 ▶ if ($self->[$__typeAddresses]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeAddresses]) 0 0 0
148 0 $buf .= "\n".$self->[$__typeAddresses]->print;
149 }
150 0 ▶ if ($self->[$__typePortId]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typePortId]) 0 0 0
151 0 $buf .= "\n".$self->[$__typePortId]->print;
152 }
153 0 ▶ if ($self->[$__typeCapabilities]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeCapabilities]) 0 0 0
154 0 $buf .= "\n".$self->[$__typeCapabilities]->print;
155 }
156 0 ▶ if ($self->[$__typeSoftwareVersion]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__typeSoftwareVersion]) 0 0 0
157 0 $buf .= "\n".$self->[$__typeSoftwareVersion]->print;
158 }
159  
160 0 $buf;
161 }
162  
163 1;
164  
165 __END__
↑ Summary Packet/Utils.pm »