1
2
3 """Spanning Tree Protocol."""
4 from __future__ import print_function
5 from __future__ import absolute_import
6
7 from . import dpkt
8
9
10 -class STP(dpkt.Packet):
11 """Spanning Tree Protocol.
12
13 TODO: Longer class information....
14
15 Attributes:
16 __hdr__: Header fields of STP.
17 TODO.
18 """
19
20 __hdr__ = (
21 ('proto_id', 'H', 0),
22 ('v', 'B', 0),
23 ('type', 'B', 0),
24 ('flags', 'B', 0),
25 ('root_id', '8s', ''),
26 ('root_path', 'I', 0),
27 ('bridge_id', '8s', ''),
28 ('port_id', 'H', 0),
29 ('_age', 'H', 0),
30 ('_max_age', 'H', 0),
31 ('_hello', 'H', 0),
32 ('_fd', 'H', 0)
33 )
34
35 @property
38
39 @age.setter
42
43 @property
46
47 @max_age.setter
50
51 @property
54
55 @hello.setter
58
59 @property
62
63 @fd.setter
66
69 buf = b'\x00\x00\x02\x02\x3e\x80\x00\x08\x00\x27\xad\xa3\x41\x00\x00\x00\x00\x80\x00\x08\x00\x27\xad\xa3\x41\x80\x01\x00\x00\x14\x00\x02\x00\x0f\x00\x00\x00\x00\x00\x02\x00\x14\x00'
70 stp = STP(buf)
71
72 assert stp.proto_id == 0
73 assert stp.port_id == 0x8001
74 assert stp.age == 0
75 assert stp.max_age == 20
76 assert stp.hello == 2
77 assert stp.fd == 15
78
79 assert bytes(stp) == buf
80
81 stp.fd = 100
82 assert stp.pack_hdr()[-2:] == b'\x64\x00'
83
84
85 if __name__ == '__main__':
86
87 test_stp()
88 print('Tests Successful...')
89