Example #1
0
    def test_traffic_flows(self):
        """
           Attach the tunnel flows with UE IP address and
           send GTP and ARP traffic.
        """
        # Need to delete all default flows in table 0 before
        # install the specific flows test case.
        self.test_detach_default_tunnel_flows()

        # Attach the tunnel flows towards UE.
        seid1 = 5000
        self.classifier_controller.add_tunnel_flows(65525, 1, 1000,
                                                    "192.168.128.30",
                                                    self.EnodeB_IP, seid1)
        # Create a set of packets
        pkt_sender = ScapyPacketInjector(self.BRIDGE)
        eth = Ether(dst=self.MAC_1, src=self.MAC_2)
        ip = IP(src=self.Dst_nat, dst='192.168.128.30')
        o_udp = UDP(sport=2152, dport=2152)
        i_udp = UDP(sport=1111, dport=2222)
        i_tcp = TCP(seq=1, sport=1111, dport=2222)
        i_ip = IP(src='192.168.60.142', dst=self.EnodeB_IP)

        arp = ARP(hwdst=self.MAC_1,
                  hwsrc=self.MAC_2,
                  psrc=self.Dst_nat,
                  pdst='192.168.128.30')

        gtp_packet_udp = eth / ip / o_udp / GTP_U_Header(
            teid=0x1, length=28, gtp_type=255) / i_ip / i_udp
        gtp_packet_tcp = eth / ip / o_udp / GTP_U_Header(
            teid=0x1, length=68, gtp_type=255) / i_ip / i_tcp
        arp_packet = eth / arp

        # Check if these flows were added (queries should return flows)
        flow_queries = [
            FlowQuery(self._tbl_num,
                      self.testing_controller,
                      match=MagmaMatch(tunnel_id=1, in_port=32768)),
            FlowQuery(self._tbl_num,
                      self.testing_controller,
                      match=MagmaMatch(ipv4_dst='192.168.128.30'))
        ]
        # =========================== Verification ===========================
        # Verify 5 flows installed for classifier table (3 pkts matched)

        flow_verifier = FlowVerifier([
            FlowTest(FlowQuery(self._tbl_num, self.testing_controller), 3, 5),
            FlowTest(flow_queries[0], 0, 1),
        ], lambda: wait_after_send(self.testing_controller))

        snapshot_verifier = SnapshotVerifier(self, self.BRIDGE,
                                             self.service_manager)

        with flow_verifier, snapshot_verifier:
            pkt_sender.send(gtp_packet_udp)
            pkt_sender.send(gtp_packet_tcp)
            pkt_sender.send(arp_packet)

        flow_verifier.verify()
Example #2
0
    def test_traffic_paging_flow(self):
        """
           Add paging flow in table 0
        """
        # Need to delete all default flows in table 0 before
        # install the specific flows test case.
        self.classifier_controller._delete_all_flows()

        ue_ip_addr = "192.168.128.30"
        self.classifier_controller.install_paging_flow(
            IPAddress(version=IPAddress.IPV4,
                      address=ue_ip_addr.encode('utf-8')), 200, True)
        # Create a set of packets
        pkt_sender = ScapyPacketInjector(self.BRIDGE)
        eth = Ether(dst=self.MAC_1, src=self.MAC_2)
        ip = IP(src=self.Dst_nat, dst='192.168.128.30')
        o_udp = UDP(sport=2152, dport=2152)
        i_udp = UDP(sport=1111, dport=2222)
        i_tcp = TCP(seq=1, sport=1111, dport=2222)
        i_ip = IP(src='192.168.60.142', dst=self.EnodeB_IP)

        gtp_packet_udp = eth / ip / o_udp / GTP_U_Header(
            teid=0x1, length=28, gtp_type=255) / i_ip / i_udp
        gtp_packet_tcp = eth / ip / o_udp / GTP_U_Header(
            teid=0x1, length=68, gtp_type=255) / i_ip / i_tcp

        # Check if these flows were added (queries should return flows)
        flow_queries = [
            FlowQuery(self._tbl_num,
                      self.testing_controller,
                      match=MagmaMatch(tunnel_id=1, in_port=32768)),
            FlowQuery(self._tbl_num,
                      self.testing_controller,
                      match=MagmaMatch(ipv4_dst='192.168.128.30'))
        ]
        # =========================== Verification ===========================
        # Verify 2 flows installed for classifier table (2 pkts matched)

        flow_verifier = FlowVerifier([
            FlowTest(FlowQuery(self._tbl_num, self.testing_controller), 2, 2),
        ], lambda: wait_after_send(self.testing_controller))

        snapshot_verifier = SnapshotVerifier(self, self.BRIDGE,
                                             self.service_manager)

        with flow_verifier, snapshot_verifier:
            pkt_sender.send(gtp_packet_udp)
            pkt_sender.send(gtp_packet_tcp)

        flow_verifier.verify()
Example #3
0
 def verify_gtp_forwarding(self):
     payload = self.build_from_ue_to_sgi(b"42", remote_ip=self.remote_ip)
     # UE -> remote_ip
     self.send_from_grx(GTP_U_Header(seq=42, teid=self.teid) / payload)
     self.assert_packet_sent_to_sgi(b"42", remote_ip=self.remote_ip)
     # remote_ip -> UE
     self.send_from_sgi_to_ue(b"4242", remote_ip=self.remote_ip)
     self.assert_packet_sent_to_ue(b"4242", remote_ip=self.remote_ip)
Example #4
0
 def encap_mcast(self, pkt, src_ip, src_mac, vni):
     """
     Encapsulate the original payload frame by adding GTPU header with its
     UDP, IP and Ethernet fields
     """
     return (Ether(src=src_mac, dst=self.mcast_mac) /
             IP(src=src_ip, dst=self.mcast_ip4) /
             UDP(sport=self.dport, dport=self.dport, chksum=0) /
             GTP_U_Header(teid=vni, gtp_type=self.gtp_type, length=150) /
             pkt)
 def encapsulate(self, pkt, vni):
     """
     Encapsulate the original payload frame by adding GTPU header with its
     UDP, IP and Ethernet fields
     """
     return (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
             IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
             UDP(sport=self.dport, dport=self.dport, chksum=0) /
             GTP_U_Header(TEID=vni, gtp_type=self.gtp_type, length=150) /
             pkt)
Example #6
0
 def test_gtp_echo(self):
     try:
         self.associate()
         self.heartbeat()
         self.establish_session()
         self.verify_gtp_echo(GTP_U_Header(seq=42) / GTPEchoRequest())
         # no sequence number => drop
         self.verify_gtp_no_echo(GTP_U_Header(S=0) / GTPEchoRequest())
         self.verify_gtp_echo(GTP_U_Header(seq=42) / GTPEchoRequest())
         self.verify_gtp_echo(
             GTP_U_Header(seq=42, teid=self.UNODE_TEID) / GTPEchoRequest())
         # Verify stripping extensions (these extensions are
         # used here just b/c they're available in Scapy GTP module)
         self.verify_gtp_echo(
             GTP_U_Header(seq=42, PN=1, npdu=123) / GTPEchoRequest() /
             GTP_UDPPort_ExtensionHeader(udp_port=1234) /
             GTP_PDCP_PDU_ExtensionHeader(pdcp_pdu=123))
         # Verify stripping IE (the IE is not relevant here)
         self.verify_gtp_echo(
             GTP_U_Header(seq=42) / GTPEchoRequest() / IE_SelectionMode())
         self.verify_gtp_forwarding()
         self.delete_session()
     finally:
         self.vapi.cli("show error")
from scapy.contrib.gtp import (GTP_U_Header, GTPPDUSessionContainer)
from scapy.all import *

sendp(Ether() / IP(src="192.168.50.100", dst="192.168.50.200") /
      UDP(sport=2152, dport=2152) / GTP_U_Header(teid=100, next_ex=133) /
      GTPPDUSessionContainer(type=1, QFI=6) /
      IP(src="192.168.128.79", dst="8.8.8.8") / TCP(sport=5001, dport=53),
      iface="veth0",
      count=5)
from scapy.all import *
from scapy.contrib.gtp import GTP_U_Header

data= "Orange Lab Network - SGI Primary"

sendp(Ether(dst="00:0c:29:46:1f:53")/
	IP(src="172.20.16.3",dst="172.20.16.2")/
	UDP(dport=2152)/GTP_U_Header(teid=1234)/
	IP(src="10.10.10.10",dst="172.22.16.3",version=4)/
	UDP()/data, iface="n3")
Example #9
0
def main():
    """Send packet from one traffic generator interface to the other."""

    args = TrafficScriptArg([
        u"tg_if1_mac",
        u"dut_if1_mac",
        u"flow_type",
        u"proto",
    ], [u"src_ip", u"dst_ip", u"src_port", u"dst_port", u"value"])
    tx_if = args.get_arg(u"tx_if")
    tx_src_mac = args.get_arg(u"tg_if1_mac")
    tx_dst_mac = args.get_arg(u"dut_if1_mac")
    flow_type = args.get_arg(u"flow_type")
    proto = args.get_arg(u"proto")

    src = args.get_arg(u"src_ip")
    dst = args.get_arg(u"dst_ip")
    sport = eval(args.get_arg(u"src_port"))
    dport = eval(args.get_arg(u"dst_port"))
    value = eval(args.get_arg(u"value"))

    txq = TxQueue(tx_if)

    if flow_type == u"IP4":
        pkt_raw = (Ether(src=tx_src_mac, dst=tx_dst_mac) /
                   IP(src=src, dst=dst))
    elif flow_type == u"IP6":
        pkt_raw = (Ether(src=tx_src_mac, dst=tx_dst_mac) /
                   IPv6(src=src, dst=dst))
    elif flow_type == u"ETHER":
        pkt_raw = Ether(src=tx_src_mac, dst=tx_dst_mac)
    else:
        raise ValueError(f"Flow type error: {flow_type}")

    if proto == u"TCP":
        pkt_raw /= TCP(sport=sport, dport=dport)
    elif proto == u"UDP":
        pkt_raw /= UDP(sport=sport, dport=dport)
    elif proto == u"AH":
        pkt_raw /= AH(spi=value)
    elif proto == u"ESP":
        pkt_raw /= ESP(spi=value)
    elif proto == u"GTPU":
        pkt_raw /= (UDP() / GTP_U_Header(teid=value) /
                    IP(src=u"192.168.10.20"))
    elif proto == u"L2TPV3":
        value_hex = hex(value).replace('0x', (8 - len(hex(value)) + 2) * '0')
        session_id = binascii.a2b_hex(value_hex)
        pkt_raw.proto = 115
        pkt_raw /= Raw(session_id)
    elif proto == u"VXLAN":
        pkt_raw /= (UDP() / VXLAN(vni=value))
    elif proto == u"ARP":
        pkt_raw.type = value
        pkt_raw /= ARP()
    else:
        raise ValueError(f"Flow proto error: {proto}")

    pkt_raw /= Raw()
    txq.send(pkt_raw)
    sys.exit(0)
Example #10
0
File: upf.py Project: usha1830/p4c
def pkt_gtpu_encap(pkt, teid, ip_dst, ip_src):
    return Ether(src=pkt[Ether].src, dst=pkt[Ether].dst) / \
           IP(src=ip_src,dst=ip_dst)/UDP(dport=GTPU_UDP_PORT)/GTP_U_Header(teid=teid)/pkt[Ether].payload
Example #11
0
#!/usr/bin/env python3

# sudo /home/vagrant/build/python/bin/python gtp-cmd.py 192.168.60.141 192.168.60.142 192.168.128.12 192.168.129.42 eth1

import sys
import time

from scapy.all import *
from scapy.contrib.gtp import GTP_U_Header, GTPPDUSessionContainer
from scapy.layers.l2 import getmacbyip

ip_src = sys.argv[1]
ip_dst = sys.argv[2]
i_ip_src = sys.argv[3]
i_ip_dst = sys.argv[4]
egress_dev = sys.argv[5]

dst_mac = getmacbyip(ip_dst)

eth = Ether(src='08:00:27:d3:52:d1', dst=dst_mac)
ip = IP(src=ip_src, dst=ip_dst)
udp = UDP(sport=2152, dport=2152)

i_ip = IP(src=i_ip_src, dst=i_ip_dst)
i_udp = UDP(sport=56531, dport=5001)

gtp_packet_tcp = eth / ip / udp / GTP_U_Header(teid=104) / i_ip / i_udp

sendp(gtp_packet_tcp, iface=egress_dev, count=1)
time.sleep(.5)
from scapy.all import *
from scapy.contrib.gtp import GTP_U_Header

data = "Orange Lab Network - SGI Seconary"

sendp(Ether(dst="00:0c:29:46:1f:53") /
      IP(src="172.20.16.3", dst="172.20.16.2") / UDP(dport=2152) /
      GTP_U_Header(teid=5678) /
      IP(src="20.20.20.20", dst="172.23.16.3", version=4) / UDP() / data,
      iface="n3")