Exemplo n.º 1
0
    def _test_pcap_single(f):
        zebra_pcap_file = os.path.join(PCAP_DATA_DIR, f + '.pcap')
        # print('*** testing %s' % zebra_pcap_file)

        for _, buf in pcaplib.Reader(open(zebra_pcap_file, 'rb')):
            # Checks if Zebra message can be parsed as expected.
            pkt = packet.Packet(buf)
            zebra_pkts = pkt.get_protocols(zebra.ZebraMessage)
            for zebra_pkt in zebra_pkts:
                ok_(isinstance(zebra_pkt, zebra.ZebraMessage),
                    'Failed to parse Zebra message: %s' % pkt)
            ok_(not isinstance(pkt.protocols[-1],
                               (six.binary_type, bytearray)),
                'Some messages could not be parsed in %s: %s' % (f, pkt))

            # Checks if Zebra message can be serialized as expected.
            pkt.serialize()
            eq_(binary_str(buf), binary_str(pkt.data))
Exemplo n.º 2
0
    def test_parser(self):
        files = [
            'geneve_unknown',
        ]

        for f in files:
            # print('*** testing %s ...' % f)
            for _, buf in pcaplib.Reader(
                    open(GENEVE_DATA_DIR + f + '.pcap', 'rb')):
                # Checks if message can be parsed as expected.
                pkt = packet.Packet(buf)
                geneve_pkt = pkt.get_protocol(geneve.geneve)
                ok_(isinstance(geneve_pkt, geneve.geneve),
                    'Failed to parse Geneve message: %s' % pkt)

                # Checks if message can be serialized as expected.
                pkt.serialize()
                eq_(buf, pkt.data,
                    "b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
Exemplo n.º 3
0
    def test_parser(self):
        files = [
            'bgp4-open',
            'bgp4-update',
            'bgp4-update_ipv6',
            'bgp4-update_vpnv6',
            'bgp4-keepalive',
            'evpn_esi_arbitrary',
            'evpn_esi_lacp',
            'evpn_esi_l2_bridge',
            'evpn_esi_mac_base',
            'evpn_esi_router_id',
            'evpn_esi_as_based',
            'evpn_nlri_eth_a-d',
            'evpn_nlri_mac_ip_ad',
            'evpn_nlri_inc_multi_eth_tag',
            'evpn_nlri_eth_seg',
            'evpn_nlri_ip_prefix',
            'flowspec_nlri_ipv4',
            'flowspec_nlri_vpn4',
            'flowspec_nlri_ipv6',
            'flowspec_nlri_vpn6',
            'flowspec_nlri_l2vpn',
            'flowspec_action_traffic_rate',
            'flowspec_action_traffic_action',
            'flowspec_action_redirect',
            'flowspec_action_traffic_marking',
        ]

        for f in files:
            LOG.debug('*** testing %s ...', f)
            for _, buf in pcaplib.Reader(
                    open(BGP4_PACKET_DATA_DIR + f + '.pcap', 'rb')):
                # Checks if BGP message can be parsed as expected.
                pkt = packet.Packet(buf)
                ok_(isinstance(pkt.protocols[-1], bgp.BGPMessage),
                    'Failed to parse BGP message: %s' % pkt)

                # Checks if BGP message can be serialized as expected.
                pkt.serialize()
                eq_(buf, pkt.data,
                    "b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
Exemplo n.º 4
0
    def test_pcap(self):
        files = [
            'openflow_flowmod',
            'openflow_flowstats_req',
            'openflow_invalid_version',
        ]

        for f in files:
            # print('*** testing %s ...' % f)
            for _, buf in pcaplib.Reader(
                    open(OPENFLOW_DATA_DIR + f + '.pcap', 'rb')):
                # Checks if message can be parsed as expected.
                pkt = packet.Packet(buf)
                openflow_pkt = pkt.get_protocol(openflow.openflow)
                ok_(isinstance(openflow_pkt, openflow.openflow),
                    'Failed to parse OpenFlow message: %s' % pkt)

                # Checks if message can be serialized as expected.
                pkt.serialize()
                eq_(buf, pkt.data,
                    "b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))