Commit 54f7e1ff authored by aligungr's avatar aligungr

UE/gNB executable refactor

parent 8c7e960e
......@@ -153,7 +153,7 @@ static void ReceiveCommand(app::CliMessage &msg)
}
auto *gnb = g_gnbMap[msg.nodeName];
gnb->pushCommand(std::move(cmd), msg.clientAddr, g_cliRespTask);
gnb->pushCommand(std::move(cmd), msg.clientAddr);
}
static void Loop()
......@@ -196,15 +196,18 @@ int main(int argc, char **argv)
std::cout << cons::Name << std::endl;
auto *gnb = new nr::gnb::GNodeB(g_refConfig, nullptr);
if (!g_options.disableCmd)
{
g_cliServer = new app::CliServer{};
g_cliRespTask = new app::CliResponseTask(g_cliServer);
}
auto *gnb = new nr::gnb::GNodeB(g_refConfig, nullptr, g_cliRespTask);
g_gnbMap[g_refConfig->name] = gnb;
if (!g_options.disableCmd)
{
g_cliServer = new app::CliServer{};
app::CreateProcTable(g_gnbMap, g_cliServer->assignedAddress().getPort());
g_cliRespTask = new app::CliResponseTask(g_cliServer);
g_cliRespTask->start();
}
......
......@@ -23,6 +23,16 @@
namespace nr::gnb
{
void GnbCmdHandler::sendResult(const InetAddress &address, const std::string &output)
{
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, false));
}
void GnbCmdHandler::sendError(const InetAddress &address, const std::string &output)
{
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, true));
}
void GnbCmdHandler::pauseTasks()
{
m_base->gtpTask->requestPause();
......@@ -77,7 +87,7 @@ void GnbCmdHandler::handleCmd(NwGnbCliCommand &msg)
if (!isPaused)
{
msg.sendError("gNB is unable process command due to pausing timeout");
sendError(msg.address, "gNB is unable process command due to pausing timeout");
}
else
{
......@@ -92,27 +102,27 @@ void GnbCmdHandler::handleCmdImpl(NwGnbCliCommand &msg)
switch (msg.cmd->present)
{
case app::GnbCliCommand::STATUS: {
msg.sendResult(ToJson(m_base->appTask->m_statusInfo).dumpYaml());
sendResult(msg.address, ToJson(m_base->appTask->m_statusInfo).dumpYaml());
break;
}
case app::GnbCliCommand::INFO: {
msg.sendResult(ToJson(*m_base->config).dumpYaml());
sendResult(msg.address, ToJson(*m_base->config).dumpYaml());
break;
}
case app::GnbCliCommand::AMF_LIST: {
Json json = Json::Arr({});
for (auto &amf : m_base->ngapTask->m_amfCtx)
json.push(Json::Obj({{"id", amf.first}}));
msg.sendResult(json.dumpYaml());
sendResult(msg.address, json.dumpYaml());
break;
}
case app::GnbCliCommand::AMF_INFO: {
if (m_base->ngapTask->m_amfCtx.count(msg.cmd->amfId) == 0)
msg.sendError("AMF not found with given ID");
sendError(msg.address, "AMF not found with given ID");
else
{
auto amf = m_base->ngapTask->m_amfCtx[msg.cmd->amfId];
msg.sendResult(ToJson(*amf).dumpYaml());
sendResult(msg.address, ToJson(*amf).dumpYaml());
}
break;
}
......@@ -126,11 +136,11 @@ void GnbCmdHandler::handleCmdImpl(NwGnbCliCommand &msg)
{"amf-ngap-id", ue.second->amfUeNgapId},
}));
}
msg.sendResult(json.dumpYaml());
sendResult(msg.address, json.dumpYaml());
break;
}
case app::GnbCliCommand::UE_COUNT: {
msg.sendResult(std::to_string(m_base->ngapTask->m_ueCtx.size()));
sendResult(msg.address, std::to_string(m_base->ngapTask->m_ueCtx.size()));
break;
}
}
......
......@@ -33,6 +33,10 @@ class GnbCmdHandler
private:
void handleCmdImpl(NwGnbCliCommand &msg);
private:
void sendResult(const InetAddress &address, const std::string &output);
void sendError(const InetAddress &address, const std::string &output);
};
} // namespace nr::gnb
......@@ -20,12 +20,13 @@
namespace nr::gnb
{
GNodeB::GNodeB(GnbConfig *config, app::INodeListener *nodeListener)
GNodeB::GNodeB(GnbConfig *config, app::INodeListener *nodeListener, NtsTask *cliCallbackTask)
{
auto *base = new TaskBase();
base->config = config;
base->logBase = new LogBase("logs/" + config->name + ".log");
base->nodeListener = nodeListener;
base->cliCallbackTask = cliCallbackTask;
base->appTask = new GnbAppTask(base);
base->sctpTask = new SctpTask(base);
......@@ -68,9 +69,9 @@ void GNodeB::start()
taskBase->gtpTask->start();
}
void GNodeB::pushCommand(std::unique_ptr<app::GnbCliCommand> cmd, const InetAddress &address, NtsTask *callbackTask)
void GNodeB::pushCommand(std::unique_ptr<app::GnbCliCommand> cmd, const InetAddress &address)
{
taskBase->appTask->push(new NwGnbCliCommand(std::move(cmd), address, callbackTask));
taskBase->appTask->push(new NwGnbCliCommand(std::move(cmd), address));
}
} // namespace nr::gnb
......@@ -27,12 +27,12 @@ class GNodeB
TaskBase *taskBase;
public:
GNodeB(GnbConfig *config, app::INodeListener *nodeListener);
GNodeB(GnbConfig *config, app::INodeListener *nodeListener, NtsTask *cliCallbackTask);
virtual ~GNodeB();
public:
void start();
void pushCommand(std::unique_ptr<app::GnbCliCommand> cmd, const InetAddress &address, NtsTask *callbackTask);
void pushCommand(std::unique_ptr<app::GnbCliCommand> cmd, const InetAddress &address);
};
} // namespace nr::gnb
\ No newline at end of file
......@@ -246,22 +246,11 @@ struct NwGnbCliCommand : NtsMessage
{
std::unique_ptr<app::GnbCliCommand> cmd;
InetAddress address;
NtsTask *callbackTask;
NwGnbCliCommand(std::unique_ptr<app::GnbCliCommand> cmd, InetAddress address, NtsTask *callbackTask)
: NtsMessage(NtsMessageType::GNB_CLI_COMMAND), cmd(std::move(cmd)), address(address), callbackTask(callbackTask)
NwGnbCliCommand(std::unique_ptr<app::GnbCliCommand> cmd, InetAddress address)
: NtsMessage(NtsMessageType::GNB_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::gnb
......@@ -316,6 +316,7 @@ struct TaskBase
GnbConfig *config{};
LogBase *logBase{};
app::INodeListener *nodeListener{};
NtsTask *cliCallbackTask{};
GnbAppTask *appTask{};
GtpTask *gtpTask{};
......
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