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

Source Code for Module dpkt.pim

 1  # $Id: pim.py 23 2006-11-08 15:45:33Z dugsong $ 
 2  # -*- coding: utf-8 -*- 
 3  """Protocol Independent Multicast.""" 
 4  from __future__ import absolute_import 
 5   
 6  from . import dpkt 
 7  from .decorators import deprecated 
8 9 10 -class PIM(dpkt.Packet):
11 """Protocol Independent Multicast. 12 13 TODO: Longer class information.... 14 15 Attributes: 16 __hdr__: Header fields of PIM. 17 TODO. 18 """ 19 20 __hdr__ = ( 21 ('_v_type', 'B', 0x20), 22 ('rsvd', 'B', 0), 23 ('sum', 'H', 0) 24 ) 25 26 @property
27 - def v(self):
28 return self._v_type >> 4
29 30 @v.setter
31 - def v(self, v):
32 self._v_type = (v << 4) | (self._v_type & 0xf)
33 34 @property
35 - def type(self):
36 return self._v_type & 0xf
37 38 @type.setter
39 - def type(self, type):
40 self._v_type = (self._v_type & 0xf0) | type
41
42 - def __bytes__(self):
43 if not self.sum: 44 self.sum = dpkt.in_cksum(dpkt.Packet.__bytes__(self)) 45 return dpkt.Packet.__bytes__(self)
46
47 -def test_pim():
48 pimdata = PIM(b'\x20\x00\x9f\xf4\x00\x01\x00\x02\x00\x69') 49 assert pimdata.v == 2 50 assert pimdata.type == 0 51 52 # test setters 53 pimdata.v = 3 54 pimdata.type = 1 55 assert bytes(pimdata) == b'\x31\x00\x9f\xf4\x00\x01\x00\x02\x00\x69'
56