Packet/STP.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Packet/OSPF.pm ↑ Summary Packet/DescL3.pm »
1 #
2 # $Id: STP.pm 2002 2015-02-15 16:50:35Z gomor $
3 #
4 package Net::Packet::STP;
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(:stp :layer);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 0 ▶use Net::Packet::Utils qw(convertMac);
Subroutine BEGIN: called CC=1 SCAR=2.6
13  
14 our @AS = qw(
15 protocolIdentifier
16 protocolVersionIdentifier
17 bpduType
18 bpduFlags
19 rootIdentifier
20 rootPathCost
21 bridgeIdentifier
22 portIdentifier
23 messageAge
24 maxAge
25 helloTime
26 forwardDelay
27 );
28 __PACKAGE__->cgBuildIndices;
29 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
30  
31 #no strict 'vars';
32  
33 sub new {
34 shift->SUPER::new(
35 protocolIdentifier => NP_STP_PROTOCOL_IDENTIFIER_STP,
36 protocolVersionIdentifier => 0,
37 bpduType => 0x00,
38 bpduFlags => 0x00,
39 rootIdentifier => '1/00:11:22:33:44:55',
40 rootPathCost => 1,
41 bridgeIdentifier => '2/11:22:33:44:55:66',
42 portIdentifier => 0x0001,
43 messageAge => 1,
44 maxAge => 10,
45 helloTime => 1,
46 forwardDelay => 10,
47 @_,
48 );
49 }
50  
51 sub getLength { NP_STP_HDR_LEN }
52  
53 sub pack {
54 my $self = shift;
55  
56 my ($root, $id1) = split('\s*/\s*', $self->rootIdentifier);
57 my ($bridge, $id2) = split('\s*/\s*', $self->bridgeIdentifier);
58  
59 $id1 =~ s/://g;
60 $id2 =~ s/://g;
61  
62 $self->raw($self->SUPER::pack('nCCCnH12NnH12nvvvv',
63 $self->protocolIdentifier, $self->protocolVersionIdentifier,
64 $self->bpduType, $self->bpduFlags, $root, $id1, $self->rootPathCost,
65 $bridge, $id2, $self->portIdentifier, $self->messageAge, $self->maxAge,
66 $self->helloTime, $self->forwardDelay)
67 ) or return undef;
68  
69 1;
70 }
71  
72 sub unpack {
73 my $self = shift;
74  
75 my ($protocolIdentifier, $protocolVersionIdentifier, $bpduType, $bpduFlags,
76 $root, $identifier1, $rootPathCost, $bridge, $identifier2,
77 $portIdentifier, $messageAge, $maxAge, $helloTime, $forwardDelay,
78 $payload) = $self->SUPER::unpack('nCCCnH12NnH12nvvvv a*', $self->raw)
79 or return undef;
80  
81 my $id1 = $root.'/'.convertMac($identifier1);
82 my $id2 = $bridge.'/'.convertMac($identifier2);
83 $self->rootIdentifier($id1);
84 $self->bridgeIdentifier($id2);
85  
86 $self->protocolIdentifier($protocolIdentifier);
87 $self->protocolVersionIdentifier($protocolVersionIdentifier);
88 $self->bpduType($bpduType);
89 $self->bpduFlags($bpduFlags);
90 $self->rootPathCost($rootPathCost);
91 $self->portIdentifier($portIdentifier);
92 $self->messageAge($messageAge);
93 $self->maxAge($maxAge);
94 $self->helloTime($helloTime);
95 $self->forwardDelay($forwardDelay);
96  
97 $self->payload($payload);
98  
99 1;
100 }
101  
102 sub encapsulate {
103 my $types = {
104 NP_LAYER_NONE() => NP_LAYER_NONE(),
105 };
106  
107 $types->{NP_LAYER_NONE()} || NP_LAYER_UNKNOWN();
108 }
109  
110 sub print {
111 my $self = shift;
112  
113 my $l = $self->layer;
114 my $i = $self->is;
115 sprintf "$l:+$i: protocolIdentifier:0x%04x protocolVersionIdentifier:%d\n".
116 "$l: $i: bpduType:0x%02x bpduFlags:0x%02x\n".
117 "$l: $i: rootIdentifier:%s rootPathCost:%d\n".
118 "$l: $i: bridgeIdentifier:%s portIdentifier:0x%04x\n".
119 "$l: $i: messageAge:%d maxAge:%d helloTime:%d forwardDelay:%d",
120 $self->protocolIdentifier, $self->protocolVersionIdentifier,
121 $self->bpduType, $self->bpduFlags, $self->rootIdentifier,
122 $self->rootPathCost, $self->bridgeIdentifier,
123 $self->portIdentifier, $self->messageAge, $self->maxAge,
124 $self->helloTime, $self->forwardDelay;
125 }
126  
127 1;
128  
129 __END__
« Packet/OSPF.pm ↑ Summary Packet/DescL3.pm »