class SpgwUtil(object): """ Helper class to communicate with spgw for the tests. """ def __init__(self): """ Initialize spgw util. """ self._stub = SpgwServiceStub(get_rpc_channel("spgw_service")) def create_bearer(self, imsi, lbi): """ Sends a CreateBearer Request to SPGW service """ print('Sending CreateBearer request to spgw service') req = CreateBearerRequest( sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, policy_rules=[ PolicyRule( qos=FlowQos( qci=1, gbr_ul=10000000, gbr_dl=10000000, max_req_bw_ul=10000000, max_req_bw_dl=10000000, arp=QosArp( priority_level=1, pre_capability=1, pre_vulnerability=0, ) ) ) ] ) self._stub.CreateBearer(req) def delete_bearer(self, imsi, lbi, ebi): """ Sends a DeleteBearer Request to SPGW service """ print('Sending DeleteBearer request to spgw service') req = DeleteBearerRequest( sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, eps_bearer_ids=[ebi] ) self._stub.DeleteBearer(req)
class SpgwUtil(object): """ Helper class to communicate with spgw for the tests. """ def __init__(self): """ Initialize spgw util. """ self._stub = SpgwServiceStub(get_rpc_channel("spgw_service")) def create_bearer(self, imsi, lbi, qci_val=1): """ Sends a CreateBearer Request to SPGW service """ print("Sending CreateBearer request to spgw service") req = CreateBearerRequest( sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, policy_rules=[ PolicyRule( id="rar_rule_1", qos=FlowQos( qci=qci_val, gbr_ul=10000000, gbr_dl=10000000, max_req_bw_ul=10000000, max_req_bw_dl=10000000, arp=QosArp( priority_level=1, pre_capability=1, pre_vulnerability=0, ), ), flow_list=[ FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV4, address="0.0.0.0/0".encode('utf-8')), tcp_dst=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV4, address="192.168.129.42/24".encode( 'utf-8')), tcp_dst=5002, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV4, address="192.168.129.42".encode('utf-8')), tcp_dst=5003, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV4, address="192.168.129.42".encode('utf-8')), tcp_dst=5004, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV4, address="192.168.129.42".encode('utf-8')), tcp_dst=5005, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.DENY, ), FlowDescription( match=FlowMatch( ip_src=IPAddress( version=IPAddress.IPV4, address="192.168.129.42".encode('utf-8')), tcp_src=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_src=IPAddress(version=IPAddress.IPV4, address="".encode('utf-8')), tcp_dst=5002, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_src=IPAddress( version=IPAddress.IPV4, address="192.168.129.64/26".encode( 'utf-8')), tcp_src=5003, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_src=IPAddress( version=IPAddress.IPV4, address="192.168.129.42/16".encode( 'utf-8')), tcp_src=5004, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ip_src=IPAddress( version=IPAddress.IPV4, address="192.168.129.42".encode('utf-8')), tcp_src=5005, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.DENY, ), ], ) ], ) self._stub.CreateBearer(req) def create_bearer_ipv4v6(self, imsi, lbi, qci_val=1, ipv4=False, ipv6=False): """ Sends a CreateBearer Request with ipv4/ipv6/ipv4v6 packet """ """ filters to SPGW service """ print("Sending CreateBearer request to spgw service") flow_match_list = [] if ipv4: flow_match_list.append( FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV4, address="192.168.129.42/24".encode("utf-8"), ), tcp_dst=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, )) flow_match_list.append( FlowDescription( match=FlowMatch( ip_src=IPAddress( version=IPAddress.IPV4, address="192.168.129.42".encode("utf-8"), ), tcp_src=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, )) if ipv6: flow_match_list.append( FlowDescription( match=FlowMatch( ip_dst=IPAddress( version=IPAddress.IPV6, address="5546:222:2259::226".encode("utf-8"), ), tcp_dst=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, )) flow_match_list.append( FlowDescription( match=FlowMatch( ip_src=IPAddress( version=IPAddress.IPV6, address="fdee:0005:006c:018c::8c99".encode( "utf-8"), ), tcp_src=5002, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, )) req = CreateBearerRequest( sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, policy_rules=[ PolicyRule( id="rar_rule_1", qos=FlowQos( qci=qci_val, gbr_ul=10000000, gbr_dl=10000000, max_req_bw_ul=10000000, max_req_bw_dl=10000000, arp=QosArp( priority_level=1, pre_capability=1, pre_vulnerability=0, ), ), flow_list=flow_match_list, ) ], ) self._stub.CreateBearer(req) def delete_bearer(self, imsi, lbi, ebi): """ Sends a DeleteBearer Request to SPGW service """ print("Sending DeleteBearer request to spgw service") req = DeleteBearerRequest(sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, eps_bearer_ids=[ebi]) self._stub.DeleteBearer(req)
class SpgwUtil(object): """ Helper class to communicate with spgw for the tests. """ def __init__(self): """ Initialize spgw util. """ self._stub = SpgwServiceStub(get_rpc_channel("spgw_service")) def create_bearer(self, imsi, lbi, qci_val=1): """ Sends a CreateBearer Request to SPGW service """ print("Sending CreateBearer request to spgw service") req = CreateBearerRequest( sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, policy_rules=[ PolicyRule( qos=FlowQos( qci=qci_val, gbr_ul=10000000, gbr_dl=10000000, max_req_bw_ul=10000000, max_req_bw_dl=10000000, arp=QosArp(priority_level=1, pre_capability=1, pre_vulnerability=0), ), flow_list=[ FlowDescription( match=FlowMatch( ipv4_dst="0.0.0.0/0", tcp_dst=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_dst="192.168.129.42/24", tcp_dst=5002, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_dst="192.168.129.42", tcp_dst=5003, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_dst="192.168.129.42", tcp_dst=5004, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_dst="192.168.129.42", tcp_dst=5005, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.UPLINK, ), action=FlowDescription.DENY, ), FlowDescription( match=FlowMatch( ipv4_src="192.168.129.42", tcp_src=5001, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_src="", tcp_src=5002, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_src="192.168.129.64/26", tcp_src=5003, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_src="192.168.129.42/16", tcp_src=5004, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.PERMIT, ), FlowDescription( match=FlowMatch( ipv4_src="192.168.129.42", tcp_src=5005, ip_proto=FlowMatch.IPPROTO_TCP, direction=FlowMatch.DOWNLINK, ), action=FlowDescription.DENY, ), ], ) ], ) self._stub.CreateBearer(req) def delete_bearer(self, imsi, lbi, ebi): """ Sends a DeleteBearer Request to SPGW service """ print("Sending DeleteBearer request to spgw service") req = DeleteBearerRequest(sid=SIDUtils.to_pb(imsi), link_bearer_id=lbi, eps_bearer_ids=[ebi]) self._stub.DeleteBearer(req)