1
2
3 """Virtual Router Redundancy Protocol."""
4 from __future__ import print_function
5 from __future__ import absolute_import
6
7 from . import dpkt
8 from .decorators import deprecated
9
10
11 -class VRRP(dpkt.Packet):
12 """Virtual Router Redundancy Protocol.
13
14 TODO: Longer class information....
15
16 Attributes:
17 __hdr__: Header fields of VRRP.
18 TODO.
19 """
20
21 __hdr__ = (
22 ('_v_type', 'B', 0x21),
23 ('vrid', 'B', 0),
24 ('priority', 'B', 0),
25 ('count', 'B', 0),
26 ('atype', 'B', 0),
27 ('advtime', 'B', 0),
28 ('sum', 'H', 0),
29 )
30 addrs = ()
31 auth = ''
32
33 @property
35 return self._v_type >> 4
36
37 @v.setter
40
41 @property
43 return self._v_type & 0x0f
44
45 @type.setter
48
58
61
67
69
70 s = b'\x00\x00\x00\x00\x00\x00\xff\xff'
71 v = VRRP(s)
72 assert v.sum == 0xffff
73 assert bytes(v) == s
74
75
76 s = b'\x21\x01\x64\x01\x00\x01\xba\x52\xc0\xa8\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00'
77 v = VRRP(s)
78 assert v.count == 1
79 assert v.addrs == [b'\xc0\xa8\x00\x01']
80 assert bytes(v) == s
81
82
83 v.sum = 0
84 assert bytes(v) == s
85
86
87 assert len(v) == len(s)
88
89
90 assert v.v == 2
91 assert v.type == 1
92
93
94 v.v = 3
95 v.type = 2
96 assert bytes(v)[0] == b'\x32'[0]
97
98
99 if __name__ == '__main__':
100 test_vrrp()
101
102 print('Tests Successful...')
103