packet lib: igmp: support default parameters

Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Yuichi Ito 2013-12-02 10:13:51 +09:00 committed by FUJITA Tomonori
parent ba963ae2cf
commit ddf1cbc5f6
2 changed files with 11 additions and 1 deletions

View File

@ -90,7 +90,8 @@ class igmp(packet_base.PacketBase):
_PACK_STR = '!BBH4s'
_MIN_LEN = struct.calcsize(_PACK_STR)
def __init__(self, msgtype, maxresp, csum, address):
def __init__(self, msgtype=IGMP_TYPE_QUERY, maxresp=0, csum=0,
address='0.0.0.0'):
super(igmp, self).__init__()
self.msgtype = msgtype
self.maxresp = maxresp

View File

@ -145,3 +145,12 @@ class Test_igmp(unittest.TestCase):
def test_malformed_igmp(self):
m_short_buf = self.buf[1:igmp._MIN_LEN]
igmp.parser(m_short_buf)
def test_default_args(self):
ig = igmp()
buf = ig.serialize(bytearray(), None)
res = unpack_from(igmp._PACK_STR, str(buf))
eq_(res[0], 0x11)
eq_(res[1], 0)
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))