MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen
Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/src/mme-app/utils/defaultMmeProcedureCtxt.cpp b/src/mme-app/utils/defaultMmeProcedureCtxt.cpp
new file mode 100644
index 0000000..590ce10
--- /dev/null
+++ b/src/mme-app/utils/defaultMmeProcedureCtxt.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utils/defaultMmeProcedureCtxt.h>
+#include <mmeStates/defaultMmeState.h>
+
+using namespace mme;
+
+DefaultMmeProcedureCtxt::DefaultMmeProcedureCtxt()
+{
+ setNextState(DefaultMmeState::Instance());
+ setCtxtType(defaultMmeProcedure_c);
+}
+
+DefaultMmeProcedureCtxt::~DefaultMmeProcedureCtxt()
+{
+
+}
+
+DefaultMmeProcedureCtxt* DefaultMmeProcedureCtxt::Instance()
+{
+ static DefaultMmeProcedureCtxt defaultMmeProcedureCtxt;
+ return &defaultMmeProcedureCtxt;
+}
+
+
+
+
diff --git a/src/mme-app/utils/mmeCommonUtils.cpp b/src/mme-app/utils/mmeCommonUtils.cpp
new file mode 100644
index 0000000..9fc6c68
--- /dev/null
+++ b/src/mme-app/utils/mmeCommonUtils.cpp
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utils/mmeCommonUtils.h>
+#include <controlBlock.h>
+#include <contextManager/dataBlocks.h>
+#include <contextManager/subsDataGroupManager.h>
+#include <log.h>
+#include <mme_app.h>
+#include <msgBuffer.h>
+#include <s1ap_structs.h>
+#include <utils/defaultMmeProcedureCtxt.h>
+
+using namespace mme;
+
+extern mme_config g_mme_cfg;
+
+bool MmeCommonUtils::isLocalGuti(const guti &guti_r)
+{
+ bool rc = false;
+
+ if (guti_r.mme_grp_id == g_mme_cfg.mme_group_id &&
+ guti_r.mme_code == g_mme_cfg.mme_code)
+ {
+ rc = true;
+ }
+
+ return rc;
+}
+
+uint32_t MmeCommonUtils::allocateMtmsi()
+{
+ uint32_t tmsi = 0;
+
+ while(1)
+ {
+ tmsi = rand() % 10000;
+
+ if (SubsDataGroupManager::Instance()->findCBWithmTmsi(tmsi) == -1)
+ break;
+ }
+
+ log_msg(LOG_INFO, "MTMSI allocated is %u\n", tmsi);
+
+ return tmsi;
+}
+
+AttachType MmeCommonUtils::getAttachType(UEContext* ueContext_p,
+ const struct ue_attach_info& ue_info)
+{
+ log_msg(LOG_INFO, "deriveAttachType\n");
+
+ AttachType attachType = maxAttachType_c;
+
+ if(UE_ID_IMSI(ue_info.flags))
+ {
+ log_msg(LOG_INFO, "IMSI attach received.\n");
+
+ attachType = imsiAttach_c;
+ }
+ else if (UE_ID_GUTI(ue_info.flags))
+ {
+ log_msg(LOG_INFO, "GUTI attach received. mTMSI is %u \n",
+ ue_info.mi_guti.m_TMSI);
+
+ attachType = unknownGutiAttach_c;
+
+ if (isLocalGuti(ue_info.mi_guti))
+ {
+ // The guti is allocated by this MME, check if a context exists.
+ // If the context does not exist, treat as unknown GUTI attach?
+ log_msg(LOG_INFO, "GUTI is local..");
+
+ if (ueContext_p != NULL)
+ {
+ if (ueContext_p->getMtmsi() == ue_info.mi_guti.m_TMSI)
+ {
+ log_msg(LOG_INFO, "and known\n");
+
+ attachType = knownGutiAttach_c;
+ }
+ else
+ {
+ log_msg(LOG_INFO, "mTMSI mismatches with UE context. "
+ "Treat as unknown GUTI attach\n");
+ }
+ }
+ else
+ {
+ log_msg(LOG_INFO, "UE context is null. Unknown GUTI attach triggered\n");
+ }
+
+ }
+ else
+ {
+ log_msg(LOG_INFO, "GUTI is not local..");
+ }
+ }
+ return attachType;
+}
+
+SM::ControlBlock* MmeCommonUtils::findControlBlock(cmn::utils::MsgBuffer* buf)
+{
+ SM::ControlBlock *cb = NULL;
+
+ const s1_incoming_msg_data_t* msgData_p = (s1_incoming_msg_data_t*)(buf->getDataPointer());
+ if(msgData_p == NULL)
+ {
+ log_msg(LOG_INFO, "MsgData is NULL .\n");
+ return cb;
+ }
+
+ switch (msgData_p->msg_type)
+ {
+ case attach_request:
+ {
+ const struct ue_attach_info &ue_info = (msgData_p->msg_data.ue_attach_info_m);
+ if(UE_ID_IMSI(ue_info.flags))
+ {
+ log_msg(LOG_INFO, "IMSI attach received.\n");
+
+ cb = SubsDataGroupManager::Instance()->allocateCB();
+ cb->setTempDataBlock(DefaultMmeProcedureCtxt::Instance());
+ }
+ else if (UE_ID_GUTI(ue_info.flags))
+ {
+ log_msg(LOG_INFO, "GUTI attach received.\n");
+
+ if (isLocalGuti(ue_info.mi_guti))
+ {
+ log_msg(LOG_INFO, "GUTI is local.\n");
+
+ int cbIndex = SubsDataGroupManager::Instance()->findCBWithmTmsi(ue_info.mi_guti.m_TMSI);
+ if (cbIndex > 0)
+ {
+ cb = SubsDataGroupManager::Instance()->findControlBlock(cbIndex);
+ }
+ else
+ {
+ log_msg(LOG_ERROR, "Failed to find control block with mTmsi.\n");
+
+ // allocate new cb and proceed?
+ cb = SubsDataGroupManager::Instance()->allocateCB();
+ cb->setTempDataBlock(DefaultMmeProcedureCtxt::Instance());
+ }
+ }
+ else
+ {
+ cb = SubsDataGroupManager::Instance()->allocateCB();
+ cb->setTempDataBlock(DefaultMmeProcedureCtxt::Instance());
+ }
+ }
+ break;
+ }
+ case service_request:
+ {
+ const struct service_req_Q_msg &service_req = (msgData_p->msg_data.service_req_Q_msg_m);
+ int cbIndex = SubsDataGroupManager::Instance()->findCBWithmTmsi(service_req.s_tmsi.m_TMSI);
+ if (cbIndex > 0)
+ {
+ cb = SubsDataGroupManager::Instance()->findControlBlock(cbIndex);
+ }
+ else
+ {
+ log_msg(LOG_INFO, "Failed to find control block with mTmsi.\n");
+ }
+
+ break;
+ }
+ case detach_request:
+ {
+ const struct detach_req_Q_msg &detach_Req = (msgData_p->msg_data.detachReq_Q_msg_m);
+ int cbIndex = SubsDataGroupManager::Instance()->findCBWithmTmsi(detach_Req.ue_m_tmsi);
+ if (cbIndex > 0)
+ {
+ cb = SubsDataGroupManager::Instance()->findControlBlock(cbIndex);
+ }
+ else
+ {
+ log_msg(LOG_INFO, "Failed to find control block with mTmsi. %d\n", detach_Req.ue_m_tmsi);
+ }
+ break;
+ }
+ case tau_request:
+ {
+ cb = SubsDataGroupManager::Instance()->findControlBlock(msgData_p->ue_idx);
+
+ if (cb == NULL)
+ log_msg(LOG_INFO, "Failed to retrieve CB using idx %d.\n", msgData_p->ue_idx);
+
+ break;
+ }
+ default:
+ {
+ log_msg(LOG_INFO, "Unhandled message is NULL .\n");
+ }
+ }
+
+ return cb;
+}
+
+
+
+
diff --git a/src/mme-app/utils/mmeContextManagerUtils.cpp b/src/mme-app/utils/mmeContextManagerUtils.cpp
new file mode 100644
index 0000000..933600a
--- /dev/null
+++ b/src/mme-app/utils/mmeContextManagerUtils.cpp
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <controlBlock.h>
+#include <contextManager/subsDataGroupManager.h>
+#include <log.h>
+#include <utils/mmeContextManagerUtils.h>
+
+using namespace mme;
+
+bool MmeContextManagerUtils::deleteProcedureCtxt(MmeProcedureCtxt* procedure_p)
+{
+ log_msg(LOG_DEBUG, "deleteProcedureCtxt: Entry");
+
+ if (procedure_p == NULL)
+ {
+ log_msg(LOG_INFO, "Procedure Context is NULL");
+
+ return false;
+ }
+
+ SubsDataGroupManager* subsDgMgr_p = SubsDataGroupManager::Instance();
+
+ log_msg(LOG_INFO, "Procedure Type is %d", procedure_p->getCtxtType());
+
+ bool rc = true;
+ switch (procedure_p->getCtxtType())
+ {
+ case attach_c:
+ case s1Release_c:
+ {
+ subsDgMgr_p->deleteMmeProcedureCtxt(procedure_p);
+ break;
+ }
+ case detach_c:
+ {
+ MmeDetachProcedureCtxt* detachProc_p =
+ static_cast<MmeDetachProcedureCtxt *>(procedure_p);
+
+ subsDgMgr_p->deleteMmeDetachProcedureCtxt(detachProc_p);
+
+ break;
+ }
+ case serviceRequest_c:
+ {
+ MmeSvcReqProcedureCtxt* svcReqProc_p =
+ static_cast<MmeSvcReqProcedureCtxt*>(procedure_p);
+
+ subsDgMgr_p->deleteMmeSvcReqProcedureCtxt(svcReqProc_p);
+
+ break;
+ }
+ case tau_c:
+ {
+ MmeTauProcedureCtxt* tauProc_p =
+ static_cast<MmeTauProcedureCtxt*>(procedure_p);
+
+ subsDgMgr_p->deleteMmeTauProcedureCtxt(tauProc_p);
+
+ break;
+ }
+ default:
+ {
+ log_msg(LOG_INFO, "Unsupported procedure type %d\n", procedure_p->getCtxtType());
+ rc = false;
+ }
+ }
+ return rc;
+}
+
+bool MmeContextManagerUtils::deallocateProcedureCtxt(SM::ControlBlock& cb_r, ProcedureType procType)
+{
+ bool rc = false;
+
+ MmeProcedureCtxt* procedure_p =
+ static_cast<MmeProcedureCtxt*>(cb_r.getTempDataBlock());
+
+ MmeProcedureCtxt* prevProcedure_p = NULL;
+ MmeProcedureCtxt* nextProcedure_p = NULL;
+
+ while (procedure_p != NULL)
+ {
+ nextProcedure_p =
+ static_cast<MmeProcedureCtxt*>(procedure_p->getNextTempDataBlock());
+
+ ProcedureType procedureType = procedure_p->getCtxtType();
+ if (procType == procedureType)
+ {
+ log_msg(LOG_INFO, "Procedure type %d\n", procedureType);
+
+ rc = deleteProcedureCtxt(procedure_p);
+
+ if (rc == true)
+ {
+ if (prevProcedure_p != NULL)
+ {
+ if (nextProcedure_p != NULL)
+ {
+ prevProcedure_p->setNextTempDataBlock(nextProcedure_p);
+ }
+ }
+ else
+ {
+ cb_r.setTempDataBlock(nextProcedure_p);
+ }
+ }
+ // break out of while loop
+ break;
+ }
+ prevProcedure_p = procedure_p;
+ procedure_p = nextProcedure_p;
+ }
+
+ return rc;
+}
+
+bool MmeContextManagerUtils::deallocateAllProcedureCtxts(SM::ControlBlock& cb_r)
+{
+ bool rc = false;
+
+ MmeProcedureCtxt* procedure_p =
+ static_cast<MmeProcedureCtxt*>(cb_r.getTempDataBlock());
+
+ MmeProcedureCtxt* nextProcedure_p = NULL;
+
+ while (procedure_p != NULL)
+ {
+ nextProcedure_p =
+ static_cast<MmeProcedureCtxt*>(procedure_p->getNextTempDataBlock());
+
+ if (procedure_p->getCtxtType() != defaultMmeProcedure_c)
+ {
+ rc = deleteProcedureCtxt(procedure_p);
+ }
+
+ procedure_p = nextProcedure_p;
+ }
+ return rc;
+}
+
+MmeProcedureCtxt* MmeContextManagerUtils::findProcedureCtxt(SM::ControlBlock& cb_r, ProcedureType procType)
+{
+ MmeProcedureCtxt* mmeProcCtxt_p = NULL;
+
+ MmeProcedureCtxt* currentProcedure_p =
+ static_cast<MmeProcedureCtxt*>(cb_r.getTempDataBlock());
+
+ MmeProcedureCtxt* nextProcedure_p = NULL;
+
+ while (currentProcedure_p != NULL)
+ {
+ nextProcedure_p = static_cast<MmeProcedureCtxt*>(
+ currentProcedure_p->getNextTempDataBlock());
+
+ if (currentProcedure_p->getCtxtType() == procType)
+ {
+ mmeProcCtxt_p = currentProcedure_p;
+ break;
+ }
+ currentProcedure_p = nextProcedure_p;
+ }
+
+ return mmeProcCtxt_p;
+}
+
+void MmeContextManagerUtils::deleteSessionContext(SM::ControlBlock& cb_r)
+{
+ UEContext* ueCtxt_p = static_cast<UEContext *>(cb_r.getPermDataBlock());
+ if (ueCtxt_p == NULL)
+ {
+ log_msg(LOG_DEBUG, "Failed to retrieve UEContext from control block %u", cb_r.getCBIndex());
+ return;
+ }
+
+ SessionContext* sessCtxt_p = ueCtxt_p->getSessionContext();
+ if (sessCtxt_p == NULL)
+ {
+ log_msg(LOG_DEBUG, "Failed to retrieve SessionContext from UEContext %u", cb_r.getCBIndex());
+ return;
+ }
+
+ BearerContext* bearerCtxt_p = sessCtxt_p->getBearerContext();
+ if(bearerCtxt_p != NULL)
+ {
+ log_msg(LOG_INFO, "Deallocating bearer context for UE block %u", cb_r.getCBIndex());
+
+ SubsDataGroupManager::Instance()->deleteBearerContext(bearerCtxt_p);
+ sessCtxt_p->setBearerContext(NULL);
+ }
+
+ log_msg(LOG_INFO, "Deallocating session context for UE block %u", cb_r.getCBIndex());
+
+ SubsDataGroupManager::Instance()->deleteSessionContext(sessCtxt_p);
+ ueCtxt_p->setSessionContext(NULL);
+}
+
+void MmeContextManagerUtils::deleteUEContext(uint32_t cbIndex)
+{
+ SM::ControlBlock* cb_p = SubsDataGroupManager::Instance()->findControlBlock(cbIndex);
+ if (cb_p == NULL)
+ {
+ log_msg(LOG_DEBUG, "Failed to find control block for index %u", cbIndex);
+ return;
+ }
+
+ deallocateAllProcedureCtxts(*cb_p);
+
+ deleteSessionContext(*cb_p);
+
+ UEContext* ueCtxt_p = static_cast<UEContext *>(cb_p->getPermDataBlock());
+ if (ueCtxt_p == NULL)
+ {
+ log_msg(LOG_DEBUG, "Failed to retrieve UEContext from control block %u", cbIndex);
+ }
+ else
+ {
+ MmContext* mmContext_p = ueCtxt_p->getMmContext();
+ if (mmContext_p != NULL)
+ {
+ SubsDataGroupManager::Instance()->deleteMmContext(mmContext_p);
+ ueCtxt_p->setMmContext(NULL);
+ }
+
+ // Remove IMSI -> CBIndex key mapping
+ const DigitRegister15& ue_imsi = ueCtxt_p->getImsi();
+ SubsDataGroupManager::Instance()->deleteimsikey(ue_imsi);
+
+ // Remove mTMSI -> CBIndex mapping
+ SubsDataGroupManager::Instance()->deletemTmsikey(ueCtxt_p->getMtmsi());
+
+ SubsDataGroupManager::Instance()->deleteUEContext(ueCtxt_p);
+ }
+
+ SubsDataGroupManager::Instance()->deAllocateCB(cb_p->getCBIndex());
+}