Commit 7b7c4a22 authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'nf_heartbeat' into 'develop'

nf_heartbeat procedure added

See merge request oai/cn5g/oai-cn5g-ausf!20
parents 936b74a6 334742dd
#
# Copyright (c) 2015, EURECOM (www.eurecom.fr)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.
#
# see https://clang.llvm.org/docs/ClangFormatStyleOptions.html for explanation
# of style options
BasedOnStyle: Google
Language: Cpp
IndentWidth: 2
ColumnLimit: 80
IncludeBlocks: Preserve
SortIncludes: false
# alignment
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
DerivePointerAlignment: false
PointerAlignment: Left
# function style
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakAfterReturnType: None
IndentWrappedFunctionNames: false
# template style
AlwaysBreakTemplateDeclarations: Yes
# preprocessor style
IndentPPDirectives: None
# block style
AllowShortBlocksOnASingleLine: false
KeepEmptyLinesAtTheStartOfBlocks: false
# break style
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakStringLiterals: true
CompactNamespaces: false
ContinuationIndentWidth: 4
MaxEmptyLinesToKeep: 1
ReflowComments: true
# spacing style
UseTab: Never
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
# class style
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
# case statements
IndentCaseLabels: true
# cpp
Cpp11BracedListStyle: true
FixNamespaceComments: true
NamespaceIndentation: None
SortUsingDeclarations: true
# todo
# AlwaysBreakBeforeMultilineStrings: bool
# PenaltyBreakAssignment (unsigned)
# PenaltyBreakBeforeFirstCallParameter (unsigned)
# PenaltyBreakComment (unsigned)
# PenaltyBreakFirstLessLess (unsigned)
# PenaltyBreakString (unsigned)
# PenaltyBreakTemplateDeclaration (unsigned)
# PenaltyExcessCharacter (unsigned)
# PenaltyReturnTypeOnItsOwnLine (unsigned)
/*
* 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
*/
/**
* Nausf_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB,
* ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.1.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "PatchItem.h"
#include <iostream>
using namespace std;
namespace oai {
namespace ausf_server {
namespace model {
PatchItem::PatchItem() {
m_Path = "";
m_From = "";
m_Value = "";
m_FromIsSet = false;
m_ValueIsSet = false;
}
PatchItem::~PatchItem() {}
void PatchItem::validate() {
// TODO: implement validation
}
void to_json(nlohmann::json &j, const PatchItem &o) {
j = nlohmann::json();
j["op"] = o.m_Op;
j["path"] = o.m_Path;
if (o.fromIsSet())
j["from"] = o.m_From;
if (o.valueIsSet())
j["value"] = o.m_Value;
}
void from_json(const nlohmann::json &j, PatchItem &o) {
j.at("op").get_to(o.m_Op);
j.at("path").get_to(o.m_Path);
if (j.find("from") != j.end()) {
j.at("from").get_to(o.m_From);
o.m_FromIsSet = true;
}
if (j.find("value") != j.end()) {
j.at("value").get_to(o.m_Value);
o.m_ValueIsSet = true;
}
}
std::string PatchItem::getOp() const { return m_Op; }
void PatchItem::setOp(std::string const &value) { m_Op = value; }
std::string PatchItem::getPath() const { return m_Path; }
void PatchItem::setPath(std::string const &value) { m_Path = value; }
std::string PatchItem::getFrom() const { return m_From; }
void PatchItem::setFrom(std::string const &value) {
m_From = value;
m_FromIsSet = true;
}
bool PatchItem::fromIsSet() const { return m_FromIsSet; }
void PatchItem::unsetFrom() { m_FromIsSet = false; }
std::string PatchItem::getValue() const { return m_Value; }
void PatchItem::setValue(std::string const &value) {
m_Value = value;
m_ValueIsSet = true;
}
bool PatchItem::valueIsSet() const { return m_ValueIsSet; }
void PatchItem::unsetValue() { m_ValueIsSet = false; }
} // namespace model
} // namespace ausf_server
} // namespace oai
/*
* 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
*/
/**
* Nausf_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB,
* ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.1.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
* PatchItem.h
*
*
*/
#ifndef PatchItem_H_
#define PatchItem_H_
#include <string>
#include "PatchOperation.h"
//#include "AnyType.h"
#include <nlohmann/json.hpp>
namespace oai {
namespace ausf_server {
namespace model {
/// <summary>
///
/// </summary>
class PatchItem {
public:
PatchItem();
virtual ~PatchItem();
void validate();
/////////////////////////////////////////////
/// PatchItem members
/// <summary>
///
/// </summary>
std::string getOp() const;
void setOp(std::string const &value);
/// <summary>
///
/// </summary>
std::string getPath() const;
void setPath(std::string const &value);
/// <summary>
///
/// </summary>
std::string getFrom() const;
void setFrom(std::string const &value);
bool fromIsSet() const;
void unsetFrom();
/// <summary>
///
/// </summary>
std::string getValue() const;
void setValue(std::string const &value);
bool valueIsSet() const;
void unsetValue();
friend void to_json(nlohmann::json &j, const PatchItem &o);
friend void from_json(const nlohmann::json &j, PatchItem &o);
protected:
std::string m_Op;
std::string m_Path;
std::string m_From;
bool m_FromIsSet;
std::string m_Value;
bool m_ValueIsSet;
};
} // namespace model
} // namespace ausf_server
} // namespace oai
#endif /* PatchItem_H_ */
/*
* 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
*/
/**
* Nausf_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB,
* ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.1.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "PatchOperation.h"
namespace oai {
namespace ausf_server {
namespace model {
PatchOperation::PatchOperation() {}
PatchOperation::~PatchOperation() {}
void PatchOperation::validate() {
// TODO: implement validation
}
void to_json(nlohmann::json &j, const PatchOperation &o) {
j = nlohmann::json();
}
void from_json(const nlohmann::json &j, PatchOperation &o) {}
} // namespace model
} // namespace ausf_server
} // namespace oai
/*
* 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
*/
/**
* NUDR_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB,
* ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.1.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
* PatchOperation.h
*
*
*/
#ifndef PatchOperation_H_
#define PatchOperation_H_
#include <nlohmann/json.hpp>
#define PATCH_OPERATION_ADD "add"
#define PATCH_OPERATION_COPY "copy"
#define PATCH_OPERATION_MOVE "move"
#define PATCH_OPERATION_REMOVE "remove"
#define PATCH_OPERATION_REPLACE "replace"
namespace oai {
namespace ausf_server {
namespace model {
/// <summary>
///
/// </summary>
class PatchOperation {
public:
PatchOperation();
virtual ~PatchOperation();
void validate();
/////////////////////////////////////////////
/// PatchOperation members
friend void to_json(nlohmann::json &j, const PatchOperation &o);
friend void from_json(const nlohmann::json &j, PatchOperation &o);
protected:
};
} // namespace model
} // namespace ausf_server
} // namespace oai
#endif /* PatchOperation_H_ */
......@@ -31,6 +31,8 @@ add_library (AUSF STATIC
ausf_app.cpp
ausf_client.cpp
ausf_config.cpp
task_manager.cpp
ausf_event.cpp
ausf_profile.cpp
ausf_nrf.cpp
)
This diff is collapsed.
......@@ -29,15 +29,16 @@
#ifndef FILE_AUSF_APP_HPP_SEEN
#define FILE_AUSF_APP_HPP_SEEN
#include "ausf_event.hpp"
#include <string>
#include "AuthenticationInfo.h"
#include "UEAuthenticationCtx.h"
#include "ConfirmationData.h"
#include "UEAuthenticationCtx.h"
#include "ausf.h"
#include <pistache/http.h>
#include <map>
#include <pistache/http.h>
#include <shared_mutex>
#include <string>
namespace oai {
namespace ausf {
......@@ -46,56 +47,58 @@ namespace app {
using namespace oai::ausf_server::model;
class security_context {
public:
public:
security_context() : xres_star() {
// supi = {};
ausf_av_s = {};
supi_ausf = "";
auth_type = "";
ausf_av_s = {};
supi_ausf = "";
auth_type = "";
serving_nn = "";
kausf_tmp = "";
kausf_tmp = "";
}
// supi64_t supi;
AUSF_AV_s ausf_av_s;
uint8_t xres_star[16]; // store xres*
std::string supi_ausf; // store supi
std::string auth_type; // store authType
std::string serving_nn; // store serving network name
std::string kausf_tmp; // store Kausf(string)
uint8_t xres_star[16]; // store xres*
std::string supi_ausf; // store supi
std::string auth_type; // store authType
std::string serving_nn; // store serving network name
std::string kausf_tmp; // store Kausf(string)
};
// class ausf_config;
class ausf_app {
public:
explicit ausf_app(const std::string& config_file);
ausf_app(ausf_app const&) = delete;
void operator=(ausf_app const&) = delete;
public:
explicit ausf_app(const std::string &config_file, ausf_event &ev);
ausf_app(ausf_app const &) = delete;
void operator=(ausf_app const &) = delete;
virtual ~ausf_app();
void handle_ue_authentications(
const AuthenticationInfo& authenticationInfo, nlohmann::json& json_data,
std::string& location, Pistache::Http::Code& code,
uint8_t http_version = 1);
void handle_ue_authentications(const AuthenticationInfo &authenticationInfo,
nlohmann::json &json_data,
std::string &location,
Pistache::Http::Code &code,
uint8_t http_version = 1);
void handle_ue_authentications_confirmation(
const std::string& authCtxId, const ConfirmationData& confirmation_data,
nlohmann::json& json_data, Pistache::Http::Code& code);
bool is_supi_2_security_context(const std::string& supi) const;
std::shared_ptr<security_context> supi_2_security_context(
const std::string& supi) const;
void set_supi_2_security_context(
const std::string& supi, std::shared_ptr<security_context> sc);
bool is_contextId_2_security_context(const std::string& contextId) const;
std::shared_ptr<security_context> contextId_2_security_context(
const std::string& contextId) const;
void set_contextId_2_security_context(
const std::string& contextId, std::shared_ptr<security_context> sc);
private:
const std::string &authCtxId, const ConfirmationData &confirmation_data,
nlohmann::json &json_data, Pistache::Http::Code &code);
bool is_supi_2_security_context(const std::string &supi) const;
std::shared_ptr<security_context>
supi_2_security_context(const std::string &supi) const;
void set_supi_2_security_context(const std::string &supi,
std::shared_ptr<security_context> sc);
bool is_contextId_2_security_context(const std::string &contextId) const;
std::shared_ptr<security_context>
contextId_2_security_context(const std::string &contextId) const;
void set_contextId_2_security_context(const std::string &contextId,
std::shared_ptr<security_context> sc);
private:
ausf_event &event_sub;
std::map<supi64_t, std::shared_ptr<security_context>> imsi2security_context;
mutable std::shared_mutex m_imsi2security_context;
......@@ -107,9 +110,9 @@ class ausf_app {
contextId2security_context;
mutable std::shared_mutex m_contextId2security_context;
};
} // namespace app
} // namespace ausf
} // namespace oai
} // namespace app
} // namespace ausf
} // namespace oai
#include "ausf_config.hpp"
#endif /* FILE_AUSF_APP_HPP_SEEN */
......@@ -30,13 +30,13 @@
#include "ausf_client.hpp"
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include <pistache/http.h>
#include <pistache/mime.h>
#include <nlohmann/json.hpp>
#include <stdexcept>
#include "logger.hpp"
#include "ausf.h"
#include "logger.hpp"
using namespace Pistache::Http;
using namespace Pistache::Http::Mime;
......@@ -44,13 +44,13 @@ using namespace oai::ausf::app;
using namespace config;
using json = nlohmann::json;
extern ausf_client* ausf_client_inst;
extern ausf_client *ausf_client_inst;
extern ausf_config ausf_cfg;
//------------------------------------------------------------------------------
// To read content of the response from NF
static std::size_t callback(
const char* in, std::size_t size, std::size_t num, std::string* out) {
static std::size_t callback(const char *in, std::size_t size, std::size_t num,
std::string *out) {
const std::size_t totalBytes(size * num);
out->append(in, totalBytes);
return totalBytes;
......@@ -65,25 +65,25 @@ ausf_client::~ausf_client() {
}
//------------------------------------------------------------------------------
void ausf_client::curl_http_client(
std::string remoteUri, std::string method, std::string msgBody,
std::string& response) {
void ausf_client::curl_http_client(std::string remoteUri, std::string method,
std::string msgBody, std::string &response) {
Logger::ausf_app().info("Send HTTP message with body %s", msgBody.c_str());
uint32_t str_len = msgBody.length();
char* body_data = (char*) malloc(str_len + 1);
char *body_data = (char *)malloc(str_len + 1);
memset(body_data, 0, str_len + 1);
memcpy((void*) body_data, (void*) msgBody.c_str(), str_len);
memcpy((void *)body_data, (void *)msgBody.c_str(), str_len);
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init();
CURL *curl = curl_easy_init();
uint8_t http_version = 1;
if (ausf_cfg.use_http2) http_version = 2;
if (ausf_cfg.use_http2)
http_version = 2;
if (curl) {
CURLcode res = {};
struct curl_slist* headers = nullptr;
CURLcode res = {};
struct curl_slist *headers = nullptr;
if ((method.compare("POST") == 0) or (method.compare("PUT") == 0) or
(method.compare("PATCH") == 0)) {
std::string content_type = "Content-Type: application/json";
......@@ -112,8 +112,8 @@ void ausf_client::curl_http_client(
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(
curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
}
// Response information.
......@@ -135,13 +135,13 @@ void ausf_client::curl_http_client(
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
// Process the response
response = *httpData.get();
response = *httpData.get();
bool is_response_ok = true;
Logger::ausf_app().info("Get response with HTTP code (%d)", httpCode);
if (httpCode == 0) {
Logger::ausf_app().info(
"Cannot get response when calling %s", remoteUri.c_str());
Logger::ausf_app().info("Cannot get response when calling %s",
remoteUri.c_str());
// free curl before returning
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
......@@ -166,14 +166,14 @@ void ausf_client::curl_http_client(
if (!is_response_ok) {
try {
response_data = nlohmann::json::parse(response);
} catch (nlohmann::json::exception& e) {
} catch (nlohmann::json::exception &e) {
Logger::ausf_app().info("Could not get JSON content from the response");
// Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout";
}
Logger::ausf_app().info(
"Get response with jsonData: %s", response.c_str());
Logger::ausf_app().info("Get response with jsonData: %s",
response.c_str());
std::string cause = response_data["error"]["cause"];
Logger::ausf_app().info("Call Network Function services failure");
......
......@@ -34,26 +34,25 @@
#include <curl/curl.h>
#include "logger.hpp"
#include "ausf_config.hpp"
#include "logger.hpp"
namespace oai {
namespace ausf {
namespace app {
class ausf_client {
private:
public:
private:
public:
ausf_client();
virtual ~ausf_client();
ausf_client(ausf_client const&) = delete;
ausf_client(ausf_client const &) = delete;
void curl_http_client(
std::string remoteUri, std::string method, std::string msgBody,
std::string& response);
void curl_http_client(std::string remoteUri, std::string method,
std::string msgBody, std::string &response);
};
} // namespace app
} // namespace ausf
} // namespace oai
} // namespace app
} // namespace ausf
} // namespace oai
#endif /* FILE_AUSF_CLIENT_HPP_SEEN */
This diff is collapsed.
......@@ -33,11 +33,11 @@
#include <arpa/inet.h>
#include <libconfig.h++>
#include <mutex>
#include <netinet/in.h>
#include <string>
#include <sys/socket.h>
#include <mutex>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
......@@ -85,11 +85,11 @@ typedef struct interface_cfg_s {
} interface_cfg_t;
class ausf_config {
public:
public:
ausf_config();
~ausf_config();
int load(const std::string& config_file);
int load_interface(const Setting& if_cfg, interface_cfg_t& cfg);
int load(const std::string &config_file);
int load_interface(const Setting &if_cfg, interface_cfg_t &cfg);
void display();
unsigned int instance;
......@@ -120,6 +120,6 @@ class ausf_config {
bool use_http2;
};
} // namespace config
} // namespace config
#endif
/*
* 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 ausf_event.cpp
\brief
\author Tien-Thinh NGUYEN (EURECOM)
\company
\date 2022
\email: contact@openairinterface.org
*/
#include "ausf_event.hpp"
using namespace oai::ausf::app;
bs2::connection
ausf_event::subscribe_task_nf_heartbeat(const task_sig_t::slot_type &sig,
uint64_t period, uint64_t start) {
/* Wrap the actual callback in a lambda. The latter checks whether the
* current time is after start time, and ensures that the callback is only
* called every X ms with X being the period time. This way, it is possible
* to register to be notified every X ms instead of every ms, which provides
* greater freedom to implementations. */
auto f = [period, start, sig](uint64_t t) {
if (t >= start && (t - start) % period == 0)
sig(t);
};
return task_tick.connect(f);
}
//------------------------------------------------------------------------------
bs2::connection ausf_event::subscribe_loss_of_connectivity(
const loss_of_connectivity_sig_t::slot_type &sig) {
return loss_of_connectivity.connect(sig);
}
//------------------------------------------------------------------------------
bs2::connection ausf_event::subscribe_ue_reachability_for_data(
const ue_reachability_for_data_sig_t::slot_type &sig) {
return ue_reachability_for_data.connect(sig);
}
/*
* 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 ausf_event.hpp
\brief
\author Tien-Thinh NGUYEN (EURECOM)
\company
\date 2022
\email: contact@openairinterface.org
*/
#ifndef FILE_AUSF_EVENT_HPP_SEEN
#define FILE_AUSF_EVENT_HPP_SEEN
#include <boost/signals2.hpp>
namespace bs2 = boost::signals2;
#include "ausf.h"
#include "ausf_event_sig.hpp"
#include "task_manager.hpp"
namespace oai::ausf::app {
class task_manager;
class ausf_event {
public:
ausf_event(){};
ausf_event(ausf_event const &) = delete;
void operator=(ausf_event const &) = delete;
static ausf_event &get_instance() {
static ausf_event instance;
return instance;
}
// class register/handle event
friend class ausf_app;
friend class ausf_nrf;
friend class task_manager;
//------------------------------------------------------------------------------
/*
* Subscribe to the task tick event
* @param [const task_sig_t::slot_type &] sig
* @param [uint64_t] period: interval between two events
* @param [uint64_t] start:
* @return void
*/
bs2::connection subscribe_task_nf_heartbeat(const task_sig_t::slot_type &sig,
uint64_t period,
uint64_t start = 0);
//------------------------------------------------------------------------------
/*
* Subscribe to UE Loss of Connectivity Status signal
* @param [const loss_of_connectivity_sig_t::slot_type&] sig: slot_type
* parameter
* @return boost::signals2::connection: the connection between the signal and
* the slot
*/
bs2::connection subscribe_loss_of_connectivity(
const loss_of_connectivity_sig_t::slot_type &sig);
/*
* Subscribe to UE Reachability for Data signal
* @param [const ue_reachability_for_data_sig_t::slot_type&] sig: slot_type
* parameter
* @return boost::signals2::connection: the connection between the signal and
* the slot
*/
bs2::connection subscribe_ue_reachability_for_data(
const ue_reachability_for_data_sig_t::slot_type &sig);
private:
task_sig_t task_tick;
loss_of_connectivity_sig_t
loss_of_connectivity; // Signal for Loss of Connectivity Report
ue_reachability_for_data_sig_t
ue_reachability_for_data; // Signal for UE Reachability for Data Report
};
} // namespace oai::ausf::app
#endif
/*
* 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 ausf_event_sig.hpp
\brief
\author Tien-Thinh NGUYEN (EURECOM)
\company
\date 2022
\email: contact@openairinterface.org
*/
#ifndef FILE_AUSF_EVENT_SIG_HPP_SEEN
#define FILE_AUSF_EVENT_SIG_HPP_SEEN
#include <boost/signals2.hpp>
#include <string>
namespace bs2 = boost::signals2;
namespace oai::ausf::app {
typedef bs2::signal_type<void(uint64_t),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
task_sig_t;
// Signal for Loss of Connectivity
// SUPI, Connectivity status, HTTP version
typedef bs2::signal_type<void(std::string, uint8_t, uint8_t),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
loss_of_connectivity_sig_t;
// Signal for UE Reachability for Data
// SUPI, Reachability status, HTTP version
typedef bs2::signal_type<void(std::string, uint8_t, uint8_t),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
ue_reachability_for_data_sig_t;
// UE_REACHABILITY_FOR_SMS
// LOCATION_REPORTING
// CHANGE_OF_SUPI_PEI_ASSOCIATION
// ROAMING_STATUS
// COMMUNICATION_FAILURE
// AVAILABILITY_AFTER_DNN_FAILURE
// CN_TYPE_CHANGE
} // namespace oai::ausf::app
#endif
......@@ -29,19 +29,19 @@
#include "ausf_nrf.hpp"
#include "ausf_app.hpp"
#include "ausf_profile.hpp"
#include "ausf_client.hpp"
#include "ausf_profile.hpp"
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include <pistache/http.h>
#include <pistache/mime.h>
#include <nlohmann/json.hpp>
#include <stdexcept>
#include "logger.hpp"
#include "ausf.h"
#include "logger.hpp"
using namespace config;
// using namespace ausf;
......@@ -50,22 +50,22 @@ using namespace oai::ausf::app;
using json = nlohmann::json;
extern ausf_config ausf_cfg;
extern ausf_nrf* ausf_nrf_inst;
ausf_client* ausf_client_instance = nullptr;
extern ausf_nrf *ausf_nrf_inst;
ausf_client *ausf_client_instance = nullptr;
//------------------------------------------------------------------------------
ausf_nrf::ausf_nrf() {}
ausf_nrf::ausf_nrf(ausf_event &ev) : m_event_sub(ev) {}
//---------------------------------------------------------------------------------------------
void ausf_nrf::get_ausf_api_root(std::string& api_root) {
void ausf_nrf::get_ausf_api_root(std::string &api_root) {
api_root = std::string(
inet_ntoa(*((struct in_addr*) &ausf_cfg.nrf_addr.ipv4_addr))) +
inet_ntoa(*((struct in_addr *)&ausf_cfg.nrf_addr.ipv4_addr))) +
":" + std::to_string(ausf_cfg.nrf_addr.port) + NNRF_NFM_BASE +
ausf_cfg.nrf_addr.api_version;
}
//---------------------------------------------------------------------------------------------
void ausf_nrf::generate_ausf_profile(
ausf_profile& ausf_nf_profile, std::string& ausf_instance_id) {
void ausf_nrf::generate_ausf_profile(ausf_profile &ausf_nf_profile,
std::string &ausf_instance_id) {
// TODO: remove hardcoded values
ausf_nf_profile.set_nf_instance_id(ausf_instance_id);
ausf_nf_profile.set_nf_instance_name("OAI-AUSF");
......@@ -75,7 +75,7 @@ void ausf_nrf::generate_ausf_profile(
ausf_nf_profile.set_nf_priority(1);
ausf_nf_profile.set_nf_capacity(100);
// ausf_nf_profile.set_fqdn(ausf_cfg.fqdn);
ausf_nf_profile.add_nf_ipv4_addresses(ausf_cfg.sbi.addr4); // N4's Addr
ausf_nf_profile.add_nf_ipv4_addresses(ausf_cfg.sbi.addr4); // N4's Addr
// AUSF info (Hardcoded for now)
ausf_info_t ausf_info_item;
......@@ -83,9 +83,9 @@ void ausf_nrf::generate_ausf_profile(
ausf_info_item.groupid = "oai-ausf-testgroupid";
ausf_info_item.routing_indicators.push_back("0210");
ausf_info_item.routing_indicators.push_back("9876");
supi_ranges.supi_range.start = "109238210938";
supi_ranges.supi_range.start = "109238210938";
supi_ranges.supi_range.pattern = "209238210938";
supi_ranges.supi_range.start = "q0930j0c80283ncjf";
supi_ranges.supi_range.start = "q0930j0c80283ncjf";
ausf_info_item.supi_ranges.push_back(supi_ranges);
ausf_nf_profile.set_ausf_info(ausf_info_item);
// AUSF info item end
......@@ -95,8 +95,7 @@ void ausf_nrf::generate_ausf_profile(
//---------------------------------------------------------------------------------------------
void ausf_nrf::register_to_nrf() {
// generate UUID
std::string ausf_instance_id; // AUSF instance id
ausf_instance_id = to_string(boost::uuids::random_generator()());
ausf_instance_id = to_string(boost::uuids::random_generator()());
nlohmann::json response_data = {};
// Generate NF Profile
......@@ -105,8 +104,8 @@ void ausf_nrf::register_to_nrf() {
// Send NF registeration request
std::string ausf_api_root = {};
std::string response = {};
std::string method = {"PUT"};
std::string response = {};
std::string method = {"PUT"};
get_ausf_api_root(ausf_api_root);
std::string remoteUri =
ausf_api_root + AUSF_NF_REGISTER_URL + ausf_instance_id;
......@@ -114,16 +113,63 @@ void ausf_nrf::register_to_nrf() {
ausf_nf_profile.to_json(json_data);
Logger::ausf_nrf().info("Sending NF registeration request");
ausf_client_instance->curl_http_client(
remoteUri, method, json_data.dump().c_str(), response);
ausf_client_instance->curl_http_client(remoteUri, method,
json_data.dump().c_str(), response);
try {
response_data = nlohmann::json::parse(response);
if (response_data["nfStatus"].dump().c_str() == "REGISTERED") {
// ToDo Trigger NF heartbeats
response_data = nlohmann::json::parse(response);
if (response.find("REGISTERED") != 0) {
start_event_nf_heartbeat(remoteUri);
}
} catch (nlohmann::json::exception& e) {
} catch (nlohmann::json::exception &e) {
Logger::ausf_nrf().info("NF registeration procedure failed");
}
}
//---------------------------------------------------------------------------------------------
void ausf_nrf::start_event_nf_heartbeat(std::string &remoteURI) {
// get current time
uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
struct itimerspec its;
its.it_value.tv_sec = HEART_BEAT_TIMER; // seconds
its.it_value.tv_nsec = 0; // 100 * 1000 * 1000; //100ms
const uint64_t interval =
its.it_value.tv_sec * 1000 +
its.it_value.tv_nsec / 1000000; // convert sec, nsec to msec
task_connection = m_event_sub.subscribe_task_nf_heartbeat(
boost::bind(&ausf_nrf::trigger_nf_heartbeat_procedure, this, _1),
interval, ms + interval);
}
//---------------------------------------------------------------------------------------------
void ausf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) {
_unused(ms);
oai::ausf_server::model::PatchItem patch_item = {};
std::vector<oai::ausf_server::model::PatchItem> patch_items;
//{"op":"replace","path":"/nfStatus", "value": "REGISTERED"}
patch_item.setOp("replace");
patch_item.setPath("/nfStatus");
patch_item.setValue("REGISTERED");
patch_items.push_back(patch_item);
Logger::ausf_nrf().info("Sending NF heartbeat request");
std::string response = {};
std::string method = {"PATCH"};
nlohmann::json json_data = nlohmann::json::array();
for (auto i : patch_items) {
nlohmann::json item = {};
to_json(item, i);
json_data.push_back(item);
}
std::string ausf_api_root = {};
get_ausf_api_root(ausf_api_root);
std::string remoteUri =
ausf_api_root + AUSF_NF_REGISTER_URL + ausf_instance_id;
ausf_client_instance->curl_http_client(remoteUri, method,
json_data.dump().c_str(), response);
if (!response.empty())
task_connection.disconnect();
}
\ No newline at end of file
......@@ -34,34 +34,49 @@
#include <curl/curl.h>
#include "logger.hpp"
#include "PatchItem.h"
#include "ausf_config.hpp"
#include "ausf_event.hpp"
#include "ausf_profile.hpp"
#include "logger.hpp"
using namespace oai::ausf_server::model;
namespace oai {
namespace ausf {
namespace app {
class ausf_nrf {
private:
public:
ausf_profile ausf_nf_profile; // AUSF profile
std::string ausf_instance_id; // AUSF instance id
private:
public:
ausf_profile ausf_nf_profile; // AUSF profile
std::string ausf_instance_id; // AUSF instance id
// timer_id_t timer_ausf_heartbeat;
ausf_nrf();
ausf_nrf(ausf_nrf const&) = delete;
void operator=(ausf_nrf const&) = delete;
ausf_nrf(ausf_event &ev);
ausf_nrf(ausf_nrf const &) = delete;
void operator=(ausf_nrf const &) = delete;
void generate_uuid();
/*
* Start event nf heartbeat procedure
* @param [void]
* @return void
*/
void start_event_nf_heartbeat(std::string &remoteURI);
/*
* Trigger NF heartbeat procedure
* @param [void]
* @return void
*/
void trigger_nf_heartbeat_procedure(uint64_t ms);
/*
* Generate a AUSF profile for this instance
* @param [void]
* @return void
*/
void generate_ausf_profile(
ausf_profile& ausf_nf_profile, std::string& ausf_instance_id);
void generate_ausf_profile(ausf_profile &ausf_nf_profile,
std::string &ausf_instance_id);
/*
* Trigger NF instance registration to NRF
......@@ -74,9 +89,13 @@ class ausf_nrf {
* @param [std::string& ] api_root: ausf's API Root
* @return void
*/
void get_ausf_api_root(std::string& api_root);
void get_ausf_api_root(std::string &api_root);
private:
ausf_event &m_event_sub;
bs2::connection task_connection;
};
} // namespace app
} // namespace ausf
} // namespace oai
} // namespace app
} // namespace ausf
} // namespace oai
#endif /* FILE_AUSF_NRF_SEEN */
This diff is collapsed.
......@@ -36,53 +36,42 @@
#include <shared_mutex>
#include <vector>
#include "logger.hpp"
#include "3gpp_29.510.h"
#include "ausf.h"
#include "logger.hpp"
namespace oai {
namespace ausf {
namespace app {
class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
public:
public:
ausf_profile()
: nf_type("NF_TYPE_UNKNOWN"),
heartBeat_timer(0),
snssais(),
fqdn(),
ipv4_addresses(),
priority(0),
capacity(0) {
: nf_type("NF_TYPE_UNKNOWN"), heartBeat_timer(0), snssais(), fqdn(),
ipv4_addresses(), priority(0), capacity(0) {
nf_instance_name = {};
nf_status = {};
nf_status = {};
}
ausf_profile(const std::string& id)
: nf_instance_id(id),
heartBeat_timer(0),
snssais(),
fqdn(),
ipv4_addresses(),
priority(0),
capacity(0),
nf_type("NF_TYPE_UNKNOWN") {
ausf_profile(const std::string &id)
: nf_instance_id(id), heartBeat_timer(0), snssais(), fqdn(),
ipv4_addresses(), priority(0), capacity(0), nf_type("NF_TYPE_UNKNOWN") {
nf_instance_name = {};
nf_status = {};
nf_status = {};
}
ausf_profile& operator=(const ausf_profile& s) {
nf_instance_id = s.nf_instance_id;
heartBeat_timer = s.heartBeat_timer;
snssais = s.snssais;
fqdn = s.fqdn;
ipv4_addresses = s.ipv4_addresses;
priority = s.priority;
capacity = s.capacity;
nf_type = s.nf_type;
ausf_profile &operator=(const ausf_profile &s) {
nf_instance_id = s.nf_instance_id;
heartBeat_timer = s.heartBeat_timer;
snssais = s.snssais;
fqdn = s.fqdn;
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;
ausf_info = s.ausf_info;
nf_status = s.nf_status;
ausf_info = s.ausf_info;
return *this;
}
// ausf_profile(ausf_profile &b) = delete;
......@@ -96,13 +85,13 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const std::string &] instance_id: instance id
* @return void
*/
void set_nf_instance_id(const std::string& instance_id);
void set_nf_instance_id(const std::string &instance_id);
/*
* Get NF instance ID
* @param [std::string &] instance_id: store instance id
* @return void:
*/
void get_nf_instance_id(std::string& instance_id) const;
void get_nf_instance_id(std::string &instance_id) const;
/*
* Get NF instance ID
......@@ -116,14 +105,14 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const std::string &] instance_name: instance name
* @return void
*/
void set_nf_instance_name(const std::string& instance_name);
void set_nf_instance_name(const std::string &instance_name);
/*
* Get NF instance ID
* @param [std::string &] instance_name: store instance name
* @return void:
*/
void get_nf_instance_name(std::string& instance_name) const;
void get_nf_instance_name(std::string &instance_name) const;
/*
* Get NF instance name
......@@ -137,14 +126,14 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const std::string &] status: instance status
* @return void
*/
void set_nf_status(const std::string& status);
void set_nf_status(const std::string &status);
/*
* Get NF instance status
* @param [std::string &] status: store instance status
* @return void:
*/
void get_nf_status(std::string& status) const;
void get_nf_status(std::string &status) const;
/*
* Get NF status
......@@ -165,21 +154,21 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const nf_type_t &] type: nf type
* @return void
*/
void set_nf_type(const std::string& type);
void set_nf_type(const std::string &type);
/*
* Set NF instance heartBeat_timer
* @param [const std::string &] timer: heartBeat_timer
* @return void
*/
void set_nf_heartBeat_timer(const int32_t& timer);
void set_nf_heartBeat_timer(const int32_t &timer);
/*
* Get NF instance heartBeat_timer
* @param [std::string &] timer: store heartBeat_timer
* @return void:
*/
void get_nf_heartBeat_timer(int32_t& timer) const;
void get_nf_heartBeat_timer(int32_t &timer) const;
/*
* Get NF heartBeat_timer
......@@ -193,14 +182,14 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const uint16_t] p: instance priority
* @return void
*/
void set_nf_priority(const uint16_t& p);
void set_nf_priority(const uint16_t &p);
/*
* Get NF instance priority
* @param [uint16_t] p: store instance priority
* @return void:
*/
void get_nf_priority(uint16_t& p) const;
void get_nf_priority(uint16_t &p) const;
/*
* Get NF instance priority
......@@ -214,14 +203,14 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const uint16_t] c: instance capacity
* @return void
*/
void set_nf_capacity(const uint16_t& c);
void set_nf_capacity(const uint16_t &c);
/*
* Get NF instance priority
* @param [uint16_t ] c: store instance capacity
* @return void:
*/
void get_nf_capacity(uint16_t& c) const;
void get_nf_capacity(uint16_t &c) const;
/*
* Get NF instance priority
......@@ -235,21 +224,21 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [std::vector<snssai_t> &] s: SNSSAIs
* @return void
*/
void set_nf_snssais(const std::vector<snssai_t>& s);
void set_nf_snssais(const std::vector<snssai_t> &s);
/*
* Add SNSSAI
* @param [snssai_t &] s: SNSSAI
* @return void
*/
void add_snssai(const snssai_t& s);
void add_snssai(const snssai_t &s);
/*
* Get NF instance SNSSAIs
* @param [std::vector<snssai_t> &] s: store instance's SNSSAIs
* @return void:
*/
void get_nf_snssais(std::vector<snssai_t>& s) const;
void get_nf_snssais(std::vector<snssai_t> &s) const;
/*
* Get NF fqdn
......@@ -263,42 +252,42 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [const fqdn_t &] fqdn: nf fqdn
* @return void
*/
void set_fqdn(const std::string& fqdn);
void set_fqdn(const std::string &fqdn);
/*
* Set NF instance ipv4_addresses
* @param [std::vector<struct in_addr> &] a: ipv4_addresses
* @return void
*/
void set_nf_ipv4_addresses(const std::vector<struct in_addr>& a);
void set_nf_ipv4_addresses(const std::vector<struct in_addr> &a);
/*
* Add an IPv4 address to the list of addresses
* @param [const struct in_addr &] a: ipv4_address
* @return void
*/
void add_nf_ipv4_addresses(const struct in_addr& a);
void add_nf_ipv4_addresses(const struct in_addr &a);
/*
* Get NF instance ipv4_addresses
* @param [std::vector<struct in_addr> &] a: store instance's ipv4_addresses
* @return void:
*/
void get_nf_ipv4_addresses(std::vector<struct in_addr>& a) const;
void get_nf_ipv4_addresses(std::vector<struct in_addr> &a) const;
/*
* Set ausf info
* @param [ausf_info_t &] s: ausf info
* @return void
*/
void set_ausf_info(const ausf_info_t& s);
void set_ausf_info(const ausf_info_t &s);
/*
* Get NF instance ausf info
* @param [ausf_info_t &] s: store instance's ausf info
* @return void:
*/
void get_ausf_info(ausf_info_t& s) const;
void get_ausf_info(ausf_info_t &s) const;
/*
* Print related-information for NF profile
......@@ -312,14 +301,14 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
* @param [nlohmann::json &] data: Json data
* @return void
*/
void to_json(nlohmann::json& data) const;
void to_json(nlohmann::json &data) const;
/*
* Covert from a json represetation to ausf profile
* @param [nlohmann::json &] data: Json data
* @return void
*/
void from_json(const nlohmann::json& data);
void from_json(const nlohmann::json &data);
/*
* Handle heartbeart timeout event
......@@ -328,7 +317,7 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
*/
void handle_heartbeart_timeout(uint64_t ms);
protected:
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;
......@@ -343,8 +332,8 @@ class ausf_profile : public std::enable_shared_from_this<ausf_profile> {
ausf_info_t ausf_info;
};
} // namespace app
} // namespace ausf
} // namespace oai
} // namespace app
} // namespace ausf
} // namespace oai
#endif
/*
* 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 task_manager.cpp
\brief
\author
\company Eurecom
\date 2020
\email: Tien-Thinh.Nguyen@eurecom.fr
*/
#include "task_manager.hpp"
#include <iostream>
#include <thread>
#include <unistd.h>
#include "logger.hpp"
using namespace oai::ausf::app;
//------------------------------------------------------------------------------
task_manager::task_manager(ausf_event &ev) : event_sub_(ev) {
struct itimerspec its;
sfd = timerfd_create(CLOCK_MONOTONIC, 0);
/* Start the timer */
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 1000 * 1000;
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
if (timerfd_settime(sfd, TFD_TIMER_ABSTIME, &its, NULL) == -1) {
Logger::ausf_app().error("Failed to set timer for task manager");
}
}
//------------------------------------------------------------------------------
void task_manager::run() { manage_tasks(); }
//------------------------------------------------------------------------------
void task_manager::manage_tasks() {
// starting from current time
uint64_t t = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
while (1) {
event_sub_.task_tick(t);
t++;
wait_for_cycle();
}
}
//------------------------------------------------------------------------------
void task_manager::wait_for_cycle() {
uint64_t exp;
ssize_t res;
if (sfd > 0) {
res = read(sfd, &exp, sizeof(exp));
if ((res < 0) || (res != sizeof(exp))) {
Logger::ausf_app().error("Failed in task manager timer wait");
}
}
}
/*
* 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 task_manager.hpp
\brief
\author
\company Eurecom
\date 2020
\email: Tien-Thinh.Nguyen@eurecom.fr
*/
#ifndef TASK_MANAGER_H_
#define TASK_MANAGER_H_
#include "ausf_event.hpp"
#include <linux/types.h>
#include <sys/timerfd.h>
using namespace oai::ausf::app;
namespace oai {
namespace ausf {
namespace app {
class ausf_event;
class task_manager {
public:
task_manager(ausf_event &ev);
/*
* Manage the tasks
* @param [void]
* @return void
*/
void manage_tasks();
/*
* Run the tasks (for the moment, simply call function manage_tasks)
* @param [void]
* @return void
*/
void run();
private:
/*
* Make sure that the task tick run every 1ms
* @param [void]
* @return void
*/
void wait_for_cycle();
ausf_event &event_sub_;
int sfd;
};
} // namespace app
} // namespace ausf
} // namespace oai
#endif
......@@ -24,29 +24,32 @@
#define HEART_BEAT_TIMER 10
#define _unused(x) ((void) (x))
#define _unused(x) ((void)(x))
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define AUSF_NF_REGISTER_URL "/nf-instances/"
typedef enum nf_type_s {
NF_TYPE_NRF = 0,
NF_TYPE_AMF = 1,
NF_TYPE_SMF = 2,
NF_TYPE_AUSF = 3,
NF_TYPE_NEF = 4,
NF_TYPE_PCF = 5,
NF_TYPE_SMSF = 6,
NF_TYPE_NSSF = 7,
NF_TYPE_UDR = 8,
NF_TYPE_LMF = 9,
NF_TYPE_GMLC = 10,
NF_TYPE_5G_EIR = 11,
NF_TYPE_SEPP = 12,
NF_TYPE_UPF = 13,
NF_TYPE_N3IWF = 14,
NF_TYPE_AF = 15,
NF_TYPE_UDSF = 16,
NF_TYPE_BSF = 17,
NF_TYPE_CHF = 18,
NF_TYPE_NWDAF = 19,
NF_TYPE_NRF = 0,
NF_TYPE_AMF = 1,
NF_TYPE_SMF = 2,
NF_TYPE_AUSF = 3,
NF_TYPE_NEF = 4,
NF_TYPE_PCF = 5,
NF_TYPE_SMSF = 6,
NF_TYPE_NSSF = 7,
NF_TYPE_UDR = 8,
NF_TYPE_LMF = 9,
NF_TYPE_GMLC = 10,
NF_TYPE_5G_EIR = 11,
NF_TYPE_SEPP = 12,
NF_TYPE_UPF = 13,
NF_TYPE_N3IWF = 14,
NF_TYPE_AF = 15,
NF_TYPE_UDSF = 16,
NF_TYPE_BSF = 17,
NF_TYPE_CHF = 18,
NF_TYPE_NWDAF = 19,
NF_TYPE_UNKNOWN = 20
} nf_type_t;
......@@ -56,12 +59,12 @@ static const std::vector<std::string> nf_type_e2str = {
"N3IWF", "AF", "UDSF", "BSF", "CHF", "NWDAF", "UNKNOWN"};
typedef enum patch_op_type_s {
PATCH_OP_ADD = 0,
PATCH_OP_REMOVE = 1,
PATCH_OP_ADD = 0,
PATCH_OP_REMOVE = 1,
PATCH_OP_REPLACE = 2,
PATCH_OP_MOVE = 3,
PATCH_OP_COPY = 4,
PATCH_OP_TEST = 5,
PATCH_OP_MOVE = 3,
PATCH_OP_COPY = 4,
PATCH_OP_TEST = 5,
PATCH_OP_UNKNOWN = 6
} patch_op_type_t;
......@@ -70,7 +73,7 @@ static const std::vector<std::string> patch_op_type_e2str = {
"ADD", "REMOVE", "REPLACE", "MOVE", "COPY", "TEST", "UNKNOWN"};
#define CURL_TIMEOUT_MS 1000L
#define MAX_WAIT_MSECS 20000 // 1 second
#define MAX_WAIT_MSECS 20000 // 1 second
typedef struct {
uint8_t rand[16];
......@@ -83,29 +86,29 @@ typedef uint64_t supi64_t;
// 3GPP TS 29.571 (Common data)
enum http_response_codes_e {
HTTP_RESPONSE_CODE_OK = 200,
HTTP_RESPONSE_CODE_CREATED = 201,
HTTP_RESPONSE_CODE_ACCEPTED = 202,
HTTP_RESPONSE_CODE_NO_CONTENT = 204,
HTTP_RESPONSE_CODE_BAD_REQUEST = 400,
HTTP_RESPONSE_CODE_UNAUTHORIZED = 401,
HTTP_RESPONSE_CODE_FORBIDDEN = 403,
HTTP_RESPONSE_CODE_NOT_FOUND = 404,
HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED = 405,
HTTP_RESPONSE_CODE_REQUEST_TIMEOUT = 408,
HTTP_RESPONSE_CODE_406_NOT_ACCEPTED = 406,
HTTP_RESPONSE_CODE_CONFLICT = 409,
HTTP_RESPONSE_CODE_GONE = 410,
HTTP_RESPONSE_CODE_LENGTH_REQUIRED = 411,
HTTP_RESPONSE_CODE_PRECONDITION_FAILED = 412,
HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE = 413,
HTTP_RESPONSE_CODE_URI_TOO_LONG = 414,
HTTP_RESPONSE_CODE_OK = 200,
HTTP_RESPONSE_CODE_CREATED = 201,
HTTP_RESPONSE_CODE_ACCEPTED = 202,
HTTP_RESPONSE_CODE_NO_CONTENT = 204,
HTTP_RESPONSE_CODE_BAD_REQUEST = 400,
HTTP_RESPONSE_CODE_UNAUTHORIZED = 401,
HTTP_RESPONSE_CODE_FORBIDDEN = 403,
HTTP_RESPONSE_CODE_NOT_FOUND = 404,
HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED = 405,
HTTP_RESPONSE_CODE_REQUEST_TIMEOUT = 408,
HTTP_RESPONSE_CODE_406_NOT_ACCEPTED = 406,
HTTP_RESPONSE_CODE_CONFLICT = 409,
HTTP_RESPONSE_CODE_GONE = 410,
HTTP_RESPONSE_CODE_LENGTH_REQUIRED = 411,
HTTP_RESPONSE_CODE_PRECONDITION_FAILED = 412,
HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE = 413,
HTTP_RESPONSE_CODE_URI_TOO_LONG = 414,
HTTP_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS = 429,
HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500,
HTTP_RESPONSE_CODE_NOT_IMPLEMENTED = 501,
HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE = 503,
HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT = 504
HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS = 429,
HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500,
HTTP_RESPONSE_CODE_NOT_IMPLEMENTED = 501,
HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE = 503,
HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT = 504
};
#define NAUSF_AUTH_BASE "/nausf-auth/"
......
......@@ -24,22 +24,23 @@
#include <boost/asio.hpp>
#include <iostream>
bool fqdn::resolve(
const std::string& host_name, std::string& address, uint32_t& port,
uint8_t& addr_type, const std::string& protocol) {
bool fqdn::resolve(const std::string &host_name, std::string &address,
uint32_t &port, uint8_t &addr_type,
const std::string &protocol) {
try {
Logger::ausf_app().debug("Resolving DNS:- %s", host_name.c_str());
boost::asio::io_context io_context = {};
boost::asio::ip::tcp::resolver resolver{io_context};
boost::asio::ip::tcp::resolver::results_type endpoints =
resolver.resolve(host_name, protocol);
addr_type = 0; // IPv4 by default
addr_type = 0; // IPv4 by default
for (auto it = endpoints.cbegin(); it != endpoints.cend(); it++) {
// get the first Endpoint
boost::asio::ip::tcp::endpoint endpoint = *it;
address = endpoint.address().to_string();
port = endpoint.port();
address = endpoint.address().to_string();
port = endpoint.port();
Logger::ausf_app().debug(
"Resolve a DNS (name %s, protocol %s): Ip Addr %s, port %u",
host_name.c_str(), protocol.c_str(), address.c_str(), port);
......@@ -49,9 +50,9 @@ bool fqdn::resolve(
addr_type = 1;
return true;
}
} catch (std::exception& e) {
throw std::runtime_error(
"Cannot resolve a DNS name " + std::string(e.what()));
} catch (std::exception &e) {
throw std::runtime_error("Cannot resolve a DNS name " +
std::string(e.what()));
return false;
}
......
......@@ -14,11 +14,11 @@
* limitations under the License.
*/
#include "logger.hpp"
#include "ausf-api-server.h"
#include "ausf-http2-server.h"
#include "ausf_config.hpp"
#include "ausf_app.hpp"
#include "ausf_config.hpp"
#include "logger.hpp"
#include "options.hpp"
#include "pid_file.hpp"
......@@ -26,12 +26,12 @@
#include "pistache/http.h"
#include "pistache/router.h"
#include <iostream>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h> // srand
#include <unistd.h> // get_pid(), pause()
#include <iostream>
#include <stdlib.h> // srand
#include <thread>
#include <unistd.h> // get_pid(), pause()
using namespace oai::ausf::app;
using namespace util;
......@@ -40,9 +40,9 @@ using namespace std;
using namespace config;
ausf_config ausf_cfg;
ausf_app* ausf_app_inst = nullptr;
AUSFApiServer* api_server = nullptr;
ausf_http2_server* ausf_api_server_2 = nullptr;
ausf_app *ausf_app_inst = nullptr;
AUSFApiServer *api_server = nullptr;
ausf_http2_server *ausf_api_server_2 = nullptr;
//------------------------------------------------------------------------------
void my_app_signal_handler(int s) {
......@@ -68,7 +68,7 @@ void my_app_signal_handler(int s) {
}
//------------------------------------------------------------------------------
int main(int argc, char** argv) {
int main(int argc, char **argv) {
srand(time(NULL));
// Command line options
......@@ -87,42 +87,49 @@ int main(int argc, char** argv) {
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
// Event subsystem
ausf_event ev;
// Config
ausf_cfg.load(Options::getlibconfigConfig());
ausf_cfg.display();
// AUSF application layer
ausf_app_inst = new ausf_app(Options::getlibconfigConfig());
ausf_app_inst = new ausf_app(Options::getlibconfigConfig(), ev);
// Task Manager
task_manager tm(ev);
std::thread task_manager_thread(&task_manager::run, &tm);
// PID file
// Currently hard-coded value. TODO: add as config option.
string pid_file_name = get_exe_absolute_path("/var/run", ausf_cfg.instance);
if (!is_pid_file_lock_success(pid_file_name.c_str())) {
Logger::ausf_server().error(
"Lock PID file %s failed\n", pid_file_name.c_str());
Logger::ausf_server().error("Lock PID file %s failed\n",
pid_file_name.c_str());
exit(-EDEADLK);
}
// AUSF Pistache API server (HTTP1)
Pistache::Address addr(
std::string(inet_ntoa(*((struct in_addr*) &ausf_cfg.sbi.addr4))),
std::string(inet_ntoa(*((struct in_addr *)&ausf_cfg.sbi.addr4))),
Pistache::Port(ausf_cfg.sbi.port));
api_server = new AUSFApiServer(addr, ausf_app_inst);
api_server->init(2);
std::thread ausf_manager(&AUSFApiServer::start, api_server);
// AUSF NGHTTP API server (HTTP2)
ausf_api_server_2 = new ausf_http2_server(
conv::toString(ausf_cfg.sbi.addr4), ausf_cfg.sbi_http2_port,
ausf_app_inst);
ausf_api_server_2 =
new ausf_http2_server(conv::toString(ausf_cfg.sbi.addr4),
ausf_cfg.sbi_http2_port, ausf_app_inst);
std::thread ausf_http2_manager(&ausf_http2_server::start, ausf_api_server_2);
ausf_manager.join();
ausf_http2_manager.join();
FILE* fp = NULL;
FILE *fp = NULL;
std::string filename = fmt::format("/tmp/ausf_{}.status", getpid());
fp = fopen(filename.c_str(), "w+");
fp = fopen(filename.c_str(), "w+");
fprintf(fp, "STARTED\n");
fflush(fp);
fclose(fp);
......
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