Commit 840e6403 authored by LiBingxuan's avatar LiBingxuan

modify some code and update README.md

parent f74a9eb1
# OpenXG-UDR
<img src="README.assets/openxglogo.png" alt="OpenXG" style="zoom: 100;" />
# 1. Generals
OpenXG is a series of 5G/6G-oriented open source projects developed by Open Source Radio Access Network Community. Currently, the community has developed the project from five aspects, including:
* Core network projects, 3GPP R15/R16 specification compliant network functions have been developed, including AMF, SMF, NRF, UPF, AUSF, UDM, AUSF, NWDAF, etc. Message level stateless mechanism is introduced in to the core network to make it better adapted to the cloud environment.
* Open hardware reference design, the reference design of heterogeneous computing hardware, white-box radio frontend, and open source UE hardware are also opened to the community.
* Radio access network projects, currently CU, DU and UE protocol software are developed, which is mainly compliant with 3GPP R15/R16 specifications. The software is developed by a modular-design, and which is flexible to customize to different vertical scenarios.
* AI-enabled management projects, three kinds of projects are developed under this category, including the AIEngine, which is aimed to provide the core AI capability for the management, the network measurement, and computing network for cloud-edge-end collaborative.
* Uses cases and applications in verticals, some key use cases when applying OpenXG to vertical scenarios are also developed as a reference for the community.
# 2. License
The OpenXG series projects are distributed under OS-RAN license, which is derived from the Fair, Reasonable, and Non-Discriminatory principle. See [online version for details](http://www.openxg.org.cn/?falu_69.html).
OpenXG-UDR Arch
```
├── build: Build directory, contains targets and object files generated by compilation of network functions.
├── scripts: Directory containing scripts for building network functions.
├── ext: Directory containing spdlog and pistache and the JSON library.
└── UDR: Directory containing object files generated by compilation of UDR network function.
├── etc: Directory containing the configuration file to be deployed for UDR.
└── src: Source files of UDR.
├── udr_app: UDR Procedures handling logic.
├── common: Common definitions for 3GPP specifications.
├── model: UDR service.
├── api: UDR service.
└── impl: UDR service.
```
# 3. How to start
## Download source code from Gitlab
```
git clone http://git.opensource5g.org/openxg/openxg-udr.git
git clone http://git.opensource5g.org/openxg/udr.git
cd openxg-udr/
```
As master branch is usually the stable branch, so we would suggest you start from the master:
```
git checkout master
```
## install dependencies
OpenXG-UDR relies on some third-party software or libraries, please install the dependencies when you first build the project, run by:
```
cd ./build/scripts
sudo ./build_udr -I
```
## build UDR
When you finish install the dependencies, you can finally build the UDR executables by:
```
sudo ./build_udr -c -b Debug -j
```
## launch UDR
UDR executable files will be installed to /usr/local/bin/ by default, you can run UDR by simply type:
```
sudo ./build/UDR/udr -c etc/udr.conf -o
```
\ No newline at end of file
sudo udr -c etc/udr.conf -o
```
etc/udr.conf is the config file for UDR.
Customize the config file according to your environments.
Enjoy.
################################################################################
# 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
# brief
# author Jian Yang
# date 2020
# email: contact@openairinterface.org
# Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
# Software Alliance under one or more contributor license agreements. The
# initial OpenXG series projects are derided from OAI projects, the files from
# OAI projects are all in compliance with OAI Public License, Version 1.1.
# codes and files developed from OpenXG projects and from OS-RAN Alliance
# are all under OS-RAN licenses; you may not use this file except in compliance
# with the license. You may get a copy of the license at:
# http://www.openxg.org.cn/?falu_69.html
# For more information about OpenXG, please contact:
# contact@openxg.org.cn
################################################################################
## udr configuration file
......
################################################################################
# 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
# brief
# author Jian Yang
# date 2020
# email: contact@openairinterface.org
# Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
# Software Alliance under one or more contributor license agreements. The
# initial OpenXG series projects are derided from OAI projects, the files from
# OAI projects are all in compliance with OAI Public License, Version 1.1.
# codes and files developed from OpenXG projects and from OS-RAN Alliance
# are all under OS-RAN licenses; you may not use this file except in compliance
# with the license. You may get a copy of the license at:
# http://www.openxg.org.cn/?falu_69.html
# For more information about OpenXG, please contact:
# contact@openxg.org.cn
################################################################################
## udr configuration file
......
/*
* 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 logger.cpp
\brief
\date 2020
\email: contact@openairinterface.org
* Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
* Software Alliance under one or more contributor license agreements. The
* initial OpenXG series projects are derided from OAI projects, the files from
* OAI projects are all in compliance with OAI Public License, Version 1.1.
* codes and files developed from OpenXG projects and from OS-RAN Alliance
* are all under OS-RAN licenses; you may not use this file except in compliance
* with the license. You may get a copy of the license at:
* http://www.openxg.org.cn/?falu_69.html
* For more information about OpenXG, please contact:
* contact@openxg.org.cn
*/
#include "logger.hpp"
......
/*
* 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 logger.hpp
\brief
\date 2020
\email: contact@openairinterface.org
* Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
* Software Alliance under one or more contributor license agreements. The
* initial OpenXG series projects are derided from OAI projects, the files from
* OAI projects are all in compliance with OAI Public License, Version 1.1.
* codes and files developed from OpenXG projects and from OS-RAN Alliance
* are all under OS-RAN licenses; you may not use this file except in compliance
* with the license. You may get a copy of the license at:
* http://www.openxg.org.cn/?falu_69.html
* For more information about OpenXG, please contact:
* contact@openxg.org.cn
*/
#ifndef __LOGGER_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
* Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
* Software Alliance under one or more contributor license agreements. The
* initial OpenXG series projects are derided from OAI projects, the files from
* OAI projects are all in compliance with OAI Public License, Version 1.1.
* codes and files developed from OpenXG projects and from OS-RAN Alliance
* are all under OS-RAN licenses; you may not use this file except in compliance
* with the license. You may get a copy of the license at:
* http://www.openxg.org.cn/?falu_69.html
* For more information about OpenXG, please contact:
* contact@openxg.org.cn
*/
/*! file
......
#include "udr_config.hpp"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#include <iostream>
#include <libconfig.h++>
#include "logger.hpp"
using namespace libconfig;
namespace config {
udr_config::udr_config() {api_version = "v2";}
udr_config::~udr_config() {}
int udr_config::load(const std ::string &config_file) {
Logger::udr_app().debug("\nLoad UDR system configuration file(%s)",
config_file.c_str());
Config cfg;
try {
cfg.readFile(config_file.c_str());
} catch (const FileIOException &fioex) {
Logger::udr_app().error("I/O error while reading file %s - %s",
config_file.c_str(), fioex.what());
throw;
} catch (const ParseException &pex) {
Logger::udr_app().error("Parse error at %s:%d - %s", pex.getFile(),
pex.getLine(), pex.getError());
throw;
}
const Setting &root = cfg.getRoot();
try {
const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG];
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(), nfex.getPath());
return -1;
}
const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG];
try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_INSTANCE_ID, instance);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath());
}
try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_PID_DIRECTORY, pid_dir);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath());
}
try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_API_VERSION, api_version);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath());
}
try {
const Setting &new_if_cfg = udr_cfg[UDR_CONFIG_STRING_INTERFACES];
const Setting &sbi_cfg = new_if_cfg[UDR_CONFIG_STRING_INTERFACE_SBI];
load_interface(sbi_cfg, sbi);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath());
return -1;
}
try {
const Setting &mysql_cfg = udr_cfg[UDR_CONFIG_STRING_MYSQL];
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_SERVER, mysql.mysql_server);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_USER, mysql.mysql_user);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_PASS, mysql.mysql_pass);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_DB, mysql.mysql_db);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_PORT, mysql.mysql_port);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath());
return -1;
}
return 0;
}
int udr_config::getip(std::string &ip, std::string &ifname)
{
int sock;
struct sockaddr_in sin;
struct ifreq ifr;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
{
perror("socket");
return -1;
}
strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0;
if (ioctl(sock, SIOCGIFADDR, &ifr) < 0)
{
perror("ioctl");
return -1;
}
memcpy(&sin, &ifr.ifr_addr, sizeof(sin));
printf("ip = %s",inet_ntoa(sin.sin_addr));
//sprintf(ip, "%s", inet_ntoa(sin.sin_addr));
ip = std::string(inet_ntoa(sin.sin_addr));
return 0;
}
int udr_config::load_interface(const libconfig::Setting &if_cfg,
interface_cfg_t &cfg) {
if_cfg.lookupValue(UDR_CONFIG_STRING_INTERFACE_NAME, cfg.if_name);
if_cfg.lookupValue(UDR_CONFIG_STRING_IPV4_ADDRESS, cfg.addr4);
if(!cfg.addr4.compare("read"))
{
if(getip(cfg.addr4,cfg.if_name) < 0) return -1;
}
if_cfg.lookupValue(UDR_CONFIG_STRING_PORT, cfg.port);
return 0;
}
void udr_config::display() {
Logger::config().info(
"====================== UDR =====================");
Logger::config().info("Configuration UDR:");
Logger::config().info("");
Logger::config().info(
"- Instance .........................................: %d", instance);
Logger::config().info(
"- PID dir ..........................................: %s",
pid_dir.c_str());
Logger::config().info(
"- API version ......................................: %s", api_version.c_str());
Logger::config().info("");
Logger::config().info("- SBI Networking:");
Logger::config().info(" iface ................: %s", sbi.if_name.c_str());
Logger::config().info(" ip ...................: %s", sbi.addr4.c_str());
Logger::config().info(" port .................: %d", sbi.port);
Logger::config().info("");
Logger::config().info("- Database Configuration:");
Logger::config().info(
"- MYSQL Server Addr.................................: %s",
mysql.mysql_server.c_str());
Logger::config().info(
"- MYSQL User .......................................: %s",
mysql.mysql_user.c_str());
Logger::config().info(
"- MYSQL Pass .......................................: %s",
mysql.mysql_pass.c_str());
Logger::config().info(
"- MYSQL DB .........................................: %s",
mysql.mysql_db.c_str());
Logger::config().info(
"- MYSQL Port .......................................: %d",
mysql.mysql_port);
Logger::config().info("");
}
} // namespace config
#include "udr_config.hpp"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#include <iostream>
#include <libconfig.h++>
#include "logger.hpp"
using namespace libconfig;
namespace config {
udr_config::udr_config() {api_version = "v2";}
udr_config::~udr_config() {}
int udr_config::load(const std ::string &config_file) {
Logger::udr_app().debug("\nLoad UDR system configuration file(%s)",
config_file.c_str());
Config cfg;
try {
cfg.readFile(config_file.c_str());
} catch (const FileIOException &fioex) {
Logger::udr_app().error("I/O error while reading file %s - %s",
config_file.c_str(), fioex.what());
throw;
} catch (const ParseException &pex) {
Logger::udr_app().error("Parse error at %s:%d - %s", pex.getFile(),
pex.getLine(), pex.getError());
throw;
}
const Setting &root = cfg.getRoot();
try {
const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG];
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(), nfex.getPath());
return -1;
}
const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG];
try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_INSTANCE_ID, instance);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath());
}
try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_PID_DIRECTORY, pid_dir);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath());
}
try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_API_VERSION, api_version);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath());
}
try {
const Setting &new_if_cfg = udr_cfg[UDR_CONFIG_STRING_INTERFACES];
const Setting &sbi_cfg = new_if_cfg[UDR_CONFIG_STRING_INTERFACE_SBI];
load_interface(sbi_cfg, sbi);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath());
return -1;
}
try {
const Setting &mysql_cfg = udr_cfg[UDR_CONFIG_STRING_MYSQL];
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_SERVER, mysql.mysql_server);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_USER, mysql.mysql_user);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_PASS, mysql.mysql_pass);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_DB, mysql.mysql_db);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_PORT, mysql.mysql_port);
} catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath());
return -1;
}
return 0;
}
int udr_config::getip(std::string &ip, std::string &ifname)
{
int sock;
struct sockaddr_in sin;
struct ifreq ifr;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
{
perror("socket");
return -1;
}
strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0;
if (ioctl(sock, SIOCGIFADDR, &ifr) < 0)
{
perror("ioctl");
return -1;
}
memcpy(&sin, &ifr.ifr_addr, sizeof(sin));
printf("ip = %s",inet_ntoa(sin.sin_addr));
//sprintf(ip, "%s", inet_ntoa(sin.sin_addr));
ip = std::string(inet_ntoa(sin.sin_addr));
return 0;
}
int udr_config::load_interface(const libconfig::Setting &if_cfg,
interface_cfg_t &cfg) {
if_cfg.lookupValue(UDR_CONFIG_STRING_INTERFACE_NAME, cfg.if_name);
if_cfg.lookupValue(UDR_CONFIG_STRING_IPV4_ADDRESS, cfg.addr4);
if(!cfg.addr4.compare("read"))
{
if(getip(cfg.addr4,cfg.if_name) < 0) return -1;
}
if_cfg.lookupValue(UDR_CONFIG_STRING_PORT, cfg.port);
return 0;
}
void udr_config::display() {
Logger::config().info(
"====================== UDR =====================");
Logger::config().info("Configuration UDR:");
Logger::config().info("");
Logger::config().info(
"- Instance .........................................: %d", instance);
Logger::config().info(
"- PID dir ..........................................: %s",
pid_dir.c_str());
Logger::config().info(
"- API version ......................................: %s", api_version.c_str());
Logger::config().info("");
Logger::config().info("- SBI Networking:");
Logger::config().info(" iface ................: %s", sbi.if_name.c_str());
Logger::config().info(" ip ...................: %s", sbi.addr4.c_str());
Logger::config().info(" port .................: %d", sbi.port);
Logger::config().info("");
Logger::config().info("- Database Configuration:");
Logger::config().info(
"- MYSQL Server Addr.................................: %s",
mysql.mysql_server.c_str());
Logger::config().info(
"- MYSQL User .......................................: %s",
mysql.mysql_user.c_str());
Logger::config().info(
"- MYSQL Pass .......................................: %s",
mysql.mysql_pass.c_str());
Logger::config().info(
"- MYSQL DB .........................................: %s",
mysql.mysql_db.c_str());
Logger::config().info(
"- MYSQL Port .......................................: %d",
mysql.mysql_port);
Logger::config().info("");
}
} // namespace config
#ifndef _UDR_CONFIG_H_
#define _UDR_CONFIG_H_
#include <libconfig.h++>
#include <string>
#define UDR_CONFIG_STRING_UDR_CONFIG "UDR"
#define UDR_CONFIG_STRING_INSTANCE_ID "INSTANCE_ID"
#define UDR_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY"
#define UDR_CONFIG_STRING_INTERFACES "INTERFACES"
#define UDR_CONFIG_STRING_INTERFACE_SBI "SBI"
#define UDR_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME"
#define UDR_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS"
#define UDR_CONFIG_STRING_PORT "PORT"
#define UDR_CONFIG_STRING_API_VERSION "API_VERSION"
#define UDR_CONFIG_STRING_MYSQL "MYSQL"
#define UDR_CONFIG_STRING_MYSQL_SERVER "MYSQL_SERVER"
#define UDR_CONFIG_STRING_MYSQL_USER "MYSQL_USER"
#define UDR_CONFIG_STRING_MYSQL_PASS "MYSQL_PASS"
#define UDR_CONFIG_STRING_MYSQL_DB "MYSQL_DB"
#define UDR_CONFIG_STRING_MYSQL_PORT "MYSQL_PORT"
using namespace libconfig;
namespace config {
typedef struct {
std::string mysql_server = "127.0.0.1";
std::string mysql_user = "yunshou";
std::string mysql_pass = "123456";
std::string mysql_db = "Witcomm-UDR-DB";
unsigned int mysql_port = 0;
} mysql_conf_t;
typedef struct interface_cfg_s {
std::string if_name;
std::string addr4;
unsigned int port;
} interface_cfg_t;
class udr_config {
public:
udr_config();
~udr_config();
int load(const std::string &config_file);
int getip(std::string &ip, std::string &ifname);
int load_interface(const Setting &if_cfg, interface_cfg_t &cfg);
void display();
unsigned int instance;
std::string pid_dir;
std::string api_version;
interface_cfg_t sbi;
mysql_conf_t mysql;
};
} // namespace config
#endif
#ifndef _UDR_CONFIG_H_
#define _UDR_CONFIG_H_
#include <libconfig.h++>
#include <string>
#define UDR_CONFIG_STRING_UDR_CONFIG "UDR"
#define UDR_CONFIG_STRING_INSTANCE_ID "INSTANCE_ID"
#define UDR_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY"
#define UDR_CONFIG_STRING_INTERFACES "INTERFACES"
#define UDR_CONFIG_STRING_INTERFACE_SBI "SBI"
#define UDR_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME"
#define UDR_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS"
#define UDR_CONFIG_STRING_PORT "PORT"
#define UDR_CONFIG_STRING_API_VERSION "API_VERSION"
#define UDR_CONFIG_STRING_MYSQL "MYSQL"
#define UDR_CONFIG_STRING_MYSQL_SERVER "MYSQL_SERVER"
#define UDR_CONFIG_STRING_MYSQL_USER "MYSQL_USER"
#define UDR_CONFIG_STRING_MYSQL_PASS "MYSQL_PASS"
#define UDR_CONFIG_STRING_MYSQL_DB "MYSQL_DB"
#define UDR_CONFIG_STRING_MYSQL_PORT "MYSQL_PORT"
using namespace libconfig;
namespace config {
typedef struct {
std::string mysql_server = "127.0.0.1";
std::string mysql_user = "yunshou";
std::string mysql_pass = "123456";
std::string mysql_db = "Witcomm-UDR-DB";
unsigned int mysql_port = 0;
} mysql_conf_t;
typedef struct interface_cfg_s {
std::string if_name;
std::string addr4;
unsigned int port;
} interface_cfg_t;
class udr_config {
public:
udr_config();
~udr_config();
int load(const std::string &config_file);
int getip(std::string &ip, std::string &ifname);
int load_interface(const Setting &if_cfg, interface_cfg_t &cfg);
void display();
unsigned int instance;
std::string pid_dir;
std::string api_version;
interface_cfg_t sbi;
mysql_conf_t mysql;
};
} // namespace config
#endif
#include "udr_server.hpp"
#include "logger.hpp"
#ifdef __linux__
static void sigHandler [[noreturn]] (int sig) {
switch (sig) {
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGHUP:
default:
// m_httpEndpoint->shutdown();
break;
}
exit(0);
}
static void setUpUnixSignals(std::vector<int> quitSignals) {
sigset_t blocking_mask;
sigemptyset(&blocking_mask);
for (auto sig : quitSignals)
sigaddset(&blocking_mask, sig);
struct sigaction sa;
sa.sa_handler = sigHandler;
sa.sa_mask = blocking_mask;
sa.sa_flags = 0;
for (auto sig : quitSignals)
sigaction(sig, &sa, nullptr);
}
#endif
using namespace org::openapitools::server::api;
UDRApiServer::UDRApiServer(Pistache::Address address, MYSQL *mysql)
: m_httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(address)) {
m_router = std::make_shared<Pistache::Rest::Router>();
m_AuthenticationSubscriptionDocumentApiserver =
std::make_shared<AuthenticationSubscriptionDocumentApiImpl>(m_router,
mysql);
m_AuthenticationStatusDocumentApiserver =
std::make_shared<AuthenticationStatusDocumentApiImpl>(m_router, mysql);
m_AccessAndMobilitySubscriptionDataDocumentApiserver =
std::make_shared<AccessAndMobilitySubscriptionDataDocumentApiImpl>(
m_router, mysql);
m_SMFSelectionSubscriptionDataDocumentApiserver =
std::make_shared<SMFSelectionSubscriptionDataDocumentApiImpl>(m_router,
mysql);
m_SessionManagementSubscriptionDataApiserver =
std::make_shared<SessionManagementSubscriptionDataApiImpl>(m_router,
mysql);
m_AMF3GPPAccessRegistrationDocumentApiserver =
std::make_shared<AMF3GPPAccessRegistrationDocumentApiImpl>(m_router,
mysql);
m_SMFRegistrationDocumentApiserver =
std::make_shared<SMFRegistrationDocumentApiImpl>(m_router, mysql);
m_SMFRegistrationsCollectionApiserver =
std::make_shared<SMFRegistrationsCollectionApiImpl>(m_router, mysql);
m_SDMSubscriptionDocumentApiserver =
std::make_shared<SDMSubscriptionDocumentApiImpl>(m_router, mysql);
m_SDMSubscriptionsCollectionApiserver =
std::make_shared<SDMSubscriptionsCollectionApiImpl>(m_router, mysql);
}
void UDRApiServer::init(size_t thr) {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs);
#endif
auto opts = Pistache::Http::Endpoint::options().threads(thr);
opts.flags(Pistache::Tcp::Options::ReuseAddr);
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
m_httpEndpoint->init(opts);
m_AuthenticationSubscriptionDocumentApiserver->init();
m_AuthenticationStatusDocumentApiserver->init();
m_AccessAndMobilitySubscriptionDataDocumentApiserver->init();
m_SMFSelectionSubscriptionDataDocumentApiserver->init();
m_SessionManagementSubscriptionDataApiserver->init();
m_AMF3GPPAccessRegistrationDocumentApiserver->init();
m_SMFRegistrationDocumentApiserver->init();
m_SMFRegistrationsCollectionApiserver->init();
m_SDMSubscriptionDocumentApiserver->init();
m_SDMSubscriptionsCollectionApiserver->init();
Logger::udr_server().debug("Initiate UDR server endpoints done!");
}
void UDRApiServer::start() {
if (m_AuthenticationSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl");
if (m_AuthenticationStatusDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationStatusDocumentApiImpl");
if (m_AccessAndMobilitySubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AccessAndMobilitySubscriptionDataDocumentApiImpl");
if (m_SMFSelectionSubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SMFSelectionSubscriptionDataDocumentApiImpl");
if (m_SessionManagementSubscriptionDataApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SessionManagementSubscriptionDataApiImpl");
if (m_AMF3GPPAccessRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AMF3GPPAccessRegistrationDocumentApiImpl");
if (m_SMFRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SMFRegistrationsCollectionApiImpl");
if (m_SMFRegistrationsCollectionApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SDMSubscriptionDocumentApiImpl");
if (m_SDMSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SDMSubscriptionsCollectionApiImpl");
if (m_SDMSubscriptionsCollectionApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl");
m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serve();
}
void UDRApiServer::shutdown() { m_httpEndpoint->shutdown(); }
#include "udr_server.hpp"
#include "logger.hpp"
#ifdef __linux__
static void sigHandler [[noreturn]] (int sig) {
switch (sig) {
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGHUP:
default:
// m_httpEndpoint->shutdown();
break;
}
exit(0);
}
static void setUpUnixSignals(std::vector<int> quitSignals) {
sigset_t blocking_mask;
sigemptyset(&blocking_mask);
for (auto sig : quitSignals)
sigaddset(&blocking_mask, sig);
struct sigaction sa;
sa.sa_handler = sigHandler;
sa.sa_mask = blocking_mask;
sa.sa_flags = 0;
for (auto sig : quitSignals)
sigaction(sig, &sa, nullptr);
}
#endif
using namespace org::openapitools::server::api;
UDRApiServer::UDRApiServer(Pistache::Address address, MYSQL *mysql)
: m_httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(address)) {
m_router = std::make_shared<Pistache::Rest::Router>();
m_AuthenticationSubscriptionDocumentApiserver =
std::make_shared<AuthenticationSubscriptionDocumentApiImpl>(m_router,
mysql);
m_AuthenticationStatusDocumentApiserver =
std::make_shared<AuthenticationStatusDocumentApiImpl>(m_router, mysql);
m_AccessAndMobilitySubscriptionDataDocumentApiserver =
std::make_shared<AccessAndMobilitySubscriptionDataDocumentApiImpl>(
m_router, mysql);
m_SMFSelectionSubscriptionDataDocumentApiserver =
std::make_shared<SMFSelectionSubscriptionDataDocumentApiImpl>(m_router,
mysql);
m_SessionManagementSubscriptionDataApiserver =
std::make_shared<SessionManagementSubscriptionDataApiImpl>(m_router,
mysql);
m_AMF3GPPAccessRegistrationDocumentApiserver =
std::make_shared<AMF3GPPAccessRegistrationDocumentApiImpl>(m_router,
mysql);
m_SMFRegistrationDocumentApiserver =
std::make_shared<SMFRegistrationDocumentApiImpl>(m_router, mysql);
m_SMFRegistrationsCollectionApiserver =
std::make_shared<SMFRegistrationsCollectionApiImpl>(m_router, mysql);
m_SDMSubscriptionDocumentApiserver =
std::make_shared<SDMSubscriptionDocumentApiImpl>(m_router, mysql);
m_SDMSubscriptionsCollectionApiserver =
std::make_shared<SDMSubscriptionsCollectionApiImpl>(m_router, mysql);
}
void UDRApiServer::init(size_t thr) {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs);
#endif
auto opts = Pistache::Http::Endpoint::options().threads(thr);
opts.flags(Pistache::Tcp::Options::ReuseAddr);
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
m_httpEndpoint->init(opts);
m_AuthenticationSubscriptionDocumentApiserver->init();
m_AuthenticationStatusDocumentApiserver->init();
m_AccessAndMobilitySubscriptionDataDocumentApiserver->init();
m_SMFSelectionSubscriptionDataDocumentApiserver->init();
m_SessionManagementSubscriptionDataApiserver->init();
m_AMF3GPPAccessRegistrationDocumentApiserver->init();
m_SMFRegistrationDocumentApiserver->init();
m_SMFRegistrationsCollectionApiserver->init();
m_SDMSubscriptionDocumentApiserver->init();
m_SDMSubscriptionsCollectionApiserver->init();
Logger::udr_server().debug("Initiate UDR server endpoints done!");
}
void UDRApiServer::start() {
if (m_AuthenticationSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl");
if (m_AuthenticationStatusDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationStatusDocumentApiImpl");
if (m_AccessAndMobilitySubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AccessAndMobilitySubscriptionDataDocumentApiImpl");
if (m_SMFSelectionSubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SMFSelectionSubscriptionDataDocumentApiImpl");
if (m_SessionManagementSubscriptionDataApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SessionManagementSubscriptionDataApiImpl");
if (m_AMF3GPPAccessRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AMF3GPPAccessRegistrationDocumentApiImpl");
if (m_SMFRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SMFRegistrationsCollectionApiImpl");
if (m_SMFRegistrationsCollectionApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SDMSubscriptionDocumentApiImpl");
if (m_SDMSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SDMSubscriptionsCollectionApiImpl");
if (m_SDMSubscriptionsCollectionApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl");
m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serve();
}
void UDRApiServer::shutdown() { m_httpEndpoint->shutdown(); }
#ifndef _UDR_SERVER_H_
#define _UDR_SERVER_H_
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#ifdef __linux__
#include <signal.h>
#include <unistd.h>
#include <vector>
#endif
#include "AMF3GPPAccessRegistrationDocumentApiImpl.h"
#include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h"
#include "AuthenticationStatusDocumentApiImpl.h"
#include "AuthenticationSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionsCollectionApiImpl.h"
#include "SMFRegistrationDocumentApiImpl.h"
#include "SMFRegistrationsCollectionApiImpl.h"
#include "SMFSelectionSubscriptionDataDocumentApiImpl.h"
#include "SessionManagementSubscriptionDataApiImpl.h"
#include <mysql/mysql.h>
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
using namespace org::openapitools::server::api;
class UDRApiServer {
public:
UDRApiServer(Pistache::Address address, MYSQL *mysql);
void init(size_t thr = 1);
void start();
void shutdown();
private:
std::shared_ptr<Pistache::Http::Endpoint> m_httpEndpoint;
std::shared_ptr<Pistache::Rest::Router> m_router;
std::shared_ptr<AuthenticationSubscriptionDocumentApiImpl>
m_AuthenticationSubscriptionDocumentApiserver;
std::shared_ptr<AuthenticationStatusDocumentApiImpl>
m_AuthenticationStatusDocumentApiserver;
std::shared_ptr<AccessAndMobilitySubscriptionDataDocumentApiImpl>
m_AccessAndMobilitySubscriptionDataDocumentApiserver;
std::shared_ptr<SMFSelectionSubscriptionDataDocumentApiImpl>
m_SMFSelectionSubscriptionDataDocumentApiserver;
std::shared_ptr<SessionManagementSubscriptionDataApiImpl>
m_SessionManagementSubscriptionDataApiserver;
std::shared_ptr<AMF3GPPAccessRegistrationDocumentApiImpl>
m_AMF3GPPAccessRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationDocumentApiImpl>
m_SMFRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationsCollectionApiImpl>
m_SMFRegistrationsCollectionApiserver;
std::shared_ptr<SDMSubscriptionDocumentApiImpl>
m_SDMSubscriptionDocumentApiserver;
std::shared_ptr<SDMSubscriptionsCollectionApiImpl>
m_SDMSubscriptionsCollectionApiserver;
};
#ifndef _UDR_SERVER_H_
#define _UDR_SERVER_H_
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#ifdef __linux__
#include <signal.h>
#include <unistd.h>
#include <vector>
#endif
#include "AMF3GPPAccessRegistrationDocumentApiImpl.h"
#include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h"
#include "AuthenticationStatusDocumentApiImpl.h"
#include "AuthenticationSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionsCollectionApiImpl.h"
#include "SMFRegistrationDocumentApiImpl.h"
#include "SMFRegistrationsCollectionApiImpl.h"
#include "SMFSelectionSubscriptionDataDocumentApiImpl.h"
#include "SessionManagementSubscriptionDataApiImpl.h"
#include <mysql/mysql.h>
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
using namespace org::openapitools::server::api;
class UDRApiServer {
public:
UDRApiServer(Pistache::Address address, MYSQL *mysql);
void init(size_t thr = 1);
void start();
void shutdown();
private:
std::shared_ptr<Pistache::Http::Endpoint> m_httpEndpoint;
std::shared_ptr<Pistache::Rest::Router> m_router;
std::shared_ptr<AuthenticationSubscriptionDocumentApiImpl>
m_AuthenticationSubscriptionDocumentApiserver;
std::shared_ptr<AuthenticationStatusDocumentApiImpl>
m_AuthenticationStatusDocumentApiserver;
std::shared_ptr<AccessAndMobilitySubscriptionDataDocumentApiImpl>
m_AccessAndMobilitySubscriptionDataDocumentApiserver;
std::shared_ptr<SMFSelectionSubscriptionDataDocumentApiImpl>
m_SMFSelectionSubscriptionDataDocumentApiserver;
std::shared_ptr<SessionManagementSubscriptionDataApiImpl>
m_SessionManagementSubscriptionDataApiserver;
std::shared_ptr<AMF3GPPAccessRegistrationDocumentApiImpl>
m_AMF3GPPAccessRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationDocumentApiImpl>
m_SMFRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationsCollectionApiImpl>
m_SMFRegistrationsCollectionApiserver;
std::shared_ptr<SDMSubscriptionDocumentApiImpl>
m_SDMSubscriptionDocumentApiserver;
std::shared_ptr<SDMSubscriptionsCollectionApiImpl>
m_SDMSubscriptionsCollectionApiserver;
};
#endif
\ No newline at end of file
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