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 # 3. How to start
```
├── 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.
```
## Download source code from Gitlab ## 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/ cd openxg-udr/
```
As master branch is usually the stable branch, so we would suggest you start from the master:
```
git checkout master git checkout master
``` ```
## install dependencies ## 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 cd ./build/scripts
sudo ./build_udr -I sudo ./build_udr -I
``` ```
## build UDR ## build UDR
When you finish install the dependencies, you can finally build the UDR executables by:
``` ```
sudo ./build_udr -c -b Debug -j sudo ./build_udr -c -b Debug -j
``` ```
## launch UDR ## 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 sudo udr -c etc/udr.conf -o
``` ```
\ No newline at end of file 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 # Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
# contributor license agreements. See the NOTICE file distributed with # Software Alliance under one or more contributor license agreements. The
# this work for additional information regarding copyright ownership. # initial OpenXG series projects are derided from OAI projects, the files from
# The OpenAirInterface Software Alliance licenses this file to You under # OAI projects are all in compliance with OAI Public License, Version 1.1.
# the OAI Public License, Version 1.1 (the "License"); you may not use this # codes and files developed from OpenXG projects and from OS-RAN Alliance
# file except in compliance with the License. You may obtain a copy of the # are all under OS-RAN licenses; you may not use this file except in compliance
# License at # with the license. You may get a copy of the license at:
# # http://www.openxg.org.cn/?falu_69.html
# http://www.openairinterface.org/?page_id=698 # For more information about OpenXG, please contact:
# # contact@openxg.org.cn
# 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
################################################################################ ################################################################################
## udr configuration file ## udr configuration file
......
################################################################################ ################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more # Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
# contributor license agreements. See the NOTICE file distributed with # Software Alliance under one or more contributor license agreements. The
# this work for additional information regarding copyright ownership. # initial OpenXG series projects are derided from OAI projects, the files from
# The OpenAirInterface Software Alliance licenses this file to You under # OAI projects are all in compliance with OAI Public License, Version 1.1.
# the OAI Public License, Version 1.1 (the "License"); you may not use this # codes and files developed from OpenXG projects and from OS-RAN Alliance
# file except in compliance with the License. You may obtain a copy of the # are all under OS-RAN licenses; you may not use this file except in compliance
# License at # with the license. You may get a copy of the license at:
# # http://www.openxg.org.cn/?falu_69.html
# http://www.openairinterface.org/?page_id=698 # For more information about OpenXG, please contact:
# # contact@openxg.org.cn
# 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
################################################################################ ################################################################################
## udr configuration file ## udr configuration file
......
/* /*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
* contributor license agreements. See the NOTICE file distributed with * Software Alliance under one or more contributor license agreements. The
* this work for additional information regarding copyright ownership. * initial OpenXG series projects are derided from OAI projects, the files from
* The OpenAirInterface Software Alliance licenses this file to You under * OAI projects are all in compliance with OAI Public License, Version 1.1.
* the OAI Public License, Version 1.1 (the "License"); you may not use this * codes and files developed from OpenXG projects and from OS-RAN Alliance
*file except in compliance with the License. You may obtain a copy of the * are all under OS-RAN licenses; you may not use this file except in compliance
*License at * with the license. You may get a copy of the license at:
* * http://www.openxg.org.cn/?falu_69.html
* http://www.openairinterface.org/?page_id=698 * For more information about OpenXG, please contact:
* * contact@openxg.org.cn
* 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
*/ */
#include "logger.hpp" #include "logger.hpp"
......
/* /*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
* contributor license agreements. See the NOTICE file distributed with * Software Alliance under one or more contributor license agreements. The
* this work for additional information regarding copyright ownership. * initial OpenXG series projects are derided from OAI projects, the files from
* The OpenAirInterface Software Alliance licenses this file to You under * OAI projects are all in compliance with OAI Public License, Version 1.1.
* the OAI Public License, Version 1.1 (the "License"); you may not use this * codes and files developed from OpenXG projects and from OS-RAN Alliance
*file except in compliance with the License. You may obtain a copy of the * are all under OS-RAN licenses; you may not use this file except in compliance
*License at * with the license. You may get a copy of the license at:
* * http://www.openxg.org.cn/?falu_69.html
* http://www.openairinterface.org/?page_id=698 * For more information about OpenXG, please contact:
* * contact@openxg.org.cn
* 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
*/ */
#ifndef __LOGGER_H #ifndef __LOGGER_H
......
/* /*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
* contributor license agreements. See the NOTICE file distributed with * Software Alliance under one or more contributor license agreements. The
* this work for additional information regarding copyright ownership. * initial OpenXG series projects are derided from OAI projects, the files from
* The OpenAirInterface Software Alliance licenses this file to You under * OAI projects are all in compliance with OAI Public License, Version 1.1.
* the OAI Public License, Version 1.1 (the "License"); you may not use this * codes and files developed from OpenXG projects and from OS-RAN Alliance
*file except in compliance with the License. You may obtain a copy of the * are all under OS-RAN licenses; you may not use this file except in compliance
*License at * with the license. You may get a copy of the license at:
* * http://www.openxg.org.cn/?falu_69.html
* http://www.openairinterface.org/?page_id=698 * For more information about OpenXG, please contact:
* * contact@openxg.org.cn
* 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 /*! file
......
#include "udr_config.hpp" #include "udr_config.hpp"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/if.h> #include <net/if.h>
#include <net/if_arp.h> #include <net/if_arp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <iostream> #include <iostream>
#include <libconfig.h++> #include <libconfig.h++>
#include "logger.hpp" #include "logger.hpp"
using namespace libconfig; using namespace libconfig;
namespace config { namespace config {
udr_config::udr_config() {api_version = "v2";} udr_config::udr_config() {api_version = "v2";}
udr_config::~udr_config() {} udr_config::~udr_config() {}
int udr_config::load(const std ::string &config_file) { int udr_config::load(const std ::string &config_file) {
Logger::udr_app().debug("\nLoad UDR system configuration file(%s)", Logger::udr_app().debug("\nLoad UDR system configuration file(%s)",
config_file.c_str()); config_file.c_str());
Config cfg; Config cfg;
try { try {
cfg.readFile(config_file.c_str()); cfg.readFile(config_file.c_str());
} catch (const FileIOException &fioex) { } catch (const FileIOException &fioex) {
Logger::udr_app().error("I/O error while reading file %s - %s", Logger::udr_app().error("I/O error while reading file %s - %s",
config_file.c_str(), fioex.what()); config_file.c_str(), fioex.what());
throw; throw;
} catch (const ParseException &pex) { } catch (const ParseException &pex) {
Logger::udr_app().error("Parse error at %s:%d - %s", pex.getFile(), Logger::udr_app().error("Parse error at %s:%d - %s", pex.getFile(),
pex.getLine(), pex.getError()); pex.getLine(), pex.getError());
throw; throw;
} }
const Setting &root = cfg.getRoot(); const Setting &root = cfg.getRoot();
try { try {
const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG]; const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG];
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(), nfex.getPath()); Logger::udr_app().error("%s : %s", nfex.what(), nfex.getPath());
return -1; return -1;
} }
const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG]; const Setting &udr_cfg = root[UDR_CONFIG_STRING_UDR_CONFIG];
try { try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_INSTANCE_ID, instance); udr_cfg.lookupValue(UDR_CONFIG_STRING_INSTANCE_ID, instance);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(), Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath()); nfex.getPath());
} }
try { try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_PID_DIRECTORY, pid_dir); udr_cfg.lookupValue(UDR_CONFIG_STRING_PID_DIRECTORY, pid_dir);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(), Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath()); nfex.getPath());
} }
try { try {
udr_cfg.lookupValue(UDR_CONFIG_STRING_API_VERSION, api_version); udr_cfg.lookupValue(UDR_CONFIG_STRING_API_VERSION, api_version);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().warn("%s : %s, using defaults", nfex.what(), Logger::udr_app().warn("%s : %s, using defaults", nfex.what(),
nfex.getPath()); nfex.getPath());
} }
try { try {
const Setting &new_if_cfg = udr_cfg[UDR_CONFIG_STRING_INTERFACES]; const Setting &new_if_cfg = udr_cfg[UDR_CONFIG_STRING_INTERFACES];
const Setting &sbi_cfg = new_if_cfg[UDR_CONFIG_STRING_INTERFACE_SBI]; const Setting &sbi_cfg = new_if_cfg[UDR_CONFIG_STRING_INTERFACE_SBI];
load_interface(sbi_cfg, sbi); load_interface(sbi_cfg, sbi);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(), Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath()); nfex.getPath());
return -1; return -1;
} }
try { try {
const Setting &mysql_cfg = udr_cfg[UDR_CONFIG_STRING_MYSQL]; 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_SERVER, mysql.mysql_server);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_USER, mysql.mysql_user); 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_PASS, mysql.mysql_pass);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_DB, mysql.mysql_db); mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_DB, mysql.mysql_db);
mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_PORT, mysql.mysql_port); mysql_cfg.lookupValue(UDR_CONFIG_STRING_MYSQL_PORT, mysql.mysql_port);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s", nfex.what(), Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath()); nfex.getPath());
return -1; return -1;
} }
return 0; return 0;
} }
int udr_config::getip(std::string &ip, std::string &ifname) int udr_config::getip(std::string &ip, std::string &ifname)
{ {
int sock; int sock;
struct sockaddr_in sin; struct sockaddr_in sin;
struct ifreq ifr; struct ifreq ifr;
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1) if (sock == -1)
{ {
perror("socket"); perror("socket");
return -1; return -1;
} }
strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ); strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0; ifr.ifr_name[IFNAMSIZ - 1] = 0;
if (ioctl(sock, SIOCGIFADDR, &ifr) < 0) if (ioctl(sock, SIOCGIFADDR, &ifr) < 0)
{ {
perror("ioctl"); perror("ioctl");
return -1; return -1;
} }
memcpy(&sin, &ifr.ifr_addr, sizeof(sin)); memcpy(&sin, &ifr.ifr_addr, sizeof(sin));
printf("ip = %s",inet_ntoa(sin.sin_addr)); printf("ip = %s",inet_ntoa(sin.sin_addr));
//sprintf(ip, "%s", inet_ntoa(sin.sin_addr)); //sprintf(ip, "%s", inet_ntoa(sin.sin_addr));
ip = std::string(inet_ntoa(sin.sin_addr)); ip = std::string(inet_ntoa(sin.sin_addr));
return 0; return 0;
} }
int udr_config::load_interface(const libconfig::Setting &if_cfg, int udr_config::load_interface(const libconfig::Setting &if_cfg,
interface_cfg_t &cfg) { interface_cfg_t &cfg) {
if_cfg.lookupValue(UDR_CONFIG_STRING_INTERFACE_NAME, cfg.if_name); if_cfg.lookupValue(UDR_CONFIG_STRING_INTERFACE_NAME, cfg.if_name);
if_cfg.lookupValue(UDR_CONFIG_STRING_IPV4_ADDRESS, cfg.addr4); if_cfg.lookupValue(UDR_CONFIG_STRING_IPV4_ADDRESS, cfg.addr4);
if(!cfg.addr4.compare("read")) if(!cfg.addr4.compare("read"))
{ {
if(getip(cfg.addr4,cfg.if_name) < 0) return -1; if(getip(cfg.addr4,cfg.if_name) < 0) return -1;
} }
if_cfg.lookupValue(UDR_CONFIG_STRING_PORT, cfg.port); if_cfg.lookupValue(UDR_CONFIG_STRING_PORT, cfg.port);
return 0; return 0;
} }
void udr_config::display() { void udr_config::display() {
Logger::config().info( Logger::config().info(
"====================== UDR ====================="); "====================== UDR =====================");
Logger::config().info("Configuration UDR:"); Logger::config().info("Configuration UDR:");
Logger::config().info(""); Logger::config().info("");
Logger::config().info( Logger::config().info(
"- Instance .........................................: %d", instance); "- Instance .........................................: %d", instance);
Logger::config().info( Logger::config().info(
"- PID dir ..........................................: %s", "- PID dir ..........................................: %s",
pid_dir.c_str()); pid_dir.c_str());
Logger::config().info( Logger::config().info(
"- API version ......................................: %s", api_version.c_str()); "- API version ......................................: %s", api_version.c_str());
Logger::config().info(""); Logger::config().info("");
Logger::config().info("- SBI Networking:"); Logger::config().info("- SBI Networking:");
Logger::config().info(" iface ................: %s", sbi.if_name.c_str()); Logger::config().info(" iface ................: %s", sbi.if_name.c_str());
Logger::config().info(" ip ...................: %s", sbi.addr4.c_str()); Logger::config().info(" ip ...................: %s", sbi.addr4.c_str());
Logger::config().info(" port .................: %d", sbi.port); Logger::config().info(" port .................: %d", sbi.port);
Logger::config().info(""); Logger::config().info("");
Logger::config().info("- Database Configuration:"); Logger::config().info("- Database Configuration:");
Logger::config().info( Logger::config().info(
"- MYSQL Server Addr.................................: %s", "- MYSQL Server Addr.................................: %s",
mysql.mysql_server.c_str()); mysql.mysql_server.c_str());
Logger::config().info( Logger::config().info(
"- MYSQL User .......................................: %s", "- MYSQL User .......................................: %s",
mysql.mysql_user.c_str()); mysql.mysql_user.c_str());
Logger::config().info( Logger::config().info(
"- MYSQL Pass .......................................: %s", "- MYSQL Pass .......................................: %s",
mysql.mysql_pass.c_str()); mysql.mysql_pass.c_str());
Logger::config().info( Logger::config().info(
"- MYSQL DB .........................................: %s", "- MYSQL DB .........................................: %s",
mysql.mysql_db.c_str()); mysql.mysql_db.c_str());
Logger::config().info( Logger::config().info(
"- MYSQL Port .......................................: %d", "- MYSQL Port .......................................: %d",
mysql.mysql_port); mysql.mysql_port);
Logger::config().info(""); Logger::config().info("");
} }
} // namespace config } // namespace config
#ifndef _UDR_CONFIG_H_ #ifndef _UDR_CONFIG_H_
#define _UDR_CONFIG_H_ #define _UDR_CONFIG_H_
#include <libconfig.h++> #include <libconfig.h++>
#include <string> #include <string>
#define UDR_CONFIG_STRING_UDR_CONFIG "UDR" #define UDR_CONFIG_STRING_UDR_CONFIG "UDR"
#define UDR_CONFIG_STRING_INSTANCE_ID "INSTANCE_ID" #define UDR_CONFIG_STRING_INSTANCE_ID "INSTANCE_ID"
#define UDR_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY" #define UDR_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY"
#define UDR_CONFIG_STRING_INTERFACES "INTERFACES" #define UDR_CONFIG_STRING_INTERFACES "INTERFACES"
#define UDR_CONFIG_STRING_INTERFACE_SBI "SBI" #define UDR_CONFIG_STRING_INTERFACE_SBI "SBI"
#define UDR_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME" #define UDR_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME"
#define UDR_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS" #define UDR_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS"
#define UDR_CONFIG_STRING_PORT "PORT" #define UDR_CONFIG_STRING_PORT "PORT"
#define UDR_CONFIG_STRING_API_VERSION "API_VERSION" #define UDR_CONFIG_STRING_API_VERSION "API_VERSION"
#define UDR_CONFIG_STRING_MYSQL "MYSQL" #define UDR_CONFIG_STRING_MYSQL "MYSQL"
#define UDR_CONFIG_STRING_MYSQL_SERVER "MYSQL_SERVER" #define UDR_CONFIG_STRING_MYSQL_SERVER "MYSQL_SERVER"
#define UDR_CONFIG_STRING_MYSQL_USER "MYSQL_USER" #define UDR_CONFIG_STRING_MYSQL_USER "MYSQL_USER"
#define UDR_CONFIG_STRING_MYSQL_PASS "MYSQL_PASS" #define UDR_CONFIG_STRING_MYSQL_PASS "MYSQL_PASS"
#define UDR_CONFIG_STRING_MYSQL_DB "MYSQL_DB" #define UDR_CONFIG_STRING_MYSQL_DB "MYSQL_DB"
#define UDR_CONFIG_STRING_MYSQL_PORT "MYSQL_PORT" #define UDR_CONFIG_STRING_MYSQL_PORT "MYSQL_PORT"
using namespace libconfig; using namespace libconfig;
namespace config { namespace config {
typedef struct { typedef struct {
std::string mysql_server = "127.0.0.1"; std::string mysql_server = "127.0.0.1";
std::string mysql_user = "yunshou"; std::string mysql_user = "yunshou";
std::string mysql_pass = "123456"; std::string mysql_pass = "123456";
std::string mysql_db = "Witcomm-UDR-DB"; std::string mysql_db = "Witcomm-UDR-DB";
unsigned int mysql_port = 0; unsigned int mysql_port = 0;
} mysql_conf_t; } mysql_conf_t;
typedef struct interface_cfg_s { typedef struct interface_cfg_s {
std::string if_name; std::string if_name;
std::string addr4; std::string addr4;
unsigned int port; unsigned int port;
} interface_cfg_t; } interface_cfg_t;
class udr_config { class udr_config {
public: public:
udr_config(); udr_config();
~udr_config(); ~udr_config();
int load(const std::string &config_file); int load(const std::string &config_file);
int getip(std::string &ip, std::string &ifname); int getip(std::string &ip, std::string &ifname);
int load_interface(const Setting &if_cfg, interface_cfg_t &cfg); int load_interface(const Setting &if_cfg, interface_cfg_t &cfg);
void display(); void display();
unsigned int instance; unsigned int instance;
std::string pid_dir; std::string pid_dir;
std::string api_version; std::string api_version;
interface_cfg_t sbi; interface_cfg_t sbi;
mysql_conf_t mysql; mysql_conf_t mysql;
}; };
} // namespace config } // namespace config
#endif #endif
#include "udr_server.hpp" #include "udr_server.hpp"
#include "logger.hpp" #include "logger.hpp"
#ifdef __linux__ #ifdef __linux__
static void sigHandler [[noreturn]] (int sig) { static void sigHandler [[noreturn]] (int sig) {
switch (sig) { switch (sig) {
case SIGINT: case SIGINT:
case SIGQUIT: case SIGQUIT:
case SIGTERM: case SIGTERM:
case SIGHUP: case SIGHUP:
default: default:
// m_httpEndpoint->shutdown(); // m_httpEndpoint->shutdown();
break; break;
} }
exit(0); exit(0);
} }
static void setUpUnixSignals(std::vector<int> quitSignals) { static void setUpUnixSignals(std::vector<int> quitSignals) {
sigset_t blocking_mask; sigset_t blocking_mask;
sigemptyset(&blocking_mask); sigemptyset(&blocking_mask);
for (auto sig : quitSignals) for (auto sig : quitSignals)
sigaddset(&blocking_mask, sig); sigaddset(&blocking_mask, sig);
struct sigaction sa; struct sigaction sa;
sa.sa_handler = sigHandler; sa.sa_handler = sigHandler;
sa.sa_mask = blocking_mask; sa.sa_mask = blocking_mask;
sa.sa_flags = 0; sa.sa_flags = 0;
for (auto sig : quitSignals) for (auto sig : quitSignals)
sigaction(sig, &sa, nullptr); sigaction(sig, &sa, nullptr);
} }
#endif #endif
using namespace org::openapitools::server::api; using namespace org::openapitools::server::api;
UDRApiServer::UDRApiServer(Pistache::Address address, MYSQL *mysql) UDRApiServer::UDRApiServer(Pistache::Address address, MYSQL *mysql)
: m_httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(address)) { : m_httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(address)) {
m_router = std::make_shared<Pistache::Rest::Router>(); m_router = std::make_shared<Pistache::Rest::Router>();
m_AuthenticationSubscriptionDocumentApiserver = m_AuthenticationSubscriptionDocumentApiserver =
std::make_shared<AuthenticationSubscriptionDocumentApiImpl>(m_router, std::make_shared<AuthenticationSubscriptionDocumentApiImpl>(m_router,
mysql); mysql);
m_AuthenticationStatusDocumentApiserver = m_AuthenticationStatusDocumentApiserver =
std::make_shared<AuthenticationStatusDocumentApiImpl>(m_router, mysql); std::make_shared<AuthenticationStatusDocumentApiImpl>(m_router, mysql);
m_AccessAndMobilitySubscriptionDataDocumentApiserver = m_AccessAndMobilitySubscriptionDataDocumentApiserver =
std::make_shared<AccessAndMobilitySubscriptionDataDocumentApiImpl>( std::make_shared<AccessAndMobilitySubscriptionDataDocumentApiImpl>(
m_router, mysql); m_router, mysql);
m_SMFSelectionSubscriptionDataDocumentApiserver = m_SMFSelectionSubscriptionDataDocumentApiserver =
std::make_shared<SMFSelectionSubscriptionDataDocumentApiImpl>(m_router, std::make_shared<SMFSelectionSubscriptionDataDocumentApiImpl>(m_router,
mysql); mysql);
m_SessionManagementSubscriptionDataApiserver = m_SessionManagementSubscriptionDataApiserver =
std::make_shared<SessionManagementSubscriptionDataApiImpl>(m_router, std::make_shared<SessionManagementSubscriptionDataApiImpl>(m_router,
mysql); mysql);
m_AMF3GPPAccessRegistrationDocumentApiserver = m_AMF3GPPAccessRegistrationDocumentApiserver =
std::make_shared<AMF3GPPAccessRegistrationDocumentApiImpl>(m_router, std::make_shared<AMF3GPPAccessRegistrationDocumentApiImpl>(m_router,
mysql); mysql);
m_SMFRegistrationDocumentApiserver = m_SMFRegistrationDocumentApiserver =
std::make_shared<SMFRegistrationDocumentApiImpl>(m_router, mysql); std::make_shared<SMFRegistrationDocumentApiImpl>(m_router, mysql);
m_SMFRegistrationsCollectionApiserver = m_SMFRegistrationsCollectionApiserver =
std::make_shared<SMFRegistrationsCollectionApiImpl>(m_router, mysql); std::make_shared<SMFRegistrationsCollectionApiImpl>(m_router, mysql);
m_SDMSubscriptionDocumentApiserver = m_SDMSubscriptionDocumentApiserver =
std::make_shared<SDMSubscriptionDocumentApiImpl>(m_router, mysql); std::make_shared<SDMSubscriptionDocumentApiImpl>(m_router, mysql);
m_SDMSubscriptionsCollectionApiserver = m_SDMSubscriptionsCollectionApiserver =
std::make_shared<SDMSubscriptionsCollectionApiImpl>(m_router, mysql); std::make_shared<SDMSubscriptionsCollectionApiImpl>(m_router, mysql);
} }
void UDRApiServer::init(size_t thr) { void UDRApiServer::init(size_t thr) {
#ifdef __linux__ #ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP}; std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs); setUpUnixSignals(sigs);
#endif #endif
auto opts = Pistache::Http::Endpoint::options().threads(thr); auto opts = Pistache::Http::Endpoint::options().threads(thr);
opts.flags(Pistache::Tcp::Options::ReuseAddr); opts.flags(Pistache::Tcp::Options::ReuseAddr);
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE); opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE); opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
m_httpEndpoint->init(opts); m_httpEndpoint->init(opts);
m_AuthenticationSubscriptionDocumentApiserver->init(); m_AuthenticationSubscriptionDocumentApiserver->init();
m_AuthenticationStatusDocumentApiserver->init(); m_AuthenticationStatusDocumentApiserver->init();
m_AccessAndMobilitySubscriptionDataDocumentApiserver->init(); m_AccessAndMobilitySubscriptionDataDocumentApiserver->init();
m_SMFSelectionSubscriptionDataDocumentApiserver->init(); m_SMFSelectionSubscriptionDataDocumentApiserver->init();
m_SessionManagementSubscriptionDataApiserver->init(); m_SessionManagementSubscriptionDataApiserver->init();
m_AMF3GPPAccessRegistrationDocumentApiserver->init(); m_AMF3GPPAccessRegistrationDocumentApiserver->init();
m_SMFRegistrationDocumentApiserver->init(); m_SMFRegistrationDocumentApiserver->init();
m_SMFRegistrationsCollectionApiserver->init(); m_SMFRegistrationsCollectionApiserver->init();
m_SDMSubscriptionDocumentApiserver->init(); m_SDMSubscriptionDocumentApiserver->init();
m_SDMSubscriptionsCollectionApiserver->init(); m_SDMSubscriptionsCollectionApiserver->init();
Logger::udr_server().debug("Initiate UDR server endpoints done!"); Logger::udr_server().debug("Initiate UDR server endpoints done!");
} }
void UDRApiServer::start() { void UDRApiServer::start() {
if (m_AuthenticationSubscriptionDocumentApiserver != nullptr) if (m_AuthenticationSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl"); "UDR handler for AuthenticationSubscriptionDocumentApiImpl");
if (m_AuthenticationStatusDocumentApiserver != nullptr) if (m_AuthenticationStatusDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for AuthenticationStatusDocumentApiImpl"); "UDR handler for AuthenticationStatusDocumentApiImpl");
if (m_AccessAndMobilitySubscriptionDataDocumentApiserver != nullptr) if (m_AccessAndMobilitySubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for AccessAndMobilitySubscriptionDataDocumentApiImpl"); "UDR handler for AccessAndMobilitySubscriptionDataDocumentApiImpl");
if (m_SMFSelectionSubscriptionDataDocumentApiserver != nullptr) if (m_SMFSelectionSubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for SMFSelectionSubscriptionDataDocumentApiImpl"); "UDR handler for SMFSelectionSubscriptionDataDocumentApiImpl");
if (m_SessionManagementSubscriptionDataApiserver != nullptr) if (m_SessionManagementSubscriptionDataApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for SessionManagementSubscriptionDataApiImpl"); "UDR handler for SessionManagementSubscriptionDataApiImpl");
if (m_AMF3GPPAccessRegistrationDocumentApiserver != nullptr) if (m_AMF3GPPAccessRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for AMF3GPPAccessRegistrationDocumentApiImpl"); "UDR handler for AMF3GPPAccessRegistrationDocumentApiImpl");
if (m_SMFRegistrationDocumentApiserver != nullptr) if (m_SMFRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for SMFRegistrationsCollectionApiImpl"); "UDR handler for SMFRegistrationsCollectionApiImpl");
if (m_SMFRegistrationsCollectionApiserver != nullptr) if (m_SMFRegistrationsCollectionApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for SDMSubscriptionDocumentApiImpl"); "UDR handler for SDMSubscriptionDocumentApiImpl");
if (m_SDMSubscriptionDocumentApiserver != nullptr) if (m_SDMSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for SDMSubscriptionsCollectionApiImpl"); "UDR handler for SDMSubscriptionsCollectionApiImpl");
if (m_SDMSubscriptionsCollectionApiserver != nullptr) if (m_SDMSubscriptionsCollectionApiserver != nullptr)
Logger::udr_server().debug( Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl"); "UDR handler for AuthenticationSubscriptionDocumentApiImpl");
m_httpEndpoint->setHandler(m_router->handler()); m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serve(); m_httpEndpoint->serve();
} }
void UDRApiServer::shutdown() { m_httpEndpoint->shutdown(); } void UDRApiServer::shutdown() { m_httpEndpoint->shutdown(); }
#ifndef _UDR_SERVER_H_ #ifndef _UDR_SERVER_H_
#define _UDR_SERVER_H_ #define _UDR_SERVER_H_
#include "pistache/endpoint.h" #include "pistache/endpoint.h"
#include "pistache/http.h" #include "pistache/http.h"
#include "pistache/router.h" #include "pistache/router.h"
#ifdef __linux__ #ifdef __linux__
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
#endif #endif
#include "AMF3GPPAccessRegistrationDocumentApiImpl.h" #include "AMF3GPPAccessRegistrationDocumentApiImpl.h"
#include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h" #include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h"
#include "AuthenticationStatusDocumentApiImpl.h" #include "AuthenticationStatusDocumentApiImpl.h"
#include "AuthenticationSubscriptionDocumentApiImpl.h" #include "AuthenticationSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionDocumentApiImpl.h" #include "SDMSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionsCollectionApiImpl.h" #include "SDMSubscriptionsCollectionApiImpl.h"
#include "SMFRegistrationDocumentApiImpl.h" #include "SMFRegistrationDocumentApiImpl.h"
#include "SMFRegistrationsCollectionApiImpl.h" #include "SMFRegistrationsCollectionApiImpl.h"
#include "SMFSelectionSubscriptionDataDocumentApiImpl.h" #include "SMFSelectionSubscriptionDataDocumentApiImpl.h"
#include "SessionManagementSubscriptionDataApiImpl.h" #include "SessionManagementSubscriptionDataApiImpl.h"
#include <mysql/mysql.h> #include <mysql/mysql.h>
#define PISTACHE_SERVER_THREADS 2 #define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768 #define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768 #define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
using namespace org::openapitools::server::api; using namespace org::openapitools::server::api;
class UDRApiServer { class UDRApiServer {
public: public:
UDRApiServer(Pistache::Address address, MYSQL *mysql); UDRApiServer(Pistache::Address address, MYSQL *mysql);
void init(size_t thr = 1); void init(size_t thr = 1);
void start(); void start();
void shutdown(); void shutdown();
private: private:
std::shared_ptr<Pistache::Http::Endpoint> m_httpEndpoint; std::shared_ptr<Pistache::Http::Endpoint> m_httpEndpoint;
std::shared_ptr<Pistache::Rest::Router> m_router; std::shared_ptr<Pistache::Rest::Router> m_router;
std::shared_ptr<AuthenticationSubscriptionDocumentApiImpl> std::shared_ptr<AuthenticationSubscriptionDocumentApiImpl>
m_AuthenticationSubscriptionDocumentApiserver; m_AuthenticationSubscriptionDocumentApiserver;
std::shared_ptr<AuthenticationStatusDocumentApiImpl> std::shared_ptr<AuthenticationStatusDocumentApiImpl>
m_AuthenticationStatusDocumentApiserver; m_AuthenticationStatusDocumentApiserver;
std::shared_ptr<AccessAndMobilitySubscriptionDataDocumentApiImpl> std::shared_ptr<AccessAndMobilitySubscriptionDataDocumentApiImpl>
m_AccessAndMobilitySubscriptionDataDocumentApiserver; m_AccessAndMobilitySubscriptionDataDocumentApiserver;
std::shared_ptr<SMFSelectionSubscriptionDataDocumentApiImpl> std::shared_ptr<SMFSelectionSubscriptionDataDocumentApiImpl>
m_SMFSelectionSubscriptionDataDocumentApiserver; m_SMFSelectionSubscriptionDataDocumentApiserver;
std::shared_ptr<SessionManagementSubscriptionDataApiImpl> std::shared_ptr<SessionManagementSubscriptionDataApiImpl>
m_SessionManagementSubscriptionDataApiserver; m_SessionManagementSubscriptionDataApiserver;
std::shared_ptr<AMF3GPPAccessRegistrationDocumentApiImpl> std::shared_ptr<AMF3GPPAccessRegistrationDocumentApiImpl>
m_AMF3GPPAccessRegistrationDocumentApiserver; m_AMF3GPPAccessRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationDocumentApiImpl> std::shared_ptr<SMFRegistrationDocumentApiImpl>
m_SMFRegistrationDocumentApiserver; m_SMFRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationsCollectionApiImpl> std::shared_ptr<SMFRegistrationsCollectionApiImpl>
m_SMFRegistrationsCollectionApiserver; m_SMFRegistrationsCollectionApiserver;
std::shared_ptr<SDMSubscriptionDocumentApiImpl> std::shared_ptr<SDMSubscriptionDocumentApiImpl>
m_SDMSubscriptionDocumentApiserver; m_SDMSubscriptionDocumentApiserver;
std::shared_ptr<SDMSubscriptionsCollectionApiImpl> std::shared_ptr<SDMSubscriptionsCollectionApiImpl>
m_SDMSubscriptionsCollectionApiserver; m_SDMSubscriptionsCollectionApiserver;
}; };
#endif #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