示例#1
0
    def test_serialize_afi_ipv4(self):
        prefix = '10.0.0.0'
        peer_ip = '172.16.0.1'
        body = b'test'  # 4 bytes
        buf = (
            b'\x11\x11\x11\x11'  # timestamp
            b'\x00\x0c\x00\x01'  # type=TYPE_TABLE_DUMP(12),
            # subtype=SUBTYPE_AFI_IPv4(1)
            b'\x00\x00\x00\x1a'  # length=26
            b'\x22\x22\x33\x33'  # view_num, seq_num
            + addrconv.ipv4.text_to_bin(prefix) +  # prefix
            b'\x18\x01'  # prefix_len=24, status=1
            b'\x44\x44\x44\x44'  # originated_time
            + addrconv.ipv4.text_to_bin(peer_ip) +  # peer_ip
            b'\xfd\xe8\x00\x04'  # peer_as=65000, attr_len=len(body)
            + body  # bgp_attributes
        )

        mock_bgp_attr = mock.MagicMock(spec=bgp._PathAttribute)
        mock_bgp_attr.serialize.return_value = body

        message = mrtlib.TableDumpAfiIPv4MrtMessage(
            view_num=0x2222,
            seq_num=0x3333,
            prefix=prefix,
            prefix_len=24,
            status=1,
            originated_time=0x44444444,
            peer_ip=peer_ip,
            peer_as=65000,
            bgp_attributes=[mock_bgp_attr],
            # attr_len=4
        )
        record = mrtlib.TableDumpMrtRecord(
            message=message,
            timestamp=0x11111111,
            # type_=None,
            # subtype=None,
            # length=None,
        )

        output = record.serialize()

        eq_(buf, output)
示例#2
0
    def test_init_without_type_subtype(self):
        type_ = mrtlib.MrtRecord.TYPE_TABLE_DUMP
        subtype = mrtlib.TableDumpMrtRecord.SUBTYPE_AFI_IPv4

        message = mrtlib.TableDumpAfiIPv4MrtMessage(
            view_num=1,
            seq_num=2,
            prefix='192.168.1.0',
            prefix_len=24,
            status=1,
            originated_time=0,
            peer_ip='10.0.0.1',
            peer_as=65000,
            bgp_attributes=[],
        )
        record = mrtlib.TableDumpMrtRecord(message)

        eq_(type_, record.type)
        eq_(subtype, record.subtype)