def test_attach_asr_tcp_data(self): """ attach + send ASR Req to session manager with a""" """ single UE """ num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) datapath = get_datapath() req = self._s1ap_wrapper.ue_req print( "********************** Running End to End attach for ", "UE id ", req.ue_id, ) # Now actually complete the attach self._s1ap_wrapper._s1_util.attach( req.ue_id, s1ap_types.tfwCmd.UE_END_TO_END_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND, s1ap_types.ueAttachAccept_t, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("Sleeping for 5 seconds") time.sleep(5) print( "********************** Sending ASR for IMSI", "".join([str(i) for i in req.imsi]), ) self._sessionManager_util.create_AbortSessionRequest( "IMSI" + "".join([str(i) for i in req.imsi]), ) # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value, ) print("**************** Received NW initiated Detach Req") print("**************** Sending Detach Accept") # Send detach accept detach_accept = s1ap_types.ueTrigDetachAcceptInd_t() detach_accept.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_TRIGGERED_DETACH_ACCEPT, detach_accept) print("Sleeping for 5 seconds") time.sleep(5) print("Checking that uplink/downlink flows were deleted") flows = get_flows(datapath, { "table_id": self.SPGW_TABLE, "priority": 0 }) self.assertEqual(len(flows), 2, "There should only be 2 default table 0 flows")
def test_attach_asr_tcp_data(self): """ attach + send ASR Req to session manager with a""" """ single UE """ num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) req = self._s1ap_wrapper.ue_req print( "********************** Running End to End attach for ", "UE id ", req.ue_id, ) # Now actually complete the attach self._s1ap_wrapper._s1_util.attach( req.ue_id, s1ap_types.tfwCmd.UE_END_TO_END_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND, s1ap_types.ueAttachAccept_t, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("Sleeping for 5 seconds") time.sleep(5) print( "********************** Sending ASR for IMSI", "".join([str(i) for i in req.imsi]), ) self._sessionManager_util.create_AbortSessionRequest( "IMSI" + "".join([str(i) for i in req.imsi]), ) # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value, ) print("**************** Received NW initiated Detach Req") print("**************** Sending Detach Accept") # Send detach accept detach_accept = s1ap_types.ueTrigDetachAcceptInd_t() detach_accept.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_TRIGGERED_DETACH_ACCEPT, detach_accept, ) print("Sleeping for 5 seconds") time.sleep(5) # Verify that all UL/DL flows are deleted self._s1ap_wrapper.s1_util.verify_flow_rules_deletion()
def test_attach_nw_initiated_detach_with_mme_restart(self): """ The test case validates retransmission of Detach Request after MME restarts Step 1: UE attaches to network Step 2: Send request to delete default bearer, since deletion is invoked for default bearer, MME initaites detach procedure Step 3: MME starts 3422 timer to receive Detach Accept message Step 4: Send command to restart MME service to validate the behavior of 3422 timer, on MME recovery, it sends Detach Request Step 5: S1ap tester shall wait on Detach Request and send Detach Accept message """ self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req print( "********************** Running End to End attach for ", "UE id ", req.ue_id, ) # Now actually complete the attach attach = self._s1ap_wrapper._s1_util.attach( req.ue_id, s1ap_types.tfwCmd.UE_END_TO_END_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND, s1ap_types.ueAttachAccept_t, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("Sleeping for 5 seconds") time.sleep(5) print( "********************** Deleting default bearer for IMSI", "".join([str(i) for i in req.imsi]), ) # Delete default bearer self._spgw_util.delete_bearer( "IMSI" + "".join([str(i) for i in req.imsi]), attach.esmInfo.epsBearerId, attach.esmInfo.epsBearerId, ) # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value, ) print("**************** Received NW initiated Detach Req") print( "************************* Restarting MME service on", "gateway", ) self._s1ap_wrapper.magmad_util.restart_services(["mme"]) for j in range(30): print("Waiting for", j, "seconds") time.sleep(1) # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value, ) print("**************** Received second NW initiated Detach Req") print("**************** Sending Detach Accept") # Send detach accept detach_accept = s1ap_types.ueTrigDetachAcceptInd_t() detach_accept.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_TRIGGERED_DETACH_ACCEPT, detach_accept, )
def test_no_attach_complete_with_mme_restart(self): """ Step 1: UE sends Attach Request, receives Attach Accept and UE shall not respond to mme Step 2: After sending Attach Accept, mme runs 3450 timer, while timer is running, mme restarts. Step 3: On mme recovery, mme sends Detach Request with re-attach required, S1ap shall send Detach Accept and release the UE contexts Step 4: Once again attach UE to network """ self._s1ap_wrapper.configIpBlock() self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req print( "************************* Running attach setup timer expiry test", ) attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = req.ue_id sec_ctxt = s1ap_types.TFW_CREATE_NEW_SECURITY_CONTEXT id_type = s1ap_types.TFW_MID_TYPE_IMSI eps_type = s1ap_types.TFW_EPS_ATTACH_TYPE_EPS_ATTACH attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = req.ue_id sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) # Receive initial context setup and attach accept indication response = ( self._s1ap_wrapper._s1_util .receive_initial_ctxt_setup_and_attach_accept() ) attach_acc = response.cast(s1ap_types.ueAttachAccept_t) print( "********************** Received attach accept for UE Id:", attach_acc.ue_Id, ) print( "************************* Restarting MME service on", "gateway", ) self._s1ap_wrapper.magmad_util.restart_services(["mme"]) for j in range(20): print("Waiting for", j, "seconds") time.sleep(1) # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() while response.msg_type == s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value: print( "Received Attach Accept retransmission from before restart", "Ignoring...", ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value, ) nw_init_detach_req = response.cast(s1ap_types.ueNwInitdetachReq_t) print( "**************** Received NW initiated Detach Req with detach " "type set to ", nw_init_detach_req.Type, ) self.assertEqual( nw_init_detach_req.Type, s1ap_types.ueNwInitDetType_t.TFW_RE_ATTACH_REQUIRED.value, ) print("**************** Sending Detach Accept") # Send detach accept detach_accept = s1ap_types.ueTrigDetachAcceptInd_t() detach_accept.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_TRIGGERED_DETACH_ACCEPT, detach_accept, ) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() # Ignore retransmitted NW Initiated Detach Request messages. # This test waits for a couple of seconds after the MME restart, but most # of the time MME comes up early after the restart and retransmits multiple # NW Initiated Detach Request messages on T3422 Timer expiry. while ( response.msg_type == s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value ): nw_init_detach_req = response.cast(s1ap_types.ueNwInitdetachReq_t) print( "**************** Received retransmitted NW Initiated Detach " "Req with detach type set to", nw_init_detach_req.Type, "Ignoring...", ) self.assertEqual( nw_init_detach_req.Type, s1ap_types.ueNwInitDetType_t.TFW_RE_ATTACH_REQUIRED.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) print("****** Received Ue context release command *********") print("****** Triggering end-end attach after mme restart *********") self._s1ap_wrapper.s1_util.attach( req.ue_id, s1ap_types.tfwCmd.UE_END_TO_END_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND, s1ap_types.ueAttachAccept_t, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() # Now detach the UE self._s1ap_wrapper.s1_util.detach( req.ue_id, s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value, wait_for_s1_ctxt_release=False, )
def test_attach_detach_nw_triggered_delete_last_pdn(self): """ attach + add dedicated bearer + delete default bearer """ """ test with a single UE """ num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) for i in range(num_ues): req = self._s1ap_wrapper.ue_req print( "********************** Running End to End attach for ", "UE id ", req.ue_id, ) # Now actually complete the attach attach = self._s1ap_wrapper._s1_util.attach( req.ue_id, s1ap_types.tfwCmd.UE_END_TO_END_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND, s1ap_types.ueAttachAccept_t, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("Sleeping for 5 seconds") time.sleep(5) print( "********************** Adding dedicated bearer to IMSI", "".join([str(i) for i in req.imsi]), ) self._spgw_util.create_bearer( "IMSI" + "".join([str(i) for i in req.imsi]), attach.esmInfo.epsBearerId, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ACT_DED_BER_REQ.value) act_ded_ber_ctxt_req = response.cast( s1ap_types.UeActDedBearCtxtReq_t) self._s1ap_wrapper.sendActDedicatedBearerAccept( req.ue_id, act_ded_ber_ctxt_req.bearerId) print("Sleeping for 5 seconds") time.sleep(5) print( "********************** Deleting default bearer for IMSI", "".join([str(i) for i in req.imsi]), ) # Delete default bearer self._spgw_util.delete_bearer( "IMSI" + "".join([str(i) for i in req.imsi]), attach.esmInfo.epsBearerId, attach.esmInfo.epsBearerId, ) # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value, ) print("**************** Received NW initiated Detach Req") print("**************** Sending Detach Accept") # Send detach accept detach_accept = s1ap_types.ueTrigDetachAcceptInd_t() detach_accept.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_TRIGGERED_DETACH_ACCEPT, detach_accept)
def test_attach_ics_drop_with_mme_restart(self): """Stateless Initial Context Setup Drop Test Case: 1. Step-by-step UE attach procedure 2. Set flag in S1APTester to drop ICS request message 3. Restart MME after getting ICS request dropped indication 4. Reset flag to not drop next ICS request messages 5. Handle UE context release after no ICS response to MME 6. Re-attach UE to verify if UE context was cleared properly after handling the NW Initiated detach once MME comes up """ self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Send Attach Request attach_req = s1ap_types.ueAttachRequest_t() sec_ctxt = s1ap_types.TFW_CREATE_NEW_SECURITY_CONTEXT id_type = s1ap_types.TFW_MID_TYPE_IMSI eps_type = s1ap_types.TFW_EPS_ATTACH_TYPE_EPS_ATTACH pdn_type = s1ap_types.pdn_Type() pdn_type.pres = True pdn_type.pdn_type = 3 attach_req.ue_Id = req.ue_id attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt attach_req.pdnType_pr = pdn_type print("******************** Sending Attach Request") self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) print("******************** Received Authentiction Request Indication") # Send Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = req.ue_id sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = 0 auth_res.sqnRcvd = sqnRecvd print("******************** Sending Authentiction Response") self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) print("******************** Received Security Mode Command Indication") print( "******************** Setting flag to drop Initial Context Setup " "Request", ) drop_init_ctxt_setup_req = s1ap_types.UeDropInitCtxtSetup() drop_init_ctxt_setup_req.ue_Id = req.ue_id drop_init_ctxt_setup_req.flag = 1 # Timer to release UE context at s1ap tester drop_init_ctxt_setup_req.tmrVal = 2000 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SET_DROP_ICS, drop_init_ctxt_setup_req, ) print("******************** Sending Security Mode Complete") # Send Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) # enbApp sends UE_ICS_DROPD_IND message to tfwApp after dropping # ICS request response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ICS_DROPD_IND.value, ) print( "******************** Received Initial Context Setup Dropped " "Indication", ) print("******************** Restarting MME service on gateway") self._s1ap_wrapper.magmad_util.restart_services(["mme"]) print( "******************** Resetting flag to not drop next Initial " "Context Setup Request messages", ) drop_init_ctxt_setup_req = s1ap_types.UeDropInitCtxtSetup() drop_init_ctxt_setup_req.ue_Id = req.ue_id drop_init_ctxt_setup_req.flag = 0 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SET_DROP_ICS, drop_init_ctxt_setup_req, ) for j in range(30): print("Waiting for", j, "seconds") time.sleep(1) # It has been observed that despite getting the restart command on # time, MME sometimes restarts after a delay of 5-6 seconds. If MME # restarts before ICS timer expiry of 4 seconds, it will send NW # initiated detach request with type re-attach required after coming # up, else MME will do implicit detach and send UE context release # command to release the S1AP context print( "******************** Waiting for NW initiated Detach Request or " "UE Context Release Indication", ) resp_count = 0 while True: resp_count += 1 # Receive NW initiated detach request response = self._s1ap_wrapper.s1_util.get_response() if ( response.msg_type == s1ap_types.tfwCmd.UE_NW_INIT_DETACH_REQUEST.value ): nw_init_detach_req = response.cast( s1ap_types.ueNwInitdetachReq_t, ) print( "******************** Received NW initiated Detach Request" " with detach type ", nw_init_detach_req.Type, ) self.assertEqual( nw_init_detach_req.Type, s1ap_types.ueNwInitDetType_t.TFW_RE_ATTACH_REQUIRED.value, ) if resp_count == 1: # Send detach accept detach_accept = s1ap_types.ueTrigDetachAcceptInd_t() detach_accept.ue_Id = req.ue_id print( "******************** Sending UE triggered Detach " "Accept message", ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_TRIGGERED_DETACH_ACCEPT, detach_accept, ) else: print( "******************** Ignoring re-transmitted (", resp_count, ") NW initiated detach request message", ) else: break self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) print("******************** Received UE Context Release indication") print( "******************** Running End to End attach to verify if " "UE context was released properly after handling ICS drop for " "UE id ", req.ue_id, ) # Now actually complete the attach self._s1ap_wrapper._s1_util.attach( req.ue_id, s1ap_types.tfwCmd.UE_END_TO_END_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND, s1ap_types.ueAttachAccept_t, ) # Wait for EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print( "******************** Running UE detach (switch-off) for ", "UE id ", req.ue_id, ) # Now detach the UE self._s1ap_wrapper.s1_util.detach( req.ue_id, s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value, True, )