Commit 505ffdb9 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update AMF to deal with SD with No Value

parent 306af566
......@@ -41,6 +41,7 @@
#include "string.hpp"
#include "thread_sched.hpp"
#include "fqdn.hpp"
#include "conversions.hpp"
extern "C" {
#include <arpa/inet.h>
......@@ -226,16 +227,15 @@ int amf_config::load(const std::string& config_file) {
std::string sd = {};
slice_item.lookupValue(AMF_CONFIG_STRING_SST, sst);
slice_item.lookupValue(AMF_CONFIG_STRING_SD, sd);
slice.sd = SD_NO_VALUE; // Default value
try {
slice.sst = std::stoi(sst);
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);
}
// Get SD if available
if (!sd.empty()) slice.sd = std::stoi(sd);
} catch (const std::exception& err) {
Logger::amf_app().error("Invalid SST/SD");
}
conv::sd_string_to_int(sd, slice.sd);
plmn_item.slice_list.push_back(slice);
}
plmn_list.push_back(plmn_item);
......@@ -713,24 +713,15 @@ void amf_config::display() {
Logger::config().info(" TAC ...................: %d", plmn_list[i].tac);
Logger::config().info(" Slice Support .........:");
for (int j = 0; j < plmn_list[i].slice_list.size(); j++) {
std::string str = {};
str = str.append(" SST")
.append(
(plmn_list[i].slice_list[j].sst >
SST_MAX_STANDARDIZED_VALUE &&
(plmn_list[i].slice_list[j].sd != SD_NO_VALUE)) ?
", SD " :
" ....")
.append("...........: ")
.append(std::to_string(plmn_list[i].slice_list[j].sst))
.append("")
.append(
(plmn_list[i].slice_list[j].sst >
SST_MAX_STANDARDIZED_VALUE &&
(plmn_list[i].slice_list[j].sd != SD_NO_VALUE)) ?
", " + std::to_string(plmn_list[i].slice_list[j].sd) :
" ");
Logger::config().info(str.c_str());
if (plmn_list[i].slice_list[j].sd != SD_NO_VALUE) {
Logger::config().info(
" SST, SD ...........: %d, %ld (0x%x)",
plmn_list[i].slice_list[j].sst, plmn_list[i].slice_list[j].sd,
plmn_list[i].slice_list[j].sd);
} else {
Logger::config().info(
" SST ...............: %d", plmn_list[i].slice_list[j].sst);
}
}
}
Logger::config().info(
......
......@@ -3766,10 +3766,11 @@ void amf_n1::initialize_registration_accept(
for (auto s : p.slice_list) {
SNSSAI_t snssai = {};
snssai.sst = s.sst;
snssai.sd = SD_NO_VALUE; // Default value
// Get SD if available for non standardized SST
if (s.sst > SST_MAX_STANDARDIZED_VALUE) {
snssai.sd = s.sd;
snssai.sd = s.sd;
if (snssai.sd == SD_NO_VALUE) {
snssai.length = SST_LENGTH;
} else {
snssai.length = SST_LENGTH + SD_LENGTH;
}
nssai.push_back(snssai);
}
......
......@@ -26,12 +26,15 @@
*/
#include "conversions.hpp"
#include "logger.hpp"
#include <arpa/inet.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <boost/algorithm/string.hpp>
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
......@@ -262,3 +265,23 @@ void conv::octet_string_2_bstring(
void conv::bstring_2_octet_string(bstring& b_str, OCTET_STRING_t& octet_str) {
OCTET_STRING_fromBuf(&octet_str, (char*) bdata(b_str), blength(b_str));
}
//------------------------------------------------------------------------------
void conv::sd_string_to_int(const std::string& sd_str, uint32_t& sd) {
sd = 0xFFFFFF;
if (sd_str.empty()) return;
uint8_t base = 10;
try {
if (sd_str.size() > 2) {
if (boost::iequals(sd_str.substr(0, 2), "0x")) {
base = 16;
}
}
sd = std::stoul(sd_str, nullptr, base);
} catch (const std::exception& e) {
Logger::amf_app().error(
"Error when converting from string to int for S-NSSAI SD, error: %s",
e.what());
sd = 0xFFFFFF;
}
}
......@@ -73,5 +73,6 @@ class conv {
std::string& input_str, std::string& output_str);
void octet_string_2_bstring(const OCTET_STRING_t& octet_str, bstring& b_str);
void bstring_2_octet_string(bstring& b_str, OCTET_STRING_t& octet_str);
static void sd_string_to_int(const std::string& sd_str, uint32_t& sd);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
......@@ -49,9 +49,9 @@ NSSAI::NSSAI(const uint8_t iei, std::vector<struct SNSSAI_s> nssai) {
S_NSSAI.assign(nssai.begin(), nssai.end());
for (int i = 0; i < nssai.size(); i++) {
length += 2; // 1 for IEI and 1 for sst
if (nssai[i].sd != SD_NO_VALUE) length += 3;
if (nssai[i].mHplmnSst != -1) length += 1;
if (nssai[i].mHplmnSd != SD_NO_VALUE) length += 3;
if (nssai[i].sd != SD_NO_VALUE) length += SD_LENGTH;
if (nssai[i].mHplmnSst != -1) length += SST_LENGTH;
if (nssai[i].mHplmnSd != SD_NO_VALUE) length += SD_LENGTH;
}
}
......@@ -84,12 +84,12 @@ int NSSAI::encode2buffer(uint8_t* buf, int len) {
encoded_size++;
for (int i = 0; i < S_NSSAI.size(); i++) {
int len_s_nssai = 1;
int len_s_nssai = SST_LENGTH;
encoded_size++;
*(buf + encoded_size) = S_NSSAI.at(i).sst;
encoded_size++;
if (S_NSSAI.at(i).sd != SD_NO_VALUE) {
len_s_nssai += 3;
len_s_nssai += SD_LENGTH;
*(buf + encoded_size) = (S_NSSAI.at(i).sd & 0x00ff0000) >> 16;
encoded_size++;
Logger::nas_mm().debug(
......@@ -104,12 +104,12 @@ int NSSAI::encode2buffer(uint8_t* buf, int len) {
"Encoded NSSAI SD third octet (%x)", *(buf + encoded_size - 1));
}
if (S_NSSAI.at(i).mHplmnSst != -1) {
len_s_nssai += 1;
len_s_nssai += SST_LENGTH;
*(buf + encoded_size) = S_NSSAI.at(i).mHplmnSst;
encoded_size++;
}
if (S_NSSAI.at(i).mHplmnSd != SD_NO_VALUE) {
len_s_nssai += 3;
len_s_nssai += SD_LENGTH;
*(buf + encoded_size) = (S_NSSAI.at(i).mHplmnSd & 0x00ff0000) >> 16;
encoded_size++;
*(buf + encoded_size) = (S_NSSAI.at(i).mHplmnSd & 0x0000ff00) >> 8;
......@@ -138,10 +138,13 @@ int NSSAI::decodefrombuffer(uint8_t* buf, int len, bool is_option) {
length = *(buf + decoded_size);
decoded_size++;
int length_tmp = length;
a.sd = SD_NO_VALUE; // Default value
a.mHplmnSd = SD_NO_VALUE; // Default value
while (length_tmp) {
switch (*(buf + decoded_size)) {
case 1: {
decoded_size++; // snssai—leagth
decoded_size++; // snssai—length
length_tmp--;
a.sst = *(buf + decoded_size);
decoded_size++;
......@@ -227,7 +230,9 @@ int NSSAI::decodefrombuffer(uint8_t* buf, int len, bool is_option) {
}
S_NSSAI.insert(S_NSSAI.end(), a);
a = {0, 0, 0, 0};
a = {0, 0, 0, 0};
a.sd = SD_NO_VALUE; // Default value
a.mHplmnSd = SD_NO_VALUE; // Default value
}
for (int i = 0; i < S_NSSAI.size(); i++) {
......
......@@ -33,6 +33,9 @@
#include <vector>
#include "nas_ie_header.hpp"
#define SST_LENGTH 1
#define SD_LENGTH 3
namespace nas {
class NSSAI {
......
......@@ -127,6 +127,16 @@ bool S_NSSAI::getSd(std::string& s_nssaiSd) const {
return sdIsSet;
}
//------------------------------------------------------------------------------
bool S_NSSAI::getSd(uint32_t& s_nssaiSd) const {
if (sdIsSet) {
s_nssaiSd = sd;
} else {
s_nssaiSd = SD_NO_VALUE;
}
return sdIsSet;
}
//------------------------------------------------------------------------------
std::string S_NSSAI::getSd() const {
if (sdIsSet) {
......
......@@ -55,6 +55,7 @@ class S_NSSAI {
void setSd(const uint32_t s);
bool getSd(std::string& s_nssaiSd) const;
std::string getSd() const;
bool getSd(uint32_t& s_nssaiSd) const;
bool encode2S_NSSAI(Ngap_S_NSSAI_t*);
bool decodefromS_NSSAI(Ngap_S_NSSAI_t*);
......
......@@ -22,6 +22,7 @@
#include "InitialContextSetupRequest.hpp"
#include "logger.hpp"
#include "amf.hpp"
#include "conversions.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -290,9 +291,11 @@ 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(std::to_string(SD_NO_VALUE)) != 0)))
snssai.setSd(list[i].sd);
uint32_t sd = 0xFFFFFF;
if (!list[i].sd.empty()) {
conv::sd_string_to_int(list[i].sd, sd);
}
snssai.setSd(sd);
snssaiList.push_back(snssai);
}
allowedNssai.setAllowedNSSAI(snssaiList);
......
......@@ -22,6 +22,7 @@
#include "NGSetupResponse.hpp"
#include "logger.hpp"
#include "amf.hpp"
#include "conversions.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -138,11 +139,12 @@ void NGSetupResponseMsg::setPlmnSupportList(
for (int j = 0; j < list[i].slice_list.size(); j++) {
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(std::to_string(SD_NO_VALUE)) !=
0)) {
snssai.setSd(list[i].slice_list[j].sd);
uint32_t sd = 0xFFFFFF;
if (!list[i].slice_list[j].sd.empty()) {
conv::sd_string_to_int(list[i].slice_list[j].sd, sd);
}
snssai.setSd(sd);
snssais.push_back(snssai);
}
plmnSupportItem.setPlmnSliceSupportList(plmn, snssais);
......
......@@ -22,6 +22,7 @@
#include "RerouteNASRequest.hpp"
#include "common_defs.h"
#include "amf.hpp"
#include "conversions.hpp"
#include "logger.hpp"
......@@ -111,9 +112,12 @@ 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(std::to_string(SD_NO_VALUE)) != 0)))
snssai.setSd(list[i].sd);
uint32_t sd = 0xFFFFFF;
if (!list[i].sd.empty()) {
conv::sd_string_to_int(list[i].sd, sd);
}
snssai.setSd(sd);
snssaiList.push_back(snssai);
}
allowedNssai->setAllowedNSSAI(snssaiList);
......
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