def setUp(self): self.msgtype = IGMP_TYPE_QUERY self.maxresp = 100 self.csum = 0 self.address = "225.0.0.1" self.s_flg = 0 self.qrv = 2 self.qqic = 10 self.num = 0 self.srcs = [] self.s_qrv = self.s_flg << 3 | self.qrv self.buf = pack( igmpv3_query._PACK_STR, self.msgtype, self.maxresp, self.csum, addrconv.ipv4.text_to_bin(self.address), self.s_qrv, self.qqic, self.num, ) self.g = igmpv3_query( self.msgtype, self.maxresp, self.csum, self.address, self.s_flg, self.qrv, self.qqic, self.num, self.srcs )
def test_default_args(self): prev = ipv4(proto=inet.IPPROTO_IGMP) g = igmpv3_query() prev.serialize(g, None) buf = g.serialize(bytearray(), prev) res = unpack_from(igmpv3_query._PACK_STR, str(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) buf = str(buf) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) eq_(res[2], checksum(buf)) eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0')) eq_(res[4], 2) eq_(res[5], 0) eq_(res[6], 0) # srcs without num prev = ipv4(proto=inet.IPPROTO_IGMP) srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3'] g = igmpv3_query(srcs=srcs) prev.serialize(g, None) buf = g.serialize(bytearray(), prev) res = unpack_from(igmpv3_query._PACK_STR, str(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) buf = str(buf) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) eq_(res[2], checksum(buf)) eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0')) eq_(res[4], 2) eq_(res[5], 0) eq_(res[6], len(srcs)) res = unpack_from('4s4s4s', str(buf), igmpv3_query._MIN_LEN) eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0])) eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1])) eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
def test_default_args(self): prev = ipv4(proto=inet.IPPROTO_IGMP) g = igmpv3_query() prev.serialize(g, None) buf = g.serialize(bytearray(), prev) res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) buf = str(buf) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) eq_(res[2], checksum(buf)) eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0')) eq_(res[4], 2) eq_(res[5], 0) eq_(res[6], 0) # srcs without num prev = ipv4(proto=inet.IPPROTO_IGMP) srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3'] g = igmpv3_query(srcs=srcs) prev.serialize(g, None) buf = g.serialize(bytearray(), prev) res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into('!H', buf, 2, 0) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) eq_(res[2], checksum(buf)) eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0')) eq_(res[4], 2) eq_(res[5], 0) eq_(res[6], len(srcs)) res = unpack_from('4s4s4s', six.binary_type(buf), igmpv3_query._MIN_LEN) eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0])) eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1])) eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
def setUp_with_srcs(self): self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3'] self.num = len(self.srcs) self.buf = pack(igmpv3_query._PACK_STR, self.msgtype, self.maxresp, self.csum, addrconv.ipv4.text_to_bin(self.address), self.s_qrv, self.qqic, self.num) for src in self.srcs: self.buf += pack('4s', addrconv.ipv4.text_to_bin(src)) self.g = igmpv3_query( self.msgtype, self.maxresp, self.csum, self.address, self.s_flg, self.qrv, self.qqic, self.num, self.srcs)
def setUp_with_srcs(self): self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3'] self.num = len(self.srcs) self.buf = pack(igmpv3_query._PACK_STR, self.msgtype, self.maxresp, self.csum, addrconv.ipv4.text_to_bin(self.address), self.s_qrv, self.qqic, self.num) for src in self.srcs: self.buf += pack('4s', addrconv.ipv4.text_to_bin(src)) self.g = igmpv3_query(self.msgtype, self.maxresp, self.csum, self.address, self.s_flg, self.qrv, self.qqic, self.num, self.srcs)
def test_default_args(self): prev = ipv4(proto=inet.IPPROTO_IGMP) g = igmpv3_query() prev.serialize(g, None) buf = g.serialize(bytearray(), prev) res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into("!H", buf, 2, 0) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) eq_(res[2], checksum(buf)) eq_(res[3], addrconv.ipv4.text_to_bin("0.0.0.0")) eq_(res[4], 2) eq_(res[5], 0) eq_(res[6], 0) # srcs without num prev = ipv4(proto=inet.IPPROTO_IGMP) srcs = ["192.168.1.1", "192.168.1.2", "192.168.1.3"] g = igmpv3_query(srcs=srcs) prev.serialize(g, None) buf = g.serialize(bytearray(), prev) res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf)) buf = bytearray(buf) pack_into("!H", buf, 2, 0) eq_(res[0], IGMP_TYPE_QUERY) eq_(res[1], 100) eq_(res[2], checksum(buf)) eq_(res[3], addrconv.ipv4.text_to_bin("0.0.0.0")) eq_(res[4], 2) eq_(res[5], 0) eq_(res[6], len(srcs)) res = unpack_from("4s4s4s", six.binary_type(buf), igmpv3_query._MIN_LEN) eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0])) eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1])) eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
def test_num_smaller_than_srcs(self): self.srcs = ["192.168.1.1", "192.168.1.2", "192.168.1.3"] self.num = len(self.srcs) - 1 self.buf = pack( igmpv3_query._PACK_STR, self.msgtype, self.maxresp, self.csum, addrconv.ipv4.text_to_bin(self.address), self.s_qrv, self.qqic, self.num, ) for src in self.srcs: self.buf += pack("4s", addrconv.ipv4.text_to_bin(src)) self.g = igmpv3_query( self.msgtype, self.maxresp, self.csum, self.address, self.s_flg, self.qrv, self.qqic, self.num, self.srcs ) self.test_parser()
def setUp(self): self.msgtype = IGMP_TYPE_QUERY self.maxresp = 100 self.csum = 0 self.address = '225.0.0.1' self.s_flg = 0 self.qrv = 2 self.qqic = 10 self.num = 0 self.srcs = [] self.s_qrv = self.s_flg << 3 | self.qrv self.buf = pack(igmpv3_query._PACK_STR, self.msgtype, self.maxresp, self.csum, addrconv.ipv4.text_to_bin(self.address), self.s_qrv, self.qqic, self.num) self.g = igmpv3_query(self.msgtype, self.maxresp, self.csum, self.address, self.s_flg, self.qrv, self.qqic, self.num, self.srcs)