Commit 83a0128f authored by aligungr's avatar aligungr

UE initiated PDU session release impl.

parent 06570837
......@@ -82,7 +82,9 @@ static std::map<std::string, std::string> g_ueCmdToDescription = {
{"info", "Show some information about the UE"},
{"status", "Show some status information about the UE"},
{"timers", "Dump current status of the timers in the UE"},
{"deregister", "Perform de-registration by the UE"},
{"deregister", "Perform a de-registration by the UE"},
{"ps-release", "Trigger a PDU session release procedure"},
{"ps-release-all", "Trigger PDU session release procedures for all active sessions"},
};
static std::map<std::string, std::string> g_ueCmdToUsage = {
......@@ -90,13 +92,13 @@ static std::map<std::string, std::string> g_ueCmdToUsage = {
{"status", ""},
{"timers", ""},
{"deregister", "<normal|disable-5g|switch-off|remove-sim>"},
{"ps-release", "<pdu-session-id>..."},
{"ps-release-all", ""},
};
static std::map<std::string, bool> g_ueCmdToHelpIfEmpty = {
{"info", false},
{"status", false},
{"timers", false},
{"deregister", true},
{"info", false}, {"status", false}, {"timers", false},
{"deregister", true}, {"ps-release", true}, {"ps-release-all", false},
};
std::unique_ptr<GnbCliCommand> ParseGnbCliCommand(std::vector<std::string> &&tokens, std::string &error,
......@@ -245,6 +247,31 @@ std::unique_ptr<UeCliCommand> ParseUeCliCommand(std::vector<std::string> &&token
"\"remove-sim\"")
return cmd;
}
else if (subCmd == "ps-release")
{
auto cmd = std::make_unique<UeCliCommand>(UeCliCommand::PS_RELEASE);
if (options.positionalCount() == 0)
CMD_ERR("At least one PDU session ID is expected")
if (options.positionalCount() > 15)
CMD_ERR("Too many PDU session IDs")
cmd->psCount = options.positionalCount();
for (int i = 0; i < cmd->psCount; i++)
{
int n = 0;
if (!utils::TryParseInt(options.getPositional(i), n))
CMD_ERR("Invalid PDU session ID value")
if (n <= 0)
CMD_ERR("PDU session IDs must be positive integer")
if (n > 15)
CMD_ERR("PDU session IDs cannot be greater than 15")
cmd->psIds[i] = static_cast<int8_t>(n);
}
return cmd;
}
else if (subCmd == "ps-release-all")
{
return std::make_unique<UeCliCommand>(UeCliCommand::PS_RELEASE_ALL);
}
return nullptr;
}
......
......@@ -12,6 +12,7 @@
#include <string>
#include <utils/common_types.hpp>
#include <vector>
#include <array>
namespace app
{
......@@ -44,11 +45,17 @@ struct UeCliCommand
STATUS,
TIMERS,
DE_REGISTER,
PS_RELEASE,
PS_RELEASE_ALL
} present;
// DE_REGISTER
EDeregCause deregCause{};
// PS_RELEASE
std::array<int8_t, 16> psIds{};
int psCount{};
explicit UeCliCommand(PR present) : present(present)
{
}
......
......@@ -129,6 +129,17 @@ void UeCmdHandler::handleCmdImpl(NwUeCliCommand &msg)
sendResult(msg.address, "De-registration procedure triggered. UE device will be switched off.");
break;
}
case app::UeCliCommand::PS_RELEASE: {
for (int i = 0; i < msg.cmd->psCount; i++)
m_base->nasTask->sm->sendReleaseRequest(static_cast<int>(msg.cmd->psIds[i]) % 16);
sendResult(msg.address, "PDU session release procedure(s) triggered");
break;
}
case app::UeCliCommand::PS_RELEASE_ALL: {
m_base->nasTask->sm->sendReleaseRequestForAll();
sendResult(msg.address, "PDU session release procedure(s) triggered");
break;
}
}
}
......
......@@ -18,16 +18,16 @@ namespace nr::ue
void NasSm::sendReleaseRequest(int psi)
{
m_logger->debug("Sending PDU Session Release Request");
/* Control the PDU session state */
auto &ps = m_pduSessions[psi];
if (ps->psState != EPsState::ACTIVE)
{
m_logger->warn("PDU session release procedure could not start: PS[%d] is not active", psi);
m_logger->warn("PDU session release procedure could not start: PS[%d] is not active already", psi);
return;
}
m_logger->debug("Sending PDU Session Release Request for PSI[%d]", psi);
/* Allocate PTI */
int pti = allocateProcedureTransactionId();
if (pti == 0)
......@@ -51,6 +51,13 @@ void NasSm::sendReleaseRequest(int psi)
sendSmMessage(psi, *pt.message);
}
void NasSm::sendReleaseRequestForAll()
{
for (auto &ps : m_pduSessions)
if (ps->psState == EPsState::ACTIVE)
sendReleaseRequest(ps->psi);
}
void NasSm::receiveReleaseReject(const nas::PduSessionReleaseReject &msg)
{
auto cause = msg.smCause.value;
......
......@@ -50,6 +50,10 @@ class NasSm
void localReleaseAllSessions();
bool anyEmergencySession();
/* Session Release */
void sendReleaseRequest(int psi);
void sendReleaseRequestForAll();
private:
/* Transport */
void sendSmMessage(int psi, const nas::SmMessage &msg);
......@@ -69,7 +73,6 @@ class NasSm
void receiveEstablishmentRoutingFailure(const nas::PduSessionEstablishmentRequest &msg);
/* Session Release */
void sendReleaseRequest(int psi);
void receiveReleaseReject(const nas::PduSessionReleaseReject& msg);
/* Timer */
......
......@@ -317,3 +317,21 @@ void utils::Trim(std::stringstream &s)
Trim(str);
s.str(str);
}
bool utils::TryParseInt(const std::string &str, int &output)
{
return TryParseInt(str.c_str(), output);
}
bool utils::TryParseInt(const char *str, int &output)
{
try
{
output = std::stoi(str);
return true;
}
catch (...)
{
return false;
}
}
......@@ -31,6 +31,8 @@ TimeStamp CurrentTimeStamp();
int NextId();
int ParseInt(const std::string &str);
int ParseInt(const char *str);
bool TryParseInt(const std::string &str, int &output);
bool TryParseInt(const char *str, int &output);
uint64_t Random64();
void Sleep(int ms);
bool IsRoot();
......
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