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

Fix Check NSSAI function

parent 97ccc2ed
...@@ -215,8 +215,16 @@ int amf_config::load(const std::string& config_file) { ...@@ -215,8 +215,16 @@ int amf_config::load(const std::string& config_file) {
for (int j = 0; j < numOfSlice; j++) { for (int j = 0; j < numOfSlice; j++) {
slice_t slice; slice_t slice;
const Setting& slice_item = slice_list_cfg[j]; const Setting& slice_item = slice_list_cfg[j];
slice_item.lookupValue(AMF_CONFIG_STRING_SST, slice.sST); std::string sst = {};
slice_item.lookupValue(AMF_CONFIG_STRING_SD, slice.sD); std::string sd = {};
slice_item.lookupValue(AMF_CONFIG_STRING_SST, sst);
slice_item.lookupValue(AMF_CONFIG_STRING_SD, sd);
try {
slice.sst = std::stoi(sst);
slice.sd = std::stoi(sd);
} catch (const std::exception& err) {
Logger::amf_app().error("Invalid SST/SD");
}
plmn_item.slice_list.push_back(slice); plmn_item.slice_list.push_back(slice);
} }
plmn_list.push_back(plmn_item); plmn_list.push_back(plmn_item);
...@@ -627,9 +635,8 @@ void amf_config::display() { ...@@ -627,9 +635,8 @@ void amf_config::display() {
Logger::config().info(" Slice Support ......:"); Logger::config().info(" Slice Support ......:");
for (int j = 0; j < plmn_list[i].slice_list.size(); j++) { for (int j = 0; j < plmn_list[i].slice_list.size(); j++) {
Logger::config().info( Logger::config().info(
" SST, SD ........: %s, %s", " SST, SD ........: %d, %d", plmn_list[i].slice_list[j].sst,
plmn_list[i].slice_list[j].sST.c_str(), plmn_list[i].slice_list[j].sd);
plmn_list[i].slice_list[j].sD.c_str());
} }
} }
Logger::config().info( Logger::config().info(
......
...@@ -153,20 +153,20 @@ typedef struct guami_s { ...@@ -153,20 +153,20 @@ typedef struct guami_s {
} guami_t; } guami_t;
typedef struct slice_s { typedef struct slice_s {
std::string sST; uint8_t sst;
std::string sD; uint32_t sd;
bool operator==(const struct slice_s& s) const { bool operator==(const struct slice_s& s) const {
if ((s.sST == this->sST) && (s.sD.compare(this->sD) == 0)) { if ((s.sst == this->sst) && (s.sd == this->sd)) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
bool operator>(const struct slice_s& s) const { bool operator>(const struct slice_s& s) const {
if (this->sST.compare(s.sST) > 0) return true; if (this->sst > s.sst) return true;
if (this->sST.compare(s.sST) == 0) { if (this->sst == s.sst) {
if (this->sD.compare(s.sD) > 0) return true; if (this->sd > s.sd) return true;
if (this->sD.compare(s.sD) < 0) return false; if (this->sd <= s.sd) return false;
} }
} }
} slice_t; } slice_t;
......
...@@ -3462,13 +3462,8 @@ void amf_n1::initialize_registration_accept( ...@@ -3462,13 +3462,8 @@ void amf_n1::initialize_registration_accept(
for (auto p : amf_cfg.plmn_list) { for (auto p : amf_cfg.plmn_list) {
for (auto s : p.slice_list) { for (auto s : p.slice_list) {
SNSSAI_t snssai = {}; SNSSAI_t snssai = {};
try { snssai.sst = s.sst;
snssai.sst = std::stoi(s.sST); snssai.sd = s.sd;
snssai.sd = std::stoi(s.sD);
} catch (const std::exception& err) {
Logger::amf_n1().warn("Invalid SST/SD");
return;
}
nssai.push_back(snssai); nssai.push_back(snssai);
} }
} }
...@@ -3514,13 +3509,8 @@ void amf_n1::initialize_registration_accept( ...@@ -3514,13 +3509,8 @@ void amf_n1::initialize_registration_accept(
(p.tac == uc.get()->tai.tac)) { (p.tac == uc.get()->tai.tac)) {
for (auto s : p.slice_list) { for (auto s : p.slice_list) {
SNSSAI_t snssai = {}; SNSSAI_t snssai = {};
try { snssai.sst = s.sst;
snssai.sst = std::stoi(s.sST); snssai.sd = s.sd;
snssai.sd = std::stoi(s.sD);
} catch (const std::exception& err) {
Logger::amf_n1().warn("Invalid SST/SD");
return;
}
nssai.push_back(snssai); nssai.push_back(snssai);
// TODO: Check with the requested NSSAI from UE // TODO: Check with the requested NSSAI from UE
/* for (auto rn : nc.get()->requestedNssai) { /* for (auto rn : nc.get()->requestedNssai) {
...@@ -3720,6 +3710,8 @@ bool amf_n1::reroute_registration_request(std::shared_ptr<nas_context>& nc) { ...@@ -3720,6 +3710,8 @@ bool amf_n1::reroute_registration_request(std::shared_ptr<nas_context>& nc) {
return false; return false;
} }
// Update subscribed NSSAIs
// Check that AMF can process the Requested NSSAIs or not // Check that AMF can process the Requested NSSAIs or not
if (check_requested_nssai(nc, nssai)) { if (check_requested_nssai(nc, nssai)) {
Logger::amf_n1().debug( Logger::amf_n1().debug(
...@@ -3792,32 +3784,83 @@ bool amf_n1::check_requested_nssai( ...@@ -3792,32 +3784,83 @@ bool amf_n1::check_requested_nssai(
result = true; result = true;
// Each S-NSSAI in the Default Single NSSAIs must be in the AMF's Slice List // Find the common NSSAIs between Requested NSSAIs and Subscribed NSSAIs
for (auto n : nssai.getDefaultSingleNssais()) { std::vector<oai::amf::model::Snssai> common_snssais;
bool found_nssai = false; for (auto s : nc->requestedNssai) {
for (auto s : p.slice_list) { std::string sd = std::to_string(s.sd);
uint8_t sst = 0; // Check with default subscribed NSSAIs
try { for (auto n : nssai.getDefaultSingleNssais()) {
sst = std::stoi(s.sST); if (s.sst == n.getSst()) {
} catch (const std::exception& err) { if ((n.sdIsSet() and (n.getSd().compare(sd) == 0)) or
Logger::amf_n1().warn("Invalid SST"); (!n.sdIsSet() and sd.empty())) {
continue; common_snssais.push_back(n);
Logger::amf_n1().debug(
"Found S-NSSAI (SST %d, SD %s)", s.sst, sd.c_str());
break;
}
} }
}
if (sst == n.getSst()) { // check with other subscribed NSSAIs
if ((n.sdIsSet() and (n.getSd().compare(s.sD) == 0)) or for (auto n : nssai.getSingleNssais()) {
(!n.sdIsSet() and s.sD.empty())) { if (s.sst == n.getSst()) {
found_nssai = true; if ((n.sdIsSet() and (n.getSd().compare(sd) == 0)) or
(!n.sdIsSet() and sd.empty())) {
common_snssais.push_back(n);
Logger::amf_n1().debug( Logger::amf_n1().debug(
"Found S-NSSAI (SST %d, SD %s)", sst, n.getSd().c_str()); "Found S-NSSAI (SST %d, SD %s)", s.sst, sd.c_str());
break; break;
} }
} }
} }
}
if (!found_nssai) { // If there no requested NSSAIs or no common NSSAIs between requested NSSAIs
result = false; // and Subscribed NSSAIs
break; if ((nc->requestedNssai.size() == 0) or (common_snssais.size() == 0)) {
// Each S-NSSAI in the Default Single NSSAIs must be in the AMF's Slice
// List
for (auto n : nssai.getDefaultSingleNssais()) {
bool found_nssai = false;
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
(!n.sdIsSet() and sd.empty())) {
found_nssai = true;
Logger::amf_n1().debug(
"Found S-NSSAI (SST %d, SD %s)", s.sst, n.getSd().c_str());
break;
}
}
}
if (!found_nssai) {
result = false;
break;
}
}
} else {
// check if AMF can serve all the common NSSAIs
for (auto n : common_snssais) {
bool found_nssai = false;
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
(!n.sdIsSet() and sd.empty())) {
found_nssai = true;
Logger::amf_n1().debug(
"Found S-NSSAI (SST %d, SD %s)", s.sst, n.getSd().c_str());
break;
}
}
}
if (!found_nssai) {
result = false;
break;
}
} }
} }
} }
......
...@@ -429,8 +429,8 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) { ...@@ -429,8 +429,8 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
tmp.mnc = amf_cfg.plmn_list[i].mnc; tmp.mnc = amf_cfg.plmn_list[i].mnc;
for (int j = 0; j < amf_cfg.plmn_list[i].slice_list.size(); j++) { for (int j = 0; j < amf_cfg.plmn_list[i].slice_list.size(); j++) {
S_Nssai s_tmp; S_Nssai s_tmp;
s_tmp.sst = amf_cfg.plmn_list[i].slice_list[j].sST; s_tmp.sst = std::to_string(amf_cfg.plmn_list[i].slice_list[j].sst);
s_tmp.sd = amf_cfg.plmn_list[i].slice_list[j].sD; s_tmp.sd = amf_cfg.plmn_list[i].slice_list[j].sd;
tmp.slice_list.push_back(s_tmp); tmp.slice_list.push_back(s_tmp);
} }
plmn_list.push_back(tmp); plmn_list.push_back(tmp);
...@@ -1464,8 +1464,8 @@ bool amf_n2::handle_itti_message(itti_handover_required& itti_msg) { ...@@ -1464,8 +1464,8 @@ bool amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
for (int j = 0; j < amf_cfg.plmn_list[i].slice_list.size(); j++) { for (int j = 0; j < amf_cfg.plmn_list[i].slice_list.size(); j++) {
S_Nssai s_tmp; S_Nssai s_tmp;
S_NSSAI s_nssai = {}; S_NSSAI s_nssai = {};
s_nssai.setSst(amf_cfg.plmn_list[i].slice_list[j].sST); s_nssai.setSst(amf_cfg.plmn_list[i].slice_list[j].sst);
s_nssai.setSd(amf_cfg.plmn_list[i].slice_list[j].sD); s_nssai.setSd(amf_cfg.plmn_list[i].slice_list[j].sd);
Allowed_Nssai.push_back(s_nssai); Allowed_Nssai.push_back(s_nssai);
} }
} }
...@@ -1601,11 +1601,11 @@ bool amf_n2::handle_itti_message(itti_handover_required& itti_msg) { ...@@ -1601,11 +1601,11 @@ bool amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
supi, curl_responses.begin()->first, psc)) { supi, curl_responses.begin()->first, psc)) {
PDUSessionResourceSetupRequestItem_t item = {}; PDUSessionResourceSetupRequestItem_t item = {};
item.pduSessionId = psc.get()->pdu_session_id; item.pduSessionId = psc.get()->pdu_session_id;
item.s_nssai.sst = 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;
item.pduSessionNAS_PDU = nullptr; item.pduSessionNAS_PDU = nullptr;
unsigned int data_len = n2_sm.length(); unsigned int data_len = n2_sm.length();
unsigned char* data = (unsigned char*) malloc(data_len + 1); unsigned char* data = (unsigned char*) malloc(data_len + 1);
memset(data, 0, data_len + 1); memset(data, 0, data_len + 1);
memcpy((void*) data, (void*) n2_sm.c_str(), data_len); memcpy((void*) data, (void*) n2_sm.c_str(), data_len);
item.pduSessionResourceSetupRequestTransfer.buf = data; item.pduSessionResourceSetupRequestTransfer.buf = data;
......
...@@ -93,6 +93,7 @@ class nas_context { ...@@ -93,6 +93,7 @@ class nas_context {
std::vector<nas::SNSSAI_t> std::vector<nas::SNSSAI_t>
requestedNssai; // TODO: update with naming convention requestedNssai; // TODO: update with naming convention
std::vector<nas::SNSSAI_t> allowed_nssai; // in Registration Accept std::vector<nas::SNSSAI_t> allowed_nssai; // in Registration Accept
// Set to true if marked as default
std::vector<std::pair<bool, nas::SNSSAI_t>> subscribed_snssai; std::vector<std::pair<bool, nas::SNSSAI_t>> subscribed_snssai;
std::vector<nas::SNSSAI_t> configured_nssai; std::vector<nas::SNSSAI_t> configured_nssai;
// std::vector<nas::SNSSAI_t> default_configured_nssai; // std::vector<nas::SNSSAI_t> default_configured_nssai;
......
...@@ -53,6 +53,7 @@ typedef struct SNSSAI_s { ...@@ -53,6 +53,7 @@ typedef struct SNSSAI_s {
return *this; return *this;
} }
} SNSSAI_t; } SNSSAI_t;
typedef struct { typedef struct {
uint8_t ie_type; uint8_t ie_type;
uint8_t ie_len; uint8_t ie_len;
......
...@@ -85,6 +85,10 @@ void S_NSSAI::setSst(const std::string charSst) { ...@@ -85,6 +85,10 @@ void S_NSSAI::setSst(const std::string charSst) {
sst = fromString<int>(charSst); sst = fromString<int>(charSst);
} }
//------------------------------------------------------------------------------
void S_NSSAI::setSst(const uint8_t s) {
sst = s;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void S_NSSAI::getSst(std::string& charSst) const { void S_NSSAI::getSst(std::string& charSst) const {
charSst = to_string((int) sst); charSst = to_string((int) sst);
...@@ -101,6 +105,11 @@ void S_NSSAI::setSd(const std::string charSd) { ...@@ -101,6 +105,11 @@ void S_NSSAI::setSd(const std::string charSd) {
sd = fromString<int>(charSd); sd = fromString<int>(charSd);
} }
//------------------------------------------------------------------------------
void S_NSSAI::setSd(const uint32_t s) {
sdIsSet = true;
sd = s;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool S_NSSAI::getSd(std::string& s_nssaiSd) const { bool S_NSSAI::getSd(std::string& s_nssaiSd) const {
if (sdIsSet) { if (sdIsSet) {
......
...@@ -48,9 +48,11 @@ class S_NSSAI { ...@@ -48,9 +48,11 @@ class S_NSSAI {
bool sDEncode2OctetString(Ngap_SD_t*); bool sDEncode2OctetString(Ngap_SD_t*);
bool sDdecodefromOctetString(Ngap_SD_t*); bool sDdecodefromOctetString(Ngap_SD_t*);
void setSst(const std::string charSst); void setSst(const std::string charSst);
void setSst(const uint8_t s);
void getSst(std::string& charSst) const; void getSst(std::string& charSst) const;
std::string getSst() const; std::string getSst() const;
void setSd(const std::string charSd); void setSd(const std::string charSd);
void setSd(const uint32_t s);
bool getSd(std::string& s_nssaiSd) const; bool getSd(std::string& s_nssaiSd) const;
std::string getSd() const; std::string getSd() const;
bool encode2S_NSSAI(Ngap_S_NSSAI_t*); bool encode2S_NSSAI(Ngap_S_NSSAI_t*);
......
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