def _ng_tunnel_update(self, pdr_entry: PDRRuleEntry, subscriber_id: str) -> bool: if pdr_entry.pdr_state == PdrState.Value('INSTALL'): ret = self._classifier_app.add_tunnel_flows(\ pdr_entry.precedence, pdr_entry.local_f_teid,\ pdr_entry.far_action.o_teid, pdr_entry.ue_ip_addr,\ pdr_entry.far_action.gnb_ip_addr, encode_imsi(subscriber_id)) elif pdr_entry.pdr_state in \ [PdrState.Value('REMOVE'), PdrState.Value('IDLE')]: ret = self._classifier_app.delete_tunnel_flows(\ pdr_entry.local_f_teid, pdr_entry.ue_ip_addr) return ret
def _pdr_create_rule_group(new_session, pdr_rules) -> Optional[MsgParseOutput]: for pdr_entry in new_session.set_gr_pdr: # PDR Validation if pdr_entry.HasField('pdi') == False or pdr_entry.pdr_id == 0: offending_ie = OffendingIE( identifier=pdr_entry.pdr_id, version=pdr_entry.pdr_version, ) return MsgParseOutput(offending_ie, CauseIE.MANDATORY_IE_INCORRECT) # If session is creted or activiated FAR_IDs cann't be 0 if len(pdr_entry.set_gr_far.ListFields()) == 0 and \ pdr_entry.pdr_state == PdrState.Value('INSTALL'): offending_ie = OffendingIE( identifier=pdr_entry.pdr_id, version=pdr_entry.pdr_version, ) return MsgParseOutput(offending_ie, CauseIE.INVALID_FORWARDING_POLICY) if not pdr_entry.pdi.ue_ip_adr: return MsgParseOutput(offending_ie, CauseIE.MANDATORY_IE_INCORRECT) pdr_rules.update( {pdr_entry.pdr_id: pdr_create_rule_entry(pdr_entry)}) return None
def gtp_handler(self, session_state, precedence: int, local_f_teid: int, o_teid: int, ue_ip_addr: IPAddress, gnb_ip_addr: str, sid: int = None, ng_flag: bool = True, ue_ipv6_address: IPAddress = None, apn: str = None, vlan: int = 0, ip_flow_dl: IPFlowDL = None): if (session_state == PdrState.Value('INSTALL') or session_state == UESessionState.ACTIVE): self.add_tunnel_flows(precedence, local_f_teid, o_teid, ue_ip_addr, gnb_ip_addr, sid, ng_flag, ue_ipv6_address, apn, vlan, ip_flow_dl) elif (session_state == PdrState.Value('IDLE') or session_state == UESessionState.INSTALL_IDLE): self.delete_tunnel_flows(local_f_teid, ue_ip_addr, gnb_ip_addr, ip_flow_dl) self.install_paging_flow(ue_ip_addr, local_f_teid, ng_flag) elif (session_state == PdrState.Value('REMOVE') or session_state == UESessionState.UNREGISTERED): self.delete_tunnel_flows(local_f_teid, ue_ip_addr, gnb_ip_addr, ip_flow_dl) self.remove_paging_flow(ue_ip_addr) elif (session_state == UESessionState.RESUME_DATA): self.resume_tunnel_flows(local_f_teid, ue_ip_addr, ip_flow_dl) elif (session_state == UESessionState.SUSPENDED_DATA): self.discard_tunnel_flows(local_f_teid, ue_ip_addr, ip_flow_dl) return True
def gtp_handler(self, pdr_state, precedence: int, local_f_teid: int, o_teid: int, ue_ip_addr: IPAddress, gnb_ip_addr: str, sid: int = None, ng_flag: bool = True): if pdr_state == PdrState.Value('INSTALL'): self.remove_paging_flow(ue_ip_addr) self.add_tunnel_flows(precedence, local_f_teid, o_teid, ue_ip_addr, gnb_ip_addr, sid, ng_flag) elif pdr_state == PdrState.Value('IDLE'): self.delete_tunnel_flows(local_f_teid, ue_ip_addr) self._install_paging_flow(ue_ip_addr, local_f_teid, ng_flag) elif pdr_state == PdrState.Value('REMOVE'): self.delete_tunnel_flows(local_f_teid, ue_ip_addr) self.remove_paging_flow(ue_ip_addr) return True
def CreateSessionWithFaultyFar(self): downlink_pdr = CreateSessionUtil.CreatePDR(1234, 1, PdrState.Value('INSTALL'), 32, 0, "90.90.90.100") self.CreateSessionMsg("IMSI001010000000001", downlink_pdr)
def CreateSessionWithFaultyPDR(self): uplink_far = CreateSessionUtil.CreateFARinPDR(0, '') uplink_pdr = CreateSessionUtil.CreatePDR(0, 1, PdrState.Value('INSTALL'), 32, 100, "90.90.90.100") self.CreateSessionMsg("IMSI001010000000001", uplink_pdr, uplink_far)
def CreateSession(self, imsi_val: str, pdr_state: str = "ADD", in_teid: int = 0, out_teid: int = 0, ue_ip_addr: str = "", gnb_ip_addr: str = "", del_rule_id: str = '', add_rule_id: str = '', ipv4_dst: str = None, allow: str = "YES", priority: int = 10, hard_timeout: int = 0): pdr_id = 1 del_qer_enforcer = None uplink_qer_enforcer = None downlink_qer_enforcer = None uplink_pdr = None downlink_pdr = None if del_rule_id: del_qer_tuple = QoSEnforceRuleEntry(imsi_val, del_rule_id, None, None, None, None, None) del_qer_enforcer = CreateSessionUtil.CreateDelQERinPDR( del_qer_tuple, ue_ip_addr) if add_rule_id: uplink_qer_tuple = QoSEnforceRuleEntry(imsi_val, add_rule_id, ipv4_dst, allow, priority, hard_timeout, FlowMatch.UPLINK) uplink_qer_enforcer = CreateSessionUtil.CreateAddQERinPDR( uplink_qer_tuple, ue_ip_addr) downlink_qer_tuple = QoSEnforceRuleEntry(imsi_val, add_rule_id, ipv4_dst, allow, priority, hard_timeout, FlowMatch.DOWNLINK) downlink_qer_enforcer = CreateSessionUtil.CreateAddQERinPDR( downlink_qer_tuple, ue_ip_addr) uplink_far = CreateSessionUtil.CreateFARinPDR(0, '') downlink_far = CreateSessionUtil.CreateFARinPDR(out_teid, gnb_ip_addr) if pdr_state == "ADD": uplink_pdr = CreateSessionUtil.CreatePDR(pdr_id, 1, PdrState.Value('INSTALL'), 32, in_teid, ue_ip_addr) pdr_id = pdr_id + 1 downlink_pdr = CreateSessionUtil.CreatePDR( pdr_id, 1, PdrState.Value('INSTALL'), 32, 0, ue_ip_addr) elif pdr_state == "IDLE": uplink_pdr = CreateSessionUtil.CreatePDR(pdr_id, 1, PdrState.Value('IDLE'), 32, in_teid, ue_ip_addr) pdr_id = pdr_id + 1 downlink_pdr = CreateSessionUtil.CreatePDR(pdr_id, 1, PdrState.Value('IDLE'), 32, 0, ue_ip_addr) else: uplink_pdr = CreateSessionUtil.CreatePDR(pdr_id, 1, PdrState.Value('REMOVE'), 32, in_teid, ue_ip_addr) pdr_id = pdr_id + 1 downlink_pdr = CreateSessionUtil.CreatePDR( pdr_id, 1, PdrState.Value('REMOVE'), 32, 0, ue_ip_addr) self.CreateSessionMsg(imsi_val, uplink_pdr, uplink_far, del_qer_enforcer, uplink_qer_enforcer) self.CreateSessionMsg(imsi_val, downlink_pdr, downlink_far, del_qer_enforcer, downlink_qer_enforcer)
def _ng_qer_update( self, request: SessionSet, pdr_entry: PDRRuleEntry, ) -> Tuple[List[RuleModResult], List[RuleModResult]]: enforcement_res = [] failed_policy_rules_results = [] local_f_teid_ng = request.local_f_teid # PDR is deleted with ActiveRules or DelActive rules recieved if pdr_entry.pdr_state == PdrState.Value('REMOVE'): qos_enforce_rule = pdr_entry.del_qos_enforce_rule if qos_enforce_rule.ip_addr: ipv4 = convert_ip_str_to_ip_proto(qos_enforce_rule.ip_addr) self._ng_deactivate_qer_flows( ipv4, local_f_teid_ng, qos_enforce_rule, ) if qos_enforce_rule.ipv6_addr: ipv6 = convert_ipv6_bytes_to_ip_proto( qos_enforce_rule.ipv6_addr) self._ng_deactivate_qer_flows( ipv6, local_f_teid_ng, qos_enforce_rule, ) elif pdr_entry.pdr_state == PdrState.Value('IDLE'): qos_enforce_rule = pdr_entry.add_qos_enforce_rule if qos_enforce_rule.ip_addr: ipv4 = convert_ipv4_str_to_ip_proto(qos_enforce_rule.ip_addr) self._ng_inactivate_qer_flows(ipv4, qos_enforce_rule) if qos_enforce_rule.ipv6_addr: ipv6 = convert_ipv6_bytes_to_ip_proto( qos_enforce_rule.ipv6_addr) self._ng_inactivate_qer_flows(ipv6, qos_enforce_rule) # Install PDR rules elif pdr_entry.pdr_state == PdrState.Value('INSTALL'): qos_enforce_rule = pdr_entry.add_qos_enforce_rule if qos_enforce_rule.ip_addr: ipv4 = convert_ip_str_to_ip_proto(qos_enforce_rule.ip_addr) enforcement_res = \ self._ng_activate_qer_flow( ipv4, local_f_teid_ng, qos_enforce_rule, ) failed_policy_rules_results = \ _retrieve_failed_results(enforcement_res) if qos_enforce_rule.ipv6_addr: ipv6 = convert_ipv6_bytes_to_ip_proto( qos_enforce_rule.ipv6_addr) enforcement_res = \ self._ng_activate_qer_flow( ipv6, local_f_teid_ng, qos_enforce_rule, ) failed_policy_rules_results = \ _retrieve_failed_results(enforcement_res) return failed_policy_rules_results
def gtp_handler( self, session_state, precedence: int, local_f_teid: int, o_teid: int, gnb_ip_addr: str, ue_ip_addr: str = None, sid: int = None, ng_flag: bool = True, ue_ipv6_address: str = None, apn: str = None, vlan: int = 0, ip_flow_dl: IPFlowDL = None, session_qfi: QCI = 0, ): ue_ip_adr = None ue_ipv6_adr = None if ue_ip_addr: ue_ip_adr = convert_ip_str_to_ip_proto(ue_ip_addr) if ue_ipv6_address: ue_ipv6_adr = convert_ip_str_to_ip_proto(ue_ipv6_address) if (session_state == PdrState.Value('INSTALL') or session_state == UESessionState.ACTIVE): # TODO: Will make same priority value for paging as active session # then probably not required remove_paging_flow call. self.remove_paging_flow(ue_ip_adr, ue_ipv6_adr) self.add_tunnel_flows( precedence, local_f_teid, o_teid, gnb_ip_addr, ue_ip_adr, sid, ng_flag, ue_ipv6_adr, apn, vlan, ip_flow_dl, session_qfi, ) elif (session_state == PdrState.Value('IDLE') or session_state == UESessionState.INSTALL_IDLE): self.delete_tunnel_flows( local_f_teid, ue_ip_adr, gnb_ip_addr, ip_flow_dl, ue_ipv6_adr, ng_flag, session_qfi, ) self.install_paging_flow(local_f_teid, ue_ip_adr, ng_flag, ue_ipv6_adr) elif (session_state == PdrState.Value('REMOVE') or session_state == UESessionState.UNREGISTERED): self.delete_tunnel_flows( local_f_teid, ue_ip_adr, gnb_ip_addr, ip_flow_dl, ue_ipv6_adr, ng_flag, session_qfi, ) self.remove_paging_flow(ue_ip_adr, ue_ipv6_adr) elif (session_state == UESessionState.RESUME_DATA): self.resume_tunnel_flows( local_f_teid, ue_ip_adr, ip_flow_dl, ) elif (session_state == UESessionState.SUSPENDED_DATA): self.discard_tunnel_flows( local_f_teid, ue_ip_adr, ip_flow_dl, ) return True