def test_add_tunnel_ip_flow_dl(self): # Need to delete all default flows in table 0 before # install the specific flows test case. self.test_detach_default_tunnel_flows() dest_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.128.12"), ) src_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.129.64"), ) ip_flow_dl = IPFlowDL( set_params=71, tcp_dst_port=0, tcp_src_port=5002, udp_dst_port=0, udp_src_port=0, ip_proto=6, dest_ip=dest_ip, src_ip=src_ip, precedence=65530, ) seid1 = 5000 ue_ip_addr = "192.168.128.30" self.classifier_controller.gtp_handler( 0, 65525, 1, 100000, self.EnodeB_IP, ue_ip_addr, seid1, ip_flow_dl=ip_flow_dl, ) dest_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.128.111"), ) src_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.129.4"), ) ip_flow_dl = IPFlowDL( set_params=70, tcp_dst_port=0, tcp_src_port=0, udp_dst_port=80, udp_src_port=5060, ip_proto=17, dest_ip=dest_ip, src_ip=src_ip, precedence=65525, ) seid2 = 5001 ue_ip_addr = "192.168.128.31" self.classifier_controller.gtp_handler( 0, 65525, 2, 100001, self.EnodeB_IP, ue_ip_addr, seid2, ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_attach_tunnel_flows(self): # Need to delete all default flows in table 0 before # install the specific flows test case. self.test_detach_default_tunnel_flows() seid1 = 5000 ue_ip_addr = "192.168.128.30" ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller.add_tunnel_flows( 65525, 1, 100000, self.EnodeB_IP, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), seid1, True, ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_attach_s8_tunnel_flows(self): # Need to delete all default flows in table 0 before # install the specific flows test case. self.test_detach_default_tunnel_flows() ip_no = hex(socket.htonl(int(ipaddress.ip_address(self.EnodeB_IP)))) buf = "g_{}".format(ip_no[2:]) BridgeTools.create_veth_pair(buf, buf + "ns") BridgeTools.add_ovs_port(self.BRIDGE, buf, "40") ue_ip_addr = "192.168.128.15" ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller.add_s8_tunnel_flows( 65525, 10, 5000, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, 5678, "192.168.60.112", 3000, True, ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_resume_tunnel_flows(self): # Need to delete all default flows in table 0 before # install the specific flows test case. self.test_detach_default_tunnel_flows() ip_flow_dl = IPFlowDL(set_params=0) ue_ip_addr = "192.168.128.80" self.classifier_controller.resume_tunnel_flows( 3, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl, ) ue_ip_addr = "192.168.128.82" self.classifier_controller.resume_tunnel_flows( 4, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_discard_tunnel_flows(self): ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller._delete_all_flows() ue_ip_addr = "192.168.128.80" self.classifier_controller.discard_tunnel_flows( 3, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl, ) ue_ip_addr = "192.168.128.82" self.classifier_controller.discard_tunnel_flows( 4, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_detach_tunnel_flows_ipv6(self): ip_flow_dl = IPFlowDL(set_params=0) ue_ip_addr = "2001::1" self.classifier_controller.delete_tunnel_flows( 1, None, ip_flow_dl=ip_flow_dl, ue_ipv6_adr=IPAddress(version=IPAddress.IPV6, address=ue_ip_addr.encode('utf-8')), ) ue_ip_addr = "2001:db8::1" self.classifier_controller.delete_tunnel_flows( 2, None, ip_flow_dl=ip_flow_dl, ue_ipv6_adr=IPAddress(version=IPAddress.IPV6, address=ue_ip_addr.encode('utf-8')), ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_detach_tunnel_flows(self): ue_ip_addr = "192.168.128.30" ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller.delete_tunnel_flows( 1, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl, ) ue_ip_addr = "192.168.128.31" self.classifier_controller.delete_tunnel_flows( 2, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
def test_resume_tunnel_ip_flow_dl(self): dest_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.128.12"), ) src_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.129.64"), ) ip_flow_dl = IPFlowDL( set_params=71, tcp_dst_port=0, tcp_src_port=5002, udp_dst_port=0, udp_src_port=0, ip_proto=6, dest_ip=dest_ip, src_ip=src_ip, precedence=65530, ) ue_ip_addr = "192.168.128.30" seid1 = 5000 self.classifier_controller.gtp_handler( 5, 65525, 1, 100000, self.EnodeB_IP, ue_ip_addr, seid1, ip_flow_dl=ip_flow_dl, ) snapshot_verifier = SnapshotVerifier( self, self.BRIDGE, self.service_manager, ) with snapshot_verifier: pass
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 ue_ip_addr = "192.168.128.30" ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller.add_tunnel_flows(65525, 1, 1000, IPAddress(version=IPAddress.IPV4,address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, seid1, True, ip_flow_dl=ip_flow_dl) # 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()
def test_discard_tunnel_flows_ipv6(self): ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller._delete_all_flows() ue_ip_addr = "2001::4" self.classifier_controller._discard_tunnel_flows(3, IPAddress(version=IPAddress.IPV6,address=ue_ip_addr.encode('utf-8')), ip_flow_dl=ip_flow_dl) snapshot_verifier = SnapshotVerifier(self, self.BRIDGE, self.service_manager) with snapshot_verifier: pass
def test_detach_s8_tunnel_flows(self): ue_ip_addr = "192.168.128.15" ip_flow_dl = IPFlowDL(set_params=0) self.classifier_controller.delete_s8_tunnel_flows( 10, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, 3000, ip_flow_dl=ip_flow_dl) snapshot_verifier = SnapshotVerifier(self, self.BRIDGE, self.service_manager) with snapshot_verifier: pass
def test_discard_tunnel_ip_flow_dl(self): dst_ip = "192.168.128.12" dest_ip = IPAddress(version=IPAddress.IPV4, address=dst_ip.encode('utf-8')) sc_ip = "192.168.129.64" src_ip = IPAddress(version=IPAddress.IPV4, address=sc_ip.encode('utf-8')) ip_flow_dl = IPFlowDL(set_params=71, tcp_dst_port=0, tcp_src_port=5002, udp_dst_port=0, udp_src_port=0, ip_proto=6, dest_ip=dest_ip, src_ip=src_ip, precedence=65530) seid1 = 5000 ue_ip_addr = "192.168.128.30" self.classifier_controller.gtp_handler( 0, 65525, 1, 100000, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, seid1, ip_flow_dl=ip_flow_dl) self.classifier_controller.gtp_handler( 4, 65525, 1, 100000, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, seid1, ip_flow_dl=ip_flow_dl) snapshot_verifier = SnapshotVerifier(self, self.BRIDGE, self.service_manager) with snapshot_verifier: pass
def __init__( self, imsi: str, priority: int, ue_v4_addr: str, ue_v6_addr: str, enb_ipv4_addr: str, apn: str, vlan: int, in_teid: int, out_teid: int, ue_state: int, flow_dl: str, ): """Do create the MME Sessions Args: imsi: Subscriber for the UE priority: Priority for the rule ue_v4_addr: UE IPv4 address ue_v6_addr : UE IPv6 address enb_ipv4_addr: GNB Ipv4 address apn: APN Name vlan: Vlan Info in_teid: Incoming teid out_teid: Outgoing teid ue_state: UE State flow_dl: Flow DL to be included """ ue_ipv4_addr = None if (ue_v4_addr): ue_ipv4_addr = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, ue_v4_addr), ) # address=args.ue_ipv4_addr.encode('utf-8')) ue_ipv6_addr = None if (ue_v6_addr): ue_ipv6_addr = IPAddress( version=IPAddress.IPV6, address=socket.inet_pton(socket.AF_INET6, ue_v6_addr), ) # address=args.ue_ipv6_addr.encode('utf-8')) enb_ip_addr = None if (enb_ipv4_addr): enb_ip_addr = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, enb_ipv4_addr), ) # address=args.enb_ip_addr.encode('utf-8')) config_ue_state = { 'ADD': UESessionState(ue_config_state=UESessionState.ACTIVE), 'DEL': UESessionState(ue_config_state=UESessionState.UNREGISTERED), 'ADD_IDLE': UESessionState(ue_config_state=UESessionState.INSTALL_IDLE), 'DEL_IDLE': UESessionState(ue_config_state=UESessionState.UNINSTALL_IDLE), 'SUSPENDED': UESessionState(ue_config_state=UESessionState.SUSPENDED_DATA), 'RESUME': UESessionState(ue_config_state=UESessionState.RESUME_DATA), } ip_flow_dl = None if (flow_dl == "ENABLE"): dest_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.128.12"), ) src_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.129.64"), ) params = 71 tcp_sport = 5002 proto_type = 6 ip_flow_dl = IPFlowDL( set_params=params, tcp_src_port=tcp_sport, ip_proto=proto_type, dest_ip=dest_ip, src_ip=src_ip, ) self._set_pg_session = UESessionSet( subscriber_id=SIDUtils.to_pb(imsi), precedence=priority, ue_ipv4_address=ue_ipv4_addr, ue_ipv6_address=ue_ipv6_addr, enb_ip_address=enb_ip_addr, apn=apn, vlan=vlan, in_teid=in_teid, out_teid=out_teid, ue_session_state=config_ue_state.get(ue_state), ip_flow_dl=ip_flow_dl, )
def test_delete_tunnel_ip_flow_dl(self): dest_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.128.12"), ) src_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.129.64"), ) ip_flow_dl = IPFlowDL(set_params=71, tcp_dst_port=0, tcp_src_port=5002, udp_dst_port=0, udp_src_port=0, ip_proto=6, dest_ip=dest_ip, src_ip=src_ip, precedence=65530) seid1 = 5000 ue_ip_addr = "192.168.128.30" self.classifier_controller.gtp_handler( 1, 65525, 1, 100000, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, seid1, ip_flow_dl=ip_flow_dl) dest_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.128.111"), ) src_ip = IPAddress( version=IPAddress.IPV4, address=socket.inet_pton(socket.AF_INET, "192.168.129.4"), ) ip_flow_dl = IPFlowDL(set_params=70, tcp_dst_port=0, tcp_src_port=0, udp_dst_port=80, udp_src_port=5060, ip_proto=17, dest_ip=dest_ip, src_ip=src_ip, precedence=65525) seid2 = 5001 ue_ip_addr = "192.168.128.31" self.classifier_controller.gtp_handler( 1, 65525, 2, 100001, IPAddress(version=IPAddress.IPV4, address=ue_ip_addr.encode('utf-8')), self.EnodeB_IP, seid2, ip_flow_dl=ip_flow_dl) snapshot_verifier = SnapshotVerifier(self, self.BRIDGE, self.service_manager) with snapshot_verifier: pass