Commit a84966ca authored by aligungr's avatar aligungr

UE executable refactor

parent 30cbc8e7
......@@ -289,7 +289,7 @@ static void ReceiveCommand(app::CliMessage &msg)
}
auto *ue = g_ueMap[msg.nodeName];
ue->pushCommand(std::move(cmd), msg.clientAddr, g_cliRespTask);
ue->pushCommand(std::move(cmd), msg.clientAddr);
}
static void Loop()
......@@ -357,19 +357,22 @@ int main(int argc, char **argv)
std::cout << cons::Name << std::endl;
if (!g_options.disableCmd)
{
g_cliServer = new app::CliServer{};
g_cliRespTask = new app::CliResponseTask(g_cliServer);
}
for (int i = 0; i < g_options.count; i++)
{
auto *config = GetConfigByUe(i);
auto *ue = new nr::ue::UserEquipment(config, &g_ueController, nullptr);
auto *ue = new nr::ue::UserEquipment(config, &g_ueController, nullptr, g_cliRespTask);
g_ueMap[config->getNodeName()] = ue;
}
if (!g_options.disableCmd)
{
g_cliServer = new app::CliServer{};
app::CreateProcTable(g_ueMap, g_cliServer->assignedAddress().getPort());
g_cliRespTask = new app::CliResponseTask(g_cliServer);
g_cliRespTask->start();
}
......
......@@ -22,34 +22,44 @@
namespace nr::ue
{
void UeCmdHandler::PauseTasks(TaskBase &base)
void UeCmdHandler::sendResult(const InetAddress &address, const std::string &output)
{
base.mrTask->requestPause();
base.nasTask->requestPause();
base.rrcTask->requestPause();
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, false));
}
void UeCmdHandler::UnpauseTasks(TaskBase &base)
void UeCmdHandler::sendError(const InetAddress &address, const std::string &output)
{
base.mrTask->requestUnpause();
base.nasTask->requestUnpause();
base.rrcTask->requestUnpause();
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, true));
}
bool UeCmdHandler::IsAllPaused(TaskBase &base)
void UeCmdHandler::pauseTasks()
{
if (!base.mrTask->isPauseConfirmed())
m_base->mrTask->requestPause();
m_base->nasTask->requestPause();
m_base->rrcTask->requestPause();
}
void UeCmdHandler::unpauseTasks()
{
m_base->mrTask->requestUnpause();
m_base->nasTask->requestUnpause();
m_base->rrcTask->requestUnpause();
}
bool UeCmdHandler::isAllPaused()
{
if (!m_base->mrTask->isPauseConfirmed())
return false;
if (!base.nasTask->isPauseConfirmed())
if (!m_base->nasTask->isPauseConfirmed())
return false;
if (!base.rrcTask->isPauseConfirmed())
if (!m_base->rrcTask->isPauseConfirmed())
return false;
return true;
}
void UeCmdHandler::HandleCmd(TaskBase &base, NwUeCliCommand &msg)
void UeCmdHandler::handleCmd(NwUeCliCommand &msg)
{
PauseTasks(base);
pauseTasks();
uint64_t currentTime = utils::CurrentTimeMillis();
uint64_t endTime = currentTime + PAUSE_CONFIRM_TIMEOUT;
......@@ -58,7 +68,7 @@ void UeCmdHandler::HandleCmd(TaskBase &base, NwUeCliCommand &msg)
while (currentTime < endTime)
{
currentTime = utils::CurrentTimeMillis();
if (IsAllPaused(base))
if (isAllPaused())
{
isPaused = true;
break;
......@@ -68,24 +78,24 @@ void UeCmdHandler::HandleCmd(TaskBase &base, NwUeCliCommand &msg)
if (!isPaused)
{
msg.sendError("UE is unable process command due to pausing timeout");
sendError(msg.address, "UE is unable process command due to pausing timeout");
}
else
{
HandleCmdImpl(base, msg);
handleCmdImpl(msg);
}
UnpauseTasks(base);
unpauseTasks();
}
void UeCmdHandler::HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg)
void UeCmdHandler::handleCmdImpl(NwUeCliCommand &msg)
{
switch (msg.cmd->present)
{
case app::UeCliCommand::STATUS: {
std::vector<Json> pduSessions{};
int index = 0;
for (auto &pduSession : base.appTask->m_statusInfo.pduSessions)
for (auto &pduSession : m_base->appTask->m_statusInfo.pduSessions)
{
if (pduSession.has_value())
{
......@@ -96,33 +106,33 @@ void UeCmdHandler::HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg)
}
Json json = Json::Obj({
{"cm-state", ToJson(base.nasTask->mm->m_cmState)},
{"rm-state", ToJson(base.nasTask->mm->m_rmState)},
{"mm-state", ToJson(base.nasTask->mm->m_mmSubState)},
{"sim-inserted", base.nasTask->mm->m_validSim},
{"stored-suci", ToJson(base.nasTask->mm->m_storedSuci)},
{"stored-guti", ToJson(base.nasTask->mm->m_storedGuti)},
{"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)},
{"sim-inserted", m_base->nasTask->mm->m_validSim},
{"stored-suci", ToJson(m_base->nasTask->mm->m_storedSuci)},
{"stored-guti", ToJson(m_base->nasTask->mm->m_storedGuti)},
{"pdu-sessions", Json::Arr(std::move(pduSessions))},
});
msg.sendResult(json.dumpYaml());
sendResult(msg.address, json.dumpYaml());
break;
}
case app::UeCliCommand::INFO: {
msg.sendResult(ToJson(*base.config).dumpYaml());
sendResult(msg.address, ToJson(*m_base->config).dumpYaml());
break;
}
case app::UeCliCommand::TIMERS: {
msg.sendResult(ToJson(base.nasTask->timers).dumpYaml());
sendResult(msg.address, ToJson(m_base->nasTask->timers).dumpYaml());
break;
}
case app::UeCliCommand::DE_REGISTER: {
base.nasTask->mm->sendDeregistration(msg.cmd->isSwitchOff ? nas::ESwitchOff::SWITCH_OFF
: nas::ESwitchOff::NORMAL_DE_REGISTRATION,
msg.cmd->dueToDisable5g);
m_base->nasTask->mm->sendDeregistration(msg.cmd->isSwitchOff ? nas::ESwitchOff::SWITCH_OFF
: nas::ESwitchOff::NORMAL_DE_REGISTRATION,
msg.cmd->dueToDisable5g);
if (!msg.cmd->isSwitchOff)
msg.sendResult("De-registration procedure triggered");
sendResult(msg.address, "De-registration procedure triggered");
else
msg.sendResult("De-registration procedure triggered. UE device will be switched off.");
sendResult(msg.address, "De-registration procedure triggered. UE device will be switched off.");
break;
}
}
......
......@@ -17,15 +17,26 @@ namespace nr::ue
class UeCmdHandler
{
private:
static void PauseTasks(TaskBase &base);
static void UnpauseTasks(TaskBase &base);
static bool IsAllPaused(TaskBase &base);
TaskBase *m_base;
public:
static void HandleCmd(TaskBase &base, NwUeCliCommand &msg);
explicit UeCmdHandler(TaskBase *base) : m_base(base)
{
}
void handleCmd(NwUeCliCommand &msg);
private:
void pauseTasks();
void unpauseTasks();
bool isAllPaused();
private:
void handleCmdImpl(NwUeCliCommand &msg);
private:
static void HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg);
void sendResult(const InetAddress &address, const std::string &output);
void sendError(const InetAddress &address, const std::string &output);
};
} // namespace nr::ue
......@@ -103,7 +103,8 @@ void UeAppTask::onLoop()
}
case NtsMessageType::UE_CLI_COMMAND: {
auto *w = dynamic_cast<NwUeCliCommand *>(msg);
UeCmdHandler::HandleCmd(*m_base, *w);
UeCmdHandler handler{m_base};
handler.handleCmd(*w);
break;
}
case NtsMessageType::TIMER_EXPIRED: {
......
......@@ -254,22 +254,11 @@ struct NwUeCliCommand : NtsMessage
{
std::unique_ptr<app::UeCliCommand> cmd;
InetAddress address;
NtsTask *callbackTask;
NwUeCliCommand(std::unique_ptr<app::UeCliCommand> cmd, InetAddress address, NtsTask *callbackTask)
: NtsMessage(NtsMessageType::UE_CLI_COMMAND), cmd(std::move(cmd)), address(address), callbackTask(callbackTask)
NwUeCliCommand(std::unique_ptr<app::UeCliCommand> cmd, InetAddress address)
: NtsMessage(NtsMessageType::UE_CLI_COMMAND), cmd(std::move(cmd)), address(address)
{
}
void sendResult(const std::string &output) const
{
callbackTask->push(new app::NwCliSendResponse(address, output, false));
}
void sendError(const std::string &output) const
{
callbackTask->push(new app::NwCliSendResponse(address, output, true));
}
};
} // namespace nr::ue
\ No newline at end of file
......@@ -101,6 +101,7 @@ struct TaskBase
LogBase *logBase{};
app::IUeController *ueController{};
app::INodeListener *nodeListener{};
NtsTask *cliCallbackTask{};
UeAppTask *appTask{};
UeMrTask *mrTask{};
......
......@@ -16,13 +16,15 @@
namespace nr::ue
{
UserEquipment::UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener)
UserEquipment::UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener,
NtsTask *cliCallbackTask)
{
auto *base = new TaskBase();
base->config = config;
base->logBase = new LogBase("logs/ue-" + config->getNodeName() + ".log");
base->ueController = ueController;
base->nodeListener = nodeListener;
base->cliCallbackTask = cliCallbackTask;
base->nasTask = new NasTask(base);
base->rrcTask = new UeRrcTask(base);
......@@ -57,10 +59,9 @@ void UserEquipment::start()
taskBase->appTask->start();
}
void UserEquipment::pushCommand(std::unique_ptr<app::UeCliCommand> cmd, const InetAddress &address,
NtsTask *callbackTask)
void UserEquipment::pushCommand(std::unique_ptr<app::UeCliCommand> cmd, const InetAddress &address)
{
taskBase->appTask->push(new NwUeCliCommand(std::move(cmd), address, callbackTask));
taskBase->appTask->push(new NwUeCliCommand(std::move(cmd), address));
}
} // namespace nr::ue
......@@ -23,12 +23,13 @@ class UserEquipment
TaskBase *taskBase;
public:
UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener);
UserEquipment(UeConfig *config, app::IUeController *ueController, app::INodeListener *nodeListener,
NtsTask *cliCallbackTask);
virtual ~UserEquipment();
public:
void start();
void pushCommand(std::unique_ptr<app::UeCliCommand> cmd, const InetAddress &address, NtsTask *callbackTask);
void pushCommand(std::unique_ptr<app::UeCliCommand> cmd, const InetAddress &address);
};
} // namespace nr::ue
\ No newline at end of file
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