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