Commit 2fd25c41 authored by aligungr's avatar aligungr

Performance improvements

parent e5c563fe
......@@ -118,19 +118,19 @@ void UeCmdHandler::handleCmdImpl(NmUeCliCommand &msg)
}
Json json = Json::Obj({
{"cm-state", ToJson(m_base->nasTask->mm->m_cmState)},
{"rm-state", ToJson(m_base->nasTask->mm->m_rmState)},
{"mm-state", ToJson(m_base->nasTask->mm->m_mmSubState)},
{"5u-state", ToJson(m_base->nasTask->mm->m_storage->uState->get())},
{"sim-inserted", m_base->nasTask->mm->m_usim->isValid()},
{"cm-state", ToJson(m_base->nasTask->layer->mm->m_cmState)},
{"rm-state", ToJson(m_base->nasTask->layer->mm->m_rmState)},
{"mm-state", ToJson(m_base->nasTask->layer->mm->m_mmSubState)},
{"5u-state", ToJson(m_base->nasTask->layer->mm->m_storage->uState->get())},
{"sim-inserted", m_base->nasTask->layer->mm->m_usim->isValid()},
{"selected-plmn", ::ToJson(m_base->shCtx.selectedPlmn.get())},
{"current-cell", ::ToJson(currentCellId)},
{"current-plmn", ::ToJson(currentPlmn)},
{"current-tac", ::ToJson(currentTac)},
{"last-tai", ToJson(m_base->nasTask->mm->m_storage->lastVisitedRegisteredTai)},
{"stored-suci", ToJson(m_base->nasTask->mm->m_storage->storedSuci->get())},
{"stored-guti", ToJson(m_base->nasTask->mm->m_storage->storedGuti->get())},
{"has-emergency", ::ToJson(m_base->nasTask->mm->hasEmergency())},
{"last-tai", ToJson(m_base->nasTask->layer->mm->m_storage->lastVisitedRegisteredTai)},
{"stored-suci", ToJson(m_base->nasTask->layer->mm->m_storage->storedSuci->get())},
{"stored-guti", ToJson(m_base->nasTask->layer->mm->m_storage->storedGuti->get())},
{"has-emergency", ::ToJson(m_base->nasTask->layer->mm->hasEmergency())},
});
sendResult(msg.address, json.dumpYaml());
break;
......@@ -141,7 +141,7 @@ void UeCmdHandler::handleCmdImpl(NmUeCliCommand &msg)
{"hplmn", ToJson(m_base->config->hplmn)},
{"imei", ::ToJson(m_base->config->imei)},
{"imeisv", ::ToJson(m_base->config->imeiSv)},
{"ecall-only", ::ToJson(m_base->nasTask->usim->m_isECallOnly)},
{"ecall-only", ::ToJson(m_base->nasTask->layer->usim->m_isECallOnly)},
{"uac-aic", Json::Obj({
{"mps", m_base->config->uacAic.mps},
{"mcs", m_base->config->uacAic.mcs},
......@@ -154,18 +154,18 @@ void UeCmdHandler::handleCmdImpl(NmUeCliCommand &msg)
{"class-14", m_base->config->uacAcc.cls14},
{"class-15", m_base->config->uacAcc.cls15},
})},
{"is-high-priority", m_base->nasTask->mm->isHighPriority()},
{"is-high-priority", m_base->nasTask->layer->mm->isHighPriority()},
});
sendResult(msg.address, json.dumpYaml());
break;
}
case app::UeCliCommand::TIMERS: {
sendResult(msg.address, ToJson(m_base->nasTask->timers).dumpYaml());
sendResult(msg.address, ToJson(m_base->nasTask->layer->timers).dumpYaml());
break;
}
case app::UeCliCommand::DE_REGISTER: {
m_base->nasTask->mm->deregistrationRequired(msg.cmd->deregCause);
m_base->nasTask->layer->mm->deregistrationRequired(msg.cmd->deregCause);
if (msg.cmd->deregCause != EDeregCause::SWITCH_OFF)
sendResult(msg.address, "De-registration procedure triggered");
......@@ -175,12 +175,12 @@ void UeCmdHandler::handleCmdImpl(NmUeCliCommand &msg)
}
case app::UeCliCommand::PS_RELEASE: {
for (int i = 0; i < msg.cmd->psCount; i++)
m_base->nasTask->sm->sendReleaseRequest(static_cast<int>(msg.cmd->psIds[i]) % 16);
m_base->nasTask->layer->sm->sendReleaseRequest(static_cast<int>(msg.cmd->psIds[i]) % 16);
sendResult(msg.address, "PDU session release procedure(s) triggered");
break;
}
case app::UeCliCommand::PS_RELEASE_ALL: {
m_base->nasTask->sm->sendReleaseRequestForAll();
m_base->nasTask->layer->sm->sendReleaseRequestForAll();
sendResult(msg.address, "PDU session release procedure(s) triggered");
break;
}
......@@ -190,13 +190,13 @@ void UeCmdHandler::handleCmdImpl(NmUeCliCommand &msg)
config.isEmergency = msg.cmd->isEmergency;
config.apn = msg.cmd->apn;
config.sNssai = msg.cmd->sNssai;
m_base->nasTask->sm->sendEstablishmentRequest(config);
m_base->nasTask->layer->sm->sendEstablishmentRequest(config);
sendResult(msg.address, "PDU session establishment procedure triggered");
break;
}
case app::UeCliCommand::PS_LIST: {
Json json = Json::Obj({});
for (auto *pduSession : m_base->nasTask->sm->m_pduSessions)
for (auto *pduSession : m_base->nasTask->layer->sm->m_pduSessions)
{
if (pduSession->psi == 0 || pduSession->psState == EPsState::INACTIVE)
continue;
......
#include "layer.hpp"
namespace nr::ue
{
NasLayer::NasLayer(TaskBase *base) : base{base}, timers{}
{
logger = base->logBase->makeUniqueLogger(base->config->getLoggerPrefix() + "nas");
mm = new NasMm(base, &timers);
sm = new NasSm(base, &timers);
usim = new Usim();
}
void NasLayer::onStart()
{
usim->initialize(base->config->supi.has_value());
sm->onStart(mm);
mm->onStart(sm, usim);
}
void NasLayer::onQuit()
{
mm->onQuit();
sm->onQuit();
delete mm;
delete sm;
delete usim;
}
void NasLayer::handleSapMessage(std::unique_ptr<NtsMessage> msg)
{
switch (msg->msgType)
{
case NtsMessageType::UE_RRC_TO_NAS: {
mm->handleRrcEvent(dynamic_cast<NmUeRrcToNas &>(*msg));
break;
}
case NtsMessageType::UE_TUN_TO_APP: {
auto &w = dynamic_cast<NmUeTunToApp &>(*msg);
switch (w.present)
{
case NmUeTunToApp::DATA_PDU_DELIVERY: {
sm->handleUplinkDataRequest(w.psi, std::move(w.data));
break;
}
default:
break;
}
break;
}
case NtsMessageType::UE_RLS_TO_NAS: {
auto &w = dynamic_cast<NmUeRlsToNas &>(*msg);
switch (w.present)
{
case NmUeRlsToNas::DATA_PDU_DELIVERY: {
sm->handleDownlinkDataRequest(w.psi, std::move(w.pdu));
break;
}
}
break;
}
default:
logger->unhandledNts(*msg);
break;
}
}
void NasLayer::performTick()
{
std::array<UeTimer *, 17> arr = {
&timers.t3346, &timers.t3396, &timers.t3444, &timers.t3445, &timers.t3502, &timers.t3510,
&timers.t3511, &timers.t3512, &timers.t3516, &timers.t3517, &timers.t3519, &timers.t3520,
&timers.t3521, &timers.t3525, &timers.t3540, &timers.t3584, &timers.t3585,
};
for (auto* timer : arr){
if (timer->performTick())
{
if (timer->isMmTimer())
mm->onTimerExpire(*timer);
else
sm->onTimerExpire(*timer);
}
}
sm->onTimerTick();
}
void NasLayer::performCycle()
{
mm->performMmCycle();
}
} // namespace nr::ue
\ No newline at end of file
#pragma once
#include <lib/crypt/milenage.hpp>
#include <lib/nas/nas.hpp>
#include <ue/nas/mm/mm.hpp>
#include <ue/nas/sm/sm.hpp>
#include <ue/nas/usim/usim.hpp>
#include <ue/nts.hpp>
#include <ue/types.hpp>
#include <utils/nts.hpp>
namespace nr::ue
{
class NasLayer
{
TaskBase *base;
std::unique_ptr<Logger> logger;
NasTimers timers;
NasMm *mm;
NasSm *sm;
Usim *usim;
friend class UeCmdHandler;
public:
explicit NasLayer(TaskBase *base);
~NasLayer() = default;
public:
void onStart();
void onQuit();
public:
void handleSapMessage(std::unique_ptr<NtsMessage> msg);
public:
void performCycle();
void performTick();
};
} // namespace nr::ue
\ No newline at end of file
......@@ -81,7 +81,7 @@ void NasMm::onQuit()
void NasMm::triggerMmCycle()
{
m_base->nasTask->push(std::make_unique<NmUeNasToNas>(NmUeNasToNas::PERFORM_MM_CYCLE));
m_base->nasTask->push(std::make_unique<NmCycleRequired>());
}
void NasMm::performMmCycle()
......
......@@ -68,7 +68,7 @@ class NasMm
friend class UeCmdHandler;
friend class NasSm;
friend class NasTask;
friend class NasLayer;
public:
NasMm(TaskBase *base, NasTimers *timers);
......@@ -196,7 +196,6 @@ class NasMm
private: /* Service Access Point */
void handleRrcEvent(const NmUeRrcToNas &msg);
void handleNasEvent(const NmUeNasToNas &msg);
};
} // namespace nr::ue
\ No newline at end of file
......@@ -62,22 +62,4 @@ void NasMm::handleRrcEvent(const NmUeRrcToNas &msg)
}
}
void NasMm::handleNasEvent(const NmUeNasToNas &msg)
{
if (m_mmState == EMmState::MM_NULL)
return;
switch (msg.present)
{
case NmUeNasToNas::PERFORM_MM_CYCLE:
performMmCycle();
break;
case NmUeNasToNas::NAS_TIMER_EXPIRE:
onTimerExpire(*msg.timer);
break;
default:
break;
}
}
} // namespace nr::ue
......@@ -18,21 +18,6 @@
namespace nr::ue
{
void NasSm::handleNasEvent(const NmUeNasToNas &msg)
{
if (m_mm->m_mmState == EMmState::MM_NULL)
return;
switch (msg.present)
{
case NmUeNasToNas::NAS_TIMER_EXPIRE:
onTimerExpire(*msg.timer);
break;
default:
break;
}
}
void NasSm::onTimerTick()
{
if (m_mm->m_mmState == EMmState::MM_NULL)
......
......@@ -33,7 +33,7 @@ class NasSm
friend class UeCmdHandler;
friend class NasMm;
friend class NasTask;
friend class NasLayer;
public:
NasSm(TaskBase *base, NasTimers *timers);
......@@ -90,7 +90,6 @@ class NasSm
void abortProcedureByPtiOrPsi(int pti, int psi);
private: /* Service Access Point */
void handleNasEvent(const NmUeNasToNas &msg);
void onTimerTick();
void handleUplinkDataRequest(int psi, OctetString &&data);
void handleDownlinkDataRequest(int psi, OctetString &&data);
......
......@@ -17,21 +17,14 @@ static const int NTS_TIMER_INTERVAL_MM_CYCLE = 1100;
namespace nr::ue
{
NasTask::NasTask(TaskBase *base) : base{base}, timers{}
NasTask::NasTask(TaskBase *base)
{
logger = base->logBase->makeUniqueLogger(base->config->getLoggerPrefix() + "nas");
mm = new NasMm(base, &timers);
sm = new NasSm(base, &timers);
usim = new Usim();
layer = std::make_unique<NasLayer>(base);
}
void NasTask::onStart()
{
usim->initialize(base->config->supi.has_value());
sm->onStart(mm);
mm->onStart(sm, usim);
layer->onStart();
setTimer(NTS_TIMER_ID_NAS_TIMER_CYCLE, NTS_TIMER_INTERVAL_NAS_TIMER_CYCLE);
setTimer(NTS_TIMER_ID_MM_CYCLE, NTS_TIMER_INTERVAL_MM_CYCLE);
......@@ -39,13 +32,7 @@ void NasTask::onStart()
void NasTask::onQuit()
{
mm->onQuit();
sm->onQuit();
delete mm;
delete sm;
delete usim;
layer->onQuit();
}
void NasTask::onLoop()
......@@ -54,122 +41,29 @@ void NasTask::onLoop()
if (!msg)
return;
switch (msg->msgType)
if (msg->msgType == NtsMessageType::UE_CYCLE_REQUIRED)
{
case NtsMessageType::UE_RRC_TO_NAS: {
mm->handleRrcEvent(dynamic_cast<NmUeRrcToNas &>(*msg));
break;
}
case NtsMessageType::UE_NAS_TO_NAS: {
auto &w = dynamic_cast<NmUeNasToNas &>(*msg);
switch (w.present)
{
case NmUeNasToNas::PERFORM_MM_CYCLE: {
mm->handleNasEvent(w);
break;
}
case NmUeNasToNas::NAS_TIMER_EXPIRE: {
if (w.timer->isMmTimer())
mm->handleNasEvent(w);
else
sm->handleNasEvent(w);
break;
}
default:
break;
}
break;
}
case NtsMessageType::UE_TUN_TO_APP: {
auto &w = dynamic_cast<NmUeTunToApp &>(*msg);
switch (w.present)
{
case NmUeTunToApp::DATA_PDU_DELIVERY: {
sm->handleUplinkDataRequest(w.psi, std::move(w.data));
break;
}
default:
break;
}
break;
layer->performCycle();
}
case NtsMessageType::UE_RLS_TO_NAS: {
auto &w = dynamic_cast<NmUeRlsToNas &>(*msg);
switch (w.present)
{
case NmUeRlsToNas::DATA_PDU_DELIVERY: {
sm->handleDownlinkDataRequest(w.psi, std::move(w.pdu));
break;
}
}
break;
}
case NtsMessageType::TIMER_EXPIRED: {
else if (msg->msgType == NtsMessageType::TIMER_EXPIRED)
{
auto &w = dynamic_cast<NmTimerExpired &>(*msg);
int timerId = w.timerId;
if (timerId == NTS_TIMER_ID_NAS_TIMER_CYCLE)
{
setTimer(NTS_TIMER_ID_NAS_TIMER_CYCLE, NTS_TIMER_INTERVAL_NAS_TIMER_CYCLE);
performTick();
layer->performTick();
}
if (timerId == NTS_TIMER_ID_MM_CYCLE)
{
setTimer(NTS_TIMER_ID_MM_CYCLE, NTS_TIMER_INTERVAL_MM_CYCLE);
mm->handleNasEvent(NmUeNasToNas{NmUeNasToNas::PERFORM_MM_CYCLE});
layer->performCycle();
}
break;
}
default:
logger->unhandledNts(*msg);
break;
else
{
layer->handleSapMessage(std::move(msg));
}
}
void NasTask::performTick()
{
auto sendExpireMsg = [this](UeTimer *timer) {
auto m = std::make_unique<NmUeNasToNas>(NmUeNasToNas::NAS_TIMER_EXPIRE);
m->timer = timer;
push(std::move(m));
};
if (timers.t3346.performTick())
sendExpireMsg(&timers.t3346);
if (timers.t3396.performTick())
sendExpireMsg(&timers.t3396);
if (timers.t3444.performTick())
sendExpireMsg(&timers.t3444);
if (timers.t3445.performTick())
sendExpireMsg(&timers.t3445);
if (timers.t3502.performTick())
sendExpireMsg(&timers.t3502);
if (timers.t3510.performTick())
sendExpireMsg(&timers.t3510);
if (timers.t3511.performTick())
sendExpireMsg(&timers.t3511);
if (timers.t3512.performTick())
sendExpireMsg(&timers.t3512);
if (timers.t3516.performTick())
sendExpireMsg(&timers.t3516);
if (timers.t3517.performTick())
sendExpireMsg(&timers.t3517);
if (timers.t3519.performTick())
sendExpireMsg(&timers.t3519);
if (timers.t3520.performTick())
sendExpireMsg(&timers.t3520);
if (timers.t3521.performTick())
sendExpireMsg(&timers.t3521);
if (timers.t3525.performTick())
sendExpireMsg(&timers.t3525);
if (timers.t3540.performTick())
sendExpireMsg(&timers.t3540);
if (timers.t3584.performTick())
sendExpireMsg(&timers.t3584);
if (timers.t3585.performTick())
sendExpireMsg(&timers.t3585);
sm->onTimerTick();
}
} // namespace nr::ue
\ No newline at end of file
......@@ -8,6 +8,8 @@
#pragma once
#include "layer.hpp"
#include <ue/nas/usim/usim.hpp>
#include <lib/crypt/milenage.hpp>
#include <lib/nas/nas.hpp>
......@@ -23,14 +25,7 @@ namespace nr::ue
class NasTask : public NtsTask
{
private:
TaskBase *base;
std::unique_ptr<Logger> logger;
NasTimers timers;
NasMm *mm;
NasSm *sm;
Usim *usim;
std::unique_ptr<NasLayer> layer;
friend class UeCmdHandler;
public:
......@@ -41,9 +36,6 @@ class NasTask : public NtsTask
void onStart() override;
void onLoop() override;
void onQuit() override;
private:
void performTick();
};
} // namespace nr::ue
\ No newline at end of file
......@@ -172,22 +172,6 @@ struct NmUeRlsToRrc : NtsMessage
}
};
struct NmUeNasToNas : NtsMessage
{
enum PR
{
PERFORM_MM_CYCLE,
NAS_TIMER_EXPIRE,
} present;
// NAS_TIMER_EXPIRE
UeTimer *timer{};
explicit NmUeNasToNas(PR present) : NtsMessage(NtsMessageType::UE_NAS_TO_NAS), present(present)
{
}
};
struct NmUeNasToApp : NtsMessage
{
enum PR
......@@ -326,4 +310,11 @@ struct NmUeCliCommand : NtsMessage
}
};
struct NmCycleRequired : NtsMessage
{
NmCycleRequired() : NtsMessage(NtsMessageType::UE_CYCLE_REQUIRED)
{
}
};
} // namespace nr::ue
\ No newline at end of file
......@@ -53,12 +53,13 @@ enum class NtsMessageType
UE_NAS_TO_RRC,
UE_RRC_TO_RLS,
UE_RRC_TO_RRC,
UE_NAS_TO_NAS,
UE_RLS_TO_RRC,
UE_RLS_TO_NAS,
UE_RLS_TO_RLS,
UE_NAS_TO_APP,
UE_NAS_TO_RLS,
UE_CYCLE_REQUIRED
};
struct NtsMessage
......
File mode changed from 100644 to 100755
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment