mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
7.2 KiB
C
187 lines
7.2 KiB
C
4 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
|
*
|
||
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
|
*
|
||
|
*/
|
||
|
#ifndef SRSENB_NGAP_H
|
||
|
#define SRSENB_NGAP_H
|
||
|
|
||
4 years ago
|
#include "ngap_metrics.h"
|
||
4 years ago
|
#include "srsenb/hdr/common/common_enb.h"
|
||
|
#include "srsran/adt/circular_map.h"
|
||
4 years ago
|
#include "srsran/adt/optional.h"
|
||
4 years ago
|
#include "srsran/asn1/asn1_utils.h"
|
||
|
#include "srsran/asn1/ngap.h"
|
||
|
#include "srsran/common/bcd_helpers.h"
|
||
|
#include "srsran/common/buffer_pool.h"
|
||
|
#include "srsran/common/common.h"
|
||
|
#include "srsran/common/network_utils.h"
|
||
|
#include "srsran/common/stack_procedure.h"
|
||
|
#include "srsran/common/standard_streams.h"
|
||
|
#include "srsran/common/task_scheduler.h"
|
||
|
#include "srsran/common/threads.h"
|
||
3 years ago
|
#include "srsran/interfaces/enb_gtpu_interfaces.h"
|
||
4 years ago
|
#include "srsran/interfaces/gnb_ngap_interfaces.h"
|
||
|
#include "srsran/interfaces/gnb_rrc_nr_interfaces.h"
|
||
|
#include "srsran/srslog/srslog.h"
|
||
4 years ago
|
#include <iostream>
|
||
|
#include <unordered_map>
|
||
4 years ago
|
|
||
|
namespace srsenb {
|
||
4 years ago
|
|
||
3 years ago
|
class ngap final : public ngap_interface_rrc_nr
|
||
4 years ago
|
{
|
||
|
public:
|
||
4 years ago
|
class ue;
|
||
4 years ago
|
ngap(srsran::task_sched_handle task_sched_,
|
||
|
srslog::basic_logger& logger,
|
||
|
srsran::socket_manager_itf* rx_socket_handler);
|
||
4 years ago
|
~ngap();
|
||
3 years ago
|
int init(const ngap_args_t& args_, rrc_interface_ngap_nr* rrc_, gtpu_interface_rrc* gtpu_);
|
||
4 years ago
|
void stop();
|
||
|
|
||
|
// RRC NR interface
|
||
|
void initial_ue(uint16_t rnti,
|
||
|
uint32_t gnb_cc_idx,
|
||
|
asn1::ngap_nr::rrcestablishment_cause_e cause,
|
||
4 years ago
|
srsran::unique_byte_buffer_t pdu);
|
||
4 years ago
|
void initial_ue(uint16_t rnti,
|
||
|
uint32_t gnb_cc_idx,
|
||
|
asn1::ngap_nr::rrcestablishment_cause_e cause,
|
||
|
srsran::unique_byte_buffer_t pdu,
|
||
4 years ago
|
uint32_t s_tmsi);
|
||
|
|
||
4 years ago
|
void write_pdu(uint16_t rnti, srsran::unique_byte_buffer_t pdu);
|
||
4 years ago
|
bool user_exists(uint16_t rnti) { return true; };
|
||
|
void user_mod(uint16_t old_rnti, uint16_t new_rnti){};
|
||
|
bool user_release(uint16_t rnti, asn1::ngap_nr::cause_radio_network_e cause_radio) { return true; };
|
||
|
bool is_amf_connected();
|
||
4 years ago
|
bool send_error_indication(const asn1::ngap_nr::cause_c& cause,
|
||
|
srsran::optional<uint32_t> ran_ue_ngap_id = {},
|
||
|
srsran::optional<uint32_t> amf_ue_ngap_id = {});
|
||
4 years ago
|
void ue_notify_rrc_reconf_complete(uint16_t rnti, bool outcome);
|
||
|
bool send_pdu_session_resource_setup_response();
|
||
4 years ago
|
|
||
|
// Stack interface
|
||
|
bool
|
||
3 years ago
|
handle_amf_rx_msg(srsran::unique_byte_buffer_t pdu, const sockaddr_in& from, const sctp_sndrcvinfo& sri, int flags);
|
||
4 years ago
|
void get_metrics(ngap_metrics_t& m);
|
||
4 years ago
|
void get_args(ngap_args_t& args_);
|
||
4 years ago
|
|
||
|
private:
|
||
|
static const int AMF_PORT = 38412;
|
||
|
static const int ADDR_FAMILY = AF_INET;
|
||
|
static const int SOCK_TYPE = SOCK_STREAM;
|
||
|
static const int PROTO = IPPROTO_SCTP;
|
||
|
static const int PPID = 60;
|
||
|
static const int NONUE_STREAM_ID = 0;
|
||
|
|
||
|
// args
|
||
4 years ago
|
rrc_interface_ngap_nr* rrc = nullptr;
|
||
3 years ago
|
gtpu_interface_rrc* gtpu = nullptr;
|
||
4 years ago
|
ngap_args_t args = {};
|
||
4 years ago
|
srslog::basic_logger& logger;
|
||
|
srsran::task_sched_handle task_sched;
|
||
|
srsran::task_queue_handle amf_task_queue;
|
||
|
srsran::socket_manager_itf* rx_socket_handler;
|
||
|
|
||
|
srsran::unique_socket amf_socket;
|
||
|
struct sockaddr_in amf_addr = {}; // AMF address
|
||
|
bool amf_connected = false;
|
||
|
bool running = false;
|
||
4 years ago
|
uint32_t next_gnb_ue_ngap_id = 1; // Next GNB-side UE identifier
|
||
4 years ago
|
uint16_t next_ue_stream_id = 1; // Next UE SCTP stream identifier
|
||
|
srsran::unique_timer amf_connect_timer, ngsetup_timeout;
|
||
|
|
||
|
// Protocol IEs sent with every UL NGAP message
|
||
|
asn1::ngap_nr::tai_s tai;
|
||
|
asn1::ngap_nr::nr_cgi_s nr_cgi;
|
||
|
|
||
|
asn1::ngap_nr::ng_setup_resp_s ngsetupresponse;
|
||
|
|
||
4 years ago
|
int build_tai_cgi();
|
||
|
bool connect_amf();
|
||
|
bool setup_ng();
|
||
|
bool sctp_send_ngap_pdu(const asn1::ngap_nr::ngap_pdu_c& tx_pdu, uint32_t rnti, const char* procedure_name);
|
||
|
|
||
|
bool handle_ngap_rx_pdu(srsran::byte_buffer_t* pdu);
|
||
4 years ago
|
bool handle_successful_outcome(const asn1::ngap_nr::successful_outcome_s& msg);
|
||
|
bool handle_unsuccessful_outcome(const asn1::ngap_nr::unsuccessful_outcome_s& msg);
|
||
|
bool handle_initiating_message(const asn1::ngap_nr::init_msg_s& msg);
|
||
|
|
||
|
// TS 38.413 - Section 8.6.2 - Downlink NAS Transport
|
||
|
bool handle_dl_nas_transport(const asn1::ngap_nr::dl_nas_transport_s& msg);
|
||
|
// TS 38.413 - Section 9.2.6.2 - NG Setup Response
|
||
|
bool handle_ng_setup_response(const asn1::ngap_nr::ng_setup_resp_s& msg);
|
||
|
// TS 38.413 - Section 9.2.6.3 - NG Setup Failure
|
||
|
bool handle_ng_setup_failure(const asn1::ngap_nr::ng_setup_fail_s& msg);
|
||
|
// TS 38.413 - Section 9.2.2.5 - UE Context Release Command
|
||
|
bool handle_ue_ctxt_release_cmd(const asn1::ngap_nr::ue_context_release_cmd_s& msg);
|
||
|
// TS 38.413 - Section 9.2.2.1 - Initial Context Setup Request
|
||
|
bool handle_initial_ctxt_setup_request(const asn1::ngap_nr::init_context_setup_request_s& msg);
|
||
|
// TS 38.413 - Section 9.2.1.1 - PDU Session Resource Setup Request
|
||
3 years ago
|
bool handle_ue_pdu_session_res_setup_request(const asn1::ngap_nr::pdu_session_res_setup_request_s& msg);
|
||
4 years ago
|
|
||
|
class user_list
|
||
|
{
|
||
|
public:
|
||
|
using value_type = std::unique_ptr<ue>;
|
||
|
using iterator = std::unordered_map<uint32_t, value_type>::iterator;
|
||
|
using const_iterator = std::unordered_map<uint32_t, value_type>::const_iterator;
|
||
|
using pair_type = std::unordered_map<uint32_t, value_type>::value_type;
|
||
|
|
||
|
ue* find_ue_rnti(uint16_t rnti);
|
||
|
ue* find_ue_gnbid(uint32_t gnbid);
|
||
|
ue* find_ue_amfid(uint32_t amfid);
|
||
|
ue* add_user(value_type user);
|
||
|
void erase(ue* ue_ptr);
|
||
|
iterator begin() { return users.begin(); }
|
||
|
iterator end() { return users.end(); }
|
||
|
const_iterator cbegin() const { return users.begin(); }
|
||
|
const_iterator cend() const { return users.end(); }
|
||
|
size_t size() const { return users.size(); }
|
||
|
|
||
|
private:
|
||
|
std::unordered_map<uint32_t, std::unique_ptr<ue> > users; // maps ran_ue_ngap_id to user
|
||
|
};
|
||
|
user_list users;
|
||
|
|
||
4 years ago
|
// procedures
|
||
|
class ng_setup_proc_t
|
||
|
{
|
||
|
public:
|
||
|
struct ngsetupresult {
|
||
|
bool success = false;
|
||
|
enum class cause_t { timeout, failure } cause;
|
||
|
};
|
||
|
|
||
|
explicit ng_setup_proc_t(ngap* ngap_) : ngap_ptr(ngap_) {}
|
||
|
srsran::proc_outcome_t init();
|
||
|
srsran::proc_outcome_t step() { return srsran::proc_outcome_t::yield; }
|
||
|
srsran::proc_outcome_t react(const ngsetupresult& event);
|
||
|
void then(const srsran::proc_state_t& result) const;
|
||
|
const char* name() const { return "AMF Connection"; }
|
||
|
|
||
|
private:
|
||
|
srsran::proc_outcome_t start_amf_connection();
|
||
|
|
||
|
ngap* ngap_ptr = nullptr;
|
||
|
};
|
||
|
|
||
4 years ago
|
ue* handle_ngapmsg_ue_id(uint32_t gnb_id, uint32_t amf_id);
|
||
4 years ago
|
|
||
|
srsran::proc_t<ng_setup_proc_t> ngsetup_proc;
|
||
|
|
||
|
std::string get_cause(const asn1::ngap_nr::cause_c& c);
|
||
|
void log_ngap_msg(const asn1::ngap_nr::ngap_pdu_c& msg, srsran::const_span<uint8_t> sdu, bool is_rx);
|
||
|
};
|
||
|
|
||
|
} // namespace srsenb
|
||
|
#endif
|