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

add nrf app

parent 1c902c5c
......@@ -12,7 +12,7 @@ NRF_CONF[@INSTANCE@]=$INSTANCE
NRF_CONF[@PREFIX@]=$PREFIX
NRF_CONF[@PID_DIRECTORY@]='/var/run'
NRF_CONF[@NRF_INTERFACE_NAME_FOR_SBI@]='ens3'
NRF_CONF[@NRF_INTERFACE_NAME_FOR_SBI@]='wlp2s0'
NRF_CONF[@NRF_INTERFACE_PORT_FOR_SBI@]='80'
NRF_CONF[@NRF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
......
......@@ -36,28 +36,6 @@
#define RETURNerror (int)1
#define RETURNok (int)0
typedef enum {
/* Fatal errors - received message should not be processed */
TLV_MAC_MISMATCH = -14,
TLV_BUFFER_NULL = -13,
TLV_BUFFER_TOO_SHORT = -12,
TLV_PROTOCOL_NOT_SUPPORTED = -11,
TLV_WRONG_MESSAGE_TYPE = -10,
TLV_OCTET_STRING_TOO_LONG_FOR_IEI = -9,
TLV_VALUE_DOESNT_MATCH = -4,
TLV_MANDATORY_FIELD_NOT_PRESENT = -3,
TLV_UNEXPECTED_IEI = -2,
// RETURNerror = -1,
// RETURNok = 0,
TLV_ERROR_OK = RETURNok,
/* Defines error code limit below which received message should be discarded
* because it cannot be further processed */
TLV_FATAL_ERROR = TLV_VALUE_DOESNT_MATCH
} error_code_e;
//------------------------------------------------------------------------------
#define DECODE_U8(bUFFER, vALUE, sIZE) \
vALUE = *(uint8_t*)(bUFFER); \
......
......@@ -23,7 +23,7 @@
#include <memory>
Logger *Logger::m_singleton = NULL;
//------------------------------------------------------------------------------
void Logger::_init(const char *app, const bool log_stdout,
bool const log_rot_file) {
int num_sinks = 0;
......@@ -46,9 +46,8 @@ void Logger::_init(const char *app, const bool log_stdout,
if (log_rot_file) {
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back(
std::make_shared<spdlog::sinks::rotating_file_sink_mt>(filename,
5 * 1024 * 1024,
3));
std::make_shared < spdlog::sinks::rotating_file_sink_mt
> (filename, 5 * 1024 * 1024, 3));
m_sinks[num_sinks++].get()->set_level(llevel);
}
......@@ -59,13 +58,10 @@ void Logger::_init(const char *app, const bool log_stdout,
m_itti = new _Logger("itti ", m_sinks, ss.str().c_str());
m_nrf_app = new _Logger("nrf_app", m_sinks, ss.str().c_str());
m_system = new _Logger("system ", m_sinks, ss.str().c_str());
m_nrf_n11 = new _Logger("nrf_n11", m_sinks, ss.str().c_str());
m_nrf_sbi = new _Logger("sbi_srv", m_sinks, ss.str().c_str());
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
_Logger::_Logger(const char *category, std::vector<spdlog::sink_ptr> &sinks,
const char *pattern)
:
......@@ -82,6 +78,7 @@ _Logger::_Logger(const char *category, std::vector<spdlog::sink_ptr> &sinks,
#endif
}
//------------------------------------------------------------------------------
void _Logger::trace(const char *format, ...) {
#if TRACE_IS_ON
va_list args;
......@@ -91,6 +88,7 @@ void _Logger::trace(const char *format, ...) {
#endif
}
//------------------------------------------------------------------------------
void _Logger::debug(const char *format, ...) {
#if DEBUG_IS_ON
va_list args;
......@@ -100,6 +98,7 @@ void _Logger::debug(const char *format, ...) {
#endif
}
//------------------------------------------------------------------------------
void _Logger::info(const char *format, ...) {
#if INFO_IS_ON
va_list args;
......@@ -109,6 +108,7 @@ void _Logger::info(const char *format, ...) {
#endif
}
//------------------------------------------------------------------------------
void _Logger::startup(const char *format, ...) {
va_list args;
va_start(args, format);
......@@ -116,6 +116,7 @@ void _Logger::startup(const char *format, ...) {
va_end(args);
}
//------------------------------------------------------------------------------
void _Logger::warn(const char *format, ...) {
va_list args;
va_start(args, format);
......@@ -123,6 +124,7 @@ void _Logger::warn(const char *format, ...) {
va_end(args);
}
//------------------------------------------------------------------------------
void _Logger::error(const char *format, ...) {
va_list args;
va_start(args, format);
......@@ -130,6 +132,7 @@ void _Logger::error(const char *format, ...) {
va_end(args);
}
//------------------------------------------------------------------------------
void _Logger::log(_LogType lt, const char *format, va_list &args) {
char buffer[2048];
......
......@@ -98,9 +98,6 @@ class Logger {
static _Logger& system() {
return *singleton().m_system;
}
static _Logger& nrf_n11() {
return *singleton().m_nrf_n11;
}
static _Logger& nrf_sbi() {
return *singleton().m_nrf_sbi;
}
......@@ -128,7 +125,6 @@ class Logger {
_Logger *m_itti;
_Logger *m_nrf_app;
_Logger *m_system;
_Logger *m_nrf_n11;
_Logger *m_nrf_sbi;
};
......
......@@ -27,6 +27,7 @@ include_directories(${SRC_TOP_DIR}/api-server/model)
include_directories(${SRC_TOP_DIR}/api-server/)
add_library (NRF STATIC
nrf_app.cpp
nrf_config.cpp
)
......@@ -19,7 +19,7 @@
* contact@openairinterface.org
*/
/*! \file smf_app.cpp
/*! \file nrf_app.cpp
\brief
\author Lionel GAUTHIER, Tien-Thinh NGUYEN
\company Eurecom
......@@ -28,5 +28,19 @@
*/
#include "nrf_app.hpp"
#include "common_defs.h"
#include "nrf_config.hpp"
#include "logger.hpp"
using namespace oai::nrf;
extern nrf_app *nrf_app_inst;
extern nrf_config nrf_cfg;
//------------------------------------------------------------------------------
nrf_app::nrf_app(const std::string &config_file)
{
Logger::nrf_app().startup("Starting...");
Logger::nrf_app().startup("Started");
}
......@@ -29,9 +29,18 @@
#ifndef FILE_NRF_APP_HPP_SEEN
#define FILE_NRF_APP_HPP_SEEN
#include <string>
namespace oai{
namespace nrf {
class nrf_app{
class nrf_config;
class nrf_app {
public:
explicit nrf_app(const std::string &config_file);
nrf_app(nrf_app const&) = delete;
void operator=(nrf_app const&) = delete;
};
}
......
......@@ -51,7 +51,6 @@
#include "logger.hpp"
#include "nrf_app.hpp"
using namespace std;
using namespace libconfig;
using namespace oai::nrf;
......@@ -74,7 +73,7 @@ int nrf_config::load_interface(const Setting &if_cfg, interface_cfg_t &cfg) {
return RETURNerror ;
}
} else {
std::vector<std::string> words;
std::vector < std::string > words;
boost::split(words, address, boost::is_any_of("/"),
boost::token_compress_on);
if (words.size() != 2) {
......@@ -83,7 +82,7 @@ int nrf_config::load_interface(const Setting &if_cfg, interface_cfg_t &cfg) {
address.c_str());
return RETURNerror ;
}
unsigned char buf_in_addr[sizeof(struct in6_addr)]; // you never know...
unsigned char buf_in_addr[sizeof(struct in6_addr)];
if (inet_pton(AF_INET, util::trim(words.at(0)).c_str(), buf_in_addr)
== 1) {
memcpy(&cfg.addr4, buf_in_addr, sizeof(struct in_addr));
......@@ -146,7 +145,6 @@ int nrf_config::load(const string &config_file) {
nfex.getPath());
}
try {
const Setting &sbi_cfg = nrf_cfg[NRF_CONFIG_STRING_INTERFACE_SBI];
......@@ -169,7 +167,6 @@ int nrf_config::load(const string &config_file) {
return RETURNerror ;
}
return true;
}
......@@ -181,20 +178,17 @@ void nrf_config::display() {
Logger::nrf_app().info("- Instance ..............: %d\n", instance);
Logger::nrf_app().info("- PID dir ...............: %s\n", pid_dir.c_str());
Logger::nrf_app().info("- SBI Networking:");
Logger::nrf_app().info("- SBI Interface:");
Logger::nrf_app().info(" Interface name ......: %s", sbi.if_name.c_str());
Logger::nrf_app().info(" IPv4 Addr ...........: %s",
inet_ntoa(sbi.addr4));
Logger::nrf_app().info(" IPv4 Addr ...........: %s", inet_ntoa(sbi.addr4));
Logger::nrf_app().info(" Port ................: %d", sbi.port);
Logger::nrf_app().info(" HTTP2 port ..........: %d", sbi_http2_port);
Logger::nrf_app().info(" API version..........: %s", sbi_api_version.c_str());
Logger::nrf_app().info(" API version..........: %s",
sbi_api_version.c_str());
}
//------------------------------------------------------------------------------
nrf_config::~nrf_config() {
}
......@@ -37,7 +37,6 @@
#include <mutex>
#include <vector>
//#include "thread_sched.hpp"
#define NRF_CONFIG_STRING_NRF_CONFIG "NRF"
#define NRF_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY"
......@@ -45,7 +44,7 @@
#define NRF_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME"
#define NRF_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS"
#define NRF_CONFIG_STRING_PORT "PORT"
#define NRF_CONFIG_STRING_INTERFACE_SBI "SBI"
#define NRF_CONFIG_STRING_INTERFACE_SBI "SBI_INTERFACE"
#define NRF_CONFIG_STRING_SBI_HTTP2_PORT "HTTP2_PORT"
#define NRF_CONFIG_STRING_API_VERSION "API_VERSION"
......
......@@ -14,11 +14,11 @@
* limitations under the License.
*/
#include "nrf_app.hpp"
#include "nrf-api-server.h"
#include "options.hpp"
#include "pid_file.hpp"
#include "nrf-api-server.h"
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
......@@ -33,7 +33,7 @@
#include "logger.hpp"
using namespace oai::nrf;
//using namespace util;
using namespace util;
using namespace std;
//using namespace oai::nrf_server::api;
......@@ -120,16 +120,16 @@ int main(int argc, char **argv)
// async_shell_cmd_inst = new async_shell_cmd(nrf_cfg.itti.async_cmd_sched_params);
// SMF application layer
// nrf_app_inst = new nrf_app(Options::getlibconfigConfig());
nrf_app_inst = new nrf_app(Options::getlibconfigConfig());
// PID file
// Currently hard-coded value. TODO: add as config option.
/* string pid_file_name = get_exe_absolute_path("/var/run", nrf_cfg.instance);
string pid_file_name = get_exe_absolute_path("/var/run", nrf_cfg.instance);
if (! is_pid_file_lock_success(pid_file_name.c_str())) {
Logger::nrf_app().error( "Lock PID file %s failed\n", pid_file_name.c_str());
exit (-EDEADLK);
}
*/
/*
//SMF Pistache API server (HTTP1)
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&nrf_cfg.sbi.addr4))) , Pistache::Port(nrf_cfg.sbi.port));
......@@ -139,14 +139,14 @@ int main(int argc, char **argv)
std::thread nrf_http1_manager(&SMFApiServer::start, nrf_api_server_1);
nrf_http1_manager.join();
*/
/*
FILE *fp = NULL;
std::string filename = fmt::format("/tmp/nrf_{}.status", getpid());
fp = fopen(filename.c_str(), "w+");
fprintf(fp, "STARTED\n");
fflush(fp);
fclose(fp);
*/
pause();
return 0;
}
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