예제 #1
0
def build_icmp_packet(vlan_id,
                      src_mac="00:22:00:00:00:02",
                      dst_mac="ff:ff:ff:ff:ff:ff",
                      src_ip="192.168.0.1",
                      dst_ip="192.168.0.2",
                      ttl=64):

    pkt = testutils.simple_icmp_packet(
        pktlen=100 if vlan_id == 0 else 104,
        eth_dst=dst_mac,
        eth_src=src_mac,
        dl_vlan_enable=False if vlan_id == 0 else True,
        vlan_vid=vlan_id,
        vlan_pcp=0,
        ip_src=src_ip,
        ip_dst=dst_ip,
        ip_ttl=ttl)
    return pkt
예제 #2
0
def test_host_vlan_no_floodling(
    duthosts,
    rand_one_dut_hostname,
    ptfadapter,
    setup_host_vlan_intf_mac,
    testbed_params,
    toggle_all_simulator_ports_to_rand_selected_tor,
):
    """
    Aims to verify that for packets detinated to the host vlan interface, the packets should not be flooding
    in the host bridge vlan member ports.
    """
    duthost = duthosts[rand_one_dut_hostname]
    vlan_intf, vlan_member_ports_to_ptf_ports = testbed_params
    vlan_intf_mac = duthost.get_dut_iface_mac(vlan_intf["attachto"])
    selected_test_ports = random.sample(vlan_member_ports_to_ptf_ports, HOST_PORT_FLOODING_CHECK_COUNT + 1)
    test_dut_port = selected_test_ports[0]
    test_ptf_port = vlan_member_ports_to_ptf_ports[test_dut_port]
    test_ptf_port_mac = ptfadapter.dataplane.get_mac(0, test_ptf_port)
    dut_ports_to_check = selected_test_ports[1:]

    icmp_pkt = testutils.simple_icmp_packet(
        eth_dst=vlan_intf_mac,
        eth_src=test_ptf_port_mac,
        ip_src=ICMP_PKT_SRC_IP,
        ip_dst=vlan_intf["addr"],
        icmp_data=ICMP_PKT_FINGERPRINT
    )

    ptfadapter.before_send = lambda *kargs, **kwargs: time.sleep(.5)
    for dut_port_to_check in dut_ports_to_check:
        with log_icmp_updates(duthost, iface=dut_port_to_check, save_path=DUT_ICMP_DUMP_FILE):
            testutils.send(ptfadapter, test_ptf_port, icmp_pkt, count=ICMP_PKT_COUNT)

        with tempfile.NamedTemporaryFile() as tmp_pcap:
            duthost.fetch(src=DUT_ICMP_DUMP_FILE, dest=tmp_pcap.name, flat=True)
            icmp_pkts = sniff(offline=tmp_pcap.name)

            if len([_ for _ in icmp_pkts if ICMP_PKT_FINGERPRINT in str(_)]) > 0:
                pytest.fail("Received ICMP packet destinated to VLAN interface %s on host interface %s" % (vlan_intf["attachto"], dut_port_to_check))
예제 #3
0
 def icmp_packet(self, setup, direction, ptfadapter, ip_version, src_ip=None, dst_ip=None, icmp_type=8, icmp_code=0):
     """Generate an ICMP packet for testing."""
     src_ip = src_ip or DEFAULT_SRC_IP[ip_version]
     dst_ip = dst_ip or self.get_dst_ip(direction, ip_version)
     if ip_version == "ipv4":
         return testutils.simple_icmp_packet(
             eth_dst=setup["destination_mac"][direction][self.src_port],
             eth_src=ptfadapter.dataplane.get_mac(0, 0),
             ip_dst=dst_ip,
             ip_src=src_ip,
             icmp_type=icmp_type,
             icmp_code=icmp_code,
             ip_ttl=64,
         )
     else:
         return testutils.simple_icmpv6_packet(
             eth_dst=setup["destination_mac"][direction][self.src_port],
             eth_src=ptfadapter.dataplane.get_mac(0, 0),
             ipv6_dst=dst_ip,
             ipv6_src=src_ip,
             icmp_type=icmp_type,
             icmp_code=icmp_code,
             ipv6_hlim=64,
         )
예제 #4
0
def create_packet(eth_dst,
                  eth_src,
                  ip_dst,
                  ip_src,
                  vlan_vid,
                  tr_type,
                  ttl,
                  dl_vlan_enable=False,
                  icmp_type=8,
                  pktlen=100,
                  ip_tunnel=None):
    """
    Generate packet to send.

    Args:
        eth_dst: Destination Ethernet address
        eth_src: Source Ethernet address
        ip_dst: Destination IP address
        ip_src: Source IP address
        vlan_vid: VLAN ID
        tr_type: Type of traffic
        ttl: Time to live
        dl_vlan_enable: True if the packet is with vlan, False otherwise
        icmp_type: ICMP type
        pktlen: packet length
        ip_tunnel: Tunnel IP address of DUT

    Returns: simple packet
    """
    if 'TCP' in tr_type:
        return testutils.simple_tcp_packet(eth_dst=eth_dst,
                                           eth_src=eth_src,
                                           ip_dst=ip_dst,
                                           ip_src=ip_src,
                                           tcp_sport=TCP_PORT,
                                           tcp_dport=TCP_PORT,
                                           vlan_vid=vlan_vid,
                                           dl_vlan_enable=dl_vlan_enable,
                                           ip_ttl=ttl,
                                           pktlen=pktlen)
    elif 'UDP' in tr_type:
        return testutils.simple_udp_packet(eth_dst=eth_dst,
                                           eth_src=eth_src,
                                           ip_dst=ip_dst,
                                           ip_src=ip_src,
                                           udp_sport=UDP_PORT,
                                           udp_dport=UDP_PORT,
                                           vlan_vid=vlan_vid,
                                           dl_vlan_enable=dl_vlan_enable,
                                           ip_ttl=ttl,
                                           pktlen=pktlen)
    elif 'ICMP' in tr_type:
        return testutils.simple_icmp_packet(eth_dst=eth_dst,
                                            eth_src=eth_src,
                                            ip_dst=ip_dst,
                                            ip_src=ip_src,
                                            icmp_type=icmp_type,
                                            vlan_vid=vlan_vid,
                                            dl_vlan_enable=dl_vlan_enable,
                                            ip_ttl=ttl,
                                            pktlen=pktlen)
    elif 'decap' in tr_type:
        inner_dscp = random.choice(range(0, 33))
        inner_ttl = random.choice(range(3, 65))

        inner_packet = testutils.simple_tcp_packet(
            ip_dst=ip_dst,
            ip_src=ip_src,
            tcp_sport=TCP_PORT,
            tcp_dport=TCP_PORT,
            ip_ttl=inner_ttl,
            ip_dscp=inner_dscp)[packet.IP]

        return testutils.simple_ipv4ip_packet(eth_dst=eth_dst,
                                              eth_src=eth_src,
                                              ip_src='1.1.1.1',
                                              ip_dst=ip_tunnel,
                                              ip_dscp=inner_dscp,
                                              ip_ttl=64,
                                              vlan_vid=vlan_vid,
                                              dl_vlan_enable=dl_vlan_enable,
                                              inner_frame=inner_packet)

    return None
예제 #5
0
def create_packet(eth_dst,
                  eth_src,
                  ip_dst,
                  ip_src,
                  vlan_vid,
                  tr_type,
                  ttl,
                  dl_vlan_enable=False,
                  icmp_type=8,
                  pktlen=100):
    """
    Generate packet to send.

    Args:
        eth_dst: Destination Ethernet address
        eth_src: Source Ethernet address
        ip_dst: Destination IP address
        ip_src: Source IP address
        vlan_vid: VLAN ID
        tr_type: Type of traffic
        ttl: Time to live
        dl_vlan_enable: True if the packet is with vlan, False otherwise
        icmp_type: ICMP type
        pktlen: packet length

    Returns: simple packet
    """
    if 'TCP' in tr_type:
        return testutils.simple_tcp_packet(eth_dst=eth_dst,
                                           eth_src=eth_src,
                                           ip_dst=ip_dst,
                                           ip_src=ip_src,
                                           tcp_sport=TCP_PORT,
                                           tcp_dport=TCP_PORT,
                                           vlan_vid=vlan_vid,
                                           dl_vlan_enable=dl_vlan_enable,
                                           ip_ttl=ttl,
                                           pktlen=pktlen)
    elif 'UDP' in tr_type:
        return testutils.simple_udp_packet(eth_dst=eth_dst,
                                           eth_src=eth_src,
                                           ip_dst=ip_dst,
                                           ip_src=ip_src,
                                           udp_sport=UDP_PORT,
                                           udp_dport=UDP_PORT,
                                           vlan_vid=vlan_vid,
                                           dl_vlan_enable=dl_vlan_enable,
                                           ip_ttl=ttl,
                                           pktlen=pktlen)
    elif 'ICMP' in tr_type:
        return testutils.simple_icmp_packet(eth_dst=eth_dst,
                                            eth_src=eth_src,
                                            ip_dst=ip_dst,
                                            ip_src=ip_src,
                                            icmp_type=icmp_type,
                                            vlan_vid=vlan_vid,
                                            dl_vlan_enable=dl_vlan_enable,
                                            ip_ttl=ttl,
                                            pktlen=pktlen)

    return None
예제 #6
0
    def runTest(self):
        pkt = simple_icmp_packet()
        exp_pkt = simple_icmp_packet()

        send_packet(self, (0, 1), pkt)
        verify_packets(self, exp_pkt, device_number=0, ports=[2])