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) {
slice_item.lookupValue(AMF_CONFIG_STRING_SD, sd);
try {
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) {
Logger::amf_app().error("Invalid SST/SD");
}
......
......@@ -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.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);
if (0 != ret) {
......@@ -4134,10 +4134,13 @@ bool amf_n1::check_requested_nssai(const std::shared_ptr<nas_context>& nc) {
bool found_nssai = false;
for (auto s : p.slice_list) {
std::string sd = std::to_string(s.sd);
if ((s.sst == n.sst) and (s.sd == n.sd)) {
found_nssai = true;
Logger::amf_n1().debug("Found S-NSSAI (SST %d, SD %d)", s.sst, n.sd);
break;
if (s.sst == n.sst) {
if ((s.sst <= SST_MAX_STANDARDIZED_VALUE) or (s.sd == n.sd)) {
found_nssai = true;
Logger::amf_n1().debug(
"Found S-NSSAI (SST %d, SD %d)", s.sst, n.sd);
break;
}
}
}
if (!found_nssai) {
......@@ -4184,7 +4187,8 @@ bool amf_n1::check_subscribed_nssai(
// Check with default subscribed NSSAIs
for (auto n : nssai.getDefaultSingleNssais()) {
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())) {
common_snssais.push_back(n);
Logger::amf_n1().debug(
......@@ -4197,7 +4201,8 @@ bool amf_n1::check_subscribed_nssai(
// check with other subscribed NSSAIs
for (auto n : nssai.getSingleNssais()) {
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())) {
common_snssais.push_back(n);
Logger::amf_n1().debug(
......@@ -4218,7 +4223,8 @@ bool amf_n1::check_subscribed_nssai(
for (auto s : p.slice_list) {
std::string sd = std::to_string(s.sd);
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())) {
found_nssai = true;
Logger::amf_n1().debug(
......@@ -4240,7 +4246,8 @@ bool amf_n1::check_subscribed_nssai(
for (auto s : p.slice_list) {
std::string sd = std::to_string(s.sd);
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())) {
found_nssai = true;
Logger::amf_n1().debug(
......@@ -4498,8 +4505,9 @@ bool amf_n1::get_network_slice_selection_from_conf_file(
Logger::amf_n1().debug(
"Get the Network Slice Selection Information from 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(
if (Snssai.count("sd") > 0) sd = Snssai["sd"].get<string>();
if (sst == snssai.sST) {
// 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(
"S-NSSAI [SST- %d, SD -%s] is matched for SMF profile",
snssai.sST, snssai.sD.c_str());
......
......@@ -983,9 +983,8 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) {
supi, itti_msg.pdu_session_id, psc)) {
Logger::amf_n2().warn(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
// TODO: remove hardcoded value
item.s_nssai.sst = "01";
item.s_nssai.sd = "none";
item.s_nssai.sst = "01"; // TODO: remove the default value
item.s_nssai.sd = std::to_string(SD_NO_VALUE);
} else {
item.s_nssai.sst = std::to_string(psc.get()->snssai.sST);
item.s_nssai.sd = psc.get()->snssai.sD;
......@@ -1093,8 +1092,9 @@ void amf_n2::handle_itti_message(
supi, itti_msg.pdu_session_id, psc)) {
Logger::amf_n2().warn(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sd = "none"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sd =
std::to_string(SD_NO_VALUE); // TODO: get from N1N2msgTranferMsg
} else {
item.s_nssai.sst = std::to_string(psc.get()->snssai.sST);
item.s_nssai.sd = psc.get()->snssai.sD;
......@@ -2325,13 +2325,16 @@ bool amf_n2::get_common_plmn(
Logger::amf_n2().debug(
"S-NSSAI from AMF (SST %d, SD %s)", s2.sst,
std::to_string(s2.sd).c_str());
if ((s1.sst.compare(std::to_string(s2.sst)) == 0) and
(s1.sd.compare(std::to_string(s2.sd)) == 0)) {
Logger::amf_n2().debug(
"Common S-NSSAI (SST %s, SD %s)", s1.sst.c_str(),
s1.sd.c_str());
plmn_slice_support_item.slice_list.push_back(s1);
found_common_plmn = true;
if (s1.sst.compare(std::to_string(s2.sst)) == 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(
"Common S-NSSAI (SST %s, SD %s)", s1.sst.c_str(),
s1.sd.c_str());
plmn_slice_support_item.slice_list.push_back(s1);
found_common_plmn = true;
}
}
}
}
......
......@@ -69,6 +69,9 @@ constexpr uint64_t SECONDS_SINCE_FIRST_EPOCH = 2208988800;
#define NAS_MESSAGE_DOWNLINK 1
#define NAS_MESSAGE_UPLINK 0
const uint32_t SD_NO_VALUE = 0xFFFFFF;
const uint8_t SST_MAX_STANDARDIZED_VALUE = 127;
typedef enum {
PlainNasMsg = 0x0,
IntegrityProtected = 0x1,
......
......@@ -47,7 +47,7 @@ NSSAI::NSSAI(const uint8_t iei, std::vector<struct SNSSAI_s> nssai) {
length = 0;
S_NSSAI.assign(nssai.begin(), nssai.end());
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].mHplmnSst != -1) length += 1;
if (nssai[i].mHplmnSd != -1) length += 3;
......
......@@ -43,13 +43,16 @@ namespace nas {
typedef struct SNSSAI_s {
uint8_t sst;
int32_t sd;
int32_t mHplmnSst;
int8_t mHplmnSst;
int32_t mHplmnSd;
uint8_t length;
SNSSAI_s& operator=(const struct SNSSAI_s& s) {
sst = s.sst;
sd = s.sd;
mHplmnSst = s.mHplmnSst;
mHplmnSd = s.mHplmnSd;
length = s.length;
return *this;
}
} SNSSAI_t;
......
......@@ -27,7 +27,7 @@
*/
#include "S-NSSAI.hpp"
#include "amf.hpp"
#include "String2Value.hpp"
using namespace std;
......@@ -38,7 +38,7 @@ namespace ngap {
S_NSSAI::S_NSSAI() {
sdIsSet = false;
sst = 0;
sd = 0;
sd = SD_NO_VALUE;
}
//------------------------------------------------------------------------------
......@@ -116,13 +116,14 @@ void S_NSSAI::setSd(const uint32_t s) {
sdIsSet = true;
sd = s;
}
//------------------------------------------------------------------------------
bool S_NSSAI::getSd(std::string& s_nssaiSd) const {
if (sdIsSet) {
s_nssaiSd = to_string(sd);
} else
s_nssaiSd = "None";
} else {
s_nssaiSd = to_string(SD_NO_VALUE);
}
return sdIsSet;
}
......@@ -131,19 +132,19 @@ std::string S_NSSAI::getSd() const {
if (sdIsSet) {
return to_string(sd);
} else
return "None";
return to_string(SD_NO_VALUE);
}
//------------------------------------------------------------------------------
bool S_NSSAI::encode2S_NSSAI(Ngap_S_NSSAI_t* s_NSSAI) {
if (!sSTEncode2OctetString(s_NSSAI->sST)) return false;
if (sdIsSet) {
Ngap_SD_t* sd = (Ngap_SD_t*) calloc(1, sizeof(Ngap_SD_t));
if (!sd) return false;
if (!sDEncode2OctetString(sd)) {
free(sd);
if (sdIsSet && (sd != SD_NO_VALUE)) {
Ngap_SD_t* sd_tmp = (Ngap_SD_t*) calloc(1, sizeof(Ngap_SD_t));
if (!sd_tmp) return false;
if (!sDEncode2OctetString(sd_tmp)) {
free(sd_tmp);
return false;
}
s_NSSAI->sD = sd;
s_NSSAI->sD = sd_tmp;
}
return true;
}
......@@ -154,6 +155,8 @@ bool S_NSSAI::decodefromS_NSSAI(Ngap_S_NSSAI_t* s_NSSAI) {
if (s_NSSAI->sD) {
sdIsSet = true;
if (!sDdecodefromOctetString(s_NSSAI->sD)) return false;
} else {
sd = SD_NO_VALUE;
}
return true;
}
......
......@@ -21,6 +21,7 @@
#include "InitialContextSetupRequest.hpp"
#include "logger.hpp"
#include "amf.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -289,8 +290,8 @@ void InitialContextSetupRequestMsg::setAllowedNssai(
for (int i = 0; i < list.size(); i++) {
S_NSSAI snssai = {};
snssai.setSst(list[i].sst);
if (!list[i].sd.empty() && ((list[i].sd.compare("None") != 0) &&
(list[i].sd.compare("none") != 0)))
if (!list[i].sd.empty() &&
((list[i].sd.compare(std::to_string(SD_NO_VALUE)) != 0)))
snssai.setSd(list[i].sd);
snssaiList.push_back(snssai);
}
......
......@@ -21,6 +21,7 @@
#include "NGSetupResponse.hpp"
#include "logger.hpp"
#include "amf.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -138,8 +139,8 @@ void NGSetupResponseMsg::setPlmnSupportList(
S_NSSAI snssai = {};
snssai.setSst(list[i].slice_list[j].sst);
if (!list[i].slice_list[j].sd.empty() &&
(list[i].slice_list[j].sd.compare("None") != 0) &&
(list[i].slice_list[j].sd.compare("none") != 0)) {
(list[i].slice_list[j].sd.compare(std::to_string(SD_NO_VALUE)) !=
0)) {
snssai.setSd(list[i].slice_list[j].sd);
}
snssais.push_back(snssai);
......
......@@ -21,6 +21,7 @@
#include "RerouteNASRequest.hpp"
#include "common_defs.h"
#include "amf.hpp"
#include "logger.hpp"
......@@ -110,8 +111,8 @@ void RerouteNASRequest::setAllowedNssai(const std::vector<S_Nssai>& list) {
for (int i = 0; i < list.size(); i++) {
S_NSSAI snssai = {};
snssai.setSst(list[i].sst);
if (!list[i].sd.empty() && ((list[i].sd.compare("None") != 0) &&
(list[i].sd.compare("none") != 0)))
if (!list[i].sd.empty() &&
((list[i].sd.compare(std::to_string(SD_NO_VALUE)) != 0)))
snssai.setSd(list[i].sd);
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