Commit a84966ca authored by aligungr's avatar aligungr

UE executable refactor

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