示例#1
0
def test_decap_active_tor(build_encapsulated_packet, request, ptfhost,
                          rand_selected_interface, ptfadapter, tbinfo,
                          rand_selected_dut, tunnel_traffic_monitor):
    @contextlib.contextmanager
    def stop_garp(ptfhost):
        """Temporarily stop garp service."""
        ptfhost.shell("supervisorctl stop garp_service")
        yield
        ptfhost.shell("supervisorctl start garp_service")

    if is_t0_mocked_dualtor(tbinfo):
        request.getfixturevalue('apply_active_state_to_orchagent')
    else:
        request.getfixturevalue(
            'toggle_all_simulator_ports_to_rand_selected_tor')

    tor = rand_selected_dut
    encapsulated_packet = build_encapsulated_packet
    iface, _ = rand_selected_interface

    exp_ptf_port_index = get_ptf_server_intf_index(tor, tbinfo, iface)
    exp_pkt = build_expected_packet_to_server(encapsulated_packet,
                                              decrease_ttl=True)

    ptf_t1_intf = random.choice(get_t1_ptf_ports(tor, tbinfo))
    logging.info("send encapsulated packet from ptf t1 interface %s",
                 ptf_t1_intf)
    with stop_garp(ptfhost):
        ptfadapter.dataplane.flush()
        testutils.send(ptfadapter, int(ptf_t1_intf.strip("eth")),
                       encapsulated_packet)
        testutils.verify_packet(ptfadapter,
                                exp_pkt,
                                exp_ptf_port_index,
                                timeout=10)
示例#2
0
    def runArpBroadcastTest(self, tagged_ports, untagged_ports):
        zero_mac_addr = ":".join(["00"] * 6)
        vlan_id = 10
        next_id = vlan_id
        mcast_group_id = vlan_id
        all_ports = set(tagged_ports + untagged_ports)
        arp_pkt = testutils.simple_arp_packet(pktlen=76)
        # Account for VLAN header size in total pktlen
        vlan_arp_pkt = testutils.simple_arp_packet(vlan_vid=vlan_id, pktlen=80)

        for port in tagged_ports:
            self.set_ingress_port_vlan(port, True, vlan_id, vlan_id)
        for port in untagged_ports:
            self.set_ingress_port_vlan(port, False, 0, vlan_id)
        self.add_bridging_entry(vlan_id, zero_mac_addr, zero_mac_addr, next_id)
        self.add_next_multicast(next_id, mcast_group_id)
        self.add_mcast_group(mcast_group_id, all_ports)
        for port in untagged_ports:
            self.set_egress_vlan_pop(port, vlan_id)

        for inport in all_ports:
            pkt_to_send = vlan_arp_pkt if inport in tagged_ports else arp_pkt
            testutils.send_packet(self, inport, str(pkt_to_send))
            # Packet should be received on all ports expect the ingress one.
            verify_tagged_ports = set(tagged_ports)
            verify_tagged_ports.discard(inport)
            for tport in verify_tagged_ports:
                testutils.verify_packet(self, vlan_arp_pkt, tport)
            verify_untagged_ports = set(untagged_ports)
            verify_untagged_ports.discard(inport)
            for uport in verify_untagged_ports:
                testutils.verify_packet(self, arp_pkt, uport)
        testutils.verify_no_other_packets(self)
示例#3
0
def mux_sim_check_downstream(active_tor, standby_tor, ptfadapter,
                             active_tor_ping_tgt_ip, standby_tor_ping_tgt_ip,
                             active_tor_exp_pkt, standby_tor_exp_pkt,
                             ptf_port_index, tor_mux_intf):
    failed = False
    reason = ''
    host = None
    ping_cmd = 'ping -I {} {} -c 1 -W 1; true'

    # Clear ARP tables to start in consistent state
    active_tor.shell("ip neigh flush all")
    standby_tor.shell("ip neigh flush all")

    # Ping from both ToRs, expect only message from active ToR to reach PTF
    active_tor.shell(ping_cmd.format(tor_mux_intf, active_tor_ping_tgt_ip))
    try:
        testutils.verify_packet(ptfadapter, active_tor_exp_pkt, ptf_port_index)
    except AssertionError:
        failed = True
        reason = 'Packet from active ToR {} not received'.format(active_tor)
        host = active_tor.hostname
        return failed, reason, host

    standby_tor.shell(ping_cmd.format(tor_mux_intf, standby_tor_ping_tgt_ip))
    try:
        testutils.verify_no_packet(ptfadapter, standby_tor_exp_pkt,
                                   ptf_port_index)
    except AssertionError:
        failed = True
        reason = 'Packet from standby ToR {} received'.format(standby_tor)
        host = standby_tor.hostname

    return failed, reason, host
def send_and_verify_traffic(ptfadapter,
                            pkt,
                            exp_pkt,
                            src_port,
                            dst_port,
                            pkt_action=ACTION_FORWARD):
    """
    Send traffic and verify that traffic was received

    Args:
        ptfadapter: PTF adapter
        pkt: Packet that should be sent
        exp_pkt: Expected packet
        src_port: Source port
        dst_port: Destination port
        pkt_action: Packet action (forward or drop)
    """

    ptfadapter.dataplane.flush()
    logger.info("Send packet from port {} to port {}".format(
        src_port, dst_port))
    testutils.send(ptfadapter, src_port, pkt)

    if pkt_action == ACTION_FORWARD:
        testutils.verify_packet(ptfadapter, exp_pkt, dst_port)
    elif pkt_action == ACTION_DROP:
        testutils.verify_no_packet(ptfadapter, exp_pkt, dst_port)
示例#5
0
    def verify_ack_received(self):
        dhcp_ack = self.create_dhcp_ack_relayed_packet()

        masked_ack = Mask(dhcp_ack)

        masked_ack.set_do_not_care_scapy(scapy.IP, "version")
        masked_ack.set_do_not_care_scapy(scapy.IP, "ihl")
        masked_ack.set_do_not_care_scapy(scapy.IP, "tos")
        masked_ack.set_do_not_care_scapy(scapy.IP, "len")
        masked_ack.set_do_not_care_scapy(scapy.IP, "id")
        masked_ack.set_do_not_care_scapy(scapy.IP, "flags")
        masked_ack.set_do_not_care_scapy(scapy.IP, "frag")
        masked_ack.set_do_not_care_scapy(scapy.IP, "ttl")
        masked_ack.set_do_not_care_scapy(scapy.IP, "proto")
        masked_ack.set_do_not_care_scapy(scapy.IP, "chksum")
        masked_ack.set_do_not_care_scapy(scapy.IP, "options")

        masked_ack.set_do_not_care_scapy(scapy.UDP, "len")
        masked_ack.set_do_not_care_scapy(scapy.UDP, "chksum")

        masked_ack.set_do_not_care_scapy(scapy.BOOTP, "sname")
        masked_ack.set_do_not_care_scapy(scapy.BOOTP, "file")

        masked_ack.set_do_not_care_scapy(scapy.DHCP, "lease_time")

        # NOTE: verify_packet() will fail for us via an assert, so no need to check a return value here
        testutils.verify_packet(self, masked_ack, self.client_port_index)
示例#6
0
    def runTest(self):
        target = gc.Target(device_id=0, pipe_id=0xffff)
        # Get bfrt_info and set it as part of the test
        bfrt_info = self.interface.bfrt_info_get(p4_program_name)

        # Set default output port
        table_output_port = bfrt_info.table_get("SwitchIngress.output_port")
        action_data = table_output_port.make_data(
            action_name="SwitchIngress.set_output_port",
            data_field_list_in=[gc.DataTuple(name="port_id", val=swports[1])])
        table_output_port.default_entry_set(target=target, data=action_data)

        # Set a default entry in the rewrite table so all packets get
        # their checksum updated.
        table_translate = bfrt_info.table_get("SwitchIngress.translate")

        action_data = table_translate.make_data(
            action_name="SwitchIngress.snupat",
            data_field_list_in=[
                gc.DataTuple(name="src_addr", val=gc.ipv4_to_bytes("4.3.2.1")),
                gc.DataTuple(name="src_port", val=gc.to_bytes(0x4321, 2)),
                gc.DataTuple(name="update", val=0x0)
            ],
        )

        table_translate.default_entry_set(target=target, data=action_data)

        try:
            ipkt = testutils.simple_udp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='00:00:00:00:00:00',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               udp_sport=0x1234,
                                               udp_dport=0xabcd,
                                               with_udp_chksum=True)

            epkt = testutils.simple_udp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='00:00:00:00:00:00',
                                               ip_src='4.3.2.1',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               udp_sport=0x4321,
                                               udp_dport=0xabcd,
                                               with_udp_chksum=False)
            # We expect the packet to have the same TCP checksum as the packet
            # we sent in. Calling str forces scapy to calculate the checksum
            # for the given layer.
            epkt[scapy.all.IP].chksum = ipkt[scapy.all.IP].__class__(
                str(ipkt[scapy.all.IP])).chksum
            epkt[scapy.all.UDP].chksum = ipkt[scapy.all.UDP].__class__(
                str(ipkt[scapy.all.UDP])).chksum

            testutils.send_packet(self, swports[0], ipkt)
            testutils.verify_packet(self, epkt, swports[1])
        finally:
            table_output_port.default_entry_reset(target)
            table_translate.default_entry_reset(target)
示例#7
0
    def test_reply_qinq(self, port_number):
        intf = 'iif%d' % port_number
        stag = 10
        ctag = 20
        self.client.add_interface(intf)
        self.client.add_ip(intf, stag, ctag, 0x01020304)
        src_mac = self.my_mac[port_number]
        packet = simple_arp_packet(
            pktlen=42,
            eth_src=src_mac,
            ip_snd='1.2.3.1',
            ip_tgt='1.2.3.4',
            hw_snd=src_mac,
            hw_tgt='00:00:00:00:00:00',
        )
        tagged_packet = self.insert_tags(packet, stag, ctag)
        testutils.send_packet(self, (0, port_number), tagged_packet)
        self.client.del_ip(intf, stag, ctag)
        self.client.del_interface(intf)

        exp_packet = simple_arp_packet(pktlen=42,
                                       eth_dst=src_mac,
                                       eth_src=self.remote_mac[port_number],
                                       arp_op=2,
                                       ip_snd='1.2.3.4',
                                       ip_tgt='1.2.3.1',
                                       hw_snd=self.remote_mac[port_number],
                                       hw_tgt=src_mac)
        tagged_exp_packet = self.insert_tags(exp_packet, stag, ctag)
        testutils.verify_packet(self, tagged_exp_packet, port_number)
示例#8
0
 def verify_packet(self, exp_pkt, port):
     port_list = []
     port_list.append(port)
     if self.generate_tv:
         tvutils.add_traffic_expectation(self.tc, port_list, exp_pkt)
     else:
         testutils.verify_packet(self, exp_pkt, port)
示例#9
0
def generate_and_verify_traffic(duthost1,
                                duthost2,
                                ptfadapter,
                                ptfhost,
                                src_port,
                                dst_ip,
                                router_mac,
                                get_routes,
                                collect,
                                down_link_on_dut=None,
                                pkt_action=ACTION_FORWARD):
    """
    Generate traffic, send and verify it
    Args:
        duthost1: DUT host object
        duthost2: DUT host object
        ptfadapter: PTF adapter
        ptfhost: PTF host object
        src_port: Source port from which pkt will be sent
        dst_ip: Destination ip address
        get_routes: Dict with routes for each DUT
        collect: Fixture which collects main info about link connection
        down_link_on_dut: Name of DUT on which link is down
        pkt_action: Action to verify, forward or drop
    """
    router1_mac = duthost1.facts["router_mac"]
    router2_mac = duthost2.facts["router_mac"]
    dst_ports = get_dst_port(duthost1, duthost2, get_routes, dst_ip, collect)
    src_port = get_port_number(ptfhost, src_port)
    pkt = craft_pkt(ptfadapter, router_mac, src_port, dst_ip)
    expected_src_mac = router1_mac if dst_ports == collect[
        duthost1.hostname]['vm_link_on_ptf'] else router2_mac

    exp_pkt = pkt.copy()
    if down_link_on_dut:
        exp_ttl = predict_exp_ttl(duthost1, duthost2, dst_ip, down_link_on_dut)
        exp_pkt[packet.IP].ttl = exp_ttl
    exp_pkt[packet.Ether].src = unicode(expected_src_mac)

    exp_pkt = mask.Mask(exp_pkt)
    exp_pkt.set_do_not_care_scapy(packet.Ether, "dst")
    exp_pkt.set_do_not_care_scapy(packet.IP, "id")
    exp_pkt.set_do_not_care_scapy(packet.IP, "chksum")
    exp_pkt.set_do_not_care_scapy(packet.TCP, "chksum")
    if not down_link_on_dut:
        exp_pkt.set_do_not_care_scapy(packet.IP, "ttl")

    ptfadapter.dataplane.flush()
    time.sleep(2)

    logger.info(
        "Sending pkt from port {} to dst_ip = {}, expected dst_port = {}".
        format(src_port, dst_ip, dst_ports))
    logger.info(pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%"))
    testutils.send(ptfadapter, src_port, pkt)

    if pkt_action == ACTION_FORWARD:
        testutils.verify_packet(ptfadapter, exp_pkt, dst_ports)
    elif pkt_action == ACTION_DROP:
        testutils.verify_no_packet(ptfadapter, exp_pkt, dst_ports)
示例#10
0
    def doRunTest(self, pkt, sid_list):
        if IPv6 not in pkt or Ether not in pkt:
            self.fail("Cannot do IPv6 test with packet that is not IPv6")
        # l2_my_station -> srv6_transit -> l3_table -> l2_exact_table
        self.add_l2_my_station_entry(SWITCH1_MAC)
        sid_len = len(sid_list)
        getattr(self,
                "add_srv6_transit_%dsegment_entry" % sid_len)(pkt[IPv6].dst,
                                                              128, *sid_list)
        self.add_l3_ecmp_entry(sid_list[0], 128, [SWITCH2_MAC])
        self.add_l2_exact_entry(SWITCH2_MAC, self.port2)

        exp_pkt = Ether(src=SWITCH1_MAC, dst=SWITCH2_MAC)
        exp_pkt /= IPv6(dst=sid_list[0], src=pkt[IPv6].src, hlim=63)
        exp_pkt /= IPv6ExtHdrSegmentRouting(nh=pkt[IPv6].nh,
                                            addresses=sid_list[::-1],
                                            len=sid_len * 2,
                                            segleft=sid_len - 1,
                                            lastentry=sid_len - 1)
        exp_pkt /= pkt[IPv6].payload

        if ICMPv6EchoRequest in exp_pkt:
            # FIXME: the P4 pipeline should calculate correct ICMPv6 checksum
            exp_pkt[ICMPv6EchoRequest].cksum = pkt[ICMPv6EchoRequest].cksum

        testutils.send_packet(self, self.port1, str(pkt))
        testutils.verify_packet(self, exp_pkt, self.port2)
示例#11
0
    def runTest(self):
        target = gc.Target(device_id=0, pipe_id=0xffff)
        # Get bfrt_info and set it as part of the test
        bfrt_info = self.interface.bfrt_info_get(p4_program_name)

        # Set default output port
        table_output_port = bfrt_info.table_get("SwitchIngress.output_port")
        action_data = table_output_port.make_data(
            action_name="SwitchIngress.set_output_port",
            data_field_list_in=[gc.DataTuple(name="port_id", val=swports[1])])
        table_output_port.default_entry_set(target=target, data=action_data)

        try:
            ipkt = testutils.simple_tcp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='22:33:44:55:66:77',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               tcp_sport=0x1234,
                                               tcp_dport=0xabcd,
                                               with_tcp_chksum=True)

            epkt = ipkt

            testutils.send_packet(self, swports[0], ipkt)
            testutils.verify_packet(self, epkt, swports[1])
        finally:
            table_output_port.default_entry_reset(target)
示例#12
0
    def runTest(self):
        pkt = "ab" * 20

        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_packet(self, pkt, (1, 1))

        # We remove a port to test port_remove, but in order to execute
        # subsequent tests, we need to make sure we re-add the port
        # afterwards. In order to re-add the port, we need the interface name,
        # which is what this method is for. This is a little hacky but fine for
        # testing. In practice, you would not be removing ports which are part
        # of the original ptf config.
        def find_ifname(device_number, port_number):
            for port_id, ifname in config["port_map"].items():
                if (device_number, port_number) == port_id:
                    return ifname

        ifname = find_ifname(1, 1)
        self.assertTrue(self.dataplane.port_remove(1, 1))
        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_no_other_packets(self, device_number=1)

        self.dataplane.port_add(ifname, 1, 1)
        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_packet(self, pkt, (1, 1))
示例#13
0
    def runTest(self):
        def check_counters(device, port):
            counters = self.dataplane.get_nn_counters(device, port)
            self.assertIsNotNone(counters)
            self.assertTrue(type(counters) is tuple)
            self.assertEqual(len(counters), 2)

            return counters

        counters_01_b = check_counters(0, 1)
        counters_11_b = check_counters(1, 1)
        print "Counters:"
        print " (0, 1) %d:%d" % counters_01_b
        print " (1, 1) %d:%d" % counters_11_b
        pkt = "ab" * 20
        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_packet(self, pkt, (1, 1))
        counters_01_e = check_counters(0, 1)
        counters_11_e = check_counters(1, 1)
        print "Counters:"
        print " (0, 1) %d:%d" % counters_01_e
        print " (1, 1) %d:%d" % counters_11_e
        self.assertTrue(counters_01_e[1] > counters_01_b[1])
        self.assertTrue(counters_11_e[0] > counters_11_b[0])
示例#14
0
    def runTest(self):
        def check_counters(device, port):
            counters = self.dataplane.get_nn_counters(device, port)
            self.assertIsNotNone(counters)
            self.assertTrue(type(counters) is tuple)
            self.assertEqual(len(counters), 2)

            return counters

        counters_01_b = check_counters(0, 1)
        counters_11_b = check_counters(1, 1)
        print "Counters:"
        print " (0, 1) %d:%d" % counters_01_b
        print " (1, 1) %d:%d" % counters_11_b
        pkt = "ab" * 20
        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_packet(self, pkt, (1, 1))
        counters_01_e = check_counters(0, 1)
        counters_11_e = check_counters(1, 1)
        print "Counters:"
        print " (0, 1) %d:%d" % counters_01_e
        print " (1, 1) %d:%d" % counters_11_e
        self.assertTrue(counters_01_e[1] > counters_01_b[1])
        self.assertTrue(counters_11_e[0] > counters_11_b[0])
示例#15
0
    def test(self, pkt):
        mcast_group_id = 10
        mcast_ports = [self.port1, self.port2, self.port3]

        self.add_mcast_group(group_id=mcast_group_id, ports=mcast_ports)
        self.add_l2_ternary_entry(eth_dst=MAC_BROADCAST,
                                  eth_dst_mask=MAC_FULL_MASK,
                                  mcast_group_id=mcast_group_id)
        self.add_l2_ternary_entry(eth_dst=MAC_MULTICAST,
                                  eth_dst_mask=MAC_MULTICAST_MASK,
                                  mcast_group_id=mcast_group_id)

        self.add_acl_cpu_entry(eth_type=ARP_ETH_TYPE, clone=True)
        self.add_acl_cpu_entry(eth_type=IPV6_ETH_TYPE,
                               ip_proto=ICMPV6_IP_PROTO,
                               icmp_type=NS_ICMPV6_TYPE,
                               clone=True)
        self.add_clone_session(CPU_CLONE_SESSION_ID, [self.cpu_port])

        for inport in mcast_ports:
            testutils.send_packet(self, inport, str(pkt))
            # Pkt should be received on CPU and on all ports
            # except the ingress one.
            self.verify_packet_in(exp_pkt=pkt, exp_in_port=inport)
            verify_ports = set(mcast_ports)
            verify_ports.discard(inport)
            for port in verify_ports:
                testutils.verify_packet(self, pkt, port)
        testutils.verify_no_other_packets(self)
示例#16
0
    def runTest(self):
        target = gc.Target(device_id=0, pipe_id=0xffff)
        # Get bfrt_info and set it as part of the test
        bfrt_info = self.interface.bfrt_info_get(p4_program_name)

        # Set default output port
        ipv4_match_regular = bfrt_info.table_get("SwitchIngress.ipv4_match_regular")
        action_data = ipv4_match_regular.make_data(
            action_name="SwitchIngress.set_output_port",
            data_field_list_in=[gc.DataTuple(name="port_id", val=swports[0])]
        )
        ipv4_match_regular.default_entry_set(
            target=target,
            data=action_data)

        try:
            ipkt = testutils.simple_udp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='22:22:22:22:22:22',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               udp_sport=0x1234,
                                               udp_dport=0xabcd)

            testutils.send_packet(self, swports[0], ipkt)
            testutils.verify_packet(self, ipkt, swports[0])

        finally:
            ipv4_match_regular.default_entry_reset(target)
示例#17
0
    def _verify_acl_traffic(self, setup, direction, ptfadapter, pkt, dropped,
                            ip_version):
        exp_pkt = self.expected_mask_routed_packet(pkt, ip_version)

        if ip_version == "ipv4":
            downstream_dst_port = DOWNSTREAM_IP_PORT_MAP.get(
                pkt[packet.IP].dst)
        else:
            downstream_dst_port = DOWNSTREAM_IP_PORT_MAP.get(
                pkt[packet.IPv6].dst)
        ptfadapter.dataplane.flush()
        testutils.send(ptfadapter, self.src_port, pkt)
        if direction == "uplink->downlink" and downstream_dst_port:
            if dropped:
                testutils.verify_no_packet(ptfadapter, exp_pkt,
                                           downstream_dst_port)
            else:
                testutils.verify_packet(ptfadapter, exp_pkt,
                                        downstream_dst_port)
        else:
            if dropped:
                testutils.verify_no_packet_any(ptfadapter,
                                               exp_pkt,
                                               ports=self.get_dst_ports(
                                                   setup, direction))
            else:
                testutils.verify_packet_any_port(ptfadapter,
                                                 exp_pkt,
                                                 ports=self.get_dst_ports(
                                                     setup, direction),
                                                 timeout=20)
示例#18
0
def send_recv_eth(duthost, ptfadapter, source_ports, source_mac, dest_ports,
                  dest_mac, src_vlan, dst_vlan):
    """
    send ethernet packet and verify it on dest_port
    :param ptfadapter: PTF adapter object
    :param source_port: source port
    :param source_mac: source MAC
    :param dest_port: destination port to receive packet on
    :param dest_mac: destination MAC
    :param vlan_id: VLAN id
    :return:
    """
    pkt = simple_eth_packet(eth_dst=dest_mac,
                            eth_src=source_mac,
                            vlan_vid=src_vlan)
    exp_pkt = simple_eth_packet(eth_dst=dest_mac,
                                eth_src=source_mac,
                                vlan_vid=dst_vlan)
    if dst_vlan:
        # expect to receive tagged packet:
        # sonic device might modify the 802.1p field,
        # need to use Mask to ignore the priority field.
        exp_pkt = Mask(exp_pkt)
        exp_pkt.set_do_not_care_scapy(scapy.Dot1Q, "prio")
    logger.debug(
        'send packet src port {} smac: {} dmac: {} vlan: {} verifying on dst port {}'
        .format(source_ports, source_mac, dest_mac, src_vlan, dest_ports))

    # fdb test will send lots of pkts between paired ports, it's hard to guarantee there is no congestion
    # on server side during this period. So tolerant to retry 3 times before complain the assert.

    retry_count = 3
    for _ in range(retry_count):
        try:
            ptfadapter.dataplane.flush()
            testutils.send(ptfadapter, source_ports[0], pkt)
            if len(dest_ports) == 1:
                testutils.verify_packet(
                    ptfadapter,
                    exp_pkt,
                    dest_ports[0],
                    timeout=FDB_WAIT_EXPECTED_PACKET_TIMEOUT)
            else:
                testutils.verify_packet_any_port(
                    ptfadapter,
                    exp_pkt,
                    dest_ports,
                    timeout=FDB_WAIT_EXPECTED_PACKET_TIMEOUT)
            break
        except:
            pass
    else:
        result = duthost.command("show mac", module_ignore_errors=True)
        logger.debug("Show mac results {}".format(result['stdout']))
        pytest_assert(
            False, "Expected packet was not received on ports {}"
            "Dest MAC in fdb is {}".format(
                dest_ports,
                dest_mac.lower() in result['stdout'].lower()))
示例#19
0
 def runTest(self):
     pktlen = 400
     pkt = testutils.simple_ipv6ip_packet(pktlen=pktlen)
     self.assertEqual(len(pkt), pktlen)
     testutils.send_packet(self, (0, 1), pkt)
     print("packet sent")
     testutils.verify_packet(self, pkt, (1, 1))
     testutils.verify_no_other_packets(self, 1)
示例#20
0
    def runTest(self):
        self.setup_int()

        dport = 5060

        # int_type=hop-by-hop
        int_shim = INT_L45_HEAD(int_type=1, length=4)
        # ins_cnt: 5 = switch id + ports + q occupancy + ig port + eg port)
        # max_hop_count: 3
        # total_hop_count: 0
        # instruction_mask_0003: 0xd = switch id (0), ports (1), q occupancy (3)
        # instruction_mask_0407: 0xc = ig timestamp (4), eg timestamp (5)
        int_header = "\x00\x05\x03\x00\xdc\x00\x00\x00"
        # IP proto (UDP), UDP dport (4096)
        int_tail = INT_L45_TAIL(next_proto=17, proto_param=dport)

        payload = "\xab" * 128
        inner_udp = UDP(sport=5061, dport=dport, chksum=0)
        # IP tos is 0x04 to enable INT
        pkt = Ether(src=self.DMAC_2, dst=self.SWITCH_MAC_2) / \
              IP(tos=0x04, src=self.S1U_ENB_IPV4, dst=self.END_POINT_IPV4) / \
              inner_udp / \
              int_shim / int_header / int_tail / \
              payload

        exp_int_shim = INT_L45_HEAD(int_type=1, length=9)
        # total_hop_count: 1
        exp_int_header = "\x00\x05\x03\x01\xdc\x00\x00\x00"
        # switch id: 1
        exp_int_metadata = "\x00\x00\x00\x01"
        # ig port: port2, eg port: port2
        exp_int_metadata += stringify(self.port2, 2) + stringify(self.port1, 2)
        # q id: 0, q occupancy: ?
        exp_int_metadata += "\x00\x00\x00\x00"
        # ig timestamp: ?
        # eg timestamp: ?
        exp_int_metadata += "\x00\x00\x00\x00" * 2

        exp_int = exp_int_shim / exp_int_header / exp_int_metadata / int_tail

        exp_pkt = Ether(src=self.SWITCH_MAC_1, dst=self.DMAC_1) / \
                  MPLS(label=self.mpls_label, cos=0, s=1, ttl=64) / \
                  IP(tos=0, id=0x1513, flags=0, frag=0,
                     src=self.S1U_SGW_IPV4, dst=self.S1U_ENB_IPV4) / \
                  UDP(sport=2152, dport=2152, chksum=0) / \
                  make_gtp(20 + len(inner_udp) + len(exp_int) + len(payload), 1) / \
                  IP(tos=0x04, src=self.S1U_ENB_IPV4, dst=self.END_POINT_IPV4, ttl=64) / \
                  inner_udp / \
                  exp_int / \
                  payload
        # We mask off the timestamps as well as the queue occupancy
        exp_pkt = Mask(exp_pkt)
        offset_metadata = 14 + 4 + 20 + 8 + 8 + 20 + 8 + 4 + 8
        exp_pkt.set_do_not_care((offset_metadata + 9) * 8, 11 * 8)

        testutils.send_packet(self, self.port2, str(pkt))
        testutils.verify_packet(self, exp_pkt, self.port1)
示例#21
0
    def runTest(self):
        pkt = genNdpNsPkt(HOST1_MAC, HOST1_IPV6, SWITCH1_IPV6)
        exp_pkt = genNdpNaPkt(SWITCH1_MAC, IPV6_MCAST_MAC_1, SWITCH1_IPV6,
                              HOST1_IPV6)

        self.add_ndp_reply_entry(SWITCH1_IPV6, SWITCH1_MAC)

        testutils.send_packet(self, self.port1, str(pkt))
        testutils.verify_packet(self, exp_pkt, self.port1)
示例#22
0
    def runTest(self):
        pkt = testutils.simple_tcp_packet(pktlen=100)

        try:
            testutils.send_packet(self, (0, 1), pkt)
        except Exception as e:
            print(e)

        testutils.verify_packet(self, pkt, (1, 1))
示例#23
0
    def runTest(self):
        pktlen = 70
        pkt = testutils.simple_ipv4ip_packet(pktlen=pktlen)
        pkt2 = testutils.simple_ipv4ip_packet(pktlen=pktlen,
                                              inner_frame=pkt["IP"])

        testutils.send_packet(self, (0, 1), pkt2)
        print("packet sent")
        testutils.verify_packet(self, pkt2, (1, 1))
        testutils.verify_no_other_packets(self, 1)
示例#24
0
    def verify_packet_out(self, pkt, out_port):
        port_hex = stringify(out_port, 2)
        packet_out = p4runtime_pb2.PacketOut()
        packet_out.payload = str(pkt)
        egress_physical_port = packet_out.metadata.add()
        egress_physical_port.metadata_id = 1
        egress_physical_port.value = port_hex

        self.send_packet_out(packet_out)
        testutils.verify_packet(self, pkt, out_port)
示例#25
0
    def runTest(self):
        def check_mac(device, port):
            mac = self.dataplane.get_mac(device, port)
            self.assertIsNotNone(mac)
            self.assertEqual(mac.count(":"), 5)

        check_mac(0, 1)
        pkt = "ab" * 20
        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_packet(self, pkt, (1, 1))
        check_mac(1, 1)
示例#26
0
    def runPacketOutTest(self, pkt):
        for port in [self.port1, self.port2]:
            port_hex = stringify(port, 2)
            packet_out = p4runtime_pb2.PacketOut()
            packet_out.payload = str(pkt)
            egress_physical_port = packet_out.metadata.add()
            egress_physical_port.metadata_id = 1
            egress_physical_port.value = port_hex

            self.send_packet_out(packet_out)
            testutils.verify_packet(self, pkt, port)
        testutils.verify_no_other_packets(self)
示例#27
0
    def runTest(self):
        target = gc.Target(device_id=0, pipe_id=0xffff)

        # Get bfrt_info
        bfrt_info = self.interface.bfrt_info_get(p4_program_name)

        # Set default output port
        table_output_port = bfrt_info.table_get("SwitchIngress.output_port")
        action_data = table_output_port.make_data(
            action_name="SwitchIngress.set_output_port",
            data_field_list_in=[gc.DataTuple(name="port_id", val=swports[1])])
        table_output_port.default_entry_set(target=target, data=action_data)

        # Add bridge_md to ig_intr_md
        table_bridge_md_ctl = bfrt_info.table_get(
            "SwitchIngress.bridge_md_ctrl")

        action_data = table_bridge_md_ctl.make_data(
            [
                gc.DataTuple(name="dst_mac_addr_low", val=0xffeeddcc),
                gc.DataTuple(name="src_mac_addr_low", val=0x11223344),
            ],
            action_name="SwitchIngress.bridge_add_example_hdr")

        table_bridge_md_ctl.default_entry_set(target=target, data=action_data)

        try:
            ipkt = testutils.simple_tcp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='22:22:22:22:22:22',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               tcp_sport=0x1234,
                                               tcp_dport=0xabcd,
                                               with_tcp_chksum=True)

            epkt = testutils.simple_tcp_packet(eth_dst='00:00:ff:ee:dd:cc',
                                               eth_src='00:00:11:22:33:44',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               tcp_sport=0x1234,
                                               tcp_dport=0xabcd,
                                               with_tcp_chksum=True)

            testutils.send_packet(self, swports[0], ipkt)

            testutils.verify_packet(self, epkt, swports[1])
        finally:
            table_output_port.default_entry_reset(target)
            table_bridge_md_ctl.default_entry_reset(target)
示例#28
0
    def verify_relayed_reply(self):
        # Create a packet resembling a DHCPv6 REPLY packet
        reply_packet = self.create_dhcp_reply_packet()

        # Mask off fields we don't care about matching
        masked_packet = Mask(reply_packet)
        masked_packet.set_do_not_care_scapy(IPv6, "fl")
        masked_packet.set_do_not_care_scapy(packet.UDP, "chksum")
        masked_packet.set_do_not_care_scapy(packet.UDP, "len")

        # NOTE: verify_packet() will fail for us via an assert, so no need to check a return value here
        testutils.verify_packet(self, masked_packet, self.client_port_index)
示例#29
0
    def runTest(self):
        target = gc.Target(device_id=0, pipe_id=0xffff)
        # Get bfrt_info and set it as part of the test
        bfrt_info = self.interface.bfrt_info_get(p4_program_name)

        # Set default output port
        table_output_port = bfrt_info.table_get("SwitchIngress.output_port")
        action_data = table_output_port.make_data(
            action_name="SwitchIngress.set_output_port",
            data_field_list_in=[gc.DataTuple(name="port_id", val=swports[1])])
        table_output_port.default_entry_set(target=target, data=action_data)

        # Set a default entry in the rewrite table so all packets get
        # their checksum updated.
        table_translate = bfrt_info.table_get("SwitchIngress.translate")

        action_data = table_translate.make_data(
            action_name="SwitchIngress.sntpat",
            data_field_list_in=[
                gc.DataTuple(name="src_addr", val=gc.ipv4_to_bytes("4.3.2.1")),
                gc.DataTuple(name="src_port", val=gc.to_bytes(0x4321, 2)),
                gc.DataTuple(name="update", val=0x1)
            ],
        )

        table_translate.default_entry_set(target=target, data=action_data)

        try:
            ipkt = testutils.simple_tcp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='00:00:00:00:00:00',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               tcp_sport=0x1234,
                                               tcp_dport=0xabcd,
                                               with_tcp_chksum=True)

            epkt = testutils.simple_tcp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='00:00:00:00:00:00',
                                               ip_src='4.3.2.1',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               tcp_sport=0x4321,
                                               tcp_dport=0xabcd,
                                               with_tcp_chksum=True)

            testutils.send_packet(self, swports[0], ipkt)
            testutils.verify_packet(self, epkt, swports[1])
        finally:
            table_output_port.default_entry_reset(target)
            table_translate.default_entry_reset(target)
示例#30
0
    def runTest(self):
        pktlen = 1000
        udp = testutils.simple_udp_packet()
        ipv6 = testutils.simple_ipv6ip_packet(inner_frame=udp['UDP'])
        gre = testutils.simple_grev6_packet(pktlen=pktlen,
                                            inner_frame=ipv6["IPv6"])

        self.assertEqual(gre['GRE'].proto, 0x86DD)
        testutils.send_packet(self, (0, 1), gre)
        print("packet sent")
        testutils.verify_packet(self, gre, (1, 1))
        testutils.verify_no_other_packets(self, 1)
示例#31
0
文件: test.py 项目: mbrar/ptf
    def runTest(self):
        def check_mac(device, port):
            mac = self.dataplane.get_mac(device, port)
            self.assertIsNotNone(mac)
            self.assertEqual(mac.count(":"), 5)

        check_mac(0, 1)
        pkt = "ab" * 20
        testutils.send_packet(self, (0, 1), str(pkt))
        print "packet sent"
        testutils.verify_packet(self, pkt, (1, 1))
        check_mac(1, 1)
示例#32
0
    def runTest(self):
        target = gc.Target(device_id=0, pipe_id=0xffff)

        # Get bfrt_info and set it as part of the test
        bfrt_info = self.interface.bfrt_info_get(p4_program_name)

        ipv4_match_regular = bfrt_info.table_get("SwitchIngress.ipv4_match_regular")
        ipv4_match_regular.info.key_field_annotation_add('hdr.ethernet.dst_addr',
                                                         'mac')
        ipv4_match_regular.info.key_field_annotation_add('hdr.ethernet.src_addr',
                                                         'mac')
        ipv4_match_regular.info.key_field_annotation_add('hdr.ipv4.dst_addr',
                                                         'ipv4')
        ipv4_match_regular.info.key_field_annotation_add('hdr.ipv4.src_addr',
                                                         'ipv4')

        key_data_regular = ipv4_match_regular.make_key([
            gc.KeyTuple(name='hdr.ethernet.dst_addr',
                        value='11:11:11:11:11:11'),
            gc.KeyTuple(name='hdr.ethernet.src_addr',
                        value='22:22:22:22:22:22'),
            gc.KeyTuple(name='hdr.ipv4.dst_addr',
                        value='100.99.98.97'),
            gc.KeyTuple(name='hdr.ipv4.src_addr',
                        value='1.2.3.4'),
        ])

        action_data_regular = ipv4_match_regular.make_data(
            [gc.DataTuple(name='port_id', val=swports[3])], 'SwitchIngress.set_output_port'
        )

        ipv4_match_regular.entry_add(
            target,
            [key_data_regular],
            [action_data_regular])

        try:
            ipkt = testutils.simple_udp_packet(eth_dst='11:11:11:11:11:11',
                                               eth_src='22:22:22:22:22:22',
                                               ip_src='1.2.3.4',
                                               ip_dst='100.99.98.97',
                                               ip_id=101,
                                               ip_ttl=64,
                                               udp_sport=0x1234,
                                               udp_dport=0xabcd)

            testutils.send_packet(self, swports[0], ipkt)
            testutils.verify_packet(self, ipkt, swports[3])

        finally:
            ipv4_match_regular.default_entry_reset(target)
            ipv4_match_regular.entry_del(target, [key_data_regular])
示例#33
0
 def runTest(self):
     pkt = "ab" * 20
     testutils.send_packet(self, (0, 1), str(pkt))
     print "packet sent"
     testutils.verify_packet(self, pkt, (1, 1))