예제 #1
0
    def test_default_args(self):
        prev = ipv4(proto=inet.IPPROTO_IGMP)
        g = igmpv3_report()
        prev.serialize(g, None)
        buf = g.serialize(bytearray(), prev)
        res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
        buf = bytearray(buf)
        pack_into('!H', buf, 2, 0)

        eq_(res[0], IGMP_TYPE_REPORT_V3)
        eq_(res[1], checksum(buf))
        eq_(res[2], 0)

        # records without record_num
        prev = ipv4(proto=inet.IPPROTO_IGMP)
        record1 = igmpv3_report_group(MODE_IS_INCLUDE, 0, 0, '225.0.0.1')
        record2 = igmpv3_report_group(MODE_IS_INCLUDE, 0, 2, '225.0.0.2',
                                      ['172.16.10.10', '172.16.10.27'])
        record3 = igmpv3_report_group(MODE_IS_INCLUDE, 1, 0, '225.0.0.3', [],
                                      b'abc\x00')
        record4 = igmpv3_report_group(MODE_IS_INCLUDE, 1, 2, '225.0.0.4',
                                      ['172.16.10.10', '172.16.10.27'],
                                      b'abc\x00')
        records = [record1, record2, record3, record4]
        g = igmpv3_report(records=records)
        prev.serialize(g, None)
        buf = g.serialize(bytearray(), prev)
        res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
        buf = bytearray(buf)
        pack_into('!H', buf, 2, 0)

        eq_(res[0], IGMP_TYPE_REPORT_V3)
        eq_(res[1], checksum(buf))
        eq_(res[2], len(records))
예제 #2
0
 def setUp_with_aux(self):
     self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
     self.aux_len = len(self.aux) // 4
     self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
                     self.aux_len, self.num,
                     addrconv.ipv4.text_to_bin(self.address))
     self.buf += self.aux
     self.g = igmpv3_report_group(self.type_, self.aux_len, self.num,
                                  self.address, self.srcs, self.aux)
예제 #3
0
 def test_aux_len_smaller_than_aux(self):
     self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
     self.aux_len = len(self.aux) // 4 - 1
     self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
                     self.aux_len, self.num,
                     addrconv.ipv4.text_to_bin(self.address))
     self.buf += self.aux
     self.g = igmpv3_report_group(self.type_, self.aux_len, self.num,
                                  self.address, self.srcs, self.aux)
     self.test_parser()
예제 #4
0
 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_report_group._PACK_STR, self.type_,
                     self.aux_len, self.num,
                     addrconv.ipv4.text_to_bin(self.address))
     for src in self.srcs:
         self.buf += pack('4s', addrconv.ipv4.text_to_bin(src))
     self.g = igmpv3_report_group(self.type_, self.aux_len, self.num,
                                  self.address, self.srcs, self.aux)
예제 #5
0
 def setUp_with_records(self):
     self.record1 = igmpv3_report_group(MODE_IS_INCLUDE, 0, 0, '225.0.0.1')
     self.record2 = igmpv3_report_group(MODE_IS_INCLUDE, 0, 2, '225.0.0.2',
                                        ['172.16.10.10', '172.16.10.27'])
     self.record3 = igmpv3_report_group(MODE_IS_INCLUDE, 1, 0, '225.0.0.3',
                                        [], b'abc\x00')
     self.record4 = igmpv3_report_group(MODE_IS_INCLUDE, 2, 2, '225.0.0.4',
                                        ['172.16.10.10', '172.16.10.27'],
                                        b'abcde\x00\x00\x00')
     self.records = [self.record1, self.record2, self.record3, self.record4]
     self.record_num = len(self.records)
     self.buf = pack(igmpv3_report._PACK_STR, self.msgtype, self.csum,
                     self.record_num)
     self.buf += self.record1.serialize()
     self.buf += self.record2.serialize()
     self.buf += self.record3.serialize()
     self.buf += self.record4.serialize()
     self.g = igmpv3_report(self.msgtype, self.csum, self.record_num,
                            self.records)
예제 #6
0
 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_report_group._PACK_STR, self.type_,
                     self.aux_len, self.num,
                     addrconv.ipv4.text_to_bin(self.address))
     for src in self.srcs:
         self.buf += pack('4s', addrconv.ipv4.text_to_bin(src))
     self.g = igmpv3_report_group(self.type_, self.aux_len, self.num,
                                  self.address, self.srcs, self.aux)
     self.test_parser()
예제 #7
0
    def test_default_args(self):
        rep = igmpv3_report_group()
        buf = rep.serialize()
        res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))

        eq_(res[0], 0)
        eq_(res[1], 0)
        eq_(res[2], 0)
        eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))

        # srcs without num
        srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
        rep = igmpv3_report_group(srcs=srcs)
        buf = rep.serialize()
        res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))

        eq_(res[0], 0)
        eq_(res[1], 0)
        eq_(res[2], len(srcs))
        eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))

        res = unpack_from('4s4s4s', six.binary_type(buf),
                          igmpv3_report_group._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]))

        # aux without aux_len
        aux = b'abcde'
        rep = igmpv3_report_group(aux=aux)
        buf = rep.serialize()
        res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))

        eq_(res[0], 0)
        eq_(res[1], 2)
        eq_(res[2], 0)
        eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
        eq_(buf[igmpv3_report_group._MIN_LEN:], b'abcde\x00\x00\x00')
예제 #8
0
 def setUp_with_srcs_and_aux(self):
     self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
     self.num = len(self.srcs)
     self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
     self.aux_len = len(self.aux) // 4
     self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
                     self.aux_len, self.num,
                     addrconv.ipv4.text_to_bin(self.address))
     for src in self.srcs:
         self.buf += pack('4s', addrconv.ipv4.text_to_bin(src))
     self.buf += self.aux
     self.g = igmpv3_report_group(self.type_, self.aux_len, self.num,
                                  self.address, self.srcs, self.aux)
예제 #9
0
    def setUp(self):
        self.type_ = MODE_IS_INCLUDE
        self.aux_len = 0
        self.num = 0
        self.address = '225.0.0.1'
        self.srcs = []
        self.aux = None

        self.buf = pack(igmpv3_report_group._PACK_STR, self.type_,
                        self.aux_len, self.num,
                        addrconv.ipv4.text_to_bin(self.address))

        self.g = igmpv3_report_group(self.type_, self.aux_len, self.num,
                                     self.address, self.srcs, self.aux)