1SpanningTree(3)       User Contributed Perl Documentation      SpanningTree(3)
2
3
4

NAME

6       "NetPacket::SpanningTree" - Assemble and disassemble IEEE 802.1D
7       Spanning Tree protocol packets.
8

SYNOPSIS

10        use NetPacket::LLC;
11        use NetPacket::SpanningTree;
12
13        $llc_data = NetPacket::Ethernet->strip($raw_packet);
14        $st_data = NetPacket::LLC->strip($llc_data);
15        $st_obj = NetPacket::SpanningTree->decode($st_data);
16

DESCRIPTION

18       "NetPacket::SpanningTree" provides a set of routines for assembling and
19       disassembling packets using the IEEE standard Spanning Tree Protocol.
20       Spanning Tree is a layer 2 protocol defined by the IEEE 802.1D
21       specification.
22
23   Methods
24       "NetPacket::SpanningTree->decode([ST DATA])"
25           Decode the spanning tree packet data and return an object
26           containing instance data.  This method will probably decode garbage
27           input, but it won't mean much.
28
29       "NetPacket::SpanningTree->encode($st_hash)"
30           Encode the hash into a raw data stream that may be appended to LLC
31           data, then to an ethernet packet.  This allows the user to create
32           his/her own Spanning Tree protocol packet and subsequently send it
33           out on the wire (though sending on the wire isn't a function of
34           this application).
35
36   Functions
37       "NetPacket::SpanningTree->strip([ST DATA])"
38           Strip the spanning tree data from the packet, and return any
39           underlying data.  This returns undef since there is no "data" per
40           say included in the spanning tree packet.
41
42   Instance data
43       The instance data contains in the hash returned by the encode and
44       decode methodsof the "NetPacket::SpanningTree" module contain the
45       following fields.  Note, please refer to the IEEE spec for a
46       description of these fields.  They are not described in detail here
47       unless relevant to encoding.  When available, values not suppiled will
48       be set to IEEE 802.1D defaults.
49
50       max_age
51       message_age
52       bpdu_flags
53               A single octet, representing the topology change flag (TC) (LSB) and the
54               topology change notification acknowledgement (TCA) (MSB).  This parameter
55               is contructed when encoding, please refer to the TC and TCA items to set
56               the appropriate bits.
57
58       bridge_mac
59               This (along with bridge_priority) is used to build the bridge_id when encoding.
60
61       bpdu_type
62       topology_change
63       bridge_priority
64               This (along with bridge_mac) is used to build the bridge_id when encoding.
65
66       topology_change_ack
67       protocol_version
68               This value should always be 0, defaults to 0.  Note, this value also
69               contains the message type (which is also always 0).
70
71       forward_delay
72       hello_time
73       port_num
74       root_priority
75               This (along with root_mac) is used to build the root_id when encoding.
76
77       root_path_cost
78       protocol_id
79               This value should always be 0, defaults to 0.
80
81       root_mac
82               This (along with root_priority) is used to build the root_id when encoding.
83
84       port_priority
85               This (along with port_num) is used to build the port_id when encoding.
86
87       root_id
88       port_id
89       bridge_id
90
91   Exports
92       exportable
93           st_strip
94
95       tags
96           The following tags group together related exportable items.
97
98           ":strip"
99               Import the strip function "st_strip"
100
101           ":ALL"
102               All the above exportable items
103

EXAMPLE

105       The following is a script that listens on device "eth1" for spanning
106       tree packets.  It then decodes the packets, re-encodes them, and
107       verifies that the both the original and re-encoded data are identical.
108
109       #!/usr/bin/perl -w # # Perl script to verify that LACP packet intervals
110       are correct # # #
111
112       use strict; use Net::PcapUtils; use NetPacket::Ethernet; use
113       NetPacket::LLC; use NetPacket::SpanningTree;
114
115       {
116           my $iface = "eth1";
117           my $errmsg = Net::PcapUtils::loop(\&process_pkt,
118                                             DEV => $iface );
119           if (defined $errmsg) { die "$errmsg\n"; } }
120
121       sub process_pkt {
122           my ($arg, $hdr, $pkt)  = @_;
123           my $eth_obj = NetPacket::Ethernet->decode($pkt);
124
125           if ((defined $eth_obj->{length}) &&
126               ($eth_obj->{dest_mac} =~ m/^0180c200000/)) { # Spanning Tree protocol
127               my $llc_obj = NetPacket::LLC->decode($eth_obj->{data});
128               my $st_obj = NetPacket::SpanningTree->decode($llc_obj->{data});
129               verifyEncoding($st_obj);
130
131               my $newdata = NetPacket::SpanningTree->encode($st_obj);
132               return;
133           }
134        }
135
136       # # Decode a packet and compare it to a hash of data to be encoded.  #
137       # Input is a hash of data to be encoded.  The subroutine encodes and #
138       subsequently decodes the data and verifies the data matches.  #
139
140       sub verifyEncoding {
141           my ($st_obj) = @_;
142           my $newdata =
143               NetPacket::SpanningTree->encode($st_obj);
144           my $st_obj1 =
145               NetPacket::SpanningTree->decode($newdata);
146           foreach my $key (keys %$st_obj) {
147               if ($key =~ m/data/i) { next; }
148               if ($key =~ m/frame/i) { next; }
149               if ($key =~ m/_parent/i) { next; }
150               if ($st_obj->{$key} eq $st_obj1->{$key}) {
151                   print "$key is identical ($st_obj1->{$key})\n";
152               } else {
153                   print
154                       "$key is $st_obj->{$key} before $st_obj1->{$key}
155       after\n";
156               }
157           }
158        }
159

TODO

161       Better documentation
162       Clean up some code.
163

SEE ALSO

165       "NetPacket::LLC"
166               Module to decode LLC packets (Logical Link Control)
167
168       "NetPacket::Ethernet"
169               Module to decode Ethernet Packets
170
171       "Net::RawIP"
172               Module to send encoded data out.
173
174       "Net::PcapUtils"
175               Utility module to be used for packet capture.
176
178       Copyright (c) 2002 Chander Ganesan.
179
180       This package is free software and is provided "as is" without express
181       or implied warranty.  It may be used, redistributed and/or modified
182       under the terms of the Perl Artistic License (see
183       http://www.perl.com/perl/misc/Artistic.html)
184
185       This software and all associated data and documentation ('Software') is
186       available free of charge.  You may make copies of the Software but you
187       must include all of this notice on any copy.
188
189       The Software was developed for research purposes does not warrant that
190       it is error free or fit for any purpose.  The author disclaims any
191       liability for all claims, expenses, losses, damages and costs any user
192       may incur as a result of using, copying or modifying the Software.
193

AUTHOR

195       Chander Ganesan <cganesan@cpan.org<gt>
196
197
198
199perl v5.28.0                      2018-07-15                   SpanningTree(3)
Impressum