Skip to content

Commit

Permalink
Merge pull request #731 from spring-iitd/master
Browse files Browse the repository at this point in the history
Added intelligent AMF selection at gNB
  • Loading branch information
aligungr authored Feb 2, 2025
2 parents 7bf0cc9 + 933bca2 commit 5c09fc8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/gnb/ngap/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void NgapTask::createAmfContext(const GnbAmfConfig &conf)
m_amfCtx[ctx->ctxId] = ctx;
}

void NgapTask::createUeContext(int ueId)
void NgapTask::createUeContext(int ueId, int32_t &requestedSliceType)
{
auto *ctx = new NgapUeContext(ueId);
ctx->amfUeNgapId = -1;
Expand All @@ -42,7 +42,7 @@ void NgapTask::createUeContext(int ueId)
m_ueCtx[ctx->ctxId] = ctx;

// Perform AMF selection
auto *amf = selectAmf(ueId);
auto *amf = selectAmf(ueId, requestedSliceType);
if (amf == nullptr)
m_logger->err("AMF selection for UE[%d] failed. Could not find a suitable AMF.", ueId);
else
Expand Down
46 changes: 43 additions & 3 deletions src/gnb/ngap/nas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,53 @@
#include <asn/ngap/ASN_NGAP_ProtocolIE-Field.h>
#include <asn/ngap/ASN_NGAP_RerouteNASRequest.h>
#include <asn/ngap/ASN_NGAP_UplinkNASTransport.h>
#include <ue/nas/enc.hpp>
#include "encode.hpp"
#include <stdexcept>

namespace nr::gnb
{

void NgapTask::handleInitialNasTransport(int ueId, const OctetString &nasPdu, int64_t rrcEstablishmentCause,
const std::optional<GutiMobileIdentity> &sTmsi)
int32_t extractSliceInfoAndModifyPdu(OctetString &nasPdu) {
nas::RegistrationRequest *regRequest = nullptr;
int32_t requestedSliceType = -1;
const uint8_t *m_data = nasPdu.data();
size_t m_dataLength = nasPdu.length();
OctetView octetView(m_data, m_dataLength);
auto nasMessage = nas::DecodeNasMessage(octetView);
if (nasMessage->epd == nas::EExtendedProtocolDiscriminator::MOBILITY_MANAGEMENT_MESSAGES)
{
nas::MmMessage *mmMessage = dynamic_cast<nas::MmMessage *>(nasMessage.get());
if (mmMessage)
{
nas::PlainMmMessage *plainMmMessage = dynamic_cast<nas::PlainMmMessage *>(mmMessage);
if (plainMmMessage)
{
regRequest = dynamic_cast<nas::RegistrationRequest *>(plainMmMessage);
if (regRequest)
{
auto sz = regRequest->requestedNSSAI->sNssais.size();
if (sz > 0) {
requestedSliceType = static_cast<uint8_t>(regRequest->requestedNSSAI->sNssais[0].sst);
}
}
}
}
}
if (regRequest && regRequest->requestedNSSAI)
regRequest->requestedNSSAI = std::nullopt;

OctetString modifiedNasPdu;
nas::EncodeNasMessage(*nasMessage, modifiedNasPdu);
nasPdu = std::move(modifiedNasPdu);
return requestedSliceType;
}

void NgapTask::handleInitialNasTransport(int ueId, OctetString &nasPdu, int64_t rrcEstablishmentCause,
const std::optional<GutiMobileIdentity> &sTmsi)
{
int32_t requestedSliceType = extractSliceInfoAndModifyPdu(nasPdu);

m_logger->debug("Initial NAS message received from UE[%d]", ueId);

if (m_ueCtx.count(ueId))
Expand All @@ -35,7 +75,7 @@ void NgapTask::handleInitialNasTransport(int ueId, const OctetString &nasPdu, in
return;
}

createUeContext(ueId);
createUeContext(ueId, requestedSliceType);

auto *ueCtx = findUeContext(ueId);
if (ueCtx == nullptr)
Expand Down
15 changes: 11 additions & 4 deletions src/gnb/ngap/nnsf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
namespace nr::gnb
{

NgapAmfContext *NgapTask::selectAmf(int ueId)
NgapAmfContext *NgapTask::selectAmf(int ueId, int32_t &requestedSliceType)
{
// todo:
for (auto &amf : m_amfCtx)
return amf.second; // return the first one
for (auto &amf : m_amfCtx) {
for (const auto &plmnSupport : amf.second->plmnSupportList) {
for (const auto &singleSlice : plmnSupport->sliceSupportList.slices) {
int32_t supportedSliceType = static_cast<int32_t>(singleSlice.sst);
if (supportedSliceType == requestedSliceType) {
return amf.second;
}
}
}
}
return nullptr;
}

Expand Down
6 changes: 3 additions & 3 deletions src/gnb/ngap/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NgapTask : public NtsTask
/* Utility functions */
void createAmfContext(const GnbAmfConfig &config);
NgapAmfContext *findAmfContext(int ctxId);
void createUeContext(int ueId);
void createUeContext(int ueId, int32_t &requestedSliceType);
NgapUeContext *findUeContext(int ctxId);
NgapUeContext *findUeByRanId(int64_t ranUeNgapId);
NgapUeContext *findUeByAmfId(int64_t amfUeNgapId);
Expand All @@ -98,7 +98,7 @@ class NgapTask : public NtsTask
bool handleSctpStreamId(int amfId, int stream, const ASN_NGAP_NGAP_PDU &pdu);

/* NAS transport */
void handleInitialNasTransport(int ueId, const OctetString &nasPdu, int64_t rrcEstablishmentCause,
void handleInitialNasTransport(int ueId, OctetString &nasPdu, int64_t rrcEstablishmentCause,
const std::optional<GutiMobileIdentity> &sTmsi);
void handleUplinkNasTransport(int ueId, const OctetString &nasPdu);
void receiveDownlinkNasTransport(int amfId, ASN_NGAP_DownlinkNASTransport *msg);
Expand All @@ -118,7 +118,7 @@ class NgapTask : public NtsTask
void sendContextRelease(int ueId, NgapCause cause);

/* NAS Node Selection */
NgapAmfContext *selectAmf(int ueId);
NgapAmfContext *selectAmf(int ueId, int32_t &requestedSliceType);
NgapAmfContext *selectNewAmfForReAllocation(int ueId, int initiatedAmfId, int amfSetId);

/* Radio resource control */
Expand Down
1 change: 0 additions & 1 deletion src/ue/nas/mm/messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static void RemoveCleartextIEs(nas::PlainMmMessage &msg, OctetString &&nasMsgCon
regReq.micoIndication = std::nullopt;
regReq.networkSlicingIndication = std::nullopt;
regReq.mmCapability = std::nullopt;
regReq.requestedNSSAI = std::nullopt;
regReq.requestedDrxParameters = std::nullopt;
regReq.uesUsageSetting = std::nullopt;
regReq.updateType = std::nullopt;
Expand Down

0 comments on commit 5c09fc8

Please sign in to comment.