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 @@
#include <app/cli_base.hpp>
#include <app/cli_cmd.hpp>
#include <app/proc_table.hpp>
#include <app/ue_ctl.hpp>
#include <iostream>
#include <ue/ue.hpp>
#include <unistd.h>
......@@ -324,6 +325,19 @@ static void Loop()
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)
{
app::Initialize();
......@@ -346,7 +360,7 @@ int main(int argc, char **argv)
for (int i = 0; i < g_options.count; 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;
}
......
......@@ -119,7 +119,10 @@ void UeCmdHandler::HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg)
base.nasTask->mm->sendDeregistration(msg.cmd->isSwitchOff ? nas::ESwitchOff::SWITCH_OFF
: nas::ESwitchOff::NORMAL_DE_REGISTRATION,
msg.cmd->dueToDisable5g);
msg.sendResult("De-registration procedure triggered");
if (!msg.cmd->isSwitchOff)
msg.sendResult("De-registration procedure triggered");
else
msg.sendResult("De-registration procedure triggered. UE device will be switched off.");
break;
}
}
......
......@@ -14,6 +14,9 @@
#include <utils/common.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
{
......@@ -83,6 +86,17 @@ void UeAppTask::onLoop()
}
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: {
receiveStatusUpdate(*dynamic_cast<NwUeStatusUpdate *>(msg));
break;
......@@ -92,6 +106,15 @@ void UeAppTask::onLoop()
UeCmdHandler::HandleCmd(*m_base, *w);
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:
m_logger->unhandledNts(msg);
break;
......
......@@ -8,6 +8,7 @@
#include "mm.hpp"
#include <nas/utils.hpp>
#include <ue/app/task.hpp>
#include <ue/sm/sm.hpp>
namespace nr::ue
......@@ -56,7 +57,9 @@ void NasMm::sendDeregistration(nas::ESwitchOff switchOff, bool dueToDisable5g)
switchMmState(EMmState::MM_DEREGISTERED_INITIATED, EMmSubState::MM_DEREGISTERED_INITIATED_NA);
// 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)
......
......@@ -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
{
static constexpr const int SESSION_ESTABLISHMENT = 5;
......
......@@ -9,6 +9,7 @@
#pragma once
#include <app/monitor.hpp>
#include <app/ue_ctl.hpp>
#include <nas/nas.hpp>
#include <nas/timer.hpp>
#include <utils/common_types.hpp>
......@@ -98,6 +99,7 @@ struct TaskBase
{
UeConfig *config{};
LogBase *logBase{};
app::IUeController *ueController{};
app::INodeListener *nodeListener{};
UeAppTask *appTask{};
......
......@@ -16,11 +16,12 @@
namespace nr::ue
{
UserEquipment::UserEquipment(UeConfig *config, app::INodeListener *nodeListener)
UserEquipment::UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener)
{
auto *base = new TaskBase();
base->config = config;
base->logBase = new LogBase("logs/ue-" + config->getNodeName() + ".log");
base->ueController = ueController;
base->nodeListener = nodeListener;
base->nasTask = new NasTask(base);
......
......@@ -23,7 +23,7 @@ class UserEquipment
TaskBase *taskBase;
public:
UserEquipment(UeConfig *config, app::INodeListener *nodeListener);
UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener);
virtual ~UserEquipment();
public:
......
......@@ -52,7 +52,8 @@ enum class NtsMessageType
UE_RRC_TO_NAS,
UE_NAS_TO_RRC,
UE_RRC_TO_MR,
UE_NAS_TO_NAS,
UE_NAS_TO_NAS,
UE_NAS_TO_APP,
};
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