Commit e403b589 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Merge branch 'fix_sd_optional' into 'develop'

Fix sd optional

See merge request oai/cn5g/oai-cn5g-amf!122
parents 7a1510be 9aa5fc03
...@@ -228,7 +228,11 @@ int amf_config::load(const std::string& config_file) { ...@@ -228,7 +228,11 @@ int amf_config::load(const std::string& config_file) {
slice_item.lookupValue(AMF_CONFIG_STRING_SD, sd); slice_item.lookupValue(AMF_CONFIG_STRING_SD, sd);
try { try {
slice.sst = std::stoi(sst); slice.sst = std::stoi(sst);
slice.sd = std::stoi(sd); slice.sd = SD_NO_VALUE; // Default value
// Get SD if available for non standardized SST
if (slice.sst > SST_MAX_STANDARDIZED_VALUE) {
if (!sd.empty()) slice.sd = std::stoi(sd);
}
} catch (const std::exception& err) { } catch (const std::exception& err) {
Logger::amf_app().error("Invalid SST/SD"); Logger::amf_app().error("Invalid SST/SD");
} }
......
...@@ -261,7 +261,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) { ...@@ -261,7 +261,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
} }
itti_modify_request_msg->s_NSSAI.setSd(psc->snssai.sD); itti_modify_request_msg->s_NSSAI.setSd(psc->snssai.sD);
itti_modify_request_msg->s_NSSAI.setSst(std::to_string(psc->snssai.sST)); itti_modify_request_msg->s_NSSAI.setSst(psc->snssai.sST);
int ret = itti_inst->send_msg(itti_modify_request_msg); int ret = itti_inst->send_msg(itti_modify_request_msg);
if (0 != ret) { if (0 != ret) {
...@@ -4134,12 +4134,15 @@ bool amf_n1::check_requested_nssai(const std::shared_ptr<nas_context>& nc) { ...@@ -4134,12 +4134,15 @@ bool amf_n1::check_requested_nssai(const std::shared_ptr<nas_context>& nc) {
bool found_nssai = false; bool found_nssai = false;
for (auto s : p.slice_list) { for (auto s : p.slice_list) {
std::string sd = std::to_string(s.sd); std::string sd = std::to_string(s.sd);
if ((s.sst == n.sst) and (s.sd == n.sd)) { if (s.sst == n.sst) {
if ((s.sst <= SST_MAX_STANDARDIZED_VALUE) or (s.sd == n.sd)) {
found_nssai = true; found_nssai = true;
Logger::amf_n1().debug("Found S-NSSAI (SST %d, SD %d)", s.sst, n.sd); Logger::amf_n1().debug(
"Found S-NSSAI (SST %d, SD %d)", s.sst, n.sd);
break; break;
} }
} }
}
if (!found_nssai) { if (!found_nssai) {
result = false; result = false;
break; break;
...@@ -4184,7 +4187,8 @@ bool amf_n1::check_subscribed_nssai( ...@@ -4184,7 +4187,8 @@ bool amf_n1::check_subscribed_nssai(
// Check with default subscribed NSSAIs // Check with default subscribed NSSAIs
for (auto n : nssai.getDefaultSingleNssais()) { for (auto n : nssai.getDefaultSingleNssais()) {
if (s.sst == n.getSst()) { if (s.sst == n.getSst()) {
if ((n.sdIsSet() and (n.getSd().compare(sd) == 0)) or if ((s.sst <= SST_MAX_STANDARDIZED_VALUE) or
(n.sdIsSet() and (n.getSd().compare(sd) == 0)) or
(!n.sdIsSet() and sd.empty())) { (!n.sdIsSet() and sd.empty())) {
common_snssais.push_back(n); common_snssais.push_back(n);
Logger::amf_n1().debug( Logger::amf_n1().debug(
...@@ -4197,7 +4201,8 @@ bool amf_n1::check_subscribed_nssai( ...@@ -4197,7 +4201,8 @@ bool amf_n1::check_subscribed_nssai(
// check with other subscribed NSSAIs // check with other subscribed NSSAIs
for (auto n : nssai.getSingleNssais()) { for (auto n : nssai.getSingleNssais()) {
if (s.sst == n.getSst()) { if (s.sst == n.getSst()) {
if ((n.sdIsSet() and (n.getSd().compare(sd) == 0)) or if ((s.sst <= SST_MAX_STANDARDIZED_VALUE) or
(n.sdIsSet() and (n.getSd().compare(sd) == 0)) or
(!n.sdIsSet() and sd.empty())) { (!n.sdIsSet() and sd.empty())) {
common_snssais.push_back(n); common_snssais.push_back(n);
Logger::amf_n1().debug( Logger::amf_n1().debug(
...@@ -4218,7 +4223,8 @@ bool amf_n1::check_subscribed_nssai( ...@@ -4218,7 +4223,8 @@ bool amf_n1::check_subscribed_nssai(
for (auto s : p.slice_list) { for (auto s : p.slice_list) {
std::string sd = std::to_string(s.sd); std::string sd = std::to_string(s.sd);
if (s.sst == n.getSst()) { if (s.sst == n.getSst()) {
if ((n.sdIsSet() and (n.getSd().compare(sd) == 0)) or if ((s.sst <= SST_MAX_STANDARDIZED_VALUE) or
(n.sdIsSet() and (n.getSd().compare(sd) == 0)) or
(!n.sdIsSet() and sd.empty())) { (!n.sdIsSet() and sd.empty())) {
found_nssai = true; found_nssai = true;
Logger::amf_n1().debug( Logger::amf_n1().debug(
...@@ -4240,7 +4246,8 @@ bool amf_n1::check_subscribed_nssai( ...@@ -4240,7 +4246,8 @@ bool amf_n1::check_subscribed_nssai(
for (auto s : p.slice_list) { for (auto s : p.slice_list) {
std::string sd = std::to_string(s.sd); std::string sd = std::to_string(s.sd);
if (s.sst == n.getSst()) { if (s.sst == n.getSst()) {
if ((n.sdIsSet() and (n.getSd().compare(sd) == 0)) or if ((s.sst <= SST_MAX_STANDARDIZED_VALUE) or
(n.sdIsSet() and (n.getSd().compare(sd) == 0)) or
(!n.sdIsSet() and sd.empty())) { (!n.sdIsSet() and sd.empty())) {
found_nssai = true; found_nssai = true;
Logger::amf_n1().debug( Logger::amf_n1().debug(
...@@ -4498,8 +4505,9 @@ bool amf_n1::get_network_slice_selection_from_conf_file( ...@@ -4498,8 +4505,9 @@ bool amf_n1::get_network_slice_selection_from_conf_file(
Logger::amf_n1().debug( Logger::amf_n1().debug(
"Get the Network Slice Selection Information from configuration file"); "Get the Network Slice Selection Information from configuration file");
// TODO: Get Authorized Network Slice Info from local configuration file // TODO: Get Authorized Network Slice Info from local configuration file
Logger::amf_n1().info("This feature has not been implemented yet!");
return true; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -900,7 +900,8 @@ bool amf_n11::discover_smf( ...@@ -900,7 +900,8 @@ bool amf_n11::discover_smf(
if (Snssai.count("sd") > 0) sd = Snssai["sd"].get<string>(); if (Snssai.count("sd") > 0) sd = Snssai["sd"].get<string>();
if (sst == snssai.sST) { if (sst == snssai.sST) {
// Match SD (optional) only if it is provided // Match SD (optional) only if it is provided
if (sd.empty() or (snssai.sD.compare(sd) == 0)) { if ((sst <= SST_MAX_STANDARDIZED_VALUE) or sd.empty() or
(snssai.sD.compare(sd) == 0)) {
Logger::amf_n11().debug( Logger::amf_n11().debug(
"S-NSSAI [SST- %d, SD -%s] is matched for SMF profile", "S-NSSAI [SST- %d, SD -%s] is matched for SMF profile",
snssai.sST, snssai.sD.c_str()); snssai.sST, snssai.sD.c_str());
......
...@@ -983,9 +983,8 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) { ...@@ -983,9 +983,8 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) {
supi, itti_msg.pdu_session_id, psc)) { supi, itti_msg.pdu_session_id, psc)) {
Logger::amf_n2().warn( Logger::amf_n2().warn(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str()); "Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
// TODO: remove hardcoded value item.s_nssai.sst = "01"; // TODO: remove the default value
item.s_nssai.sst = "01"; item.s_nssai.sd = std::to_string(SD_NO_VALUE);
item.s_nssai.sd = "none";
} else { } else {
item.s_nssai.sst = std::to_string(psc.get()->snssai.sST); item.s_nssai.sst = std::to_string(psc.get()->snssai.sST);
item.s_nssai.sd = psc.get()->snssai.sD; item.s_nssai.sd = psc.get()->snssai.sD;
...@@ -1094,7 +1093,8 @@ void amf_n2::handle_itti_message( ...@@ -1094,7 +1093,8 @@ void amf_n2::handle_itti_message(
Logger::amf_n2().warn( Logger::amf_n2().warn(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str()); "Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sd = "none"; // TODO: get from N1N2msgTranferMsg item.s_nssai.sd =
std::to_string(SD_NO_VALUE); // TODO: get from N1N2msgTranferMsg
} else { } else {
item.s_nssai.sst = std::to_string(psc.get()->snssai.sST); item.s_nssai.sst = std::to_string(psc.get()->snssai.sST);
item.s_nssai.sd = psc.get()->snssai.sD; item.s_nssai.sd = psc.get()->snssai.sD;
...@@ -2325,8 +2325,10 @@ bool amf_n2::get_common_plmn( ...@@ -2325,8 +2325,10 @@ bool amf_n2::get_common_plmn(
Logger::amf_n2().debug( Logger::amf_n2().debug(
"S-NSSAI from AMF (SST %d, SD %s)", s2.sst, "S-NSSAI from AMF (SST %d, SD %s)", s2.sst,
std::to_string(s2.sd).c_str()); std::to_string(s2.sd).c_str());
if ((s1.sst.compare(std::to_string(s2.sst)) == 0) and if (s1.sst.compare(std::to_string(s2.sst)) == 0) {
(s1.sd.compare(std::to_string(s2.sd)) == 0)) { if ((s2.sst <= SST_MAX_STANDARDIZED_VALUE) or
(s1.sd.compare(std::to_string(s2.sd)) ==
0)) { // don't need to check SD for standard NSSAI
Logger::amf_n2().debug( Logger::amf_n2().debug(
"Common S-NSSAI (SST %s, SD %s)", s1.sst.c_str(), "Common S-NSSAI (SST %s, SD %s)", s1.sst.c_str(),
s1.sd.c_str()); s1.sd.c_str());
...@@ -2335,6 +2337,7 @@ bool amf_n2::get_common_plmn( ...@@ -2335,6 +2337,7 @@ bool amf_n2::get_common_plmn(
} }
} }
} }
}
item.b_plmn_list.push_back(plmn_slice_support_item); item.b_plmn_list.push_back(plmn_slice_support_item);
result.push_back(item); result.push_back(item);
......
...@@ -69,6 +69,9 @@ constexpr uint64_t SECONDS_SINCE_FIRST_EPOCH = 2208988800; ...@@ -69,6 +69,9 @@ constexpr uint64_t SECONDS_SINCE_FIRST_EPOCH = 2208988800;
#define NAS_MESSAGE_DOWNLINK 1 #define NAS_MESSAGE_DOWNLINK 1
#define NAS_MESSAGE_UPLINK 0 #define NAS_MESSAGE_UPLINK 0
const uint32_t SD_NO_VALUE = 0xFFFFFF;
const uint8_t SST_MAX_STANDARDIZED_VALUE = 127;
typedef enum { typedef enum {
PlainNasMsg = 0x0, PlainNasMsg = 0x0,
IntegrityProtected = 0x1, IntegrityProtected = 0x1,
......
...@@ -47,7 +47,7 @@ NSSAI::NSSAI(const uint8_t iei, std::vector<struct SNSSAI_s> nssai) { ...@@ -47,7 +47,7 @@ NSSAI::NSSAI(const uint8_t iei, std::vector<struct SNSSAI_s> nssai) {
length = 0; length = 0;
S_NSSAI.assign(nssai.begin(), nssai.end()); S_NSSAI.assign(nssai.begin(), nssai.end());
for (int i = 0; i < nssai.size(); i++) { for (int i = 0; i < nssai.size(); i++) {
length += 2; // for sst length += 2; // 1 for IEI and 1 for sst
if (nssai[i].sd != -1) length += 3; if (nssai[i].sd != -1) length += 3;
if (nssai[i].mHplmnSst != -1) length += 1; if (nssai[i].mHplmnSst != -1) length += 1;
if (nssai[i].mHplmnSd != -1) length += 3; if (nssai[i].mHplmnSd != -1) length += 3;
......
...@@ -43,13 +43,16 @@ namespace nas { ...@@ -43,13 +43,16 @@ namespace nas {
typedef struct SNSSAI_s { typedef struct SNSSAI_s {
uint8_t sst; uint8_t sst;
int32_t sd; int32_t sd;
int32_t mHplmnSst; int8_t mHplmnSst;
int32_t mHplmnSd; int32_t mHplmnSd;
uint8_t length;
SNSSAI_s& operator=(const struct SNSSAI_s& s) { SNSSAI_s& operator=(const struct SNSSAI_s& s) {
sst = s.sst; sst = s.sst;
sd = s.sd; sd = s.sd;
mHplmnSst = s.mHplmnSst; mHplmnSst = s.mHplmnSst;
mHplmnSd = s.mHplmnSd; mHplmnSd = s.mHplmnSd;
length = s.length;
return *this; return *this;
} }
} SNSSAI_t; } SNSSAI_t;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
*/ */
#include "S-NSSAI.hpp" #include "S-NSSAI.hpp"
#include "amf.hpp"
#include "String2Value.hpp" #include "String2Value.hpp"
using namespace std; using namespace std;
...@@ -38,7 +38,7 @@ namespace ngap { ...@@ -38,7 +38,7 @@ namespace ngap {
S_NSSAI::S_NSSAI() { S_NSSAI::S_NSSAI() {
sdIsSet = false; sdIsSet = false;
sst = 0; sst = 0;
sd = 0; sd = SD_NO_VALUE;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -116,13 +116,14 @@ void S_NSSAI::setSd(const uint32_t s) { ...@@ -116,13 +116,14 @@ void S_NSSAI::setSd(const uint32_t s) {
sdIsSet = true; sdIsSet = true;
sd = s; sd = s;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool S_NSSAI::getSd(std::string& s_nssaiSd) const { bool S_NSSAI::getSd(std::string& s_nssaiSd) const {
if (sdIsSet) { if (sdIsSet) {
s_nssaiSd = to_string(sd); s_nssaiSd = to_string(sd);
} else } else {
s_nssaiSd = "None"; s_nssaiSd = to_string(SD_NO_VALUE);
}
return sdIsSet; return sdIsSet;
} }
...@@ -131,19 +132,19 @@ std::string S_NSSAI::getSd() const { ...@@ -131,19 +132,19 @@ std::string S_NSSAI::getSd() const {
if (sdIsSet) { if (sdIsSet) {
return to_string(sd); return to_string(sd);
} else } else
return "None"; return to_string(SD_NO_VALUE);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool S_NSSAI::encode2S_NSSAI(Ngap_S_NSSAI_t* s_NSSAI) { bool S_NSSAI::encode2S_NSSAI(Ngap_S_NSSAI_t* s_NSSAI) {
if (!sSTEncode2OctetString(s_NSSAI->sST)) return false; if (!sSTEncode2OctetString(s_NSSAI->sST)) return false;
if (sdIsSet) { if (sdIsSet && (sd != SD_NO_VALUE)) {
Ngap_SD_t* sd = (Ngap_SD_t*) calloc(1, sizeof(Ngap_SD_t)); Ngap_SD_t* sd_tmp = (Ngap_SD_t*) calloc(1, sizeof(Ngap_SD_t));
if (!sd) return false; if (!sd_tmp) return false;
if (!sDEncode2OctetString(sd)) { if (!sDEncode2OctetString(sd_tmp)) {
free(sd); free(sd_tmp);
return false; return false;
} }
s_NSSAI->sD = sd; s_NSSAI->sD = sd_tmp;
} }
return true; return true;
} }
...@@ -154,6 +155,8 @@ bool S_NSSAI::decodefromS_NSSAI(Ngap_S_NSSAI_t* s_NSSAI) { ...@@ -154,6 +155,8 @@ bool S_NSSAI::decodefromS_NSSAI(Ngap_S_NSSAI_t* s_NSSAI) {
if (s_NSSAI->sD) { if (s_NSSAI->sD) {
sdIsSet = true; sdIsSet = true;
if (!sDdecodefromOctetString(s_NSSAI->sD)) return false; if (!sDdecodefromOctetString(s_NSSAI->sD)) return false;
} else {
sd = SD_NO_VALUE;
} }
return true; return true;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "InitialContextSetupRequest.hpp" #include "InitialContextSetupRequest.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "amf.hpp"
extern "C" { extern "C" {
#include "dynamic_memory_check.h" #include "dynamic_memory_check.h"
...@@ -289,8 +290,8 @@ void InitialContextSetupRequestMsg::setAllowedNssai( ...@@ -289,8 +290,8 @@ void InitialContextSetupRequestMsg::setAllowedNssai(
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
S_NSSAI snssai = {}; S_NSSAI snssai = {};
snssai.setSst(list[i].sst); snssai.setSst(list[i].sst);
if (!list[i].sd.empty() && ((list[i].sd.compare("None") != 0) && if (!list[i].sd.empty() &&
(list[i].sd.compare("none") != 0))) ((list[i].sd.compare(std::to_string(SD_NO_VALUE)) != 0)))
snssai.setSd(list[i].sd); snssai.setSd(list[i].sd);
snssaiList.push_back(snssai); snssaiList.push_back(snssai);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "NGSetupResponse.hpp" #include "NGSetupResponse.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "amf.hpp"
extern "C" { extern "C" {
#include "dynamic_memory_check.h" #include "dynamic_memory_check.h"
...@@ -138,8 +139,8 @@ void NGSetupResponseMsg::setPlmnSupportList( ...@@ -138,8 +139,8 @@ void NGSetupResponseMsg::setPlmnSupportList(
S_NSSAI snssai = {}; S_NSSAI snssai = {};
snssai.setSst(list[i].slice_list[j].sst); snssai.setSst(list[i].slice_list[j].sst);
if (!list[i].slice_list[j].sd.empty() && if (!list[i].slice_list[j].sd.empty() &&
(list[i].slice_list[j].sd.compare("None") != 0) && (list[i].slice_list[j].sd.compare(std::to_string(SD_NO_VALUE)) !=
(list[i].slice_list[j].sd.compare("none") != 0)) { 0)) {
snssai.setSd(list[i].slice_list[j].sd); snssai.setSd(list[i].slice_list[j].sd);
} }
snssais.push_back(snssai); snssais.push_back(snssai);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "RerouteNASRequest.hpp" #include "RerouteNASRequest.hpp"
#include "common_defs.h" #include "common_defs.h"
#include "amf.hpp"
#include "logger.hpp" #include "logger.hpp"
...@@ -110,8 +111,8 @@ void RerouteNASRequest::setAllowedNssai(const std::vector<S_Nssai>& list) { ...@@ -110,8 +111,8 @@ void RerouteNASRequest::setAllowedNssai(const std::vector<S_Nssai>& list) {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
S_NSSAI snssai = {}; S_NSSAI snssai = {};
snssai.setSst(list[i].sst); snssai.setSst(list[i].sst);
if (!list[i].sd.empty() && ((list[i].sd.compare("None") != 0) && if (!list[i].sd.empty() &&
(list[i].sd.compare("none") != 0))) ((list[i].sd.compare(std::to_string(SD_NO_VALUE)) != 0)))
snssai.setSd(list[i].sd); snssai.setSd(list[i].sd);
snssaiList.push_back(snssai); snssaiList.push_back(snssai);
} }
......
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