Commit 3812bba8 authored by yangjian's avatar yangjian

update configuration file

parent d2eb70f8
## udr configuration file
UDR = UDR =
{ {
INSTANCE_ID = 10; # 0 is the default INSTANCE_ID = @INSTANCE@; # 0 is the default
PID_DIRECTORY = "/var/run"; # /var/run is the default PID_DIRECTORY = "@PID_DIRECTORY@"; # /var/run is the default
INTERFACES: INTERFACES:
{ {
# UDR binded interface for Nudr interface # UDR binded interface for Nudr interface
NUDR: SBI:
{ {
INTERFACE_NAME = "ens32"; # YOUR NETWORK CONFIG HERE INTERFACE_NAME = "@UDR_INTERFACE_NAME_FOR_SBI@"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "192.168.2.35"; IPV4_ADDRESS = "read";
PORT = 8081; # YOUR NETWORK CONFIG HERE PORT = 8081; # YOUR NETWORK CONFIG HERE
}; };
}; };
MYSQL: MYSQL:
{ {
## MySQL mandatory options ## MySQL mandatory options
MYSQL_SERVER = "127.0.0.1"; # MySQL Server address MYSQL_SERVER = "@MYSQL_SERVER@"; # MySQL Server address
MYSQL_USER = "yunshou"; # Database server login MYSQL_USER = "@MYSQL_USER@"; # Database server login
MYSQL_PASS = "123456"; # Database server password MYSQL_PASS = "@MYSQL_PASS@"; # Database server password
MYSQL_DB = "Witcomm-UDR-DB"; # Your database name MYSQL_DB = "@MYSQL_DB@"; # Your database name
# MYSQL_PORT = "@MYSQL_PORT@"; # MySQL Server port, 0 is the default
}; };
}; };
## udr configuration file
UDR =
{
INSTANCE_ID = 10; # 0 is the default
PID_DIRECTORY = "/var/run"; # /var/run is the default
INTERFACES:
{
# UDR binded interface for Nudr interface
SBI:
{
INTERFACE_NAME = "eth0"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 8081; # YOUR NETWORK CONFIG HERE
};
};
MYSQL:
{
## MySQL mandatory options
MYSQL_SERVER = "172.16.200.10"; # MySQL Server address
MYSQL_USER = "yunshou"; # Database server login
MYSQL_PASS = "123456"; # Database server password
MYSQL_DB = "Witcomm-UDR-DB"; # Your database name
# MYSQL_PORT = 3306 # MySQL Server port
};
};
...@@ -96,11 +96,11 @@ void AuthenticationSubscriptionDocumentApiImpl:: ...@@ -96,11 +96,11 @@ void AuthenticationSubscriptionDocumentApiImpl::
j += tmp_j; j += tmp_j;
} }
response.send(Pistache::Http::Code::No_Content, "");
std::string out = j.dump(); std::string out = j.dump();
Logger::udr_server().debug("AuthenticationSubscription PATCH - json:\n\"%s\"", Logger::udr_server().debug("AuthenticationSubscription PATCH - json:\n\"%s\"",
out.c_str()); out.c_str());
response.send(Pistache::Http::Code::No_Content, "");
} }
void AuthenticationSubscriptionDocumentApiImpl:: void AuthenticationSubscriptionDocumentApiImpl::
......
...@@ -45,19 +45,19 @@ int main(int argc, char **argv) { ...@@ -45,19 +45,19 @@ int main(int argc, char **argv) {
Logger::udr_app().startup("Options parsed!"); Logger::udr_app().startup("Options parsed!");
// add config file // add config file
udr_cfg.load(Options::getlibconfigConfig()); if(udr_cfg.load(Options::getlibconfigConfig()) < 0) return 0;
udr_cfg.display(); udr_cfg.display();
Logger::udr_app().debug("Initiating UDR server endpoints"); Logger::udr_app().debug("Initiating UDR server endpoints");
// Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080)); // Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080));
Pistache::Address addr(udr_cfg.nudr.addr4, Pistache::Port(udr_cfg.nudr.port)); Pistache::Address addr(udr_cfg.sbi.addr4, Pistache::Port(udr_cfg.sbi.port));
MYSQL mysql; MYSQL mysql;
mysql_init(&mysql); mysql_init(&mysql);
if (!mysql_real_connect(&mysql, udr_cfg.mysql.mysql_server.c_str(), if (!mysql_real_connect(&mysql, udr_cfg.mysql.mysql_server.c_str(),
udr_cfg.mysql.mysql_user.c_str(), udr_cfg.mysql.mysql_user.c_str(),
udr_cfg.mysql.mysql_pass.c_str(), udr_cfg.mysql.mysql_pass.c_str(),
udr_cfg.mysql.mysql_db.c_str(), 0, 0, 0)) { udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0)) {
Logger::udr_app().error("An error occurred while connecting to db: %s", Logger::udr_app().error("An error occurred while connecting to db: %s",
mysql_error(&mysql)); mysql_error(&mysql));
return 0; return 0;
......
#include "udr_config.hpp" #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 <iostream>
#include <libconfig.h++> #include <libconfig.h++>
...@@ -38,71 +48,118 @@ int udr_config::load(const std ::string &config_file) { ...@@ -38,71 +48,118 @@ int udr_config::load(const std ::string &config_file) {
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().error("%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().error("%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 &nudr_cfg = new_if_cfg[UDR_CONFIG_STRING_INTERFACE_NUDR]; const Setting &sbi_cfg = new_if_cfg[UDR_CONFIG_STRING_INTERFACE_SBI];
load_interface(nudr_cfg, nudr); load_interface(sbi_cfg, sbi);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s, using defaults", 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);
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::udr_app().error("%s : %s, using defaults", nfex.what(), Logger::udr_app().error("%s : %s", nfex.what(),
nfex.getPath()); nfex.getPath());
return -1; 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, 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(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;
} }
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(
"- 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("- 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( 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(
"- MYSQL Port .......................................: %d",
mysql.mysql_port);
Logger::config().info("");
Logger::config().info("- Nudr Networking:");
Logger::config().info(" iface ................: %s", nudr.if_name.c_str());
Logger::config().info(" ip ...................: %s", nudr.addr4.c_str());
Logger::config().info(" port .................: %d", nudr.port);
} }
} // namespace config } // namespace config
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#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_NUDR "NUDR" #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"
...@@ -18,16 +18,19 @@ ...@@ -18,16 +18,19 @@
#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"
using namespace libconfig; using namespace libconfig;
namespace config { namespace config {
typedef struct { typedef struct {
std::string mysql_server; std::string mysql_server = "127.0.0.1";
std::string mysql_user; std::string mysql_user = "yunshou";
std::string mysql_pass; std::string mysql_pass = "123456";
std::string mysql_db; std::string mysql_db = "Witcomm-UDR-DB";
unsigned int mysql_port = 0;
} mysql_conf_t; } mysql_conf_t;
typedef struct interface_cfg_s { typedef struct interface_cfg_s {
...@@ -42,12 +45,13 @@ public: ...@@ -42,12 +45,13 @@ public:
~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 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;
interface_cfg_t nudr; interface_cfg_t sbi;
mysql_conf_t mysql; mysql_conf_t mysql;
}; };
} // namespace config } // namespace config
......
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