Commit 54047050 authored by Niuhaiwen's avatar Niuhaiwen

add itti no fix

parent 991fed8a
...@@ -66,6 +66,12 @@ ...@@ -66,6 +66,12 @@
"xstring": "cpp", "xstring": "cpp",
"xtr1common": "cpp", "xtr1common": "cpp",
"xtree": "cpp", "xtree": "cpp",
"xutility": "cpp" "xutility": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"deque": "cpp",
"queue": "cpp",
"set": "cpp",
"shared_mutex": "cpp"
} }
} }
\ No newline at end of file
#include "ausf_app.hpp"
#include <boost/uuid/random_generator.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include "itti.hpp"
#include "curl.hpp"
#include "logger.hpp"
#include "3gpp_29.510.h"
#include <nlohmann/json.hpp>
using namespace ausf_application;
using namespace config;
extern itti_mw *itti_inst;
extern ausf_config ausf_cfg;
extern ausf_app *ausf_app_inst;
void ausf_app_task(void *);
void ausf_app_task(void*){
const task_id_t task_id = TASK_AUSF_APP;
itti_inst->notify_task_ready(task_id);
do
{
std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id);
auto *msg = shared_msg.get();
timer_id_t tid;
switch (msg->msg_type)
{
case TIME_OUT:
if (itti_msg_timeout *to = dynamic_cast<itti_msg_timeout *>(msg))
{
switch (to->arg1_user)
{
case TASK_AUSF_APP_PERIODIC_GETINFO:
tid = itti_inst->timer_setup(
10, 0, TASK_AUSF_APP,
TASK_AUSF_APP_PERIODIC_GETINFO, 0);
//TODO: periodic_getinfo_handler
break;
case TASK_AUSF_APP_TIMEOUT_NRF_HEARTBEAT:
amf_app_inst->timer_nrf_heartbeat_timeout(
to->timer_id, to->arg2_user);
break;
default:
Logger::ausf_app().info(
"No handler for timer(%d) with arg1_user(%d) ", to->timer_id,
to->arg1_user);
}
}
break;
default:
Logger::ausf_app().info("no handler for msg type %d", msg->msg_type);
}
} while (true);
}
ausf_app::ausf_app()
{
Logger::ausf_app().startup("Creating AUSF application functionality layer");
if(itti_inst->create_task(TASK_AUSF_APP,ausf_app_task,nullptr)){
Logger::ausf_app().error("Cannot create task TASK_AUSF_APP");
throw std::runtime_error("Cannot create task TASK_AUSF_APP");
}
if(ausf_cfg.nf_registion.compare("yes")==0){
unsigned int microsecond = 10000; // 10ms
usleep(microsecond);
register_to_nrf();
}
Logger::ausf_app().startup("Started");
}
void ausf_app::register_to_nrf(){
// Create a NF profile to this instance
generate_smf_profile();
// Send request to N11 to send NF registration to NRF
trigger_nf_registration_request();
}
void ausf_app::generate_ausf_profile(){
generate_uuid();
nf_instance_profile.set_nf_instance_id(amf_instance_id);
nf_instance_profile.set_nf_instance_name("bupt-ausf");
nf_instance_profile.set_nf_type("AUSF");
nf_instance_profile.set_nf_status("REGISTERED");
nf_instance_profile.set_nf_heartBeat_timer(50);
nf_instance_profile.set_nf_priority(1);
nf_instance_profile.set_nf_capacity(100);
nf_instance_profile.add_nf_ipv4_addresses(ausf_cfg.sbi.addr4);
nf_service_t nf_service = {};
nf_service.service_instance_id = "nausf_communication";
nf_service.service_name = "nausf_communication"; //TODO:to be updated
nf_service_version_t version = {};
version.api_version_in_uri = "v1";
version.api_full_version = "1.0.0"; // TODO: to be updated
nf_service.versions.push_back(version);
nf_service.scheme = "http";
nf_service.nf_service_status = "REGISTERED";
ip_endpoint_t endpoint = {};
endpoint.ipv4_address = ausf_cfg.sbi.addr4;
endpoint.transport = "TCP";
endpoint.port = ausf_cfg.sbi.port;
nf_service.ip_endpoints.push_back(endpoint);
nf_instance_profile.add_nf_service(nf_service);
// Display the profile
nf_instance_profile.display();
}
void ausf_app::trigger_nf_registration_request(){
Logger::ausf_app().debug("
Send ITTI msg to N11 task to trigger the registration request to NRF");
std::shared_ptr<itti_sbi_register_nf_instance_request> itti_msg =
std::make_shared<itti_sbi_register_nf_instance_request>(TASK_AUSF_APP,TASK_AUSF_APP);
itti_msg->profile=nf_instance_profile;
register_nf_instance(itti_msg);
}
void ausf_app::timer_nrf_heartbeat_timeout(){
}
void ausf_app::generate_uuid(){
ausf_instance_id = to_string(boost::uuids::random_generator()());
}
void ausf_app::register_nf_instance(std::shared_ptr<itti_sbi_register_nf_instance_request> msg)
{
}
\ No newline at end of file
#ifndef _AUSF_APP_H_
#define _AUSF_APP_H_
#include "ausf_config.hpp"
#include "itti.hpp"
#include "ausf_profile.hpp"
#include "itti_msg_sbi.hpp"
using namespace config;
namespace ausf_application{
#define TASK_AUSF_APP_PERIODIC_GETINFO (0)
#define TASK_AUSF_APP_TIMEOUT_NRF_HEARTBEAT (1)
class ausf_app{
public:
ausf_app();
~ausf_app();
void register_to_nrf();
// Create a NF profile to this instance
void generate_ausf_profile();
// Send request to N11 to send NF registration to NRF
void trigger_nf_registration_request();
void generate_uuid();
void timer_nrf_heartbeat_timeout();
void register_nf_instance(std::shared_ptr<itti_sbi_register_nf_instance_request> msg);
private:
std::string ausf_instance_id;
ausf_profile nf_instance_profile;
timer_id_t timer_nrf_heartbeat;
};
}
#endif
\ No newline at end of file
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include "logger.hpp"
#include "ausf_profile.hpp"
#include "string.hpp"
using namespace std;
using namespace ausf_application;
//------------------------------------------------------------------------------
void nf_profile::set_nf_instance_id(const std::string& instance_id) {
nf_instance_id = instance_id;
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_instance_id(std::string& instance_id) const {
instance_id = nf_instance_id;
}
//------------------------------------------------------------------------------
std::string nf_profile::get_nf_instance_id() const {
return nf_instance_id;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_instance_name(const std::string& instance_name) {
nf_instance_name = instance_name;
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_instance_name(std::string& instance_name) const {
instance_name = nf_instance_name;
}
//------------------------------------------------------------------------------
std::string nf_profile::get_nf_instance_name() const {
return nf_instance_name;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_type(const std::string& type) {
nf_type = type;
}
//------------------------------------------------------------------------------
std::string nf_profile::get_nf_type() const {
return nf_type;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_status(const std::string& status) {
nf_status = status;
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_status(std::string& status) const {
status = nf_status;
}
//------------------------------------------------------------------------------
std::string nf_profile::get_nf_status() const {
return nf_status;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_heartBeat_timer(const int32_t& timer) {
heartBeat_timer = timer;
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_heartBeat_timer(int32_t& timer) const {
timer = heartBeat_timer;
}
//------------------------------------------------------------------------------
int32_t nf_profile::get_nf_heartBeat_timer() const {
return heartBeat_timer;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_priority(const uint16_t& p) {
priority = p;
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_priority(uint16_t& p) const {
p = priority;
}
//------------------------------------------------------------------------------
uint16_t nf_profile::get_nf_priority() const {
return priority;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_capacity(const uint16_t& c) {
capacity = c;
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_capacity(uint16_t& c) const {
c = capacity;
}
//------------------------------------------------------------------------------
uint16_t nf_profile::get_nf_capacity() const {
return capacity;
}
//------------------------------------------------------------------------------
void nf_profile::set_nf_ipv4_addresses(const std::vector<struct in_addr>& a) {
ipv4_addresses = a;
}
//------------------------------------------------------------------------------
void nf_profile::add_nf_ipv4_addresses(const struct in_addr& a) {
ipv4_addresses.push_back(a);
}
//------------------------------------------------------------------------------
void nf_profile::get_nf_ipv4_addresses(std::vector<struct in_addr>& a) const {
a = ipv4_addresses;
}
//------------------------------------------------------------------------------
void nf_profile::display() const {
Logger::ausf_app().debug("NF instance info");
Logger::ausf_app().debug("\tInstance ID: %s", nf_instance_id.c_str());
Logger::ausf_app().debug("\tInstance name: %s", nf_instance_name.c_str());
Logger::ausf_app().debug("\tInstance type: %s", nf_type.c_str());
Logger::ausf_app().debug("\tStatus: %s", nf_status.c_str());
Logger::ausf_app().debug("\tHeartBeat timer: %d", heartBeat_timer);
Logger::ausf_app().debug("\tPriority: %d", priority);
Logger::ausf_app().debug("\tCapacity: %d", capacity);
// IPv4 Addresses
if (ipv4_addresses.size() > 0) {
Logger::ausf_app().debug("\tIPv4 Addr:");
}
for (auto address : ipv4_addresses) {
Logger::ausf_app().debug("\t\t %s", inet_ntoa(address));
}
}
//------------------------------------------------------------------------------
void nf_profile::to_json(nlohmann::json& data) const {
data["nfInstanceId"] = nf_instance_id;
data["nfInstanceName"] = nf_instance_name;
data["nfType"] = nf_type;
data["nfStatus"] = nf_status;
data["heartBeatTimer"] = heartBeat_timer;
// ipv4_addresses
data["ipv4Addresses"] = nlohmann::json::array();
for (auto address : ipv4_addresses) {
data["ipv4Addresses"].push_back(inet_ntoa(address));
}
data["priority"] = priority;
data["capacity"] = capacity;
}
//------------------------------------------------------------------------------
void nf_profile::from_json(const nlohmann::json& data) {
if (data.find("nfInstanceId") != data.end()) {
nf_instance_id = data["nfInstanceId"].get<std::string>();
}
if (data.find("nfInstanceName") != data.end()) {
nf_instance_name = data["nfInstanceName"].get<std::string>();
}
if (data.find("nfType") != data.end()) {
nf_type = data["nfType"].get<std::string>();
}
if (data.find("nfStatus") != data.end()) {
nf_status = data["nfStatus"].get<std::string>();
}
if (data.find("heartBeatTimer") != data.end()) {
heartBeat_timer = data["heartBeatTimer"].get<int>();
}
if (data.find("ipv4Addresses") != data.end()) {
nlohmann::json addresses = data["ipv4Addresses"];
for (auto it : addresses) {
struct in_addr addr4 = {};
std::string address = it.get<std::string>();
unsigned char buf_in_addr[sizeof(struct in_addr)];
if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) {
memcpy(&addr4, buf_in_addr, sizeof(struct in_addr));
} else {
Logger::ausf_app().warn(
"Address conversion: Bad value %s", util::trim(address).c_str());
}
add_nf_ipv4_addresses(addr4);
}
}
if (data.find("priority") != data.end()) {
priority = data["priority"].get<int>();
}
if (data.find("capacity") != data.end()) {
capacity = data["capacity"].get<int>();
}
}
/------------------------------------------------------------------------------
void ausf_profile::set_nf_services(const std::vector<nf_service_t>& n) {
nf_services = n;
}
//------------------------------------------------------------------------------
void ausf_profile::add_nf_service(const nf_service_t& n) {
nf_services.push_back(n);
}
//------------------------------------------------------------------------------
void ausf_profile::get_nf_services(std::vector<nf_service_t>& n) const {
n = nf_services;
}
//------------------------------------------------------------------------------
void ausf_profile::display() const {
// display NF part
nf_profile::display();
// NF services
if (nf_services.size() > 0) {
Logger::ausf_app().debug("\tNF Service");
}
for (auto service : nf_services) {
Logger::ausf_app().debug("\t\t%s", service.to_string().c_str());
}
}
//------------------------------------------------------------------------------
void ausf_profile::to_json(nlohmann::json& data) const {
nf_profile::to_json(data);
// NF services
data["nfServices"] = nlohmann::json::array();
for (auto service : nf_services) {
nlohmann::json srv_tmp = {};
srv_tmp["serviceInstanceId"] = service.service_instance_id;
srv_tmp["serviceName"] = service.service_name;
srv_tmp["versions"] = nlohmann::json::array();
for (auto v : service.versions) {
nlohmann::json v_tmp = {};
v_tmp["apiVersionInUri"] = v.api_version_in_uri;
v_tmp["apiFullVersion"] = v.api_full_version;
srv_tmp["versions"].push_back(v_tmp);
}
srv_tmp["scheme"] = service.scheme;
srv_tmp["nfServiceStatus"] = service.nf_service_status;
// IP endpoints
srv_tmp["ipEndPoints"] = nlohmann::json::array();
for (auto endpoint : service.ip_endpoints) {
nlohmann::json ep_tmp = {};
ep_tmp["ipv4Address"] = nlohmann::json::array();
ep_tmp["ipv4Address"] = inet_ntoa(endpoint.ipv4_address);
ep_tmp["transport"] = endpoint.transport;
ep_tmp["port"] = endpoint.port;
srv_tmp["ipEndPoints"].push_back(ep_tmp);
}
data["nfServices"].push_back(srv_tmp);
}
Logger::ausf_app().debug("AUSF profile to json:\n %s", data.dump().c_str());
}
//------------------------------------------------------------------------------
void ausf_profile::from_json(const nlohmann::json& data) {
nf_profile::from_json(data);
// TODO: custom_info;
display();
}
//------------------------------------------------------------------------------
void ausf_profile::handle_heartbeart_timeout(uint64_t ms) {
Logger::ausf_app().info(
"Handle heartbeart timeout profile %s, time %d", nf_instance_id.c_str(),
ms);
set_nf_status("SUSPENDED");
}
#ifndef FILE_AUSF_PROFILE_HPP_SEEN
#define FILE_AUSF_PROFILE_HPP_SEEN
#include <arpa/inet.h>
#include <netinet/in.h>
#include <map>
#include <memory>
#include <nlohmann/json.hpp>
#include <shared_mutex>
#include <utility>
#include <vector>
#include "logger.hpp"
namespace ausf_application{
using namespace std;
class nf_profile : public std::enable_shared_from_this<nf_profile>
{
public:
nf_profile()
: nf_type("NF_TYPE_UNKNOWN"),
heartBeat_timer(0),
ipv4_addresses(),
priority(0),
capacity(0){
nf_instance_name = "";
nf_status = "";
}
nf_profile(const std::string &id)
: nf_instance_id(id),
heartBeat_timer(0),
ipv4_addresses(),
priority(0),
capacity(0),
nf_type("NF_TYPE_UNKNOWN")
{
nf_instance_name = "";
nf_status = "";
}
nf_profile &operator=(const nf_profile &s)
{
nf_instance_id = s.nf_instance_id;
heartBeat_timer = s.heartBeat_timer;
ipv4_addresses = s.ipv4_addresses;
priority = s.priority;
capacity = s.capacity;
nf_type = s.nf_type;
nf_instance_name = s.nf_instance_name;
nf_status = s.nf_status;
}
// nf_profile(nf_profile &b) = delete;
void set_nf_instance_id(const std::string &instance_id);
void get_nf_instance_id(std::string &instance_id) const;
std::string get_nf_instance_id() const;
void set_nf_instance_name(const std::string &instance_name);
void get_nf_instance_name(std::string &instance_name) const;
std::string get_nf_instance_name() const;
void set_nf_status(const std::string &status);
void get_nf_status(std::string &status) const;
std::string get_nf_status() const;
std::string get_nf_type() const;
void set_nf_type(const std::string &type);
void set_nf_heartBeat_timer(const int32_t &timer);
void get_nf_heartBeat_timer(int32_t &timer) const;
int32_t get_nf_heartBeat_timer() const;
void set_nf_priority(const uint16_t &p);
void get_nf_priority(uint16_t &p) const;
uint16_t get_nf_priority() const;
void set_nf_capacity(const uint16_t &c);
void get_nf_capacity(uint16_t &c) const;
uint16_t get_nf_capacity() const;
void set_nf_ipv4_addresses(const std::vector<struct in_addr> &a);
void add_nf_ipv4_addresses(const struct in_addr &a);
void get_nf_ipv4_addresses(std::vector<struct in_addr> &a) const;
virtual void display() const;
virtual void to_json(nlohmann::json &data) const;
virtual void from_json(const nlohmann::json &data);
protected:
// From NFProfile (Section 6.1.6.2.2@3GPP TS 29.510 V16.0.0 (2019-06))
std::string nf_instance_id;
std::string nf_instance_name;
std::string nf_type;
std::string nf_status;
int32_t heartBeat_timer;
std::vector<struct in_addr> ipv4_addresses;
uint16_t priority;
uint16_t capacity;
};
class ausf_profile : public nf_profile {
public:
ausf_profile() : nf_profile() { custom_info = {}; }
ausf_profile(const std::string& id) : nf_profile(id) { custom_info = {}; }
ausf_profile& operator=(const ausf_profile& s) {
nf_instance_id = s.nf_instance_id;
heartBeat_timer = s.heartBeat_timer;
ipv4_addresses = s.ipv4_addresses;
priority = s.priority;
capacity = s.capacity;
nf_type = s.nf_type;
nf_instance_name = s.nf_instance_name;
nf_status = s.nf_status;
nf_services = s.nf_services;
return *this;
}
virtual ~ausf_profile() {
Logger::ausf_app().debug("Delete AUSF Profile instance...");
}
void set_nf_services(const std::vector<nf_service_t>& n);
void add_nf_service(const nf_service_t& n);
void get_nf_services(std::vector<nf_service_t>& n) const;
void display() const;
void to_json(nlohmann::json& data) const;
void from_json(const nlohmann::json& data);
void handle_heartbeart_timeout(uint64_t ms);
protected:
std::vector<nf_service_t> nf_services;
//nlohmann::json custom_info; // store extra json data
};
}
#endif
\ No newline at end of file
...@@ -26,8 +26,10 @@ ...@@ -26,8 +26,10 @@
#include "logger.hpp" #include "logger.hpp"
#include "options.hpp" #include "options.hpp"
#include "ausf_config.hpp" #include "ausf_config.hpp"
#include "itti.hpp"
#include "ausf_app.hpp"
using namespace std;
#define PISTACHE_SERVER_THREADS 2 #define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768 #define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
...@@ -63,12 +65,16 @@ static void setUpUnixSignals(std::vector<int> quitSignals) { ...@@ -63,12 +65,16 @@ static void setUpUnixSignals(std::vector<int> quitSignals) {
sigaction(sig, &sa, nullptr); sigaction(sig, &sa, nullptr);
} }
#endif #endif
using namespace std;
using namespace ausf_application;
using namespace org::openapitools::server::api; using namespace org::openapitools::server::api;
using namespace config; using namespace config;
ausf_config ausf_cfg; ausf_config ausf_cfg;
itti_mw *itti_inst = nullptr;
ausf_app *ausf_app_inst = nullptr;
int main(int argc, char **argv) { int main(int argc, char **argv) {
#ifdef __linux__ #ifdef __linux__
...@@ -83,10 +89,18 @@ int main(int argc, char **argv) { ...@@ -83,10 +89,18 @@ int main(int argc, char **argv) {
Logger::init( "ausf" , Options::getlogStdout() , Options::getlogRotFilelog()); Logger::init( "ausf" , Options::getlogStdout() , Options::getlogRotFilelog());
Logger::ausf_server().startup("Start AUSF"); Logger::ausf_server().startup("Start AUSF");
Logger::ausf_app().startup("Start ausf_app");
Logger::ausf_app().info("Options parsed!");
ausf_cfg.load(Options::getlibconfigConfig()); ausf_cfg.load(Options::getlibconfigConfig());
ausf_cfg.display(); ausf_cfg.display();
Logger::ausf_app().info("Initiating ITTI server!");
itti_inst = new itti_mw();
util::thread_sched_params itti_timer_sched_params;
itti_inst->start(itti_timer_sched_params);
ausf_app_inst = new ausf_app();
//Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(ausf_cfg.sbi.port)); //Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(ausf_cfg.sbi.port));
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&ausf_cfg.sbi.addr4))), Pistache::Port(ausf_cfg.sbi.port)); Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&ausf_cfg.sbi.addr4))), Pistache::Port(ausf_cfg.sbi.port));
......
/*
* 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
*/
#ifndef FILE_3GPP_29_510_NRF_SEEN
#define FILE_3GPP_29_510_NRF_SEEN
#include <vector>
#include "3gpp_23.003.h"
enum class nf_status_e { REGISTERED = 0, SUSPENDED = 1, UNDISCOVERABLE = 2 };
static const std::vector<std::string> nf_status_e2str = {
"REGISTERED", "SUSPENDED", "UNDISCOVERABLE"};
enum subscr_condition_type_e { // TODO: use enum class
UNKNOWN_CONDITION = 0,
NF_INSTANCE_ID_COND = 1,
NF_TYPE_COND = 2,
SERVICE_NAME_COND = 3,
AMF_COND = 4,
GUAMI_LIST_COND = 5,
NETWOTK_SLICE_COND = 6,
NF_GROUP_COND = 7
};
enum notification_event_type_t {
NOTIFICATION_TYPE_UNKNOWN_EVENT = 0,
NOTIFICATION_TYPE_NF_REGISTERED = 1,
NOTIFICATION_TYPE_NF_DEREGISTERED = 2,
NOTIFICATION_TYPE_NF_PROFILE_CHANGED = 3
};
static const std::vector<std::string> notification_event_type_e2str = {
"UNKNOWN EVENT", "NF_REGISTERED", "NF_DEREGISTERED", "NF_PROFILE_CHANGED"};
typedef struct nf_service_version_s {
std::string api_version_in_uri; // apiVersionInUri
std::string api_full_version; // apiFullVersion
nf_service_version_s& operator=(const nf_service_version_s& s) {
api_version_in_uri = s.api_version_in_uri;
api_full_version = s.api_full_version;
return *this;
}
std::string to_string() const {
std::string s = {};
s.append(", Version (");
s.append("apiVersionInUri: ");
s.append(api_version_in_uri);
s.append(", apiFullVersion: ");
s.append(api_full_version);
s.append(" )");
return s;
}
} nf_service_version_t;
typedef struct ip_endpoint_s {
struct in_addr ipv4_address;
// struct in6_addr ipv6_address;
std::string transport; // TCP
unsigned int port;
std::string to_string() const {
std::string s = {};
s.append("Ipv4 Address: ");
s.append(inet_ntoa(ipv4_address));
s.append(", TransportProtocol: ");
s.append(transport);
s.append(", Port: ");
s.append(std::to_string(port));
return s;
}
} ip_endpoint_t;
typedef struct nf_service_s {
std::string service_instance_id;
std::string service_name;
std::vector<nf_service_version_t> versions;
std::string scheme;
std::string nf_service_status;
std::vector<ip_endpoint_t> ip_endpoints;
std::string to_string() const {
std::string s = {};
s.append("Service Instance ID: ");
s.append(service_instance_id);
s.append(", Service name: ");
s.append(service_name);
for (auto v : versions) {
s.append(v.to_string());
}
s.append(", Scheme: ");
s.append(scheme);
s.append(", Service status: ");
s.append(nf_service_status);
s.append(", IpEndPoints: ");
for (auto endpoint : ip_endpoints) {
s.append(endpoint.to_string());
}
return s;
}
} nf_service_t;
#endif
...@@ -97,6 +97,8 @@ class Logger { ...@@ -97,6 +97,8 @@ class Logger {
// static _Logger &amf_n11(){return *singleton().m_amf_n11;} // static _Logger &amf_n11(){return *singleton().m_amf_n11;}
// static _Logger &task_amf_n11(){return *singleton().m_task_amf_n11;} // static _Logger &task_amf_n11(){return *singleton().m_task_amf_n11;}
static _Logger &ausf_server() { return *singleton().m_ausf_server; } static _Logger &ausf_server() { return *singleton().m_ausf_server; }
static _Logger &ausf_app() { return *singleton().m_ausf_app; }
static _Logger &itti() { return *singleton().m_itti; }
// static _Logger &udm_ueau() { return *singleton().m_udm_ueau; } // static _Logger &udm_ueau() { return *singleton().m_udm_ueau; }
private: private:
...@@ -130,6 +132,8 @@ class Logger { ...@@ -130,6 +132,8 @@ class Logger {
// _Logger *m_amf_n11; // _Logger *m_amf_n11;
// _Logger *m_task_amf_n11; // _Logger *m_task_amf_n11;
_Logger *m_ausf_server; _Logger *m_ausf_server;
_Logger *m_ausf_app;
_Logger *m_itti;
// _Logger *m_udm_ueau; // _Logger *m_udm_ueau;
}; };
......
This diff is collapsed.
/*
* 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 itti.hpp
\brief
\author Lionel GAUTHIER
\date 2018
\email: lionel.gauthier@eurecom.fr
*/
#ifndef SRC_OAI_ITTI_ITTI_HPP_INCLUDED_
#define SRC_OAI_ITTI_ITTI_HPP_INCLUDED_
#include <chrono>
#include <condition_variable>
//#include <iomanip>
#include <iostream>
#include <memory>
#include <mutex>
#include <queue>
#include <set>
#include <stdint.h>
#include <thread>
#include "itti_msg.hpp"
#include "thread_sched.hpp"
typedef volatile enum task_state_s {
TASK_STATE_NOT_CONFIGURED,
TASK_STATE_STARTING,
TASK_STATE_READY,
TASK_STATE_ENDED,
TASK_STATE_MAX,
} task_state_t;
typedef uint32_t timer_id_t;
#define ITTI_INVALID_TIMER_ID (timer_id_t) 0
class itti_timer {
public:
itti_timer(
const timer_id_t id, const task_id_t task_id, const uint32_t interval_sec,
const uint32_t interval_us, uint64_t arg1_user, uint64_t arg2_user)
: id(id), task_id(task_id), arg1_user(arg1_user), arg2_user(arg2_user) {
time_out = std::chrono::system_clock::now() +
std::chrono::seconds(interval_sec) +
std::chrono::microseconds(interval_us);
}
itti_timer(
const timer_id_t id, const task_id_t task_id,
const std::chrono::system_clock::time_point time_out, uint64_t arg1_user,
uint64_t arg2_user)
: id(id),
task_id(task_id),
time_out(time_out),
arg1_user(arg1_user),
arg2_user(arg2_user) {}
itti_timer(const itti_timer& t)
: id(t.id),
task_id(t.task_id),
time_out(t.time_out),
arg1_user(t.arg1_user),
arg2_user(t.arg2_user) {}
// itti_timer(itti_timer&& t) noexcept : id(std::move(t.id)),
// task_id(std::move(t.task_id)) , time_out(std::move(t.time_out)) {}
bool operator<(const itti_timer& t) const { return time_out < t.time_out; }
~itti_timer() {}
timer_id_t id;
task_id_t task_id;
std::chrono::system_clock::time_point time_out;
uint64_t arg1_user;
uint64_t arg2_user;
};
//------------------------------------------------------------------------------
struct timer_comparator {
bool operator()(const itti_timer& left, const itti_timer& right) const {
return (left.time_out < right.time_out);
}
};
class itti_task_ctxt {
public:
explicit itti_task_ctxt(const task_id_t task_id)
: task_id(task_id),
m_state(),
task_state(TASK_STATE_STARTING),
msg_queue(),
m_queue(),
c_queue() {}
~itti_task_ctxt() {}
const task_id_t task_id;
/*
* pthread associated with the thread
*/
// std::thread::id thread_id;
std::thread thread;
/*
* State of the thread
*/
std::mutex m_state;
volatile task_state_t task_state;
std::queue<std::shared_ptr<itti_msg>> msg_queue;
std::mutex m_queue;
std::condition_variable c_queue;
};
class itti_mw {
private:
itti_task_ctxt* itti_task_ctxts[TASK_MAX];
/*
* Current message number. Incremented every call to send_msg_to_task
*/
unsigned long msg_number;
timer_id_t timer_id;
std::mutex m_timer_id;
std::thread timer_thread;
std::atomic<int> created_tasks;
std::atomic<int> ready_tasks;
std::set<itti_timer, timer_comparator> timers;
itti_timer current_timer;
std::mutex m_timers;
std::condition_variable c_timers;
std::mutex m_timeout;
std::condition_variable c_timeout;
bool terminate;
static void timer_manager_task(const util::thread_sched_params& sched_params);
public:
itti_mw();
itti_mw(itti_mw const&) = delete;
void operator=(itti_mw const&) = delete;
~itti_mw();
void start(const util::thread_sched_params& sched_params);
timer_id_t increment_timer_id();
unsigned int increment_message_number();
/** \brief Send a broadcast message to every task
\param message_p Pointer to the message to send
@returns < 0 on failure, 0 otherwise
**/
int send_broadcast_msg(std::shared_ptr<itti_msg> message);
/** \brief Send a message to a task (could be itself)
\param message message to send
@returns -1 on failure, 0 otherwise
**/
int send_msg(std::shared_ptr<itti_msg> message);
/** \brief Retrieves a message in the queue associated to task_id.
* If the queue is empty, the thread is blocked till a new message arrives.
\param task_id Task ID of the receiving task
\param received_msg Pointer to the allocated message
**/
std::shared_ptr<itti_msg> receive_msg(task_id_t task_id);
/** \brief Try to retrieves a message in the queue associated to task_id.
\param task_id Task ID of the receiving task
\param received_msg Pointer to the allocated message
**/
std::shared_ptr<itti_msg> poll_msg(task_id_t task_id);
/** \brief Start thread associated to the task
* \param task_id task to start
* \param start_routine entry point for the task
* \param args_p Optional argument to pass to the start routine
* @returns -1 on failure, 0 otherwise
**/
int create_task(
const task_id_t task_id, void (*start_routine)(void*), void* args_p);
/** \brief Notify ITTI of a started thread
* \param task_id of started task
* \param start_routine entry point for the task
* \param args_p Optional argument to pass to the start routine
* @returns -1 on failure, 0 otherwise
**/
int notify_task_ready(const task_id_t task_id);
/** \brief Indicates to ITTI if newly created tasks should wait for all tasks
*to be ready \param wait_tasks non 0 to make new created tasks to wait, 0 to
*let created tasks to run
**/
// void wait_ready(int wait_tasks);
/** \brief Mark the task as in ready state
* \param task_id task to mark as ready
**/
// void mark_task_ready(task_id_t task_id);
/** \brief handle signals and wait for all threads to join when the process
*complete. This function should be called from the main thread after having
*created all ITTI tasks.
**/
void wait_tasks_end(void);
/** \brief Send a termination message to all tasks.
* \param src_task_id task that is broadcasting the message.
**/
int send_terminate_msg(task_id_t src_task_id);
/** \brief Request a new timer
* \param interval_sec timer interval in seconds
* \param interval_us timer interval in micro seconds
* \param task_id task id of the task requesting the timer
* @returns 0 on failure, timer id otherwise
**/
timer_id_t timer_setup(
uint32_t interval_sec, uint32_t interval_us, task_id_t task_id,
uint64_t arg1_user = 0, uint64_t arg2_user = 0);
/** \brief Remove the timer from list
* \param timer_id unique timer id
* \param task_id task id of the task that requested the timer
* @returns -1 on failure, 0 otherwise
**/
int timer_remove(timer_id_t timer_id);
static void signal_handler(int signum);
};
#endif /* SRC_OAI_ITTI_ITTI_HPP_INCLUDED_ */
/*
* 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 itti_msg.cpp
\brief
\author Lionel GAUTHIER
\date 2018
\email: lionel.gauthier@eurecom.fr
*/
#include "itti_msg.hpp"
#include "itti.hpp"
extern itti_mw* itti_inst;
itti_msg::itti_msg()
: msg_type(ITTI_MSG_TYPE_NONE), origin(TASK_NONE), destination(TASK_NONE) {
msg_num = itti_inst->increment_message_number();
};
itti_msg::itti_msg(
const itti_msg_type_t msg_type, task_id_t origin, task_id_t destination)
: msg_type(msg_type), origin(origin), destination(destination) {
msg_num = itti_inst->increment_message_number();
};
itti_msg::itti_msg(const itti_msg& i)
: msg_type(i.msg_type),
msg_num(i.msg_num),
origin(i.origin),
destination(i.destination){};
const char* itti_msg::get_msg_name() {
return "UNINITIALIZED";
}
/*
* 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 itti_msg.hpp
\brief
\author Lionel GAUTHIER
\date 2018
\email: lionel.gauthier@eurecom.fr
*/
#ifndef SRC_ITTI_ITTI_MSG_HPP_INCLUDED_
#define SRC_ITTI_ITTI_MSG_HPP_INCLUDED_
#include <stdint.h>
#include <utility>
typedef enum {
TASK_FIRST = 0,
TASK_ITTI_TIMER = TASK_FIRST,
TASK_AUSF_APP,
TASK_MAX,
TASK_NONE,
TASK_ALL = 255
} task_id_t;
typedef enum message_priorities_e {
MESSAGE_PRIORITY_MAX = 100,
MESSAGE_PRIORITY_MAX_LEAST = 85,
MESSAGE_PRIORITY_MED_PLUS = 70,
MESSAGE_PRIORITY_MED = 55,
MESSAGE_PRIORITY_MED_LEAST = 40,
MESSAGE_PRIORITY_MIN_PLUS = 25,
MESSAGE_PRIORITY_MIN = 10,
} message_priorities_t;
typedef enum {
ITTI_MSG_TYPE_NONE = -1,
ITTI_MSG_TYPE_FIRST = 0,
POLLING_GET_INFO = ITTI_MSG_TYPE_FIRST,
SBI_REGISTER_NF_INSTANCE_REQUEST,
TIME_OUT,
HEALTH_PING,
TERMINATE,
ITTI_MSG_TYPE_MAX
} itti_msg_type_t;
typedef unsigned long message_number_t;
class itti_msg {
public:
itti_msg();
itti_msg(
const itti_msg_type_t msg_type, const task_id_t origin,
const task_id_t destination);
itti_msg(const itti_msg& i);
itti_msg& operator=(itti_msg other) {
std::swap(msg_num, other.msg_num);
std::swap(origin, other.origin);
std::swap(destination, other.destination);
std::swap(msg_type, other.msg_type);
return *this;
}
virtual ~itti_msg() = default;
static const char* get_msg_name();
message_number_t msg_num;
task_id_t origin;
task_id_t destination;
itti_msg_type_t msg_type;
};
class itti_msg_timeout : public itti_msg {
public:
itti_msg_timeout(
const task_id_t origin, const task_id_t destination, uint32_t timer_id,
uint64_t arg1_user, uint64_t arg2_user)
: itti_msg(TIME_OUT, origin, destination),
timer_id(timer_id),
arg1_user(arg1_user),
arg2_user(arg2_user) {}
itti_msg_timeout(const itti_msg_timeout& i)
: itti_msg(i),
timer_id(i.timer_id),
arg1_user(i.arg1_user),
arg2_user(i.arg2_user) {}
static const char* get_msg_name() { return "TIME_OUT"; };
uint32_t timer_id;
uint64_t arg1_user;
uint64_t arg2_user;
};
class itti_msg_ping : public itti_msg {
public:
itti_msg_ping(
const task_id_t origin, const task_id_t destination, uint32_t seq)
: itti_msg(HEALTH_PING, origin, destination), seq(seq) {}
itti_msg_ping(const itti_msg_ping& i) : itti_msg(i), seq(i.seq) {}
static const char* get_msg_name() { return "HEALTH_PING"; };
uint32_t seq;
};
class itti_msg_terminate : public itti_msg {
public:
itti_msg_terminate(const task_id_t origin, const task_id_t destination)
: itti_msg(TERMINATE, origin, destination) {}
itti_msg_terminate(const itti_msg_terminate& i) : itti_msg(i) {}
static const char* get_msg_name() { return "TERMINATE"; };
};
#endif /* SRC_ITTI_ITTI_MSG_HPP_INCLUDED_ */
#ifndef _ITTI_SBI_MSG_H_
#define _ITTI_SBI_MSG_H_
#include <string>
#include "bstrlib.h"
#include "itti_msg.hpp"
#include "ausf_profile.hpp"
class itti_sbi_msg : public itti_msg {
public:
itti_sbi_msg(
const itti_msg_type_t msg_type, const task_id_t orig,
const task_id_t dest)
: itti_msg(msg_type, orig, dest) {}
itti_sbi_msg(const itti_sbi_msg& i) : itti_msg(i) {}
itti_sbi_msg(
const itti_sbi_msg& i, const task_id_t orig, const task_id_t dest)
: itti_sbi_msg(i) {
origin = orig;
destination = dest;
}
};
class itti_sbi_register_nf_instance_request : public itti_msg_sbi {
public:
itti_sbi_register_nf_instance_request(
const task_id_t orig, const task_id_t dest)
: itti_sbi_msg(SBI_REGISTER_NF_INSTANCE_REQUEST, orig, dest),
http_version(1) {}
const char *get_msg_name() { return "SBI_REGISTER_NF_INSTANCE_REQUEST"; };
ausf_application::ausf_profile profile;
uint8_t http_version;
};
#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