Commit 50e5e5ce authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'fix-clang-format' into 'develop'

fix(style): rohan removed the clang-format file in January

See merge request oai/cn5g/oai-cn5g-ausf!22
parents 61f2e615 0c2195b0
......@@ -139,6 +139,16 @@ then
exit 1
fi
# When running in a container, in /home folder
IS_CONTAINER=`egrep -c "docker|kubepods|podman|buildah|libpod" /proc/self/cgroup || true`
if [ $IS_CONTAINER -ne 0 ]
then
if [ $PWD = "/home/src" ]
then
git config --global --add safe.directory /home
fi
fi
# Merge request scenario
MERGE_COMMMIT=`git log -n1 --pretty=format:%H`
......
#
# 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)
......@@ -41,10 +41,10 @@ namespace ausf_server {
namespace model {
PatchItem::PatchItem() {
m_Path = "";
m_From = "";
m_Value = "";
m_FromIsSet = false;
m_Path = "";
m_From = "";
m_Value = "";
m_FromIsSet = false;
m_ValueIsSet = false;
}
......@@ -54,17 +54,15 @@ void PatchItem::validate() {
// TODO: implement validation
}
void to_json(nlohmann::json &j, const PatchItem &o) {
j = nlohmann::json();
j["op"] = o.m_Op;
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;
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) {
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()) {
......@@ -77,25 +75,45 @@ void from_json(const nlohmann::json &j, PatchItem &o) {
}
}
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;
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;
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; }
bool PatchItem::valueIsSet() const {
return m_ValueIsSet;
}
void PatchItem::unsetValue() {
m_ValueIsSet = false;
}
} // namespace model
} // namespace ausf_server
} // namespace oai
} // namespace model
} // namespace ausf_server
} // namespace oai
......@@ -53,7 +53,7 @@ namespace model {
///
/// </summary>
class PatchItem {
public:
public:
PatchItem();
virtual ~PatchItem();
......@@ -66,31 +66,31 @@ public:
///
/// </summary>
std::string getOp() const;
void setOp(std::string const &value);
void setOp(std::string const& value);
/// <summary>
///
/// </summary>
std::string getPath() const;
void setPath(std::string const &value);
void setPath(std::string const& value);
/// <summary>
///
/// </summary>
std::string getFrom() const;
void setFrom(std::string const &value);
void setFrom(std::string const& value);
bool fromIsSet() const;
void unsetFrom();
/// <summary>
///
/// </summary>
std::string getValue() const;
void setValue(std::string const &value);
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);
friend void to_json(nlohmann::json& j, const PatchItem& o);
friend void from_json(const nlohmann::json& j, PatchItem& o);
protected:
protected:
std::string m_Op;
std::string m_Path;
......@@ -101,8 +101,8 @@ protected:
bool m_ValueIsSet;
};
} // namespace model
} // namespace ausf_server
} // namespace oai
} // namespace model
} // namespace ausf_server
} // namespace oai
#endif /* PatchItem_H_ */
......@@ -45,12 +45,12 @@ void PatchOperation::validate() {
// TODO: implement validation
}
void to_json(nlohmann::json &j, const PatchOperation &o) {
void to_json(nlohmann::json& j, const PatchOperation& o) {
j = nlohmann::json();
}
void from_json(const nlohmann::json &j, PatchOperation &o) {}
void from_json(const nlohmann::json& j, PatchOperation& o) {}
} // namespace model
} // namespace ausf_server
} // namespace oai
} // namespace model
} // namespace ausf_server
} // namespace oai
......@@ -55,7 +55,7 @@ namespace model {
///
/// </summary>
class PatchOperation {
public:
public:
PatchOperation();
virtual ~PatchOperation();
......@@ -64,14 +64,14 @@ public:
/////////////////////////////////////////////
/// PatchOperation members
friend void to_json(nlohmann::json &j, const PatchOperation &o);
friend void from_json(const nlohmann::json &j, PatchOperation &o);
friend void to_json(nlohmann::json& j, const PatchOperation& o);
friend void from_json(const nlohmann::json& j, PatchOperation& o);
protected:
protected:
};
} // namespace model
} // namespace ausf_server
} // namespace oai
} // namespace model
} // namespace ausf_server
} // namespace oai
#endif /* PatchOperation_H_ */
This diff is collapsed.
......@@ -47,58 +47,57 @@ 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_event &ev);
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:
ausf_event &event_sub;
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;
......@@ -110,9 +109,9 @@ private:
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 */
......@@ -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(std::string remoteUri, std::string method,
// 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(std::string remoteUri, std::string method,
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(std::string remoteUri, std::string method,
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");
......
......@@ -42,17 +42,18 @@ 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.
......@@ -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 @@ public:
bool use_http2;
};
} // namespace config
} // namespace config
#endif
......@@ -30,28 +30,26 @@
#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) {
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);
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) {
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) {
const ue_reachability_for_data_sig_t::slot_type& sig) {
return ue_reachability_for_data.connect(sig);
}
......@@ -40,12 +40,12 @@ namespace bs2 = boost::signals2;
namespace oai::ausf::app {
class task_manager;
class ausf_event {
public:
public:
ausf_event(){};
ausf_event(ausf_event const &) = delete;
void operator=(ausf_event const &) = delete;
ausf_event(ausf_event const&) = delete;
void operator=(ausf_event const&) = delete;
static ausf_event &get_instance() {
static ausf_event& get_instance() {
static ausf_event instance;
return instance;
}
......@@ -63,9 +63,8 @@ public:
* @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);
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
......@@ -75,7 +74,7 @@ public:
* the slot
*/
bs2::connection subscribe_loss_of_connectivity(
const loss_of_connectivity_sig_t::slot_type &sig);
const loss_of_connectivity_sig_t::slot_type& sig);
/*
* Subscribe to UE Reachability for Data signal
......@@ -85,15 +84,15 @@ public:
* the slot
*/
bs2::connection subscribe_ue_reachability_for_data(
const ue_reachability_for_data_sig_t::slot_type &sig);
const ue_reachability_for_data_sig_t::slot_type& sig);
private:
private:
task_sig_t task_tick;
loss_of_connectivity_sig_t
loss_of_connectivity; // Signal for Loss of Connectivity Report
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
ue_reachability_for_data; // Signal for UE Reachability for Data Report
};
} // namespace oai::ausf::app
} // namespace oai::ausf::app
#endif
......@@ -37,20 +37,22 @@ namespace bs2 = boost::signals2;
namespace oai::ausf::app {
typedef bs2::signal_type<void(uint64_t),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
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
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
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
......@@ -61,5 +63,5 @@ typedef bs2::signal_type<void(std::string, uint8_t, uint8_t),
// AVAILABILITY_AFTER_DNN_FAILURE
// CN_TYPE_CHANGE
} // namespace oai::ausf::app
} // namespace oai::ausf::app
#endif
......@@ -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_event &ev) : m_event_sub(ev) {}
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_profile &ausf_nf_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_profile &ausf_nf_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,7 +95,7 @@ void ausf_nrf::generate_ausf_profile(ausf_profile &ausf_nf_profile,
//---------------------------------------------------------------------------------------------
void ausf_nrf::register_to_nrf() {
// generate UUID
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
......@@ -104,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;
......@@ -113,8 +113,8 @@ 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);
......@@ -122,22 +122,22 @@ void ausf_nrf::register_to_nrf() {
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) {
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
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
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),
......@@ -155,8 +155,8 @@ void ausf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) {
patch_items.push_back(patch_item);
Logger::ausf_nrf().info("Sending NF heartbeat request");
std::string response = {};
std::string method = {"PATCH"};
std::string response = {};
std::string method = {"PATCH"};
nlohmann::json json_data = nlohmann::json::array();
for (auto i : patch_items) {
nlohmann::json item = {};
......@@ -168,8 +168,7 @@ void ausf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) {
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();
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
......@@ -47,15 +47,15 @@ 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_event &ev);
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();
/*
......@@ -63,7 +63,7 @@ public:
* @param [void]
* @return void
*/
void start_event_nf_heartbeat(std::string &remoteURI);
void start_event_nf_heartbeat(std::string& remoteURI);
/*
* Trigger NF heartbeat procedure
* @param [void]
......@@ -75,8 +75,8 @@ public:
* @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
......@@ -89,13 +89,13 @@ public:
* @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;
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.
......@@ -45,33 +45,44 @@ 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;
......@@ -85,13 +96,13 @@ public:
* @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
......@@ -105,14 +116,14 @@ public:
* @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
......@@ -126,14 +137,14 @@ public:
* @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
......@@ -154,21 +165,21 @@ public:
* @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
......@@ -182,14 +193,14 @@ public:
* @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
......@@ -203,14 +214,14 @@ public:
* @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
......@@ -224,21 +235,21 @@ public:
* @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
......@@ -252,42 +263,42 @@ public:
* @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
......@@ -301,14 +312,14 @@ public:
* @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
......@@ -317,7 +328,7 @@ public:
*/
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;
......@@ -332,8 +343,8 @@ protected:
ausf_info_t ausf_info;
};
} // namespace app
} // namespace ausf
} // namespace oai
} // namespace app
} // namespace ausf
} // namespace oai
#endif
......@@ -38,15 +38,15 @@
using namespace oai::ausf::app;
//------------------------------------------------------------------------------
task_manager::task_manager(ausf_event &ev) : event_sub_(ev) {
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_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) {
......@@ -55,7 +55,9 @@ task_manager::task_manager(ausf_event &ev) : event_sub_(ev) {
}
//------------------------------------------------------------------------------
void task_manager::run() { manage_tasks(); }
void task_manager::run() {
manage_tasks();
}
//------------------------------------------------------------------------------
void task_manager::manage_tasks() {
......
......@@ -43,8 +43,8 @@ namespace app {
class ausf_event;
class task_manager {
public:
task_manager(ausf_event &ev);
public:
task_manager(ausf_event& ev);
/*
* Manage the tasks
......@@ -60,7 +60,7 @@ public:
*/
void run();
private:
private:
/*
* Make sure that the task tick run every 1ms
* @param [void]
......@@ -68,11 +68,11 @@ private:
*/
void wait_for_cycle();
ausf_event &event_sub_;
ausf_event& event_sub_;
int sfd;
};
} // namespace app
} // namespace ausf
} // namespace oai
} // namespace app
} // namespace ausf
} // namespace oai
#endif
......@@ -24,32 +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;
......@@ -59,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;
......@@ -73,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];
......@@ -86,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,9 +24,9 @@
#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 = {};
......@@ -35,12 +35,12 @@ bool fqdn::resolve(const std::string &host_name, std::string &address,
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);
......@@ -50,9 +50,9 @@ bool fqdn::resolve(const std::string &host_name, std::string &address,
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;
}
......
......@@ -29,9 +29,9 @@
#include <iostream>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h> // srand
#include <stdlib.h> // srand
#include <thread>
#include <unistd.h> // get_pid(), pause()
#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
......@@ -105,31 +105,31 @@ int main(int argc, char **argv) {
// 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