Ejemplo n.º 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))
Ejemplo n.º 2
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))
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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()
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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()
Ejemplo n.º 9
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)
Ejemplo n.º 10
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()
Ejemplo n.º 11
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)
Ejemplo n.º 12
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()
Ejemplo n.º 13
0
 def test_record_num_smaller_than_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',
                                        [], 'abc\x00')
     self.record4 = igmpv3_report_group(MODE_IS_INCLUDE, 1, 2, '225.0.0.4',
                                        ['172.16.10.10', '172.16.10.27'],
                                        'abc\x00')
     self.records = [self.record1, self.record2, self.record3, self.record4]
     self.record_num = len(self.records) - 1
     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)
     self.test_parser()
Ejemplo n.º 14
0
 def test_num_larger_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()
Ejemplo n.º 15
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)
Ejemplo n.º 16
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', [], 'abc\x00')
     self.record4 = igmpv3_report_group(
         MODE_IS_INCLUDE, 2, 2, '225.0.0.4',
         ['172.16.10.10', '172.16.10.27'], '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)
Ejemplo n.º 17
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')
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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 = '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')
Ejemplo n.º 21
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, str(buf))
        buf = bytearray(buf)
        pack_into('!H', buf, 2, 0)
        buf = str(buf)

        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', [], 'abc\x00')
        record4 = igmpv3_report_group(
            MODE_IS_INCLUDE, 1, 2, '225.0.0.4',
            ['172.16.10.10', '172.16.10.27'], '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, str(buf))
        buf = bytearray(buf)
        pack_into('!H', buf, 2, 0)
        buf = str(buf)

        eq_(res[0], IGMP_TYPE_REPORT_V3)
        eq_(res[1], checksum(buf))
        eq_(res[2], len(records))
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
 def test_record_num_smaller_than_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, 1, 2, '225.0.0.4',
         ['172.16.10.10', '172.16.10.27'], b'abc\x00')
     self.records = [self.record1, self.record2, self.record3,
                     self.record4]
     self.record_num = len(self.records) - 1
     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)
     self.test_parser()