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

filter: Statementstmt 91.5% 54 / 59 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 100% 6 / 6 totaltotal 87.6% 71 / 81 SCAR 11.0
CC
3
Cov
89%
pack
2.0
unpack
2.0
getLength
2.0
CRAP 3.0
↑ Summary
1 #
2 # $Id: STP.pm,v 1.2 2007/01/04 23:30:34 gomor Exp $
3 #
4 package Net::Frame::Layer::STP;
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 Net::Frame::Layer qw(:consts);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 require Exporter;
12 3 our @ISA = qw(Net::Frame::Layer Exporter);
13  
14 3 our %EXPORT_TAGS = (
15 consts => [qw(
16 NF_STP_HDR_LEN
17 NF_STP_PROTOCOL_IDENTIFIER_STP
18 )],
19 );
20 our @EXPORT_OK = (
21 3 @{$EXPORT_TAGS{consts}},
22 );
23  
24 3 ▶use constant NF_STP_HDR_LEN => 42;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use constant NF_STP_PROTOCOL_IDENTIFIER_STP => 0x0000;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 3 our @AS = qw(
28 protocolIdentifier
29 protocolVersionIdentifier
30 bpduType
31 bpduFlags
32 rootIdentifier
33 rootPathCost
34 bridgeIdentifier
35 portIdentifier
36 messageAge
37 maxAge
38 helloTime
39 forwardDelay
40 );
41 3 __PACKAGE__->cgBuildIndices;
42 3 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
43  
44 3 ▶use Net::Frame::Layer qw(:subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 sub new {
47 shift->SUPER::new(
48 1 ▶ protocolIdentifier => NF_STP_PROTOCOL_IDENTIFIER_STP,
Subroutine new: called CC=1 SCAR=0.0
Pod documented
49 protocolVersionIdentifier => 0,
50 bpduType => 0x00,
51 bpduFlags => 0x00,
52 rootIdentifier => '1/00:11:22:33:44:55',
53 rootPathCost => 1,
54 bridgeIdentifier => '2/11:22:33:44:55:66',
55 portIdentifier => 0x0001,
56 messageAge => 1,
57 maxAge => 10,
58 helloTime => 1,
59 forwardDelay => 10,
60 @_,
61 );
62 }
63  
64 0 ▶sub getLength { NF_STP_HDR_LEN }
Subroutine getLength: not called CC=1 SCAR=6.9
Pod documented
65  
66 sub pack {
67 1 ▶ my $self = shift;
Subroutine pack: called CC=2 SCAR=7.0
Pod documented
68  
69 1 my ($root, $id1) = split('\s*/\s*', $self->rootIdentifier);
70 1 my ($bridge, $id2) = split('\s*/\s*', $self->bridgeIdentifier);
71  
72 1 $id1 =~ s/://g;
73 1 $id2 =~ s/://g;
74  
75 1 ▶ $self->raw($self->SUPER::pack('nCCCnH12NnH12nvvvv',
Branch: 1 branch
BranchTrueFalseTotal
$self->raw($self->SUPER::pack("nCCCnH12NnH12nvvvv", $self->protocolIdentifier, $self->protocolVersionIdentifier, $self->bpduType, $self->bpduFlags, $root, $id1, $self->rootPathCost, $bridge, $id2, $self->portIdentifier, $self->messageAge, $self->maxAge, $self->helloTime, $self->forwardDelay)) or return undef 0 1 1
76 $self->protocolIdentifier, $self->protocolVersionIdentifier,
77 $self->bpduType, $self->bpduFlags, $root, $id1, $self->rootPathCost,
78 $bridge, $id2, $self->portIdentifier, $self->messageAge, $self->maxAge,
79 $self->helloTime, $self->forwardDelay)
80 ) or return undef;
81  
82 1 $self->raw;
83 }
84  
85 sub unpack {
86 1 ▶ my $self = shift;
Subroutine unpack: called CC=2 SCAR=6.9
Pod documented
87  
88 1 ▶ my ($protocolIdentifier, $protocolVersionIdentifier, $bpduType, $bpduFlags,
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("nCCCnH12NnH12nvvvv a*", $self->raw) or return undef 0 1 1
89 $root, $identifier1, $rootPathCost, $bridge, $identifier2,
90 $portIdentifier, $messageAge, $maxAge, $helloTime, $forwardDelay,
91 $payload) = $self->SUPER::unpack('nCCCnH12NnH12nvvvv a*', $self->raw)
92 or return undef;
93  
94 1 my $id1 = $root.'/'.convertMac($identifier1);
95 1 my $id2 = $bridge.'/'.convertMac($identifier2);
96 1 $self->rootIdentifier($id1);
97 1 $self->bridgeIdentifier($id2);
98  
99 1 $self->protocolIdentifier($protocolIdentifier);
100 1 $self->protocolVersionIdentifier($protocolVersionIdentifier);
101 1 $self->bpduType($bpduType);
102 1 $self->bpduFlags($bpduFlags);
103 1 $self->rootPathCost($rootPathCost);
104 1 $self->portIdentifier($portIdentifier);
105 1 $self->messageAge($messageAge);
106 1 $self->maxAge($maxAge);
107 1 $self->helloTime($helloTime);
108 1 $self->forwardDelay($forwardDelay);
109  
110 1 $self->payload($payload);
111  
112 1 $self;
113 }
114  
115 0 ▶sub encapsulate { shift->nextLayer }
Subroutine encapsulate: not called CC=1 SCAR=6.9
Pod documented
116  
117 sub print {
118 0 ▶ my $self = shift;
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
119  
120 0 my $l = $self->layer;
121 0 sprintf "$l: protocolIdentifier:0x%04x protocolVersionIdentifier:%d\n".
122 "$l: bpduType:0x%02x bpduFlags:0x%02x\n".
123 "$l: rootIdentifier:%s rootPathCost:%d\n".
124 "$l: bridgeIdentifier:%s portIdentifier:0x%04x\n".
125 "$l: messageAge:%d maxAge:%d helloTime:%d forwardDelay:%d",
126 $self->protocolIdentifier, $self->protocolVersionIdentifier,
127 $self->bpduType, $self->bpduFlags, $self->rootIdentifier,
128 $self->rootPathCost, $self->bridgeIdentifier,
129 $self->portIdentifier, $self->messageAge, $self->maxAge,
130 $self->helloTime, $self->forwardDelay;
131 }
132  
133 3 1;
134  
135 __END__
↑ Summary