Commit e121c5c7 authored by aligungr's avatar aligungr

PS local release improvement

parent 9206684b
......@@ -137,6 +137,13 @@ void UeAppTask::receiveStatusUpdate(NwUeStatusUpdate &msg)
m_statusInfo.pduSessions[session->id] = std::move(sessionInfo);
setupTunInterface(session);
return;
}
if (msg.what == NwUeStatusUpdate::SESSION_RELEASE)
{
// TODO
m_logger->err("todo: release");
}
}
......
......@@ -56,7 +56,8 @@ 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
// Release all PDU sessions
m_sm->localReleaseSession(0);
if (switchOff == nas::ESwitchOff::SWITCH_OFF)
m_base->appTask->push(new NwUeNasToApp(NwUeNasToApp::PERFORM_SWITCH_OFF));
......@@ -137,7 +138,8 @@ void NasMm::receiveDeregistrationRequest(const nas::DeRegistrationRequestUeTermi
msg.deRegistrationType.reRegistrationRequired == nas::EReRegistrationRequired::REQUIRED &&
!forceIgnoreReregistration;
// todo local release of pdu sessions
// Release all PDU sessions
m_sm->localReleaseSession(0);
if (reRegistrationRequired)
{
......
......@@ -239,12 +239,16 @@ struct NwUeNasToApp : NtsMessage
struct NwUeStatusUpdate : NtsMessage
{
static constexpr const int SESSION_ESTABLISHMENT = 1;
static constexpr const int SESSION_RELEASE = 2;
const int what{};
// SESSION_ESTABLISHMENT
PduSession *pduSession{};
// SESSION_RELEASE
int psi{}; // psi=0 means release all of the sessions
explicit NwUeStatusUpdate(const int what) : NtsMessage(NtsMessageType::UE_STATUS_UPDATE), what(what)
{
}
......
//
// 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 "sm.hpp"
#include <nas/utils.hpp>
namespace nr::ue
{
int NasSm::allocatePduSessionId(const SessionConfig &config)
{
if (config.type != nas::EPduSessionType::IPV4)
{
m_logger->debug("PDU session type [%s] is not supported", nas::utils::EnumToString(config.type));
return 0;
}
auto &arr = m_pduSessions;
int id = -1;
for (int i = PduSession::MIN_ID; i <= PduSession::MAX_ID; i++)
{
if (arr[i].id == 0)
{
id = i;
break;
}
}
if (id == -1)
{
m_logger->err("PDU session allocation failed");
return 0;
}
arr[id] = {};
arr[id].id = id;
arr[id].isEstablished = false;
arr[id].apn = config.apn;
arr[id].sessionType = config.type;
arr[id].sNssai = config.sNssai;
return id;
}
int NasSm::allocateProcedureTransactionId()
{
auto &arr = m_procedureTransactions;
int id = -1;
for (int i = ProcedureTransaction::MIN_ID; i <= ProcedureTransaction::MAX_ID; i++)
{
if (arr[i].id == 0)
{
id = i;
break;
}
}
if (id == -1)
{
m_logger->err("PTI allocation failed");
return 0;
}
arr[id] = {};
arr[id].id = id;
return id;
}
void NasSm::freeProcedureTransactionId(int pti)
{
if (pti == 0)
{
for (auto &transaction : m_procedureTransactions)
transaction = {};
}
else
{
m_procedureTransactions[pti].id = 0;
}
}
void NasSm::freePduSessionId(int psi)
{
if (psi == 0)
{
for (auto &session : m_pduSessions)
session = {};
}
else
{
m_pduSessions[psi] = {};
}
}
} // namespace nr::ue
\ No newline at end of file
......@@ -7,82 +7,22 @@
//
#include "sm.hpp"
#include <nas/proto_conf.hpp>
#include <nas/utils.hpp>
#include <ue/app/task.hpp>
namespace nr::ue
{
int NasSm::allocatePduSessionId(const SessionConfig &config)
void NasSm::localReleaseSession(int psi)
{
if (config.type != nas::EPduSessionType::IPV4)
{
m_logger->debug("PDU session type [%s] is not supported", nas::utils::EnumToString(config.type));
return 0;
}
m_logger->debug("Performing local release of PDU session[%d]", psi);
auto &arr = m_pduSessions;
freePduSessionId(psi);
int id = -1;
for (int i = PduSession::MIN_ID; i <= PduSession::MAX_ID; i++)
{
if (arr[i].id == 0)
{
id = i;
break;
}
}
if (id == -1)
{
m_logger->err("PDU session allocation failed");
return 0;
}
arr[id] = {};
arr[id].id = id;
arr[id].isEstablished = false;
arr[id].apn = config.apn;
arr[id].sessionType = config.type;
arr[id].sNssai = config.sNssai;
return id;
}
int NasSm::allocateProcedureTransactionId()
{
auto &arr = m_procedureTransactions;
int id = -1;
for (int i = ProcedureTransaction::MIN_ID; i <= ProcedureTransaction::MAX_ID; i++)
{
if (arr[i].id == 0)
{
id = i;
break;
}
}
if (id == -1)
{
m_logger->err("PTI allocation failed");
return 0;
}
arr[id] = {};
arr[id].id = id;
return id;
}
void NasSm::freeProcedureTransactionId(int pti)
{
m_procedureTransactions[pti].id = 0;
}
void NasSm::freePduSessionId(int psi)
{
m_pduSessions[psi].id = 0;
m_logger->info("PDU session[%d] released", psi);
auto *statusUpdate = new NwUeStatusUpdate(NwUeStatusUpdate::SESSION_RELEASE);
statusUpdate->psi = psi;
m_base->appTask->push(statusUpdate);
}
} // namespace nr::ue
\ No newline at end of file
......@@ -8,6 +8,7 @@
#pragma once
#include <array>
#include <nas/nas.hpp>
#include <nas/timer.hpp>
#include <ue/nts.hpp>
......@@ -27,7 +28,7 @@ class NasSm
std::unique_ptr<Logger> m_logger;
NasMm *m_mm;
PduSession m_pduSessions[16]{};
std::array<PduSession, 16> m_pduSessions{};
ProcedureTransaction m_procedureTransactions[255]{};
friend class UeCmdHandler;
......@@ -44,13 +45,16 @@ class NasSm
/* Transport */
void receiveSmMessage(const nas::SmMessage &msg);
/* Resource */
void localReleaseSession(int psi);
private:
/* Transport */
void sendSmMessage(int psi, const nas::SmMessage &msg);
void receiveSmStatus(const nas::FiveGSmStatus &msg);
void receiveSmCause(const nas::IE5gSmCause &msg);
/* Resource */
/* Allocation */
int allocatePduSessionId(const SessionConfig &config);
int allocateProcedureTransactionId();
void freeProcedureTransactionId(int pti);
......
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