def build_qinq_packet(outer_vlan_id, 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_qinq_tcp_packet(eth_dst=dst_mac, eth_src=src_mac, dl_vlan_outer=outer_vlan_id, vlan_vid=vlan_id, ip_src=src_ip, ip_dst=dst_ip, ip_ttl=ttl) return pkt
def craft_packet(src_mac, dst_mac, dst_ip, ip_version, stage, tagged_mode, vlan_id=10, outer_vlan_id=0, pkt_type=None): """ Generate IPV4/IPV6 packets with single or double Vlan Header Args: src_mac: Source MAC address dst_mac: Dest MAC address dst_ip: IP address of packet ip_version: Ip version of packet that should be generated stage: ingress or egress tagged_mode: TAGGED or UNTAGGED vlan_id: Vlan Id number dl_vlan_outer: Outer Vlan ID pkt_type: packet type to be created Returns: QinQ or TCP packet """ DUMMY_IP = '8.8.8.8' exp_pkt_with_tag = tagged_mode in [TYPE_TAGGED, TYPE_COMBINE_TAGGED] if ip_version == IPV4: if pkt_type == 'qinq': pkt = testutils.simple_qinq_tcp_packet(eth_src=src_mac, eth_dst=dst_mac, dl_vlan_outer=outer_vlan_id, vlan_vid=vlan_id, ip_src=DUMMY_IP, ip_dst=dst_ip) if exp_pkt_with_tag: exp_pkt = testutils.simple_tcp_packet( pktlen=96, # Default len (100) - Dot1Q len (4) eth_src=src_mac, eth_dst=dst_mac, dl_vlan_enable=True, vlan_vid=vlan_id, ip_src=DUMMY_IP, ip_dst=dst_ip) else: exp_pkt = pkt else: pkt = testutils.simple_tcp_packet(eth_src=src_mac, eth_dst=dst_mac, ip_src=DUMMY_IP, ip_dst=dst_ip) if exp_pkt_with_tag: exp_pkt = testutils.simple_tcp_packet( pktlen=104, # Default len(100) + Dot1Q len (4) eth_src=src_mac, eth_dst=dst_mac, dl_vlan_enable=True, vlan_vid=outer_vlan_id, ip_src=DUMMY_IP, ip_dst=dst_ip) else: exp_pkt = pkt.copy() exp_pkt = mask.Mask(exp_pkt) exp_pkt.set_do_not_care_scapy(Ether, 'src') exp_pkt.set_do_not_care_scapy(Ether, 'dst') exp_pkt.set_do_not_care_scapy(IP, 'ttl') exp_pkt.set_do_not_care_scapy(IP, 'chksum') else: pkt = testutils.simple_tcpv6_packet(eth_src=src_mac, eth_dst=dst_mac, dl_vlan_enable=True, vlan_vid=outer_vlan_id, ipv6_dst=dst_ip) if exp_pkt_with_tag: exp_pkt = testutils.simple_tcpv6_packet( pktlen=96, # Default len (100) - Dot1Q len (4) eth_src=src_mac, eth_dst=dst_mac, ipv6_dst=dst_ip) else: exp_pkt = pkt return pkt, exp_pkt