Ejemplo n.º 1
0
    def runTest(self):
        in_dmac = 'ee:30:ca:9d:1e:00'
        in_smac = 'ee:cd:00:7e:70:00'
        ip_dst_addr = '10.1.0.1'
        ig_port = 1

        eg_port = 2
        l2ptr = 58
        bd = 9
        out_dmac = '02:13:57:ab:cd:ef'
        out_smac = '00:11:22:33:44:55'

        # Before adding any table entries, the default behavior for
        # sending in an IPv4 packet is to drop it.
        pkt = tu.simple_tcp_packet(eth_src=in_smac, eth_dst=in_dmac,
                                   ip_dst=ip_dst_addr, ip_ttl=64)
        tu.send_packet(self, ig_port, pkt)
        tu.verify_no_other_packets(self)
        
        # Add a set of table entries that the packet should match, and
        # be forwarded out with the desired dest and source MAC
        # addresses.
        self.table_add(self.key_ipv4_da_lpm(ip_dst_addr, 32),
                       self.act_set_l2ptr(l2ptr))
        self.table_add(self.key_mac_da(l2ptr),
                       self.act_set_bd_dmac_intf(bd, out_dmac, eg_port))
        self.table_add(self.key_send_frame(bd), self.act_rewrite_mac(out_smac))

        # Check that the entry is hit, expected source and dest MAC
        # have been written into output packet, TTL has been
        # decremented, and that no other packets are received.
        exp_pkt = tu.simple_tcp_packet(eth_src=out_smac, eth_dst=out_dmac,
                                       ip_dst=ip_dst_addr, ip_ttl=63)
        tu.send_packet(self, ig_port, pkt)
        tu.verify_packets(self, exp_pkt, [eg_port])
Ejemplo n.º 2
0
    def runTest(self):
        ip_dst_addr = "10.0.0.1"
        ip_dst_addr_str = ipv4_to_binary(ip_dst_addr)
        ig_port = self.swports(1)
        eg_port = self.swports(2)
        # port is 9-bit in v1model, i.e. 2 bytes
        eg_port_str = stringify(eg_port, 2)
        smac = "\xee\xcd\x00\x7e\x70\x00"
        dmac = "\xee\x30\xca\x9d\x1e\x00"

        # we do not care about the src mac address or the src IP address
        pkt = testutils.simple_tcp_packet(eth_dst=smac,
                                          ip_dst=ip_dst_addr,
                                          ip_ttl=64)

        # no forwarding entry: packet must be dropped
        testutils.send_packet(self, ig_port, pkt)
        testutils.verify_no_other_packets(self)

        # add a forwarding entry
        self.send_request_add_entry_to_action(
            "l3_host_fwd", [self.Exact("hdr.ipv4.dst_addr", ip_dst_addr_str)],
            "set_nexthop", [("port", eg_port_str), ("smac", smac),
                            ("dmac", dmac)])

        # check that the entry is hit and that no other packets are received
        exp_pkt = testutils.simple_tcp_packet(eth_src=smac,
                                              eth_dst=dmac,
                                              ip_dst=ip_dst_addr,
                                              ip_ttl=63)
        testutils.send_packet(self, ig_port, pkt)
        testutils.verify_packets(self, exp_pkt, [eg_port])
Ejemplo n.º 3
0
    def runTest(self):
        ig_ports = [swports[1], swports[2]]
        eg_ports = [swports[2], swports[1]]
        ip2 = "2001:0000:0000::0000:0000:0002"
        ip1 = "2001:0000:0000::0000:0000:0001"
        mac2 = "00:00:00:00:00:02"
        mac1 = "00:00:00:00:00:01"
        # send pkt and verify sent
        pkt = testutils.simple_tcpv6_packet(eth_dst=mac2,
                                            eth_src=mac1,
                                            ipv6_dst=ip2)
        exp_pkt = pkt
        logger.info("Sending packet on port %d", ig_ports[0])
        testutils.send_packet(self, ig_ports[0], str(pkt))

        logger.info("Expecting packet on port %d", eg_ports[0])
        testutils.verify_packets(self, exp_pkt, [eg_ports[0]])

        # send pkt and verify sent
        pkt = testutils.simple_tcpv6_packet(eth_dst=mac1,
                                            eth_src=mac2,
                                            ipv6_dst=ip1)
        exp_pkt = pkt
        logger.info("Sending packet on port %d", ig_ports[1])
        testutils.send_packet(self, ig_ports[1], str(pkt))

        logger.info("Expecting packet on port %d", eg_ports[1])
        testutils.verify_packets(self, exp_pkt, [eg_ports[1]])
Ejemplo n.º 4
0
    def runTest(self):
        ig_ports = [swports[1], swports[2]]
        eg_ports = [swports[2], swports[1]]
        ip2 = "10.0.2.1"
        ip1 = "10.0.1.1"
        mac2 = "00:00:00:00:00:02"
        mac1 = "00:00:00:00:00:01"
        # send pkt and verify sent
        pkt = testutils.simple_tcp_packet(eth_dst=mac2, eth_src=mac1,
                                          ip_dst=ip2, with_tcp_chksum=False)
        exp_pkt = pkt
        logger.info("Sending packet on port %d", ig_ports[0])
        testutils.send_packet(self, ig_ports[0], str(pkt))

        logger.info("Expecting packet on port %d", eg_ports[0]) 
        testutils.verify_packets(self, exp_pkt, [eg_ports[0]])

        # send pkt and verify sent
        pkt = testutils.simple_tcp_packet(eth_dst=mac1, eth_src=mac2,
                                          ip_dst=ip1, with_tcp_chksum=False)
        exp_pkt = pkt
        logger.info("Sending packet on port %d", ig_ports[1])
        testutils.send_packet(self, ig_ports[1], str(pkt))

        logger.info("Expecting packet on port %d", eg_ports[1]) 
        testutils.verify_packets(self, exp_pkt, [eg_ports[1]])
Ejemplo n.º 5
0
    def runTest(self):
        in_dmac = 'ee:30:ca:9d:1e:00'
        in_smac = 'ee:cd:00:7e:70:00'
        ip_dst_addr = '100.2.3.4'

        # No table entries required for testing this P4 program
        # behavior.  Just send in a packet from the controller to the
        # switch, and verify that it sends a packet out of the proper
        # switch port.

        ttl_in = 200
        for eg_port in [5, 8]:
            pkt = tu.simple_tcp_packet(eth_src=in_smac, eth_dst=in_dmac,
                                       ip_dst=ip_dst_addr, ip_ttl=ttl_in)
            exp_pkt = pkt
            pktout_dict = {'payload': bytes(pkt),
                           'metadata': {
                               'opcode': self.opcode_name2int['SEND_TO_PORT_IN_OPERAND0'],
                               'reserved1': 0,
                               'operand0': eg_port,
                               'operand1': 0,
                               'operand2': 0,
                               'operand3': 0}}
            pktout_pb = self.encode_packet_out_metadata(pktout_dict)
            self.send_packet_out(pktout_pb)
            tu.verify_packets(self, exp_pkt, [eg_port])
            # Verify that no PacketIn message was received
            pkt_pb = self.get_packet_in()
            assert pkt_pb is None
Ejemplo n.º 6
0
    def runTest(self):
        mac_addr_mask = ":".join(["ff"] * 6)
        vlan_id = 10
        self.set_internal_vlan(self.port1, False, 0, 0, vlan_id)
        self.set_internal_vlan(self.port2, False, 0, 0, vlan_id)
        # miss on filtering.fwd_classifier => bridging
        self.add_bridging_entry(vlan_id, HOST1_MAC, mac_addr_mask, 10)
        self.add_bridging_entry(vlan_id, HOST2_MAC, mac_addr_mask, 20)
        self.add_next_hop(10, self.port1)
        self.add_next_hop(20, self.port2)
        self.set_egress_vlan_pop(self.port1, vlan_id)
        self.set_egress_vlan_pop(self.port2, vlan_id)

        pkt_1to2 = testutils.simple_tcp_packet(eth_src=HOST1_MAC,
                                               eth_dst=HOST2_MAC,
                                               ip_ttl=64)
        exp_pkt_1to2 = testutils.simple_tcp_packet(eth_src=HOST1_MAC,
                                                   eth_dst=HOST2_MAC,
                                                   ip_ttl=63)

        testutils.send_packet(self, self.port1, str(pkt_1to2))
        testutils.verify_packets(self, exp_pkt_1to2, [self.port2])

        pkt_2to1 = testutils.simple_tcp_packet(eth_src=HOST2_MAC,
                                               eth_dst=HOST1_MAC,
                                               ip_ttl=64)
        exp_pkt_2to1 = testutils.simple_tcp_packet(eth_src=HOST2_MAC,
                                                   eth_dst=HOST1_MAC,
                                                   ip_ttl=63)

        testutils.send_packet(self, self.port2, str(pkt_2to1))
        testutils.verify_packets(self, exp_pkt_2to1, [self.port1])
Ejemplo n.º 7
0
    def runTest(self):
        vlan_id = 10
        self.set_internal_vlan(self.port1, False, 0, 0, vlan_id)
        self.set_forwarding_type(self.port1, SWITCH_MAC, 0x800,
                                 FORWARDING_TYPE_UNICAST_IPV4)
        self.add_forwarding_unicast_v4_entry(HOST2_IPV4, 24, 500)
        grp_id = 77
        mpls_label = 0xaba
        mbrs = {2: (self.port2, SWITCH_MAC, HOST2_MAC, mpls_label)}
        self.add_next_hop_mpls_v4_group(500, grp_id, mbrs)
        self.set_egress_vlan_pop(self.port2, vlan_id)

        pkt_1to2 = testutils.simple_tcp_packet(eth_src=HOST1_MAC,
                                               eth_dst=SWITCH_MAC,
                                               ip_src=HOST1_IPV4,
                                               ip_dst=HOST2_IPV4,
                                               ip_ttl=64)
        exp_pkt_1to2 = testutils.simple_mpls_packet(eth_src=SWITCH_MAC,
                                                    eth_dst=HOST2_MAC,
                                                    mpls_tags=[{
                                                        "label":
                                                        mpls_label,
                                                        "tc":
                                                        0,
                                                        "s":
                                                        1,
                                                        "ttl":
                                                        DEFAULT_MPLS_TTL
                                                    }],
                                                    inner_frame=pkt_1to2[IP:])

        testutils.send_packet(self, self.port1, str(pkt_1to2))
        testutils.verify_packets(self, exp_pkt_1to2, [self.port2])
Ejemplo n.º 8
0
    def runTest(self):
        vlan_id = 10
        self.set_ingress_port_vlan(self.port1, False, 0, vlan_id)
        self.set_ingress_port_vlan(self.port2, False, 0, vlan_id)
        self.set_forwarding_type(self.port1, SWITCH_MAC, 0x800,
                                 FORWARDING_TYPE_UNICAST_IPV4)
        self.set_forwarding_type(self.port2, SWITCH_MAC, 0x800,
                                 FORWARDING_TYPE_UNICAST_IPV4)
        self.add_forwarding_unicast_v4_entry(HOST1_IPV4, 24, 100)
        self.add_forwarding_unicast_v4_entry(HOST2_IPV4, 24, 200)
        self.add_next_hop_L3(100, self.port1, SWITCH_MAC, HOST1_MAC)
        self.add_next_hop_L3(200, self.port2, SWITCH_MAC, HOST2_MAC)
        self.set_egress_vlan_pop(self.port1, vlan_id)
        self.set_egress_vlan_pop(self.port2, vlan_id)

        pkt_1to2 = testutils.simple_tcp_packet(
            eth_src=HOST1_MAC, eth_dst=SWITCH_MAC,
            ip_src=HOST1_IPV4, ip_dst=HOST2_IPV4, ip_ttl=64)
        exp_pkt_1to2 = testutils.simple_tcp_packet(
            eth_src=SWITCH_MAC, eth_dst=HOST2_MAC,
            ip_src=HOST1_IPV4, ip_dst=HOST2_IPV4, ip_ttl=63)

        testutils.send_packet(self, self.port1, str(pkt_1to2))
        testutils.verify_packets(self, exp_pkt_1to2, [self.port2])

        pkt_2to1 = testutils.simple_tcp_packet(
            eth_src=HOST2_MAC, eth_dst=SWITCH_MAC,
            ip_src=HOST2_IPV4, ip_dst=HOST1_IPV4, ip_ttl=64)
        exp_pkt_2to1 = testutils.simple_tcp_packet(
            eth_src=SWITCH_MAC, eth_dst=HOST1_MAC,
            ip_src=HOST2_IPV4, ip_dst=HOST1_IPV4, ip_ttl=63)

        testutils.send_packet(self, self.port2, str(pkt_2to1))
        testutils.verify_packets(self, exp_pkt_2to1, [self.port1])
Ejemplo n.º 9
0
    def runTest(self):
        mac_addr_mask = ":".join(["ff"] * 6)
        vlan_id = 10
        # set internal VLAN for port 2 only since packet from port 1 is tagged
        self.set_ingress_port_vlan(self.port2, False, 0, vlan_id)
        # miss on filtering.fwd_classifier => bridging
        self.add_bridging_entry(vlan_id, HOST1_MAC, mac_addr_mask, 10)
        self.add_bridging_entry(vlan_id, HOST2_MAC, mac_addr_mask, 20)
        self.add_next_hop(10, self.port1)
        self.add_next_hop(20, self.port2)
        # pops VLAN on port 2 since port 2 is an untagged port
        self.set_egress_vlan_pop(self.port2, vlan_id)

        pkt_1to2 = testutils.simple_tcp_packet(
            eth_src=HOST1_MAC, eth_dst=HOST2_MAC, dl_vlan_enable=True,
            vlan_vid=vlan_id, ip_ttl=64)
        exp_pkt_1to2 = testutils.simple_tcp_packet(
            eth_src=HOST1_MAC, eth_dst=HOST2_MAC,
            ip_ttl=63, pktlen=96)  # packet length will decrease

        testutils.send_packet(self, self.port1, str(pkt_1to2))
        testutils.verify_packets(self, exp_pkt_1to2, [self.port2])

        pkt_2to1 = testutils.simple_tcp_packet(
            eth_src=HOST2_MAC, eth_dst=HOST1_MAC, ip_ttl=64)
        exp_pkt_2to1 = testutils.simple_tcp_packet(
            eth_src=HOST2_MAC, eth_dst=HOST1_MAC, dl_vlan_enable=True,
            vlan_vid=vlan_id, ip_ttl=63, pktlen=104)  # packet length will increase

        testutils.send_packet(self, self.port2, str(pkt_2to1))
        testutils.verify_packets(self, exp_pkt_2to1, [self.port1])
Ejemplo n.º 10
0
 def verify_packets(self, pkt, ports):
     if self.generate_tv:
         for port in ports:
             port_list = []
             port_list.append(port)
             tvutils.add_traffic_expectation(self.tc, port_list, pkt)
     else:
         testutils.verify_packets(self, pkt, ports)
Ejemplo n.º 11
0
    def runTest(self):
        pkt = Ether(dst="11:11:11:11:11:11") / MPLS(
            label=20, cos=5, s=1,
            ttl=64) / simple_ip_only_packet(ip_dst="192.168.1.1")
        exp_pkt = Ether(dst="11:11:11:11:11:11") / simple_ip_only_packet(
            ip_dst="192.168.1.1")

        send_packet(self, (0, 1), pkt)
        verify_packets(self, exp_pkt, device_number=0, ports=[2])
Ejemplo n.º 12
0
    def runTest(self):
        pkt = simple_tcpv6_packet(ipv6_src='2001::1', ipv6_dst='2001::2')
        exp_pkt = simple_tcpv6_packet(ipv6_src='2001::2', ipv6_dst='2001::1')

        mask = Mask(exp_pkt)
        mask.set_do_not_care_scapy(TCP, 'chksum')

        send_packet(self, (0, 1), pkt)
        verify_packets(self, mask, device_number=0, ports=[2])
Ejemplo n.º 13
0
    def runTest(self):
        pkt = simple_ip_packet(ip_src="192.168.1.1", ip_tos=10)
        exp_pkt = simple_ip_packet(ip_src="192.168.1.1", ip_tos=255)

        mask = Mask(exp_pkt)
        mask.set_do_not_care_scapy(IP, 'chksum')

        send_packet(self, (0, 1), pkt)
        verify_packets(self, mask, device_number=0, ports=[2])
Ejemplo n.º 14
0
    def runTest(self):
        pkt = Ether() / IP(src="192.168.1.1") / TCP() / "Ala ma kota"
        exp_pkt = Ether() / IP(src="192.168.1.1",
                               proto=55) / TCP() / "Ala ma kota"

        mask = Mask(exp_pkt)
        mask.set_do_not_care_scapy(IP, 'chksum')

        send_packet(self, (0, 1), pkt)
        verify_packets(self, mask, device_number=0, ports=[2])
Ejemplo n.º 15
0
    def runTest(self):
        pkt = Ether() / IP(src="192.168.1.1",
                           flags=0) / TCP() / "Ala a un chat"
        exp_pkt = Ether() / IP(src="192.168.1.1",
                               flags=7) / TCP() / "Ala a un chat"

        mask = Mask(exp_pkt)
        mask.set_do_not_care_scapy(IP, 'chksum')

        send_packet(self, (0, 1), pkt)
        verify_packets(self, mask, device_number=0, ports=[2])
Ejemplo n.º 16
0
def test_fdb_bulk_remove(npu, dataplane):
    """
    Description:
    Bulk remove FDB entries and check with the traffic.

    Test scenario:
    1. Bulk create FDB entries
    2. Check no flooding for created FDB entries
    3. Bulk remove FDB entries
    4. Check flooding if no FDB entry
    5. Flush all entries by VLAN
    """
    src_mac = '00:00:00:11:22:33'
    macs = [
        '00:11:11:11:11:11', '00:22:22:22:22:22', '00:33:33:33:33:33',
        '00:44:44:44:44:44'
    ]

    for mac in macs:
        npu.create_fdb(npu.default_vlan_oid, mac, npu.dot1q_bp_oids[0])

    try:
        if npu.run_traffic:
            # Check no flooding for created FDB entries
            for mac in macs:
                pkt = simple_tcp_packet(eth_dst=mac, eth_src=src_mac)
                send_packet(dataplane, 1, pkt)
                verify_packets(dataplane, pkt, [0])

        # Bulk remove FDB entries
        keys = []
        entry = {
            "bvid": npu.default_vlan_oid,
            "switch_id": npu.oid,
        }
        for mac in macs:
            entry["mac"] = mac
            keys.append(entry.copy())

        npu.bulk_remove(SaiObjType.FDB_ENTRY, keys)

        if npu.run_traffic:
            # Check flooding if no FDB entry
            egress_ports = list(range(len(npu.port_oids)))
            egress_ports.remove(1)
            for mac in macs:
                pkt = simple_tcp_packet(eth_dst=mac, eth_src=src_mac)
                send_packet(dataplane, 1, pkt)
                verify_packets(dataplane, pkt, egress_ports)

    finally:
        npu.flush_fdb_entries(
            ["SAI_FDB_FLUSH_ATTR_BV_ID", npu.default_vlan_oid])
Ejemplo n.º 17
0
def test_fdb_bulk_create(npu, dataplane):
    """
    Description:
    Bulk create FDB entries and check with the traffic.

    Test scenario:
    1. Bulk create FDB entries
    2. Check no flooding for created FDB entries
    3. Check flooding if no FDB entry
    4. Flush all entries by VLAN
    """
    macs = [
        '00:11:11:11:11:11', '00:22:22:22:22:22', '00:33:33:33:33:33',
        '00:44:44:44:44:44'
    ]
    entry = {
        "bvid": npu.default_vlan_oid,
        "switch_id": npu.oid,
    }

    keys = []
    for mac in macs:
        entry["mac"] = mac
        keys.append(entry.copy())

    attrs = []
    attrs.append("SAI_FDB_ENTRY_ATTR_TYPE")
    attrs.append("SAI_FDB_ENTRY_TYPE_STATIC")
    attrs.append("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID")
    attrs.append(npu.dot1q_bp_oids[0])

    npu.bulk_create(SaiObjType.FDB_ENTRY, keys, [attrs])

    try:
        if npu.run_traffic:
            src_mac = '00:00:00:11:22:33'
            dst_mac = '00:00:00:aa:bb:cc'

            # Check no flooding for created FDB entries
            for mac in macs:
                pkt = simple_tcp_packet(eth_dst=mac, eth_src=src_mac)
                send_packet(dataplane, 1, pkt)
                verify_packets(dataplane, pkt, [0])

            # Check flooding if no FDB entry
            pkt = simple_tcp_packet(eth_dst=dst_mac, eth_src=src_mac)
            send_packet(dataplane, 1, pkt)
            egress_ports = list(range(len(npu.port_oids)))
            egress_ports.remove(1)
            verify_packets(dataplane, pkt, egress_ports)
    finally:
        npu.flush_fdb_entries(
            ["SAI_FDB_FLUSH_ATTR_BV_ID", npu.default_vlan_oid])
Ejemplo n.º 18
0
def test_l2_access_to_trunk_vlan(npu, dataplane):
    """
    Description:
    Check access to trunk VLAN members forwarding

    Test scenario:
    1. Create a VLAN 10
    2. Add a untagged interfaces for port 1 and  tagged interface for port 2 as members
    3. Setup static FDB entries for port 1 and port 2
    4. Send a simple untagged packet on port 1 and verify packet on port 2 (w/ Vlan 10)
    5. Clean up configuration
    """
    vlan_id = "10"
    macs = ['00:11:11:11:11:11', '00:22:22:22:22:22']

    vlan_oid = npu.create(SaiObjType.VLAN, ["SAI_VLAN_ATTR_VLAN_ID", vlan_id])

    npu.remove_vlan_member(npu.default_vlan_oid, npu.dot1q_bp_oids[0])
    npu.create_vlan_member(vlan_oid, npu.dot1q_bp_oids[0],
                           "SAI_VLAN_TAGGING_MODE_UNTAGGED")
    npu.create_vlan_member(vlan_oid, npu.dot1q_bp_oids[1],
                           "SAI_VLAN_TAGGING_MODE_TAGGED")
    npu.set(npu.port_oids[0], ["SAI_PORT_ATTR_PORT_VLAN_ID", vlan_id])

    for idx in range(2):
        npu.create_fdb(vlan_oid, macs[idx], npu.dot1q_bp_oids[idx])

    try:
        if npu.run_traffic:
            pkt = simple_tcp_packet(eth_dst=macs[1],
                                    eth_src=macs[0],
                                    ip_dst='10.0.0.1',
                                    ip_id=102,
                                    ip_ttl=64)
            exp_pkt = simple_tcp_packet(eth_dst=macs[1],
                                        eth_src=macs[0],
                                        ip_dst='10.0.0.1',
                                        dl_vlan_enable=True,
                                        vlan_vid=10,
                                        ip_id=102,
                                        ip_ttl=64,
                                        pktlen=104)
            send_packet(dataplane, 0, pkt)
            verify_packets(dataplane, exp_pkt, [1])
    finally:
        for idx in range(2):
            npu.remove_fdb(vlan_oid, macs[idx])
            npu.remove_vlan_member(vlan_oid, npu.dot1q_bp_oids[idx])
        npu.create_vlan_member(npu.default_vlan_oid, npu.dot1q_bp_oids[0],
                               "SAI_VLAN_TAGGING_MODE_UNTAGGED")
        npu.set(npu.port_oids[0],
                ["SAI_PORT_ATTR_PORT_VLAN_ID", npu.default_vlan_id])
        npu.remove(vlan_oid)
Ejemplo n.º 19
0
    def verifyPacketHits(self):
        pkt = testutils.simple_tcp_packet()
        exp_pkt = pkt
        for key, value in list(self.igr_to_egr_port_map.items()):
            igr_port = key
            egr_port = value
            logger.info("Sending packet on port %d", igr_port)
            testutils.send_packet(self, igr_port, pkt)

            logger.info("Expecting packet on port %d", egr_port)
            testutils.verify_packets(self, exp_pkt, [egr_port])

            logger.info("Packet received on port %d as expected", egr_port)
Ejemplo n.º 20
0
    def runTest(self):
        ig_port = swports[1]
        eg_port = swports[2]
        dmac = '22:22:22:22:22:22'

        target = client.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("tna_action_profile")

        forward_table = bfrt_info.table_get("SwitchIngress.forward")
        action_profile = bfrt_info.table_get("SwitchIngress.action_profile")

        ap_key = action_profile.make_key(
            [client.KeyTuple('$ACTION_MEMBER_ID', 1)])
        action_profile.entry_add(target, [ap_key], [
            action_profile.make_data([client.DataTuple('port', eg_port)],
                                     'SwitchIngress.set_port')
        ])

        fwd_key = forward_table.make_key([
            client.KeyTuple('ig_intr_md.ingress_port', ig_port),
            client.KeyTuple('vid', 0)
        ])

        forward_table.entry_add(target, [fwd_key], [
            forward_table.make_data([client.DataTuple('$ACTION_MEMBER_ID', 1)])
        ])

        try:
            pkt = testutils.simple_tcp_packet(eth_dst=dmac)
            logger.info("Sending packet on port %d", ig_port)
            testutils.send_packet(self, ig_port, pkt)

            exp_pkt = pkt
            logger.info("Expecting packet on port %d", eg_port)
            testutils.verify_packets(self, exp_pkt, [eg_port])
        finally:
            forward_table.entry_del(target, [fwd_key])

            action_profile.entry_del(target, [ap_key])

        try:
            logger.info("Sending packet on port %d", ig_port)
            testutils.send_packet(self, ig_port, pkt)

            logger.info("Packet is expected to get dropped.")
            testutils.verify_no_other_packets(self)
        finally:
            pass
Ejemplo n.º 21
0
def test_l2_access_to_access_vlan(npu, dataplane):
    """
    Description:
    Check access to access VLAN members forwarding

    Test scenario:
    1. Create a VLAN 10
    2. Add two ports as untagged members to the VLAN
    3. Setup static FDB entries for port 1 and port 2
    4. Send a simple untagged packet on port 1 and verify packet on port 2
    5. Clean up configuration
    """
    vlan_id = "10"
    macs = ['00:11:11:11:11:11', '00:22:22:22:22:22']
    max_port = 2
    vlan_mbr_oids = []

    vlan_oid = npu.create(SaiObjType.VLAN, ["SAI_VLAN_ATTR_VLAN_ID", vlan_id])

    for idx in range(max_port):
        npu.remove_vlan_member(npu.default_vlan_oid, npu.dot1q_bp_oids[idx])
        vlan_mbr = npu.create_vlan_member(vlan_oid, npu.dot1q_bp_oids[idx],
                                          "SAI_VLAN_TAGGING_MODE_UNTAGGED")
        vlan_mbr_oids.append(vlan_mbr)
        npu.set(npu.port_oids[idx], ["SAI_PORT_ATTR_PORT_VLAN_ID", vlan_id])
        npu.create_fdb(vlan_oid, macs[idx], npu.dot1q_bp_oids[idx])

    try:
        if npu.run_traffic:
            pkt = simple_tcp_packet(eth_dst=macs[1],
                                    eth_src=macs[0],
                                    ip_dst='10.0.0.1',
                                    ip_id=101,
                                    ip_ttl=64)

            send_packet(dataplane, 0, pkt)
            verify_packets(dataplane, pkt, [1])
    finally:
        for idx in range(max_port):
            npu.remove_fdb(vlan_oid, macs[idx])
            npu.remove(vlan_mbr_oids[idx])
            npu.create_vlan_member(npu.default_vlan_oid,
                                   npu.dot1q_bp_oids[idx],
                                   "SAI_VLAN_TAGGING_MODE_UNTAGGED")
            npu.set(npu.port_oids[idx],
                    ["SAI_PORT_ATTR_PORT_VLAN_ID", npu.default_vlan_id])

        npu.remove(vlan_oid)
Ejemplo n.º 22
0
    def runTest(self):
        pkt = Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')
        pkt /= IPv6(src='2001::1', dst='2001::2', fl=0, tc=0, hlim=64)
        pkt /= TCP(sport=1234, dport=80, flags='S')
        pkt /= "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"

        exp_pkt = Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')
        exp_pkt /= IPv6(src='2001::1', dst='2001::2', fl=0, tc=0, hlim=7)
        exp_pkt /= TCP(sport=1234, dport=80, flags='S')
        exp_pkt /= "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"

        mask = Mask(exp_pkt)
        mask.set_do_not_care_scapy(TCP, 'chksum')

        send_packet(self, (0, 1), pkt)
        verify_packets(self, mask, device_number=0, ports=[2])
Ejemplo n.º 23
0
    def send_pkt_expect_it_passed(self, idx, pkt_seqnum):
        ig_port = 0
        eg_port = 2

        pkt_in = self.make_pkt(idx, pkt_seqnum)
        tu.send_packet(self, ig_port, pkt_in)

        exp_pkt = pkt_in
        exp_next_seqnum = (pkt_seqnum + 1) % (1 << 16)
        tu.verify_packets(self, exp_pkt, [eg_port])
        seqnum_read_val = self.read_SeqNumReg(idx)
        if seqnum_read_val != exp_next_seqnum:
            logging.error("seqnum_read_val={} != {}=exp_next_seqnum"
                          " pkt_seqnum={}".format(seqnum_read_val,
                                                  exp_next_seqnum, pkt_seqnum))
            assert seqnum_read_val == exp_next_seqnum
Ejemplo n.º 24
0
    def runTest(self):
        ip_dst_addr = '2001:0db8::3210'
        in_dmac = 'ee:30:ca:9d:1e:00'
        in_smac = 'ee:cd:00:7e:70:00'
        ig_port = 0
        eg_port = 1
        out_dmac = '00:00:00:00:00:01'

        # Add a set of table entries
        self.table_add(self.key_t2(ip_dst_addr, 128),
                       self.act_set_dmac(out_dmac))

        pkt_in = tu.simple_tcpv6_packet(eth_src=in_smac,
                                        eth_dst=in_dmac,
                                        ipv6_dst=ip_dst_addr)
        exp_pkt = tu.simple_tcpv6_packet(eth_src=in_smac,
                                         eth_dst=out_dmac,
                                         ipv6_dst=ip_dst_addr)
        tu.send_packet(self, ig_port, pkt_in)
        tu.verify_packets(self, exp_pkt, [eg_port])
Ejemplo n.º 25
0
def test_l2_trunk_to_trunk_vlan(npu, dataplane):
    """
    Description:
    Check trunk to trunk VLAN members forwarding

    Test scenario:
    1. Create a VLAN 10
    2. Add two ports as tagged members to the VLAN
    3. Setup static FDB entries for port 1 and port 2
    4. Send a simple vlan tag (10) packet on port 1 and verify packet on port 2
    5. Clean up configuration
    """
    vlan_id = "10"
    macs = ['00:11:11:11:11:11', '00:22:22:22:22:22']

    vlan_oid = npu.create(SaiObjType.VLAN, ["SAI_VLAN_ATTR_VLAN_ID", vlan_id])
    vlan_member1 = npu.create_vlan_member(vlan_oid, npu.dot1q_bp_oids[0],
                                          "SAI_VLAN_TAGGING_MODE_TAGGED")
    vlan_member2 = npu.create_vlan_member(vlan_oid, npu.dot1q_bp_oids[1],
                                          "SAI_VLAN_TAGGING_MODE_TAGGED")
    npu.create_fdb(vlan_oid, macs[0], npu.dot1q_bp_oids[0])
    npu.create_fdb(vlan_oid, macs[1], npu.dot1q_bp_oids[1])

    try:
        if npu.run_traffic:
            pkt = simple_tcp_packet(eth_dst=macs[1],
                                    eth_src=macs[0],
                                    dl_vlan_enable=True,
                                    vlan_vid=10,
                                    ip_dst='10.0.0.1',
                                    ip_id=101,
                                    ip_ttl=64)

            send_packet(dataplane, 0, pkt)
            verify_packets(dataplane, pkt, [1])
    finally:
        npu.flush_fdb_entries(["SAI_FDB_FLUSH_ATTR_BV_ID", vlan_oid])
        npu.remove(vlan_member1)
        npu.remove(vlan_member2)
        npu.remove(vlan_oid)
Ejemplo n.º 26
0
    def runTest(self):
        port_list = [0, 1, 2, 3, 4, 5, 6, 7]
        dst_addr = '00:11:22:33:44:55'
        src_addr = '00:aa:bb:cc:dd:ee'

        # Create test packet.
        pkt = testutils.simple_tcp_packet(eth_dst=dst_addr, eth_src=src_addr)

        # Looped back packet has swapped ethernet addresses.
        pkt_check = testutils.simple_tcp_packet(eth_dst=src_addr, eth_src=dst_addr)

        for port in port_list:

            ig_port = self.swports(port)
            eg_port = self.swports(port)
            # port is 9-bit in v1model, i.e. 2 bytes
            ig_port_str = stringify(ig_port, 2)
            eg_port_str = stringify(eg_port, 2)

            # check that the entry is hit and that no other packets are received
            testutils.send_packet(self, ig_port, pkt)
            testutils.verify_packets(self, pkt_check, [eg_port])
Ejemplo n.º 27
0
def test_netdev_pkt(npu, dataplane, sai_hostif_obj):
    if not npu.libsaivs:
        pytest.skip("valid for saivs only")

    hostifs = {
        "100": "Ethernet0"
    }
    hostif_dataplane = npu.hostif_dataplane_start(hostifs)
    assert hostif_dataplane is not None

    pkt = simple_tcp_packet(eth_dst='00:00:00:11:11:11',
                            eth_src='00:00:00:22:22:22',
                            ip_dst='10.0.0.1',
                            ip_id=102,
                            ip_ttl=64)

    send_packet(dataplane, 0, pkt)

    npu.hostif_pkt_listen()
    verify_packets(hostif_dataplane, pkt, [100])

    npu.hostif_dataplane_stop()
Ejemplo n.º 28
0
def test_l2_flood(npu, dataplane):
    """
    Description:
    Test that the packet received on a port is flooded to all VLAN members

    Test scenario:
    1. Create a VLAN 10
    2. Add three ports as untagged members to the VLAN
    3. Send packet on each port and verify that it only shows up on the other two ports
    4. Clean up configuration
    """
    vlan_id = "10"
    macs = ['00:11:11:11:11:11', '00:22:22:22:22:22']
    vlan_mbr_oids = []

    vlan_oid = npu.create(SaiObjType.VLAN, ["SAI_VLAN_ATTR_VLAN_ID", vlan_id])

    for idx in range(3):
        npu.remove_vlan_member(npu.default_vlan_oid, npu.dot1q_bp_oids[idx])
        vlan_mbr = npu.create_vlan_member(vlan_oid, npu.dot1q_bp_oids[idx],
                                          "SAI_VLAN_TAGGING_MODE_UNTAGGED")
        vlan_mbr_oids.append(vlan_mbr)
        npu.set(npu.port_oids[idx], ["SAI_PORT_ATTR_PORT_VLAN_ID", vlan_id])

    try:
        if npu.run_traffic:
            pkt = simple_tcp_packet(eth_dst=macs[1],
                                    eth_src=macs[0],
                                    ip_dst='10.0.0.1',
                                    ip_id=107,
                                    ip_ttl=64)

            send_packet(dataplane, 0, pkt)
            verify_packets(dataplane, pkt, [1, 2])
            send_packet(dataplane, 1, pkt)
            verify_packets(dataplane, pkt, [0, 2])
            send_packet(dataplane, 2, pkt)
            verify_packets(dataplane, pkt, [0, 1])
    finally:
        for idx in range(3):
            npu.remove(vlan_mbr_oids[idx])
            npu.create_vlan_member(npu.default_vlan_oid,
                                   npu.dot1q_bp_oids[idx],
                                   "SAI_VLAN_TAGGING_MODE_UNTAGGED")
            npu.set(npu.port_oids[idx],
                    ["SAI_PORT_ATTR_PORT_VLAN_ID", npu.default_vlan_id])
        npu.remove(vlan_oid)
Ejemplo n.º 29
0
    def runTest(self):
        ig_port = swports[1]
        eg_port = swports[2]
        smac = '11:33:55:77:99:00'
        smac_mask = 'ff:ff:ff:ff:ff:ff'
        dmac = '00:11:22:33:44:55'

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

        pkt = testutils.simple_tcp_packet(eth_dst=dmac, eth_src=smac)
        exp_pkt = pkt

        target = client.Target(device_id=0, pipe_id=0xffff)
        forward_table = bfrt_info.table_get("SwitchIngress.forward")
        forward_table.info.key_field_annotation_add("hdr.ethernet.src_addr",
                                                    "mac")
        forward_table.entry_add(target, [
            forward_table.make_key([
                client.KeyTuple('hdr.ethernet.src_addr', smac, smac_mask),
                client.KeyTuple('$MATCH_PRIORITY', 0)
            ])
        ], [
            forward_table.make_data([
                client.DataTuple('port', eg_port),
                client.DataTuple('$COUNTER_SPEC_BYTES', 0),
                client.DataTuple('$COUNTER_SPEC_PKTS', 0)
            ], 'SwitchIngress.hit')
        ])

        # Default packet size is 100 bytes and model adds 4 bytes of CRC
        pkt_size = 100 + 4
        num_pkts = 3
        num_bytes = num_pkts * pkt_size

        logger.info("Sending packet on port %d", ig_port)
        for i in range(0, num_pkts):
            testutils.send_packet(self, ig_port, pkt)
            testutils.verify_packets(self, exp_pkt, [eg_port])

        logger.info("Expecting packet on port %d", eg_port)

        # Get count from sw. It should be 0
        resp = forward_table.entry_get(target, [
            forward_table.make_key([
                client.KeyTuple('hdr.ethernet.src_addr', smac, smac_mask),
                client.KeyTuple('$MATCH_PRIORITY', 0)
            ])
        ], {"from_hw": False})

        # parse resp to get the counter
        data_dict = next(resp)[0].to_dict()
        recv_pkts = data_dict["$COUNTER_SPEC_PKTS"]
        recv_bytes = data_dict["$COUNTER_SPEC_BYTES"]

        # should be 0
        if (0 != recv_pkts):
            logger.error("Error! expected 0 received count = %s",
                         str(recv_pkts))
            assert 0

        if (0 != recv_bytes):
            logger.error("Error! expected 0 received count = %s",
                         str(recv_bytes))
            assert 0

        # apply table op to sync counters on the direct table
        forward_table.operations_execute(target, 'SyncCounters')

        # Get count from sw. It should be correct
        resp = forward_table.entry_get(
            target, [
                forward_table.make_key([
                    client.KeyTuple('hdr.ethernet.src_addr', smac, smac_mask),
                    client.KeyTuple('$MATCH_PRIORITY', 0)
                ])
            ], {"from_hw": False},
            forward_table.make_data([
                client.DataTuple("$COUNTER_SPEC_BYTES"),
                client.DataTuple("$COUNTER_SPEC_PKTS")
            ], 'SwitchIngress.hit'))

        # parse resp to get the counter
        data_dict = next(resp)[0].to_dict()
        recv_pkts = data_dict["$COUNTER_SPEC_PKTS"]
        recv_bytes = data_dict["$COUNTER_SPEC_BYTES"]

        if (num_pkts != recv_pkts):
            logger.error("Error! packets sent = %s received count = %s",
                         str(num_pkts), str(recv_pkts))
            assert 0

        if (num_bytes != recv_bytes):
            logger.error("Error! bytes sent = %s received count = %s",
                         str(num_bytes), str(recv_bytes))
            assert 0

        forward_table.entry_del(target, [
            forward_table.make_key([
                client.KeyTuple('hdr.ethernet.src_addr', smac, smac_mask),
                client.KeyTuple('$MATCH_PRIORITY', 0)
            ])
        ])

        logger.info("Sending packet on port %d", ig_port)
        testutils.send_packet(self, ig_port, pkt)

        logger.info("Packet is expected to get dropped.")
        testutils.verify_no_other_packets(self)
Ejemplo n.º 30
0
    def runTest(self):
        ig_port = swports[1]
        eg_port = swports[2]
        smac = '11:33:55:77:99:00'
        dmac = '00:11:22:33:44:55'

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

        forward_dst_table = bfrt_info.table_get("SwitchIngress.forward_dst")
        forward_dst_table.info.key_field_annotation_add(
            "hdr.ethernet.dst_addr", "mac")

        indirect_counter_table = bfrt_info.table_get(
            "SwitchIngress.indirect_counter")

        pkt = testutils.simple_tcp_packet(eth_dst=dmac, eth_src=smac)
        exp_pkt = pkt

        target = client.Target(device_id=0, pipe_id=0xffff)
        # insert entry in MAT and the indirect counter table both
        forward_dst_table.entry_add(target, [
            forward_dst_table.make_key(
                [client.KeyTuple('hdr.ethernet.dst_addr', dmac)])
        ], [
            forward_dst_table.make_data([client.DataTuple('port', eg_port)],
                                        'SwitchIngress.hit_dst')
        ])

        indirect_counter_table.entry_add(target, [
            indirect_counter_table.make_key(
                [client.KeyTuple('$COUNTER_INDEX', eg_port)])
        ], [
            indirect_counter_table.make_data([
                client.DataTuple('$COUNTER_SPEC_BYTES', 0),
                client.DataTuple('$COUNTER_SPEC_PKTS', 0)
            ])
        ])

        # Default packet size is 100 bytes and model adds 4 bytes of CRC
        pkt_size = 100 + 4
        num_pkts = 6
        num_bytes = num_pkts * pkt_size

        logger.info("Sending packet on port %d", ig_port)
        for i in range(0, num_pkts):
            testutils.send_packet(self, ig_port, pkt)
            testutils.verify_packets(self, exp_pkt, [eg_port])

        logger.info("Expecting packet on port %d", eg_port)

        # Get from sw and check its value. They should be 0
        resp = indirect_counter_table.entry_get(target, [
            indirect_counter_table.make_key(
                [client.KeyTuple('$COUNTER_INDEX', eg_port)])
        ], {"from_hw": False})
        # parse resp to get the counter
        data_dict = next(resp)[0].to_dict()
        recv_pkts = data_dict["$COUNTER_SPEC_PKTS"]
        recv_bytes = data_dict["$COUNTER_SPEC_BYTES"]

        if (0 != recv_pkts):
            logger.error("Error! expected 0 received count = %s",
                         str(recv_pkts))
            assert 0

        if (0 != recv_bytes):
            logger.error("Error! expected 0 received count = %s",
                         str(recv_bytes))
            assert 0

        # apply table op to sync counters on the indirect table
        indirect_counter_table.operations_execute(target, 'Sync')

        # Get from sw and check its value. They should be the correct values now
        resp = indirect_counter_table.entry_get(target, [
            indirect_counter_table.make_key(
                [client.KeyTuple('$COUNTER_INDEX', eg_port)])
        ], {"from_hw": False})

        # parse resp to get the counter
        data_dict = next(resp)[0].to_dict()
        recv_pkts = data_dict["$COUNTER_SPEC_PKTS"]
        recv_bytes = data_dict["$COUNTER_SPEC_BYTES"]

        if (num_pkts != recv_pkts):
            logger.error("Error! packets sent = %s received count = %s",
                         str(num_pkts), str(recv_pkts))
            assert 0

        if (num_bytes != recv_bytes):
            logger.error("Error! bytes sent = %s received count = %s",
                         str(num_bytes), str(recv_bytes))
            assert 0

        forward_dst_table.entry_del(target, [
            forward_dst_table.make_key(
                [client.KeyTuple('hdr.ethernet.dst_addr', dmac)])
        ])