def test_attach_no_initial_context_setup_resp(self): """ Attach, no initial context setup response """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req ue_id = req.ue_id print("***** Running attach - initial context 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 sqnrecvd = s1ap_types.ueSqnRcvd_t() sqnrecvd.pres = 0 auth_res.sqnRcvd = sqnrecvd 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) print( "************************* Receive Initial context Setup request ", "for UE id ", ue_id, ) # Send SCTP ABORT to MME sctp_abort = s1ap_types.FwSctpAbortReq_t() sctp_abort.cause = 0 self._s1ap_wrapper._s1_util.issue_cmd(s1ap_types.tfwCmd.SCTP_ABORT_REQ, sctp_abort) print( "************************* Send Initial context Setup response ", "for UE id ", ue_id, ) print("***************** Attach Aborted and UE Context released")
def test_no_attach_complete(self): # Ground work. 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 sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = 0 auth_res.sqnRcvd = sqnRecvd 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) # EPC would resend Attach accept 4 times and then would abort attach # procedure for i in range(4): response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) print("************************* Timeout", i + 1) print("***************** Attach Aborted and UE Context released") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value)
def handle_msg(self, msg): if msg.msg_type == s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value: self.auth_req_ind_count += 1 m = msg.cast(s1ap_types.ueAuthReqInd_t) print("====> Received UE_AUTH_REQ_IND ue-id", m.ue_Id) auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = m.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 ) elif msg.msg_type == s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value: self.sec_mod_cmd_ind_count += 1 m = msg.cast(s1ap_types.ueSecModeCmdInd_t) print("============> Received UE_SEC_MOD_CMD_IND ue-id", m.ue_Id) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = m.ue_Id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete ) elif msg.msg_type == s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value: self.attach_accept_ind_count += 1 m = msg.cast(s1ap_types.ueAttachAccept_t) print("====================> Received UE_ATTACH_ACCEPT_IND ue-id", m.ue_Id) pdn_type = m.esmInfo.pAddr.pdnType addr = m.esmInfo.pAddr.addrInfo if self._s1ap_wrapper._s1_util.CM_ESM_PDN_IPV4 == pdn_type: # Cast and cache the IPv4 address ip = ipaddress.ip_address(bytes(addr[:4])) with self._s1ap_wrapper._s1_util._lock: self._s1ap_wrapper._s1_util._ue_ip_map[m.ue_Id] = ip attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = m.ue_Id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete ) elif msg.msg_type == s1ap_types.tfwCmd.UE_IDENTITY_REQ_IND.value: self.identity_req_ind_count += 1 m = msg.cast(s1ap_types.ueIdentityReqInd_t) print("=> Received UE_IDENTITY_REQ_IND ue-id", m.ue_Id) us_identity_resp = s1ap_types.ueIdentityResp_t() us_identity_resp.ue_Id = m.ue_Id us_identity_resp.idType = m.idType self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_IDENTITY_RESP, us_identity_resp ) elif msg.msg_type == s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value: self.int_ctx_setup_ind_count += 1 elif msg.msg_type == s1ap_types.tfwCmd.UE_EMM_INFORMATION.value: self.ue_emm_information_count += 1 elif msg.msg_type == s1ap_types.tfwCmd.UE_CTX_REL_IND.value: self.ue_ctx_rel_ind_count += 1 else: print("Unhandled msg type", msg.msg_type)
def test_duplicate_attach(self): """ Start the attach procedure for an UE, proceed until attach accept is recvd. from the network. Without sending an attach accept, resend an attach request. """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req print("************************* Running duplicate attach test") self._s1ap_wrapper._s1_util.attach(req.ue_id, s1ap_types.tfwCmd.UE_ATTACH_REQUEST, s1ap_types.tfwCmd.UE_AUTH_REQ_IND, s1ap_types.ueAttachComplete_t) auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = req.ue_id sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = False auth_res.sqnRcvd = sqnRecvd self._s1ap_wrapper._s1_util.issue_cmd(s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res) response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) while True: response = self._s1ap_wrapper.s1_util.get_response() if (response.msg_type == s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value): print("Recvd an Attach accept message ignoring") continue self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value) break print("************************ Running RE-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("************************* Running UE detach") # Now detach the UE self._s1ap_wrapper._s1_util.detach(req.ue_id, s1ap_types.ueDetachType_t. UE_NORMAL_DETACH.value)
def exec_sec_mode_complete_step(self, ue_id): sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete) print("Received Esm Information Request ue-id", sec_mode_complete.ue_Id) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ESM_INFORMATION_REQ.value) esm_info_req = response.cast(s1ap_types.ueEsmInformationReq_t) return esm_info_req.tId
def test_imei_restriction_wildcard_snr(self): """ This TC validates imei restriction scenario where only tac part of imei is configured i.e snr is wildcarded: 1. Send security mode complete message with a blocked imeisv where tac is same as the one configured in mme.conf.template 2. Verify that attach reject is received with cause(5) IMEI_NOT_ACCEPTED If this TC is executed individually run test_modify_mme_config_for_sanity.py to add { IMEI_TAC="99333821"} under the BLOCKED_IMEI_LIST in mme.conf.template. After execution of this TC run test_restore_mme_config_after_sanity.py to restore the old mme.conf.template. """ num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) 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 = 1 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 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) print( "********************** Sent attach req for UE id ", req.ue_id, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) auth_req = response.cast(s1ap_types.ueAuthReqInd_t) print( "********************** Received auth req for UE id", auth_req.ue_Id, ) # 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 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res, ) print("********************** Sent auth rsp for UE id", req.ue_id) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) sec_mod_cmd = response.cast(s1ap_types.ueSecModeCmdInd_t) print( "********************** Received security mode cmd for UE id", sec_mod_cmd.ue_Id, ) # Send Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = req.ue_id sec_mode_complete.imeisv_pres = True imeisv = "9933382135103723" # Check if the len of imeisv exceeds 16 self.assertLessEqual(len(imeisv), 16) for i in range(0, len(imeisv)): sec_mode_complete.imeisv[i] = ctypes.c_ubyte(int(imeisv[i])) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) print( "********************** Sent security mode complete for UE id", req.ue_id, ) # Receive Attach Reject response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_REJECT_IND.value, ) attach_rej = response.cast(s1ap_types.ueAttachRejInd_t) print( "********************** Received attach reject for UE id %d" " with emm cause %d" % (attach_rej.ue_Id, attach_rej.cause), ) # Verify cause self.assertEqual( attach_rej.cause, s1ap_types.TFW_EMM_CAUSE_IMEI_NOT_ACCEPTED, ) # UE Context release response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) ue_context_rel = response.cast(s1ap_types.ueCntxtRelReq_t) print( "********************** Received UE_CTX_REL_IND for UE id ", ue_context_rel.ue_Id, )
def test_no_esm_information_rsp_with_mme_restart(self): """ Restart MME after receiving ESM information req during attach + after MME recovers perform end-end attach + detach """ num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) req = self._s1ap_wrapper.ue_req ue_id = req.ue_id # Send Attach attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 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 # enabling ESM Information transfer flag attach_req.eti.pres = 1 attach_req.eti.esm_info_transfer_flag = 1 print("Sending Attach Request ue-id", ue_id) 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 Auth Req for ue-id", ue_id) auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = ue_id sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd print("Sending Auth Response for ue-id", ue_id) 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 for ue-id", ue_id) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete) print("Sent Security Mode Complete for ue-id", ue_id) # Esm Information Request indication response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ESM_INFORMATION_REQ.value) print("Received Esm Information Request ue-id", ue_id) 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 UE_ESM_INFORMATION_REQ, as sometimes MME retransmits # UE_ESM_INFORMATION_REQ message before it restarts # as T3489 timer is only 4 secs. response = self._s1ap_wrapper.s1_util.get_response() if response.msg_type == s1ap_types.tfwCmd.UE_ESM_INFORMATION_REQ.value: print( "Received retransmitted UE_ESM_INFORMATION_REQ for ue-id", ue_id, ) # Wait for UE_CTX_REL_IND global response response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value) # Perform end-end attach self._s1ap_wrapper.s1_util.attach( 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( "******************* Running UE detach (switch-off) for ", "UE id ", ue_id, ) # Now detach the UE self._s1ap_wrapper.s1_util.detach( ue_id, s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value, False)
def test_imei_restriction_smc(self): """ This TC does the following: 1. Send security mode complete message with a blocked imeisv which is same as the one configured in mme.conf.template 2. Verify that attach reject is received with cause(5) IMEI_NOT_ACCEPTED 3. Attach a 2nd UE with an allowed IMEISV by invoking attach utility function 4. Detach the UE If this TC is executed individually run test_modify_mme_config_for_sanity.py to add { IMEI="9900048235103723"} under the BLOCKED_IMEI_LIST in mme.conf.template. After execution of this TC run test_restore_mme_config_after_sanity.py to restore the old mme.conf.template. """ num_ues = 2 ue_ids = [] self._s1ap_wrapper.configUEDevice(num_ues) for _ in range(num_ues): req = self._s1ap_wrapper.ue_req ue_ids.append(req.ue_id) # 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 = 1 attach_req.ue_Id = ue_ids[0] attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt attach_req.pdnType_pr = pdn_type self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) print( "********************** Sent attach req for UE id ", ue_ids[0], ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) auth_req = response.cast(s1ap_types.ueAuthReqInd_t) print( "********************** Received auth req for UE id", auth_req.ue_Id, ) # Send Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = ue_ids[0] sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = 0 auth_res.sqnRcvd = sqnRecvd self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res, ) print("********************** Sent auth rsp for UE id", ue_ids[0]) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) sec_mod_cmd = response.cast(s1ap_types.ueSecModeCmdInd_t) print( "********************** Received security mode cmd for UE id", sec_mod_cmd.ue_Id, ) # Send Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = ue_ids[0] sec_mode_complete.imeisv_pres = True imeisv = "9900048235103723" # Check if the len of imeisv exceeds 16 self.assertLessEqual(len(imeisv), 16) for i in range(0, len(imeisv)): sec_mode_complete.imeisv[i] = ctypes.c_ubyte(int(imeisv[i])) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) print( "********************** Sent security mode complete for UE id", ue_ids[0], ) # Receive Attach Reject response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_REJECT_IND.value, ) attach_rej = response.cast(s1ap_types.ueAttachRejInd_t) print( "********************** Received attach reject for UE id %d" " with emm cause %d" % (attach_rej.ue_Id, attach_rej.cause), ) # Verify cause self.assertEqual( attach_rej.cause, s1ap_types.TFW_EMM_CAUSE_IMEI_NOT_ACCEPTED, ) # UE Context release response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) ue_context_rel = response.cast(s1ap_types.ueCntxtRelReq_t) print( "********************** Received UE_CTX_REL_IND for UE id ", ue_context_rel.ue_Id, ) # Attach the 2nd UE print( "************ Running end-end attach for UE id ************", ue_ids[1], ) self._s1ap_wrapper._s1_util.attach( ue_ids[1], 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 2 seconds") time.sleep(2) print("********************** Running UE detach for UE id ", ue_ids[1]) # Now detach the UE self._s1ap_wrapper.s1_util.detach( ue_ids[1], s1ap_types.ueDetachType_t.UE_NORMAL_DETACH.value, )
def test_ics_timer_expiry_ue_unregistered(self): """ Simulating ICS timer expiry by dropping ICS req during attach i.e UE is in unregistered state. Network sends UE context release cmd after ICS timer expires """ self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger 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 = 1 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 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("*** Sending indication to drop Initial Context Setup Req ***") 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) # Trigger 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 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) # Trigger 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value) print( "************************* Received UE_CTX_REL_IND for UE id ", req.ue_id, )
def test_esm_information(self): """ Testing of sending Esm Information procedure """ num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) print("************************* sending Attach Request for ue-id : 1") attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 1 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 # enabling ESM Information transfer flag attach_req.eti.pres = 1 attach_req.eti.esm_info_transfer_flag = 1 print("Sending Attach Request ue-id", attach_req.ue_Id) 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 auth req ind ") auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = 1 sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd print("Sending Auth Response ue-id", auth_res.ue_Id) 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 ue-id", auth_res.ue_Id) time.sleep(1) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete) # Esm Information Request indication print("Received Esm Information Request ue-id", sec_mode_complete.ue_Id) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ESM_INFORMATION_REQ.value) esm_info_req = response.cast(s1ap_types.ueEsmInformationReq_t) # Sending Esm Information Response print("Sending Esm Information Response ue-id", sec_mode_complete.ue_Id) esm_info_response = s1ap_types.ueEsmInformationRsp_t() esm_info_response.ue_Id = 1 esm_info_response.tId = esm_info_req.tId esm_info_response.pdnAPN_pr.pres = 1 s = "magma.ipv4" esm_info_response.pdnAPN_pr.len = len(s) esm_info_response.pdnAPN_pr.pdn_apn = (ctypes.c_ubyte * 100)( *[ctypes.c_ubyte(ord(c)) for c in s[:100]]) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ESM_INFORMATION_RSP, esm_info_response) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("*** Running UE detach ***") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = 1 detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value)
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, )
def test_attach_enb_rlf(self): """ Attach, after attach procedure is completed, eNB detects the RLF i.e., releasing the context by sending UE context release request with cause Radio Link Failure by that time we sending one more attach request """ # Ground work. self._s1ap_wrapper.configUEDevice(1) # Trigger 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 attach_req.ue_Id = 1 attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt print("***Triggering 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, ) # Trigger Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = 1 sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = 0 auth_res.sqnRcvd = sqnRecvd 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, ) # Trigger Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) print("***Triggering Re-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 attach_req.ue_Id = 1 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, ) # Send UE context release request with cause Radio Link Failure ue_ctxt_rel_req = s1ap_types.ueCntxtRelReq_t() ue_ctxt_rel_req.ue_Id = 1 ue_ctxt_rel_req.cause.causeVal = ( gpp_types.CauseRadioNetwork.RADIO_CONNECTION_WITH_UE_LOST.value) self._s1ap_wrapper.s1_util.issue_cmd( s1ap_types.tfwCmd.UE_CNTXT_REL_REQUEST, ue_ctxt_rel_req, ) time.sleep(1)
def test_resync(self): """Attach logic where we bump up the seq number stored in UE SQN array in order to trigger authentication failure from UE to verify the re-sync of seq number logic in EPC""" # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req print("************************* Running sync failure 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 # Trigger Attach 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() max_sqn_recvd = s1ap_types.ueSqnRcvd_t() # Use SQN received from EPC as is sqn_recvd.pres = False # Set UE side max SQN value to bigger than value received from EPC # This is to trigger auth failure with cause = Sync Failure max_sqn_recvd.pres = True max_sqn_recvd.sqn = (0, 0, 0, 0, 0, 96) auth_res.sqnRcvd = sqn_recvd auth_res.maxSqnRcvd = max_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() # Verify that EPC re-sends Authentication Request self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) print("************************* Retrying authentication") # Use SQN received from EPC as is sqn_recvd.pres = False 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, ) # Trigger Security mode complete message 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, ) # Trigger Attach complete message attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) print("************************* UE Attach Complete") # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("************************* Running UE detach") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = req.ue_id detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, )
def test_enb_partial_reset_con_dereg(self): """Test ENB partial reset with 1 UE while UE is connected and de-registered """ ue_ids = [] num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) for _ in range(num_ues): req = self._s1ap_wrapper.ue_req print( "************************* Calling attach for UE id", req.ue_id, ) # Trigger Attach Request with PDN_Type = IPv4v6 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 # Set PDN TYPE to IPv4V6 i.e. 3. IPV4 is equal to 1 # IPV6 is equal to 2 in value pdn_type.pdn_type = 1 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( "************************* Triggering Attach Request with PDN " "Type IPv4 test", ) 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, ) # Trigger Authentication Response 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, ) # Trigger 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, ) # 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, ) ue_ids.append(req.ue_id) # Trigger eNB Reset # Add delay to ensure S1APTester sends attach complete before sending # eNB Reset Request time.sleep(0.5) print("************************* Sending eNB Partial Reset Request") reset_req = s1ap_types.ResetReq() reset_req.rstType = s1ap_types.resetType.PARTIAL_RESET.value reset_req.cause = s1ap_types.ResetCause() reset_req.cause.causeType = ( s1ap_types.NasNonDelCauseType.TFW_CAUSE_MISC.value) # Set the cause to MISC.hardware-failure reset_req.cause.causeVal = 3 reset_req.r = s1ap_types.R() reset_req.r.partialRst = s1ap_types.PartialReset() reset_req.r.partialRst.numOfConn = num_ues reset_req.r.partialRst.ueS1apIdPairList = ( (s1ap_types.UeS1apIdPair) * reset_req.r.partialRst.numOfConn)() for indx in range(reset_req.r.partialRst.numOfConn): reset_req.r.partialRst.ueS1apIdPairList[indx].ueId = ue_ids[indx] print( "Reset_req.r.partialRst.ueS1apIdPairList[", indx, "].ueId", reset_req.r.partialRst.ueS1apIdPairList[indx].ueId, ) self._s1ap_wrapper.s1_util.issue_cmd( s1ap_types.tfwCmd.RESET_REQ, reset_req, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.RESET_ACK.value)
def test_attach_detach_ics_failure(self): """ Initial Context Setup Failure Test Case""" # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger 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("***Triggering 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, ) init_ctxt_setup_fail = s1ap_types.ueInitCtxtSetupFail() init_ctxt_setup_fail.ue_Id = req.ue_id init_ctxt_setup_fail.flag = 1 init_ctxt_setup_fail.causeType = 1 init_ctxt_setup_fail.causeType = 0 print("*** Setting Initial Context Setup Failure ***") # Trigger 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 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, ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SET_INIT_CTXT_SETUP_FAIL, init_ctxt_setup_fail, ) # Trigger 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, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) print("*** Received Initial Context Setup Failure ***") # Send SCTP ABORT to MME sctp_abort = s1ap_types.FwSctpAbortReq_t() sctp_abort.cause = 0 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.SCTP_ABORT_REQ, sctp_abort, )
def test_attach_esm_information_with_apn_correction(self): """ Testing of sending wrong APN in Esm Information procedure and using APN correction feature to override it """ num_ues = 1 print('************************* restarting mme') self._s1ap_wrapper.magmad_util.restart_services(['mme']) for j in range(15): print("Waiting mme restart for", j, "seconds") time.sleep(1) self._s1ap_wrapper.configUEDevice_ues_same_imsi(num_ues) print("************************* sending Attach Request for ue-id : 1") attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 1 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 # enabling ESM Information transfer flag attach_req.eti.pres = 1 attach_req.eti.esm_info_transfer_flag = 1 print("Sending Attach Request ue-id", attach_req.ue_Id) 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 auth req ind ") auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = 1 sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd print("Sending Auth Response ue-id", auth_res.ue_Id) 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 ue-id", auth_res.ue_Id) time.sleep(1) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) # Esm Information Request indication print( "Received Esm Information Request ue-id", sec_mode_complete.ue_Id, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ESM_INFORMATION_REQ.value, ) esm_info_req = response.cast(s1ap_types.ueEsmInformationReq_t) # Sending Esm Information Response print( "Sending Esm Information Response ue-id", sec_mode_complete.ue_Id, ) esm_info_response = s1ap_types.ueEsmInformationRsp_t() esm_info_response.ue_Id = 1 esm_info_response.tId = esm_info_req.tId esm_info_response.pdnAPN_pr.pres = 1 s = "oai" esm_info_response.pdnAPN_pr.len = len(s) esm_info_response.pdnAPN_pr.pdn_apn = (ctypes.c_ubyte * 100)( *[ctypes.c_ubyte(ord(c)) for c in s[:100]], ) print("Sending Esm Information with wrong APN ", s) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ESM_INFORMATION_RSP, esm_info_response, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("*** Running UE detach ***") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = 1 detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) # Disable APN Correction self._s1ap_wrapper.magmad_util.config_apn_correction( MagmadUtil.apn_correction_cmds.DISABLE, ) self._s1ap_wrapper.magmad_util.restart_services(['mme']) for j in range(10): print("Waiting mme restart for", j, "seconds") time.sleep(1)
def test_attach_delay_ue_ctxt_rel_cmp(self): """ Attach, Delay Ue context release complete """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger 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 attach_req.ue_Id = req.ue_id attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt print("********Triggering 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) # Trigger 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 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) # Trigger 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) delay_ue_ctxt_rel_cmp = s1ap_types.UeDelayUeCtxtRelCmp() delay_ue_ctxt_rel_cmp.ue_Id = req.ue_id delay_ue_ctxt_rel_cmp.flag = 1 delay_ue_ctxt_rel_cmp.tmrVal = 1000 print("*** Setting Delay for Ue context release complete ***") self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SET_DELAY_UE_CTXT_REL_CMP, delay_ue_ctxt_rel_cmp, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete) time.sleep(0.5) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_EMM_INFORMATION.value) time.sleep(0.5) # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = req.ue_id detach_req.ueDetType = s1ap_types.ueDetachType_t.UE_NORMAL_DETACH.value self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req) response = self._s1ap_wrapper._s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_DETACH_ACCEPT_IND.value) print( "*** Sending UE context release request ", "for UE id ***", req.ue_id, ) # Send UE context release request to move UE to idle mode # ue_ctxt_rel_req = s1ap_types.ueCntxtRelReq_t() uectxtrel_req = s1ap_types.ueCntxtRelReq_t() uectxtrel_req.ue_Id = req.ue_id uectxtrel_req.cause.causeVal = ( gpp_types.CauseRadioNetwork.RELEASE_DUE_TO_EUTRAN_GENERATED_REASON. value) self._s1ap_wrapper.s1_util.issue_cmd( s1ap_types.tfwCmd.UE_CNTXT_REL_REQUEST, uectxtrel_req) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value) time.sleep(10)
def test_imei_restriction_no_imeisv_in_smc(self): """ This TC does the following: UE 1: 1. Send security mode complete message without imeisv 2. Receive identity request with id type imeisv 3. Send identity rsp with blocked imeisv 4. Verify attach reject is received with cause(5) IMEI_NOT_ACCEPTED UE 2: 1. Send security mode complete message without imeisv 2. Receive identity request with id type imeisv 3. Send identity rsp with an allowed imeisv 4. Detach the UE If this TC is executed individually run test_modify_mme_config_for_sanity.py to add { IMEI="9900048235103723" } under the BLOCKED_IMEI_LIST in mme.conf.template. After execution of this TC run test_restore_mme_config_after_sanity.py to restore the old mme.conf.template. """ num_ues = 2 ue_ids = [] self._s1ap_wrapper.configUEDevice(num_ues) for _ in range(num_ues): req = self._s1ap_wrapper.ue_req ue_ids.append(req.ue_id) # 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 = 1 attach_req.ue_Id = ue_ids[0] attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt attach_req.pdnType_pr = pdn_type self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) print( "********************** Sent attach req for UE id ", ue_ids[0], ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) auth_req = response.cast(s1ap_types.ueAuthReqInd_t) print( "********************** Received auth req for UE id", auth_req.ue_Id, ) # Send Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = ue_ids[0] sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = 0 auth_res.sqnRcvd = sqnRecvd self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res, ) print("********************** Sent auth rsp for UE id", ue_ids[0]) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) sec_mod_cmd = response.cast(s1ap_types.ueSecModeCmdInd_t) print( "********************** Received security mode cmd for UE id", sec_mod_cmd.ue_Id, ) # Send Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = ue_ids[0] # Do not include imeisv sec_mode_complete.noImeisv = True self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) print( "********************** Sent security mode complete for UE id", ue_ids[0], ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_IDENTITY_REQ_IND.value, ) id_req = response.cast(s1ap_types.ueIdentityReqInd_t) print( "********************** Received identity req for UE id", id_req.ue_Id, ) # Mobile Identity types # IMSI=1, IMEI=2, IMEISV=3, TMSI=4, TMGI=5, GUTI=6 identity_resp = s1ap_types.ueIdentityResp_t() identity_resp.ue_Id = ue_ids[0] identity_resp.idType = 3 identity_resp.idValPres = True imeisv = "9900048235103723" # Check if the len of imeisv exceeds 16 self.assertLessEqual(len(imeisv), 16) for i in range(0, len(imeisv)): identity_resp.idVal[i] = ctypes.c_ubyte(int(imeisv[i])) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_IDENTITY_RESP, identity_resp, ) print("********************** Sent identity rsp for UE id", ue_ids[0]) # Receive Attach Reject response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_REJECT_IND.value, ) attach_rej = response.cast(s1ap_types.ueAttachRejInd_t) print( "********************** Received attach reject for UE id %d" " with emm cause %d" % (ue_ids[0], attach_rej.cause), ) # Verify cause self.assertEqual( attach_rej.cause, s1ap_types.TFW_EMM_CAUSE_IMEI_NOT_ACCEPTED, ) # UE Context release response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) ue_context_rel = response.cast(s1ap_types.ueCntxtRelReq_t) print( "********************** Received UE_CTX_REL_IND for UE id ", ue_context_rel.ue_Id, ) # Attach the 2nd UE 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 = 1 attach_req.ue_Id = ue_ids[1] attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt attach_req.pdnType_pr = pdn_type self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) print( "********************** Sent attach req for UE id ", ue_ids[1], ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) auth_req = response.cast(s1ap_types.ueAuthReqInd_t) print( "********************** Received auth req for UE id", auth_req.ue_Id, ) # Send Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = ue_ids[1] sqnRecvd = s1ap_types.ueSqnRcvd_t() sqnRecvd.pres = 0 auth_res.sqnRcvd = sqnRecvd self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res, ) print("********************** Sent auth rsp for UE id", ue_ids[1]) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) sec_mod_cmd = response.cast(s1ap_types.ueSecModeCmdInd_t) print( "********************** Received security mode cmd for UE id", sec_mod_cmd.ue_Id, ) # Send Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = ue_ids[1] # Do not include imeisv sec_mode_complete.noImeisv = True self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) print( "********************** Sent security mode complete for UE id", ue_ids[1], ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_IDENTITY_REQ_IND.value, ) id_req = response.cast(s1ap_types.ueIdentityReqInd_t) print( "********************** Received identity req for UE id", id_req.ue_Id, ) # Send Identity Request id_req = response.cast(s1ap_types.ueIdentityReqInd_t) identity_resp = s1ap_types.ueIdentityResp_t() identity_resp.ue_Id = id_req.ue_Id identity_resp.idType = id_req.idType self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_IDENTITY_RESP, identity_resp, ) print("********************** Sent identity rsp for UE id", ue_ids[1]) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) attach_acc = response.cast(s1ap_types.ueAttachAccept_t) print( "********************** Received attach accept for UE id", attach_acc.ue_Id, ) # Send Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = ue_ids[1] self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) print( "********************** Sent attach complete for UE id", ue_ids[1], ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_EMM_INFORMATION.value, ) print("********************** Sleeping for 0.5 seconds ") time.sleep(0.5) # Now detach the UE print("********************** Running UE detach for UE id ", ue_ids[1]) detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = ue_ids[1] detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) ue_context_rel = response.cast(s1ap_types.ueCntxtRelReq_t) print( "********************** Received UE_CTX_REL_IND for UE id ", ue_context_rel.ue_Id, )
def test_attach_ipv4v6_pdn_type(self): """ Test Attach for the UEs that are dual IP stack IPv4v6 capable """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger Attach Request with PDN_Type = IPv4v6 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 # Set PDN TYPE to IPv4V6 i.e. 3. IPV4 is equal to 1 # IPV6 is equal to 2 in value 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("********Triggering Attach Request with PND Type IPv4v6 test") 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) # Trigger 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 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) # Trigger 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("************************* Running UE detach") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = req.ue_id detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value)
def test_attach_esm_info_timerexpiration_max_retries(self): """Testing of sending Esm Information procedure""" num_ues = 1 # The maximum no. of allowed transmissions of ESM information request # as per 3gpp spec 24.301 is 3. Since MME does not send the PDN # connectivity reject message as of now after maximum number of # T3489 expires, test script does not receive any failure response and # has no provision to handle it as well. Therefore, test case gets # stuck waiting for response, if max_retries value is greater than 3 max_retries = 3 self._s1ap_wrapper.configUEDevice(num_ues) print("************************* sending Attach Request for ue-id : 1") attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 1 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 # enabling ESM Information transfer flag attach_req.eti.pres = 1 attach_req.eti.esm_info_transfer_flag = 1 print("Sending Attach Request ue-id", attach_req.ue_Id) 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 auth req ind ") auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = 1 sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd print("Sending Auth Response ue-id", auth_res.ue_Id) 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 ue-id", auth_res.ue_Id) time.sleep(1) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) for i in range(max_retries): # Esm Information Request indication response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ESM_INFORMATION_REQ.value, ) print( "Received Esm Information Request (", i + 1, ") ue-id", sec_mode_complete.ue_Id, ) esm_info_req = response.cast(s1ap_types.ueEsmInformationReq_t) # Sleep for 5 seconds to trigger last max retry count timer expiry time.sleep(5) # Sending Esm Information Response print( "Sending Esm Information Response ue-id", sec_mode_complete.ue_Id, ) esm_info_response = s1ap_types.ueEsmInformationRsp_t() esm_info_response.ue_Id = 1 esm_info_response.tId = esm_info_req.tId esm_info_response.pdnAPN_pr.pres = 1 s = "magma.ipv4" esm_info_response.pdnAPN_pr.len = len(s) esm_info_response.pdnAPN_pr.pdn_apn = (ctypes.c_ubyte * 100)( *[ctypes.c_ubyte(ord(c)) for c in s[:100]], ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ESM_INFORMATION_RSP, esm_info_response, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("*** Running UE detach ***") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = 1 detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, )
def test_different_enb_s1ap_id_same_ue(self): """ Testing of sending different enb S1ap-ID for same UE """ num_ues = 1 self._s1ap_wrapper.configUEDevice_ues_same_imsi(num_ues) print("************************* sending Attach Request for ue-id : 1") attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 1 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 print("Sending Attach Request ue-id", attach_req.ue_Id) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req) response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value) print("Received auth req ind ") auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = 1 sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd print("Sending Auth Response ue-id", auth_res.ue_Id) self._s1ap_wrapper._s1_util.issue_cmd(s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res) response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value) print("Received Security Mode Command ue-id", auth_res.ue_Id) attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 2 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 print("Sending Attach Request ue-id", attach_req.ue_Id) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req) time.sleep(1) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete) response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("************************* Running UE detach for UE id:1 ") print("************************* Running UE detach") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = 1 detach_req.ueDetType = s1ap_types.ueDetachType_t.\ UE_SWITCHOFF_DETACH.value self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertTrue(response, s1ap_types.tfwCmd.UE_CTX_REL_IND.value)
def _create_attach_ipv4v6_pdn_type_req(self, pdn_type_value): # Ground work. self._s1ap_wrapper.configUEDevice(1) ue_req = self._s1ap_wrapper.ue_req # Trigger Attach Request with PDN_Type = IPv4v6 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 # Set PDN TYPE to IPv4V6 i.e. 3. IPV4 is equal to 1 # IPV6 is equal to 2 in value pdn_type.pdn_type = pdn_type_value attach_req.ue_Id = ue_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( "********Triggering Attach Request with PDN Type IPv4v6 test, " "pdn_type_value", pdn_type_value, ) 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, ) # Trigger Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = ue_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, ) # Trigger Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = ue_req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) # Attach Reject will be sent since IPv6 PDN Type is not configured if pdn_type_value == 2: response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_REJECT_IND.value, ) return self._s1ap_wrapper.s1_util.get_response() # 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, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = ue_req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("************************* Running UE detach") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = ue_req.ue_id detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) # Wait for UE context release command return self._s1ap_wrapper.s1_util.get_response()
def test_enb_partial_reset(self): """ attach 32 UEs """ ue_ids = [] num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) for _ in range(num_ues): req = self._s1ap_wrapper.ue_req print( "************************* Calling attach for UE id ", req.ue_id, ) # Trigger Attach Request with PDN_Type = IPv4v6 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 # Set PDN TYPE to IPv4V6 i.e. 3. IPV4 is equal to 1 # IPV6 is equal to 2 in value pdn_type.pdn_type = 1 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("********Triggering Attach Request with PND Type IPv4 test") 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, ) # Trigger 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 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, ) # Trigger 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, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() print("response message type for ATTTACH ACC", response.msg_type) print("acc", s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) ue_ids.append(req.ue_id) # Trigger eNB Reset # Add delay to ensure S1APTester sends attach partial before sending # eNB Reset Request time.sleep(0.5) print("************************* Sending eNB Partial Reset Request") reset_req = s1ap_types.ResetReq() reset_req.rstType = s1ap_types.resetType.PARTIAL_RESET.value reset_req.cause = s1ap_types.ResetCause() reset_req.cause.causeType = ( s1ap_types.NasNonDelCauseType.TFW_CAUSE_MISC.value) # Set the cause to MISC.hardware-failure reset_req.cause.causeVal = 3 reset_req.r = s1ap_types.R() reset_req.r.partialRst = s1ap_types.PartialReset() reset_req.r.partialRst.numOfConn = num_ues reset_req.r.partialRst.ueS1apIdPairList = ( (s1ap_types.UeS1apIdPair) * reset_req.r.partialRst.numOfConn)() for indx in range(reset_req.r.partialRst.numOfConn): reset_req.r.partialRst.ueS1apIdPairList[indx].ueId = ue_ids[indx] print( "Reset_req.r.partialRst.ueS1apIdPairList[indx].ueId", reset_req.r.partialRst.ueS1apIdPairList[indx].ueId, indx, ) print("ue_ids", ue_ids) self._s1ap_wrapper.s1_util.issue_cmd( s1ap_types.tfwCmd.RESET_REQ, reset_req, ) response1 = self._s1ap_wrapper.s1_util.get_response() print("response1 message type", response1.msg_type) self.assertEqual(response1.msg_type, s1ap_types.tfwCmd.RESET_ACK.value) # Trigger detach request """time.sleep(0.5)
def test_guti_attach_with_zero_mtmsi(self): """1. Perform IMSI attach 2. Move UE to idle mode 3. Send GUTI attach request for the same UE with M-TMSI value 0 4. Detach the 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() time.sleep(0.5) # Send UE context release request to move UE to idle mode print( "************************* Sending UE context release request ", "for UE id ", req.ue_id, ) ureq = s1ap_types.ueCntxtRelReq_t() ureq.ue_Id = req.ue_id ureq.cause.causeVal = gpp_types.CauseRadioNetwork.USER_INACTIVITY.value self._s1ap_wrapper.s1_util.issue_cmd( s1ap_types.tfwCmd.UE_CNTXT_REL_REQUEST, ureq, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) time.sleep(5) # Send GUTI attach request with M-TMSI value as 0 attach_req = s1ap_types.ueAttachRequest_t() sec_ctxt = s1ap_types.TFW_CREATE_NEW_SECURITY_CONTEXT id_type = s1ap_types.TFW_MID_TYPE_GUTI eps_type = s1ap_types.TFW_EPS_ATTACH_TYPE_EPS_ATTACH pdn_type = s1ap_types.pdn_Type() pdn_type.pres = True pdn_type.pdn_type = 1 mcc = "001" mnc = "01" mcc_len = len(mcc) mnc_len = len(mnc) 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 attach_req.guti_mi.pres = True for i in range(0, mcc_len): attach_req.guti_mi.guti.mcc[i] = ctypes.c_ubyte(int(mcc[i])) for i in range(0, mnc_len): attach_req.guti_mi.guti.mnc[i] = ctypes.c_ubyte(int(mnc[i])) attach_req.guti_mi.guti.mmeGrdId = 314 attach_req.guti_mi.guti.mmeCode = 30 attach_req.guti_mi.guti.mTmsi = 0 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) print( "********************** Sent attach req for UE id ", attach_req.ue_Id, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_IDENTITY_REQ_IND.value, ) id_req = response.cast(s1ap_types.ueIdentityReqInd_t) print( "********************** Received identity req for UE id", id_req.ue_Id, ) identity_resp = s1ap_types.ueIdentityResp_t() identity_resp.ue_Id = id_req.ue_Id identity_resp.idType = s1ap_types.TFW_MID_TYPE_IMSI self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_IDENTITY_RESP, identity_resp, ) print( "********************** Sent identity rsp for UE id", id_req.ue_Id, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) auth_req = response.cast(s1ap_types.ueAuthReqInd_t) print( "********************** Received auth req for UE id", auth_req.ue_Id, ) # Send Authentication Response auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = auth_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, ) print("********************** Sent auth rsp for UE id", auth_req.ue_Id) response = self._s1ap_wrapper.s1_util.get_response() sec_mode_cmd = response.cast(s1ap_types.ueSecModeCmdInd_t) self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) print( "********************** Received security mode cmd for UE id", sec_mode_cmd.ue_Id, ) sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = sec_mode_cmd.ue_Id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) print( "********************** Sent security mode complete for UE id", sec_mode_cmd.ue_Id, ) # 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, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = attach_acc.ue_Id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) print( "********************** Sent attach complete for UE id", attach_complete.ue_Id, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print( "************************* Running UE detach for UE id ", attach_complete.ue_Id, ) # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = attach_complete.ue_Id detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, )
def test_attach_complete_after_ics_timer_expiry(self): """Simulating sending of attach complete msg after ICS timer expiry. MME should discard attach complete message as it is already in the process of implicit detach ### Do not add this TC to sanity suite ### """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger 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 = 1 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 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req, ) print("****** Sent ATTACH_REQUEST") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value, ) print("****** Received AUTH_REQ_IND") delay_init_ctxt_setup_resp = s1ap_types.UeDelayInitCtxtSetupRsp() delay_init_ctxt_setup_resp.ue_Id = req.ue_id delay_init_ctxt_setup_resp.flag = 1 delay_init_ctxt_setup_resp.tmrVal = 4500 print("*** Setting Initial Context Setup Resp Delay ***") self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SET_DELAY_ICS_RSP, delay_init_ctxt_setup_resp, ) # Trigger Authentication Response 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, ) print("****** Sent UE_AUTH_RESP") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value, ) print("****** Received UE_SEC_MOD_CMD_IND") # Trigger 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, ) print("****** Sent UE_SEC_MOD_COMPLETE") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) print("****** Received INT_CTX_SETUP_IND") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) print("****** Received UE_ATTACH_ACCEPT_IND") print("****** Sleeping for 4 seconds. Waiting for ICS timer to expire") time.sleep(4) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) print("****** Sent ATTACH_COMPLETE") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) print("****** Received UE_CTX_REL_IND")
def test_attach_complete_with_ActvDfltBearCtxtRej(self): """ Test Attach test case for sending Activate Default EPS Bearer Reject along with Attach Complete message """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger 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 = 1 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("********Triggering 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) # Trigger 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 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) # Trigger 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) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) msg = response.cast(s1ap_types.ueAttachAccept_t) bid = msg.esmInfo.epsBearerId # Trigger Attach Complete with # Activate Default EPS Bearer Context Reject time.sleep(0.2) act_rej = s1ap_types.ueActvDfltEpsBearerCtxtRej_t() act_rej.ue_Id = req.ue_id act_rej.bearerId = bid act_rej.esmCause = s1ap_types.TFW_EMM_CAUSE_REQ_REJ_UNSPECIFIED # Activate Default EPS Bearer Context Reject sent along with # Attach Complete message # Attach Complete + Activate Default EPS Bearer Context Reject self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ACTV_DEFAULT_EPS_BEARER_CNTXT_REJECT, act_rej) # Added delay to ensure S1APTester receives the emm information before # sending the detach request message time.sleep(0.5) print("************************* Running UE detach") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = req.ue_id detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req) time.sleep(0.5)
def test_attach_outoforder_attach_cmp_icsrsp(self): """ Attach, Out of order attach complete and initial context setup response """ """ Simulating this scenario by delaying ICS response message to change the order of attach complete and ics resp """ # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req # Trigger 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 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, ) delay_init_ctxt_setup_resp = s1ap_types.UeDelayInitCtxtSetupRsp() delay_init_ctxt_setup_resp.ue_Id = req.ue_id delay_init_ctxt_setup_resp.flag = 1 delay_init_ctxt_setup_resp.tmrVal = 2000 print("*** Setting Initial Context Setup Resp Delay ***") self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SET_DELAY_ICS_RSP, delay_init_ctxt_setup_resp, ) # Trigger 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 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, ) # Trigger 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, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = req.ue_id self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print( "************************* Running UE detach for UE id ", req.ue_id, ) # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = req.ue_id detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) # Wait for UE context release command response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_CTX_REL_IND.value, ) time.sleep(1)
def test_attach_detach_duplicate_nas_resp_messages(self): """ Duplicate NAS Response Messages Test Case""" # Ground work. self._s1ap_wrapper.configUEDevice(1) req = self._s1ap_wrapper.ue_req maxNasMsgRetransmission = 4 # Trigger 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 attach_req.ue_Id = req.ue_id attach_req.mIdType = id_type attach_req.epsAttachType = eps_type attach_req.useOldSecCtxt = sec_ctxt print("*** Triggering Attach Request ***") self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_REQUEST, attach_req) # Waiting for Authentication Request # Wait for last Timer T3460 Expiry for i in range(maxNasMsgRetransmission): print( "*** Waiting for Authentication Request Message (", str(i + 1), ") ***", ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_AUTH_REQ_IND.value) print( "*** Authentication Request Message Received (", str(i + 1), ") ***", ) # Trigger 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 for i in range(maxNasMsgRetransmission): print( "*** Sending Authentication Response Message (", str(i + 1), ") ***", ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_AUTH_RESP, auth_res) # Waiting for Security mode command # Wait for last Timer T3460 Expiry for i in range(maxNasMsgRetransmission): print( "*** Waiting for Security Mode Command Message (", str(i + 1), ") ***", ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_SEC_MOD_CMD_IND.value) print( "*** Security Mode Command Message Received (", str(i + 1), ") ***", ) # Trigger Security Mode Complete sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = req.ue_id for i in range(maxNasMsgRetransmission): print( "*** Sending Security Mode Complete Message (", str(i + 1), ") ***", ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete) # Waiting for Attach accept # Wait for last Timer T3450 Expiry for i in range(maxNasMsgRetransmission): print( "*** Waiting for Attach Accept Message (", str(i + 1), ") ***", ) # Attach accept will be sent in ICSR only for the first time # Re-transmitted Attach Accept will be sent in DL NAS transport if i < 1: response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual(response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value) print( "*** Attach Accept Message Received (", str(i + 1), ") ***", ) # Trigger Attach Complete attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = req.ue_id for i in range(maxNasMsgRetransmission): print( "*** Sending Attach Complete Message (", str(i + 1), ") ***", ) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete) print("*** Running UE detach ***") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = req.ue_id detach_req.ueDetType = s1ap_types.ueDetachType_t.UE_NORMAL_DETACH.value self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req)
def test_attach_with_multiple_mme_restarts(self): num_ues = 1 self._s1ap_wrapper.configUEDevice(num_ues) print("************************* Sending Attach Request for ue-id : 1") attach_req = s1ap_types.ueAttachRequest_t() attach_req.ue_Id = 1 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, ) print("************************* Received UE_AUTH_REQ_IND") # Try consecutive mme restarts self._s1ap_wrapper.magmad_util.restart_mme_and_wait() self._s1ap_wrapper.magmad_util.restart_mme_and_wait() auth_res = s1ap_types.ueAuthResp_t() auth_res.ue_Id = 1 sqn_recvd = s1ap_types.ueSqnRcvd_t() sqn_recvd.pres = 0 auth_res.sqnRcvd = sqn_recvd print("************************* Sending Auth Response ue-id", auth_res.ue_Id) 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 UE_SEC_MOD_CMD_IND") self._s1ap_wrapper.magmad_util.restart_mme_and_wait() print("************************* Sending UE_SEC_MOD_COMPLETE") sec_mode_complete = s1ap_types.ueSecModeComplete_t() sec_mode_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_SEC_MOD_COMPLETE, sec_mode_complete, ) response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.INT_CTX_SETUP_IND.value, ) print("************************* Received INT_CTX_SETUP_IND") response = self._s1ap_wrapper.s1_util.get_response() self.assertEqual( response.msg_type, s1ap_types.tfwCmd.UE_ATTACH_ACCEPT_IND.value, ) print("************************* Received UE_ATTACH_ACCEPT_IND") self._s1ap_wrapper.magmad_util.restart_mme_and_wait() # Trigger Attach Complete print("************************* Sending UE_ATTACH_COMPLETE") attach_complete = s1ap_types.ueAttachComplete_t() attach_complete.ue_Id = 1 self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_ATTACH_COMPLETE, attach_complete, ) # Wait on EMM Information from MME self._s1ap_wrapper._s1_util.receive_emm_info() print("************************* Running UE detach") # Now detach the UE detach_req = s1ap_types.uedetachReq_t() detach_req.ue_Id = 1 detach_req.ueDetType = ( s1ap_types.ueDetachType_t.UE_SWITCHOFF_DETACH.value) self._s1ap_wrapper._s1_util.issue_cmd( s1ap_types.tfwCmd.UE_DETACH_REQUEST, detach_req, ) # Wait for UE context release command return self._s1ap_wrapper.s1_util.get_response()
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, )