Package dpkt :: Module stp
[hide private]
[frames] | no frames]

Source Code for Module dpkt.stp

 1  # $Id: stp.py 23 2006-11-08 15:45:33Z dugsong $ 
 2  # -*- coding: utf-8 -*- 
 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
36 - def age(self):
37 return self._age >> 8
38 39 @age.setter
40 - def age(self, age):
41 self._age = age << 8
42 43 @property
44 - def max_age(self):
45 return self._max_age >> 8
46 47 @max_age.setter
48 - def max_age(self, max_age):
49 self._max_age = max_age << 8
50 51 @property
52 - def hello(self):
53 return self._hello >> 8
54 55 @hello.setter
56 - def hello(self, hello):
57 self._hello = hello << 8
58 59 @property
60 - def fd(self):
61 return self._fd >> 8
62 63 @fd.setter
64 - def fd(self, fd):
65 self._fd = fd << 8
66
67 68 -def test_stp():
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' # 100 << 8
83 84 85 if __name__ == '__main__': 86 # Runs all the test associated with this class/file 87 test_stp() 88 print('Tests Successful...') 89