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

remove hardcoded values for PLMN and NSSAI

parent 47faa845
......@@ -215,7 +215,7 @@ void amf_app::handle_itti_message(itti_nas_signalling_establishment_request &itt
std::shared_ptr<ue_context> uc;
//check ue context with 5g-s-tmsi
if (amf_ue_ngap_id = itti_msg.amf_ue_ngap_id == -1) {
if ((amf_ue_ngap_id = itti_msg.amf_ue_ngap_id) == -1) {
amf_ue_ngap_id = generate_amf_ue_ngap_id();
}
string ue_context_key = "app_ue_ranid_" + to_string(itti_msg.ran_ue_ngap_id) + ":amfid_" + to_string(amf_ue_ngap_id);
......
This diff is collapsed.
......@@ -37,6 +37,7 @@
#include "bstrlib.h"
#include "3gpp_ts24501.hpp"
#include "amf_statistics.hpp"
#include "amf.hpp"
#include <pthread.h>
#include <stdlib.h>
......@@ -73,6 +74,7 @@ class amf_n1 {
public: // nas message decode
void nas_signalling_establishment_request_handle(SecurityHeaderType type, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg, std::string snn, uint8_t ulCount);
void uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
void uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg, plmn_t plmn);
bool check_security_header_type(SecurityHeaderType &type, uint8_t *buffer);
public:
......@@ -101,6 +103,7 @@ class amf_n1 {
void security_mode_complete_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg);
void security_mode_reject_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg);
void ul_nas_transport_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
void ul_nas_transport_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas, plmn_t plmn);
void sha256(unsigned char *message, int msg_len, unsigned char *output);
void service_request_handle(bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
private: //authentication vector
......
......@@ -151,7 +151,7 @@ void amf_n11::handle_itti_message(itti_nsmf_pdusession_update_sm_context &itti_m
return;
}
std::string smf_addr;
if (!psc.get()->smf_avaliable) {
if (!psc.get()->smf_available) {
if (!smf_selection_from_configuration(smf_addr)) {
Logger::amf_n11().error("No candidate SMF is available");
return;
......@@ -190,6 +190,11 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
psc.get()->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id;
psc.get()->req_type = smf.req_type;
psc.get()->pdu_session_id = smf.pdu_sess_id;
psc.get()->snssai.sST = smf.snssai.sST;
psc.get()->snssai.sD = smf.snssai.sD;
psc.get()->plmn.mcc = smf.plmn.mcc;
psc.get()->plmn.mnc = smf.plmn.mnc;
//parse binary dnn and store
std::string dnn = "default";
if ((smf.dnn != nullptr) && (blength(smf.dnn) > 0)) {
......@@ -203,7 +208,7 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
psc.get()->dnn = dnn;
std::string smf_addr;
if (!psc.get()->smf_avaliable) {
if (!psc.get()->smf_available) {
if (!smf_selection_from_configuration(smf_addr)) {
Logger::amf_n11().error("No candidate for SMF is available");
return;
......@@ -229,20 +234,20 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
//------------------------------------------------------------------------------
void amf_n11::handle_pdu_session_initial_request(std::string supi, std::shared_ptr<pdu_session_context> psc, std::string smf_addr, bstring sm_msg, std::string dnn) {
//TODO: Remove hardcoded values
std::string remote_uri = smf_addr + "/nsmf-pdusession/v1/sm-contexts";
std::string remote_uri = smf_addr + "/nsmf-pdusession/v1/sm-contexts"; //TODO
nlohmann::json pdu_session_establishment_request;
pdu_session_establishment_request["supi"] = supi.c_str();
pdu_session_establishment_request["pei"] = "imei-200000000000001";
pdu_session_establishment_request["gpsi"] = "msisdn-200000000001";
pdu_session_establishment_request["dnn"] = dnn.c_str();
pdu_session_establishment_request["sNssai"]["sst"] = 222;
pdu_session_establishment_request["sNssai"]["sd"] = "123";
pdu_session_establishment_request["sNssai"]["sst"] = psc.get()->snssai.sST;
pdu_session_establishment_request["sNssai"]["sd"] = psc.get()->snssai.sD;
pdu_session_establishment_request["pduSessionId"] = psc.get()->pdu_session_id;
pdu_session_establishment_request["requestType"] = "INITIAL_REQUEST";
pdu_session_establishment_request["requestType"] = "INITIAL_REQUEST"; //TODO: from SM_MSG
pdu_session_establishment_request["servingNfId"] = "servingNfId";
pdu_session_establishment_request["servingNetwork"]["mcc"] = "208";
pdu_session_establishment_request["servingNetwork"]["mnc"] = "95";
pdu_session_establishment_request["anType"] = "3GPP_ACCESS";
pdu_session_establishment_request["servingNetwork"]["mcc"] = psc.get()->plmn.mcc;
pdu_session_establishment_request["servingNetwork"]["mnc"] = psc.get()->plmn.mnc;
pdu_session_establishment_request["anType"] = "3GPP_ACCESS"; //TODO
pdu_session_establishment_request["smContextStatusUri"] = "smContextStatusUri";
pdu_session_establishment_request["n1MessageContainer"]["n1MessageClass"] = "SM";
......
......@@ -198,13 +198,16 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
if (!itti_msg.ngSetupReq->getSupportedTAList(s_ta_list)) { //getSupportedTAList
return;
}
//TODO: should be removed, since we stored list of common PLMNs
gnbItem.mcc = s_ta_list[0].b_plmn_list[0].mcc;
gnbItem.mnc = s_ta_list[0].b_plmn_list[0].mnc;
gnbItem.tac = s_ta_list[0].tac;
//association GlobalRANNodeID with assoc_id
//store RAN Node Name in gNB context, if present
//verify PLMN Identity and TAC with configuration and store supportedTAList in gNB context, if verified; else response NG SETUP FAILURE with cause "Unknown PLMN"(9.3.1.2, ts38413)
if (!verifyPlmn(s_ta_list)) {
std::vector <SupportedItem_t> common_plmn_list = get_common_plmn(s_ta_list);
if (common_plmn_list.size() == 0) {
// if (!verifyPlmn(s_ta_list)) {
//encode NG SETUP FAILURE MESSAGE and send back
void *buffer = calloc(1, 1000);
NGSetupFailureMsg ngSetupFailure;
......@@ -216,8 +219,13 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
Logger::amf_n2().error("No common PLMN, encoding NG_SETUP_FAILURE with cause (Unknown PLMN)");
return;
} else {
gc->s_ta_list = s_ta_list;
//store only the common PLMN
gc->s_ta_list = common_plmn_list;
for (auto i: common_plmn_list) {
gnbItem.plmn_list.push_back(i);
}
}
//store Paging DRX in gNB context
Logger::amf_n2().debug("Encoding NG_SETUP_RESPONSE ...");
//encode NG SETUP RESPONSE message with information stored in configuration file and send_msg
......@@ -269,11 +277,12 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
//create ngap-ue context and store in gNB context to store UE information in gNB, for example, here RAN UE NGAP ID and location information and RRC Establishment Cause
//send NAS-PDU to NAS layer
/*get INITIAL_UE_MESSAGE IEs*/
//check the gNB context on which this UE is attached with assoc_id
itti_nas_signalling_establishment_request *itti_msg = new itti_nas_signalling_establishment_request(TASK_AMF_N2, TASK_AMF_APP);
if (!is_assoc_id_2_gnb_context(init_ue_msg.assoc_id)) {
Logger::amf_n2().error("No existed gNG context with assoc_id(%d)", init_ue_msg.assoc_id);
Logger::amf_n2().error("No existing gNG context with assoc_id (%d)", init_ue_msg.assoc_id);
return;
}
std::shared_ptr<gnb_context> gc;
......@@ -281,17 +290,18 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
if (gc.get()->ng_state == NGAP_RESETING || gc.get()->ng_state == NGAP_SHUTDOWN) {
Logger::amf_n2().warn("Received new association request on an association that is being %s, ignoring", ng_gnb_state_str[gc.get()->ng_state]);
} else if (gc.get()->ng_state != NGAP_READY) {
Logger::amf_n2().debug("gNB with assoc_id(%d) is illegal", init_ue_msg.assoc_id);
Logger::amf_n2().debug("gNB with assoc_id (%d) is illegal", init_ue_msg.assoc_id);
return;
}
//UE NGAP Context
uint32_t ran_ue_ngap_id;
if ((ran_ue_ngap_id = init_ue_msg.initUeMsg->getRanUENgapID()) == -1) {
Logger::amf_n2().error("Missing Mandatory IE (RanUeNgapId)");
return;
}
std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ne_ngap_context(ran_ue_ngap_id)) {
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().debug("Create a new UE NGAP context with ran_ue_ngap_id 0x%x", ran_ue_ngap_id);
unc = std::shared_ptr < ue_ngap_context > (new ue_ngap_context());
set_ran_ue_ngap_id_2_ue_ngap_context(ran_ue_ngap_id, unc);
......@@ -335,11 +345,11 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
std::string _5g_s_tmsi;
if (!init_ue_msg.initUeMsg->get5GS_TMSI(_5g_s_tmsi)) {
itti_msg->is_5g_s_tmsi_present = false;
Logger::amf_n2().debug("5g_s_tmsi false");
Logger::amf_n2().debug("5g_s_tmsi not present");
} else {
itti_msg->is_5g_s_tmsi_present = true;
itti_msg->_5g_s_tmsi = _5g_s_tmsi;
Logger::amf_n2().debug("5g_s_tmsi true");
Logger::amf_n2().debug("5g_s_tmsi present");
}
uint8_t *nas_buf;
......@@ -373,11 +383,11 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
}
gc = assoc_id_2_gnb_context(ul_nas_transport.assoc_id);
std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ne_ngap_context(ran_ue_ngap_id)) {
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().error("UE with ran_ue_ngap_id(0x%x) is not attached to gnb with assoc_id(%d)", ran_ue_ngap_id, ul_nas_transport.assoc_id);
return;
}
if (!is_ran_ue_id_2_ne_ngap_context(ran_ue_ngap_id)) {
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().error("No UE NGAP context with ran_ue_ngap_id(%d)", ran_ue_ngap_id);
return;
}
......@@ -402,6 +412,16 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
Logger::amf_n2().error("Missing IE NAS-PDU");
return;
}
//UserLocation
NrCgi_t cgi = {};
Tai_t tai = {};
if (ul_nas_transport.ulNas->getUserLocationInfoNR(cgi, tai)) {
itti_msg->mcc = cgi.mcc;
itti_msg->mnc = cgi.mnc;
} else {
Logger::amf_n2().debug("Missing IE UserLocationInformationNR");
}
std::shared_ptr<itti_uplink_nas_data_ind> i = std::shared_ptr < itti_uplink_nas_data_ind > (itti_msg);
int ret = itti_inst->send_msg(i);
if (0 != ret) {
......@@ -414,13 +434,13 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) {
std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(dl_nas_transport.ran_ue_ngap_id);
if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id(0x%x)", dl_nas_transport.ran_ue_ngap_id);
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", dl_nas_transport.ran_ue_ngap_id);
return;
}
std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id(0x%x)", unc.get()->gnb_assoc_id);
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return;
}
unc.get()->amf_ue_ngap_id = dl_nas_transport.amf_ue_ngap_id;
......@@ -577,7 +597,7 @@ void amf_n2::handle_itti_message(itti_ue_radio_capability_indication &itti_msg)
//Context management functions
//------------------------------------------------------------------------------
bool amf_n2::is_ran_ue_id_2_ne_ngap_context(const uint32_t &ran_ue_ngap_id) const {
bool amf_n2::is_ran_ue_id_2_ue_ngap_context(const uint32_t &ran_ue_ngap_id) const {
std::shared_lock lock(m_ranid2uecontext);
return bool { ranid2uecontext.count(ran_ue_ngap_id) > 0 };
}
......@@ -612,3 +632,24 @@ bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) {
}
return false;
}
//------------------------------------------------------------------------------
std::vector<SupportedItem_t> amf_n2::get_common_plmn(std::vector<SupportedItem_t> list) {
std::vector <SupportedItem_t> plmn_list = {};
for (int i = 0; i < amf_cfg.plmn_list.size(); i++) {
for (int j = 0; j < list.size(); j++) {
Logger::amf_n2().debug("TAC configured %d, TAC received %d", amf_cfg.plmn_list[i].tac, list[j].tac);
if (amf_cfg.plmn_list[i].tac != list[j].tac) {
continue;
}
for (int k = 0; k < list[j].b_plmn_list.size(); k++) {
if (!(list[j].b_plmn_list[k].mcc.compare(amf_cfg.plmn_list[i].mcc)) && !(list[j].b_plmn_list[k].mnc.compare(amf_cfg.plmn_list[i].mnc))) {
plmn_list.push_back(list[j]);
}
}
}
}
return plmn_list;
}
......@@ -32,6 +32,7 @@
#include "ngap_app.hpp"
#include "itti_msg_n2.hpp"
#include "ue_ngap_context.hpp"
#include "amf.hpp"
namespace amf_application{
......@@ -50,11 +51,12 @@ class amf_n2 : public ngap::ngap_app{
void handle_itti_message(itti_ue_context_release_request &itti_msg);
void handle_itti_message(itti_ue_radio_capability_indication &itti_msg);
bool verifyPlmn(std::vector<SupportedItem_t> list);
std::vector<SupportedItem_t> get_common_plmn(std::vector<SupportedItem_t> list);
private:
std::map<uint32_t, std::shared_ptr<ue_ngap_context>> ranid2uecontext;// ran ue ngap id
mutable std::shared_mutex m_ranid2uecontext;
bool is_ran_ue_id_2_ne_ngap_context(const uint32_t & ran_ue_ngap_id) const;
bool is_ran_ue_id_2_ue_ngap_context(const uint32_t & ran_ue_ngap_id) const;
std::shared_ptr<ue_ngap_context> ran_ue_id_2_ue_ngap_context(const uint32_t & ran_ue_ngap_id) const;
void set_ran_ue_ngap_id_2_ue_ngap_context(const uint32_t & ran_ue_ngap_id, std::shared_ptr<ue_ngap_context> unc);
};
......
......@@ -42,6 +42,7 @@ void statistics::display() {
Logger::amf_app().info("|----------------------------------------------------gNBs' information--------------------------------------------|");
Logger::amf_app().info("| Index | Status | Global ID | gNB Name | Tracking Area (PLMN, TAC)| ");
//TODO: Show the list of common PLMNs
for (int i = 0; i < gnbs.size(); i++) {
Logger::amf_app().info("| %d | Connected | 0x%x | %s | %s, %d | ", i + 1, gnbs[i].gnb_id, gnbs[i].gnb_name.c_str(), (gnbs[i].mcc + gnbs[i].mnc).c_str(), gnbs[i].tac);
//Logger::amf_app().info("[index %d][connected][GlobalID: 0x%x][gnb name: %s][Tracking Area: plmn(%s), tac(%d)]", i + 1, gnbs[i].gnb_id, gnbs[i].gnb_name.c_str(), (gnbs[i].mcc + gnbs[i].mnc).c_str(), gnbs[i].tac);
......
......@@ -34,10 +34,13 @@
#include <stdint.h>
#include <vector>
#include <string>
#include "amf.hpp"
#include "ngap_app.hpp"
typedef struct {
uint32_t gnb_id;
//TODO: list of PLMNs
std::vector<SupportedItem_t> plmn_list;
std::string mcc;
std::string mnc;
std::string gnb_name;
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file amf.hpp
\brief
\date 2020
\email: contact@openairinterface.org
*/
#ifndef __AMF_HPP
#define __AMF_HPP
typedef struct {
std::string mcc;
std::string mnc;
uint32_t tac;
} plmn_t;
typedef struct s_nssai // section 28.4, TS23.003
{
uint8_t sST;
//uint32_t sD:24;
std::string sD;
s_nssai(const uint8_t &sst, const std::string sd)
:
sST(sst),
sD(sd) {
}
s_nssai()
:
sST(),
sD() {
}
s_nssai(const s_nssai &p)
:
sST(p.sST),
sD(p.sD) {
}
bool operator==(const struct s_nssai &s) const {
if ((s.sST == this->sST) && (s.sD.compare(this->sD) == 0)) {
return true;
} else {
return false;
}
}
} snssai_t;
#endif
......@@ -30,7 +30,7 @@
//------------------------------------------------------------------------------
pdu_session_context::pdu_session_context() {
smf_avaliable = false;
smf_available = false;
}
//------------------------------------------------------------------------------
......
......@@ -31,6 +31,7 @@
#include <string>
#include "bstrlib.h"
#include "amf.hpp"
class pdu_session_context {
public:
......@@ -44,6 +45,8 @@ class pdu_session_context {
bstring n2sm;
std::string dnn;
std::string remote_smf_addr[0]; //"192.168.12.10:8080"
bool smf_avaliable;
bool smf_available;
snssai_t snssai;
plmn_t plmn;
};
#endif
......@@ -4,6 +4,7 @@
#include "bstrlib.h"
#include "itti_msg.hpp"
#include <string>
#include "amf.hpp"
class itti_msg_n11 : public itti_msg{
public:
......@@ -30,10 +31,10 @@ public:
uint8_t pdu_sess_id;
bstring dnn;
bstring sm_msg;
snssai_t snssai;
plmn_t plmn;
};
class itti_pdu_session_resource_setup_response : public itti_msg_n11{
public:
itti_pdu_session_resource_setup_response(const task_id_t origin, const task_id_t destination) : itti_msg_n11(PDU_SESS_RES_SET_RESP, origin, destination){}
......@@ -52,14 +53,4 @@ public:
bstring n2sm;
};
#endif
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