Commit 30cbc8e7 authored by aligungr's avatar aligungr

UE executable refactor

parent 7dfe3b0c
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#include "ue_ctl.hpp"
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#pragma once
namespace app
{
class IUeController
{
public:
virtual void performSwitchOff() = 0;
};
} // namespace app
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <app/cli_base.hpp> #include <app/cli_base.hpp>
#include <app/cli_cmd.hpp> #include <app/cli_cmd.hpp>
#include <app/proc_table.hpp> #include <app/proc_table.hpp>
#include <app/ue_ctl.hpp>
#include <iostream> #include <iostream>
#include <ue/ue.hpp> #include <ue/ue.hpp>
#include <unistd.h> #include <unistd.h>
...@@ -324,6 +325,19 @@ static void Loop() ...@@ -324,6 +325,19 @@ static void Loop()
ReceiveCommand(msg); ReceiveCommand(msg);
} }
class UeController : public app::IUeController
{
public:
void performSwitchOff() override
{
// todo ue' için ptr çek
// o ptru delete et
// mapten sil
// map boşaldıysa exit yap
// tabi bunları switc off olan appin kendi threadin yapıyoz o yüzden burası atomic değil dikkat!!
}
} g_ueController;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
app::Initialize(); app::Initialize();
...@@ -346,7 +360,7 @@ int main(int argc, char **argv) ...@@ -346,7 +360,7 @@ int main(int argc, char **argv)
for (int i = 0; i < g_options.count; i++) for (int i = 0; i < g_options.count; i++)
{ {
auto *config = GetConfigByUe(i); auto *config = GetConfigByUe(i);
auto *ue = new nr::ue::UserEquipment(config, nullptr); auto *ue = new nr::ue::UserEquipment(config, &g_ueController, nullptr);
g_ueMap[config->getNodeName()] = ue; g_ueMap[config->getNodeName()] = ue;
} }
......
...@@ -119,7 +119,10 @@ void UeCmdHandler::HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg) ...@@ -119,7 +119,10 @@ void UeCmdHandler::HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg)
base.nasTask->mm->sendDeregistration(msg.cmd->isSwitchOff ? nas::ESwitchOff::SWITCH_OFF base.nasTask->mm->sendDeregistration(msg.cmd->isSwitchOff ? nas::ESwitchOff::SWITCH_OFF
: nas::ESwitchOff::NORMAL_DE_REGISTRATION, : nas::ESwitchOff::NORMAL_DE_REGISTRATION,
msg.cmd->dueToDisable5g); msg.cmd->dueToDisable5g);
if (!msg.cmd->isSwitchOff)
msg.sendResult("De-registration procedure triggered"); msg.sendResult("De-registration procedure triggered");
else
msg.sendResult("De-registration procedure triggered. UE device will be switched off.");
break; break;
} }
} }
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include <utils/common.hpp> #include <utils/common.hpp>
#include <utils/constants.hpp> #include <utils/constants.hpp>
static constexpr const int SWITCH_OFF_TIMER_ID = 1;
static constexpr const int SWITCH_OFF_DELAY = 500;
namespace nr::ue namespace nr::ue
{ {
...@@ -83,6 +86,17 @@ void UeAppTask::onLoop() ...@@ -83,6 +86,17 @@ void UeAppTask::onLoop()
} }
break; break;
} }
case NtsMessageType::UE_NAS_TO_APP: {
auto *w = dynamic_cast<NwUeNasToApp *>(msg);
switch (w->present)
{
case NwUeNasToApp::PERFORM_SWITCH_OFF: {
setTimer(SWITCH_OFF_TIMER_ID, SWITCH_OFF_DELAY);
break;
}
}
break;
}
case NtsMessageType::UE_STATUS_UPDATE: { case NtsMessageType::UE_STATUS_UPDATE: {
receiveStatusUpdate(*dynamic_cast<NwUeStatusUpdate *>(msg)); receiveStatusUpdate(*dynamic_cast<NwUeStatusUpdate *>(msg));
break; break;
...@@ -92,6 +106,15 @@ void UeAppTask::onLoop() ...@@ -92,6 +106,15 @@ void UeAppTask::onLoop()
UeCmdHandler::HandleCmd(*m_base, *w); UeCmdHandler::HandleCmd(*m_base, *w);
break; break;
} }
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NwTimerExpired *>(msg);
if (w->timerId == SWITCH_OFF_TIMER_ID)
{
m_logger->info("UE device is switching off");
m_base->ueController->performSwitchOff();
}
break;
}
default: default:
m_logger->unhandledNts(msg); m_logger->unhandledNts(msg);
break; break;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "mm.hpp" #include "mm.hpp"
#include <nas/utils.hpp> #include <nas/utils.hpp>
#include <ue/app/task.hpp>
#include <ue/sm/sm.hpp> #include <ue/sm/sm.hpp>
namespace nr::ue namespace nr::ue
...@@ -56,7 +57,9 @@ void NasMm::sendDeregistration(nas::ESwitchOff switchOff, bool dueToDisable5g) ...@@ -56,7 +57,9 @@ void NasMm::sendDeregistration(nas::ESwitchOff switchOff, bool dueToDisable5g)
switchMmState(EMmState::MM_DEREGISTERED_INITIATED, EMmSubState::MM_DEREGISTERED_INITIATED_NA); switchMmState(EMmState::MM_DEREGISTERED_INITIATED, EMmSubState::MM_DEREGISTERED_INITIATED_NA);
// TODO local release of all PDU sessions // TODO local release of all PDU sessions
// TODO: switch off the UE if it's switch off
if (switchOff == nas::ESwitchOff::SWITCH_OFF)
m_base->appTask->push(new NwUeNasToApp(NwUeNasToApp::PERFORM_SWITCH_OFF));
} }
void NasMm::receiveDeregistrationAccept(const nas::DeRegistrationAcceptUeOriginating &msg) void NasMm::receiveDeregistrationAccept(const nas::DeRegistrationAcceptUeOriginating &msg)
......
...@@ -224,6 +224,18 @@ struct NwUeNasToNas : NtsMessage ...@@ -224,6 +224,18 @@ struct NwUeNasToNas : NtsMessage
} }
}; };
struct NwUeNasToApp : NtsMessage
{
enum PR
{
PERFORM_SWITCH_OFF,
} present;
explicit NwUeNasToApp(PR present) : NtsMessage(NtsMessageType::UE_NAS_TO_APP), present(present)
{
}
};
struct NwUeStatusUpdate : NtsMessage struct NwUeStatusUpdate : NtsMessage
{ {
static constexpr const int SESSION_ESTABLISHMENT = 5; static constexpr const int SESSION_ESTABLISHMENT = 5;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#pragma once #pragma once
#include <app/monitor.hpp> #include <app/monitor.hpp>
#include <app/ue_ctl.hpp>
#include <nas/nas.hpp> #include <nas/nas.hpp>
#include <nas/timer.hpp> #include <nas/timer.hpp>
#include <utils/common_types.hpp> #include <utils/common_types.hpp>
...@@ -98,6 +99,7 @@ struct TaskBase ...@@ -98,6 +99,7 @@ struct TaskBase
{ {
UeConfig *config{}; UeConfig *config{};
LogBase *logBase{}; LogBase *logBase{};
app::IUeController *ueController{};
app::INodeListener *nodeListener{}; app::INodeListener *nodeListener{};
UeAppTask *appTask{}; UeAppTask *appTask{};
......
...@@ -16,11 +16,12 @@ ...@@ -16,11 +16,12 @@
namespace nr::ue namespace nr::ue
{ {
UserEquipment::UserEquipment(UeConfig *config, app::INodeListener *nodeListener) UserEquipment::UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener)
{ {
auto *base = new TaskBase(); auto *base = new TaskBase();
base->config = config; base->config = config;
base->logBase = new LogBase("logs/ue-" + config->getNodeName() + ".log"); base->logBase = new LogBase("logs/ue-" + config->getNodeName() + ".log");
base->ueController = ueController;
base->nodeListener = nodeListener; base->nodeListener = nodeListener;
base->nasTask = new NasTask(base); base->nasTask = new NasTask(base);
......
...@@ -23,7 +23,7 @@ class UserEquipment ...@@ -23,7 +23,7 @@ class UserEquipment
TaskBase *taskBase; TaskBase *taskBase;
public: public:
UserEquipment(UeConfig *config, app::INodeListener *nodeListener); UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener);
virtual ~UserEquipment(); virtual ~UserEquipment();
public: public:
......
...@@ -53,6 +53,7 @@ enum class NtsMessageType ...@@ -53,6 +53,7 @@ enum class NtsMessageType
UE_NAS_TO_RRC, UE_NAS_TO_RRC,
UE_RRC_TO_MR, UE_RRC_TO_MR,
UE_NAS_TO_NAS, UE_NAS_TO_NAS,
UE_NAS_TO_APP,
}; };
struct NtsMessage struct NtsMessage
......
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