forked from acouzens/open5gs
initial code for moving configuration file format to the YAML
This commit is contained in:
parent
4f722f2807
commit
8e40a0eb64
|
@ -401,6 +401,7 @@ if test x$have_sctp_lib == xno; then
|
|||
fi
|
||||
AM_CONDITIONAL([USRSCTP], [test x$have_usrsctp_lib = xyes])
|
||||
|
||||
PKG_CHECK_MODULES([YAML], yaml-0.1 >= 0.1.7)
|
||||
PKG_CHECK_MODULES([MONGOC], libmongoc-1.0 >= 1.3.1)
|
||||
FREEDIAMETER_DIR=freeDiameter-1.2.1
|
||||
AC_SUBST(FREEDIAMETER_DIR)
|
||||
|
@ -431,6 +432,7 @@ AC_CONFIG_FILES([src/pgw/Makefile])
|
|||
AC_CONFIG_FILES([src/pcrf/Makefile])
|
||||
AC_CONFIG_FILES([src/Makefile])
|
||||
AC_CONFIG_FILES([support/config/nextepc.conf])
|
||||
AC_CONFIG_FILES([support/config/nextepc.json])
|
||||
AC_CONFIG_FILES([support/config/mme.conf])
|
||||
AC_CONFIG_FILES([support/config/sgw.conf])
|
||||
AC_CONFIG_FILES([support/config/pgw.conf])
|
||||
|
@ -464,8 +466,8 @@ version : ${PACKAGE_VERSION}
|
|||
host : ${host}
|
||||
source code location : ${srcdir}
|
||||
compiler : ${CC}
|
||||
compiler flags : ${CFLAGS}
|
||||
linker flags : ${LDFLAGS} ${LIBS} ${MONGOC_LIBS}
|
||||
compiler flags : ${CFLAGS} ${YAML_CFLAGS} ${MONGOC_CFLAGS}
|
||||
linker flags : ${LDFLAGS} ${LIBS} ${YAML_LIBS} ${MONGOC_LIBS}
|
||||
bin directory : ${BIN_DIR}
|
||||
lib directory : ${LIB_DIR}/nextepc
|
||||
config directory : ${SYSCONF_DIR}/nextepc
|
||||
|
|
|
@ -13,6 +13,7 @@ libapp_la_DEPENDENCIES = \
|
|||
|
||||
libapp_la_LIBADD = \
|
||||
$(top_srcdir)/lib/core/src/libcore.la \
|
||||
@YAML_LIBS@ \
|
||||
@MONGOC_LIBS@ \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include "core_file.h"
|
||||
#include "core_debug.h"
|
||||
#include "core_lib.h"
|
||||
#include "core_pkbuf.h"
|
||||
|
||||
#include <yaml.h>
|
||||
#include <mongoc.h>
|
||||
|
||||
#include "context.h"
|
||||
|
@ -30,6 +33,11 @@ status_t context_final()
|
|||
|
||||
if (self.config.bson)
|
||||
bson_destroy(self.config.bson);
|
||||
if (self.config.document)
|
||||
{
|
||||
yaml_document_delete(self.config.document);
|
||||
core_free(self.config.document);
|
||||
}
|
||||
|
||||
context_initialized = 0;
|
||||
|
||||
|
@ -42,6 +50,37 @@ context_t* context_self()
|
|||
}
|
||||
|
||||
status_t context_read_file()
|
||||
{
|
||||
config_t *config = &self.config;
|
||||
FILE *file;
|
||||
yaml_parser_t parser;
|
||||
yaml_document_t *document = NULL;
|
||||
|
||||
d_assert(config->path, return CORE_ERROR,);
|
||||
|
||||
file = fopen(config->path, "rb");
|
||||
d_assert(file, return CORE_ERROR,);
|
||||
|
||||
d_assert(yaml_parser_initialize(&parser), return CORE_ERROR,);
|
||||
yaml_parser_set_input_file(&parser, file);
|
||||
|
||||
document = core_calloc(1, sizeof(yaml_document_t));
|
||||
if (!yaml_parser_load(&parser, document))
|
||||
{
|
||||
d_fatal("Failed to parse configuration file '%s'", config->path);
|
||||
core_free(document);
|
||||
return CORE_ERROR;
|
||||
}
|
||||
|
||||
config->document = document;
|
||||
|
||||
yaml_parser_delete(&parser);
|
||||
d_assert(!fclose(file),,);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t context_read_old_file()
|
||||
{
|
||||
char buf[MAX_ERROR_STRING_LEN];
|
||||
config_t *config = &self.config;
|
||||
|
@ -51,13 +90,13 @@ status_t context_read_file()
|
|||
bson_error_t error;
|
||||
size_t json_len;
|
||||
|
||||
d_assert(config->path, return CORE_ERROR,);
|
||||
d_assert(config->old_path, return CORE_ERROR,);
|
||||
|
||||
rv = file_open(&file, config->path, FILE_READ, FILE_OS_DEFAULT);
|
||||
rv = file_open(&file, config->old_path, FILE_READ, FILE_OS_DEFAULT);
|
||||
if (rv != CORE_OK)
|
||||
{
|
||||
d_fatal("Can't open configuration file '%s' (errno = %d, %s)",
|
||||
config->path, rv, core_strerror(rv, buf, MAX_ERROR_STRING_LEN));
|
||||
config->old_path, rv, core_strerror(rv, buf, MAX_ERROR_STRING_LEN));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -66,7 +105,7 @@ status_t context_read_file()
|
|||
if (rv != CORE_OK)
|
||||
{
|
||||
d_fatal("Can't read configuration file '%s' (errno = %d, %s)",
|
||||
config->path, rv, core_strerror(rv, buf, MAX_ERROR_STRING_LEN));
|
||||
config->old_path, rv, core_strerror(rv, buf, MAX_ERROR_STRING_LEN));
|
||||
return rv;
|
||||
}
|
||||
file_close(file);
|
||||
|
@ -74,11 +113,11 @@ status_t context_read_file()
|
|||
config->bson = bson_new_from_json((const uint8_t *)config->json, -1, &error);;
|
||||
if (config->bson == NULL)
|
||||
{
|
||||
d_fatal("Failed to parse configuration file '%s'", config->path);
|
||||
d_fatal("Failed to parse configuration file '%s'", config->old_path);
|
||||
return CORE_ERROR;
|
||||
}
|
||||
|
||||
d_print(" Config '%s'\n", config->path);
|
||||
d_print(" Config '%s'\n", config->old_path);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
@ -91,6 +130,40 @@ static status_t context_prepare()
|
|||
}
|
||||
|
||||
status_t context_parse_config()
|
||||
{
|
||||
config_t *config = &self.config;
|
||||
yaml_document_t *document = NULL;
|
||||
yaml_node_t *node = NULL;
|
||||
|
||||
d_assert(config, return CORE_ERROR,);
|
||||
document = config->document;
|
||||
d_assert(document, return CORE_ERROR,);
|
||||
|
||||
for (node = document->nodes.start; node < document->nodes.top; node++)
|
||||
{
|
||||
#if 0
|
||||
switch (node->type)
|
||||
{
|
||||
case YAML_SCALAR_NODE:
|
||||
printf("SCALAR: %s\n", node->data.scalar.value);
|
||||
break;
|
||||
case YAML_SEQUENCE_NODE:
|
||||
printf("SEQUENCE\n");
|
||||
break;
|
||||
case YAML_MAPPING_NODE:
|
||||
printf("MAPPIGNG\n");
|
||||
break;
|
||||
default:
|
||||
d_assert(0, return CORE_ERROR,);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t context_parse_old_config()
|
||||
{
|
||||
status_t rv;
|
||||
config_t *config = &self.config;
|
||||
|
|
|
@ -12,9 +12,11 @@ extern "C" {
|
|||
#define MAX_NUM_OF_CONFIG_TOKEN 256
|
||||
|
||||
typedef struct _config_t {
|
||||
const char *old_path;
|
||||
const char *path;
|
||||
char json[MAX_CONFIG_FILE_SIZE+1];
|
||||
void *bson;
|
||||
void *document;
|
||||
} config_t;
|
||||
|
||||
#define MAX_DB_URI_LEN 256
|
||||
|
@ -61,7 +63,9 @@ CORE_DECLARE(context_t*) context_self(void);
|
|||
|
||||
CORE_DECLARE(status_t) context_read_file(void);
|
||||
CORE_DECLARE(status_t) context_parse_config(void);
|
||||
CORE_DECLARE(status_t) context_setup_trace_module(void);
|
||||
|
||||
CORE_DECLARE(status_t) context_read_old_file(void);
|
||||
CORE_DECLARE(status_t) context_parse_old_config(void);
|
||||
|
||||
CORE_DECLARE(status_t) context_db_init(const char *db_uri);
|
||||
CORE_DECLARE(status_t) context_db_final(void);
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
#include "app.h"
|
||||
|
||||
#define DEFAULT_CONFIG_FILE_PATH SYSCONF_DIR PACKAGE "/nextepc.conf"
|
||||
#define DEFAULT_CONFIG_FILE_PATH_JSON SYSCONF_DIR PACKAGE "/nextepc.json"
|
||||
#define DEFAULT_CONFIG_FILE_PATH SYSCONF_DIR PACKAGE "/nextepc.json"
|
||||
#define DEFAULT_RUNTIME_DIR_PATH LOCALSTATE_DIR "run/"
|
||||
|
||||
static status_t app_logger_init();
|
||||
|
@ -23,10 +24,19 @@ status_t app_will_initialize(const char *config_path, const char *log_path)
|
|||
|
||||
context_init();
|
||||
|
||||
context_self()->config.old_path = config_path;
|
||||
context_self()->config.path = config_path;
|
||||
if (context_self()->config.old_path == NULL)
|
||||
context_self()->config.old_path = DEFAULT_CONFIG_FILE_PATH_JSON;
|
||||
if (context_self()->config.path == NULL)
|
||||
context_self()->config.path = DEFAULT_CONFIG_FILE_PATH;
|
||||
|
||||
rv = context_read_old_file();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
rv = context_parse_old_config();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
rv = context_read_file();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
configfiles = \
|
||||
nextepc.conf \
|
||||
nextepc.json \
|
||||
mme.conf \
|
||||
sgw.conf \
|
||||
pgw.conf \
|
||||
|
|
|
@ -1,118 +1,78 @@
|
|||
{
|
||||
"DB_URI" : "mongodb://localhost/nextepc",
|
||||
"LOG" :
|
||||
{
|
||||
"FILE" : "@LOCALSTATE_DIR@/log/nextepc/nextepc.log",
|
||||
"SOCKET" :
|
||||
{
|
||||
"UNIX_DOMAIN" : "/tmp/nextepc-epcd.sock",
|
||||
"FILE" : 0
|
||||
}
|
||||
},
|
||||
"TRACE" :
|
||||
{
|
||||
"S1AP": 1,
|
||||
"NAS": 1,
|
||||
"FD": 1,
|
||||
"GTP": 1,
|
||||
"OTHERS": 1
|
||||
},
|
||||
"NODE":
|
||||
{
|
||||
"DISABLE_HSS": 0,
|
||||
"DISABLE_SGW": 0,
|
||||
"DISABLE_PGW": 0,
|
||||
"DISABLE_PCRF": 0
|
||||
},
|
||||
dbUri: "mongodb://localhost/nextepc"
|
||||
|
||||
"MME" :
|
||||
{
|
||||
"FD_CONF_PATH" : "mme.conf",
|
||||
"DEFAULT_PAGING_DRX" : "v64",
|
||||
"S1AP" :
|
||||
[
|
||||
{
|
||||
"HOSTNAME" : "127.0.0.1"
|
||||
},
|
||||
{
|
||||
"HOSTNAME" : "::1"
|
||||
}
|
||||
],
|
||||
"NETWORK" :
|
||||
{
|
||||
"GTPC_IPV4" : "127.0.0.1"
|
||||
},
|
||||
"GUMMEI" :
|
||||
[
|
||||
{
|
||||
"PLMN_ID" :
|
||||
{
|
||||
"MCC" : "001",
|
||||
"MNC" : "01"
|
||||
},
|
||||
"MME_GID" : 2,
|
||||
"MME_CODE" : 1
|
||||
}
|
||||
],
|
||||
"TAI":
|
||||
[
|
||||
{
|
||||
"PLMN_ID" :
|
||||
{
|
||||
"MCC": "001",
|
||||
"MNC": "01"
|
||||
},
|
||||
"TAC": 12345
|
||||
}
|
||||
],
|
||||
"SECURITY" :
|
||||
{
|
||||
"INTEGRITY_ORDER" : [ "EIA1", "EIA2", "EIA0" ],
|
||||
"CIPHERING_ORDER" : [ "EEA0", "EEA1", "EEA2" ]
|
||||
}
|
||||
},
|
||||
logger:
|
||||
path: "@LOCALSTATE_DIR@/log/nextepc/nextepc.log"
|
||||
trace:
|
||||
s1ap: 1
|
||||
nas: 1
|
||||
diameter: 1
|
||||
gtp: 1
|
||||
others: 1
|
||||
|
||||
"HSS" :
|
||||
{
|
||||
"FD_CONF_PATH" : "hss.conf"
|
||||
},
|
||||
parameter:
|
||||
# no_hss: true
|
||||
# no_sgw: true
|
||||
# no_pgw: true
|
||||
# no_pcrf: true
|
||||
# no_ipv4: true
|
||||
# no_ipv6: true
|
||||
# prefer_ipv4: true
|
||||
|
||||
"SGW" :
|
||||
{
|
||||
"NETWORK" :
|
||||
[
|
||||
{
|
||||
"GTPC_IPV4" : "127.0.0.2",
|
||||
"GTPU_IPV4" : "127.0.0.2"
|
||||
}
|
||||
]
|
||||
},
|
||||
mme:
|
||||
freeDiameterConfigPath: "mme.conf"
|
||||
|
||||
"PGW" :
|
||||
{
|
||||
"FD_CONF_PATH" : "pgw.conf",
|
||||
"NETWORK" :
|
||||
{
|
||||
"GTPC_IPV4" : "127.0.0.3",
|
||||
"GTPU_IPV4" : "127.0.0.3"
|
||||
},
|
||||
"UE_NETWORK":
|
||||
[
|
||||
{
|
||||
"IF_NAME" : "pgwtun",
|
||||
"IPV4_POOL" : "45.45.0.1/16"
|
||||
}
|
||||
],
|
||||
"DNS" :
|
||||
{
|
||||
"PRIMARY_IPV4" : "8.8.8.8",
|
||||
"SECONDARY_IPV4" : "4.4.4.4"
|
||||
}
|
||||
},
|
||||
defaultPagingDRX: v64
|
||||
|
||||
"PCRF" :
|
||||
{
|
||||
"FD_CONF_PATH" : "pcrf.conf"
|
||||
}
|
||||
s1ap:
|
||||
- hostname: "127.0.0.1"
|
||||
- hostname: "::1"
|
||||
gtpc:
|
||||
- hostname: "127.0.0.1"
|
||||
- hostname: "::1"
|
||||
|
||||
}
|
||||
gummei:
|
||||
- plmn_id:
|
||||
mcc: "001"
|
||||
mnc: "01"
|
||||
mme_gid: 2
|
||||
mme_code: 1
|
||||
tai:
|
||||
- plmn_id:
|
||||
mcc: "001"
|
||||
mnc: "01"
|
||||
tac: 12345
|
||||
|
||||
security:
|
||||
integrityOrder : [ EIA1, EIA2, EIA0 ]
|
||||
cipheringOrder : [ EEA0, EEA1, EEA2 ]
|
||||
|
||||
hss:
|
||||
freeDiameterConfigPath: "hss.conf"
|
||||
|
||||
sgw:
|
||||
gtpc:
|
||||
- hostname: "127.0.0.2"
|
||||
- hostname: ::2
|
||||
gtpu:
|
||||
- hostname: "127.0.0.2"
|
||||
- hostname: "::2"
|
||||
|
||||
pgw:
|
||||
freeDiameterConfigPath: "pgw.conf"
|
||||
|
||||
gtpc:
|
||||
- hostname: "127.0.0.3"
|
||||
- hostname: "::3"
|
||||
gtpu:
|
||||
- hostname: "127.0.0.3"
|
||||
- hostname: "::3"
|
||||
|
||||
pdn:
|
||||
- family: AF_INET
|
||||
pool: "45.45.0.1/16"
|
||||
dns: ["8.8.8.8", "4.4.4.4"]
|
||||
# ifName: pgwtun
|
||||
# apn: internet
|
||||
|
||||
pcrf:
|
||||
freeDiameterConfigPath: "pcrf.conf"
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
{
|
||||
"DB_URI" : "mongodb://localhost/nextepc",
|
||||
"LOG" :
|
||||
{
|
||||
"FILE" : "@LOCALSTATE_DIR@/log/nextepc/nextepc.log",
|
||||
"SOCKET" :
|
||||
{
|
||||
"UNIX_DOMAIN" : "/tmp/nextepc-epcd.sock",
|
||||
"FILE" : 0
|
||||
}
|
||||
},
|
||||
"TRACE" :
|
||||
{
|
||||
"S1AP": 1,
|
||||
"NAS": 1,
|
||||
"FD": 1,
|
||||
"GTP": 1,
|
||||
"OTHERS": 1
|
||||
},
|
||||
"NODE":
|
||||
{
|
||||
"DISABLE_HSS": 0,
|
||||
"DISABLE_SGW": 0,
|
||||
"DISABLE_PGW": 0,
|
||||
"DISABLE_PCRF": 0
|
||||
},
|
||||
|
||||
"MME" :
|
||||
{
|
||||
"FD_CONF_PATH" : "mme.conf",
|
||||
"DEFAULT_PAGING_DRX" : "v64",
|
||||
"S1AP" :
|
||||
[
|
||||
{
|
||||
"HOSTNAME" : "127.0.0.1"
|
||||
},
|
||||
{
|
||||
"HOSTNAME" : "::1"
|
||||
}
|
||||
],
|
||||
"NETWORK" :
|
||||
{
|
||||
"GTPC_IPV4" : "127.0.0.1"
|
||||
},
|
||||
"GUMMEI" :
|
||||
[
|
||||
{
|
||||
"PLMN_ID" :
|
||||
{
|
||||
"MCC" : "001",
|
||||
"MNC" : "01"
|
||||
},
|
||||
"MME_GID" : 2,
|
||||
"MME_CODE" : 1
|
||||
}
|
||||
],
|
||||
"TAI":
|
||||
[
|
||||
{
|
||||
"PLMN_ID" :
|
||||
{
|
||||
"MCC": "001",
|
||||
"MNC": "01"
|
||||
},
|
||||
"TAC": 12345
|
||||
}
|
||||
],
|
||||
"SECURITY" :
|
||||
{
|
||||
"INTEGRITY_ORDER" : [ "EIA1", "EIA2", "EIA0" ],
|
||||
"CIPHERING_ORDER" : [ "EEA0", "EEA1", "EEA2" ]
|
||||
}
|
||||
},
|
||||
|
||||
"HSS" :
|
||||
{
|
||||
"FD_CONF_PATH" : "hss.conf"
|
||||
},
|
||||
|
||||
"SGW" :
|
||||
{
|
||||
"NETWORK" :
|
||||
[
|
||||
{
|
||||
"GTPC_IPV4" : "127.0.0.2",
|
||||
"GTPU_IPV4" : "127.0.0.2"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"PGW" :
|
||||
{
|
||||
"FD_CONF_PATH" : "pgw.conf",
|
||||
"NETWORK" :
|
||||
{
|
||||
"GTPC_IPV4" : "127.0.0.3",
|
||||
"GTPU_IPV4" : "127.0.0.3"
|
||||
},
|
||||
"UE_NETWORK":
|
||||
[
|
||||
{
|
||||
"IF_NAME" : "pgwtun",
|
||||
"IPV4_POOL" : "45.45.0.1/16"
|
||||
}
|
||||
],
|
||||
"DNS" :
|
||||
{
|
||||
"PRIMARY_IPV4" : "8.8.8.8",
|
||||
"SECONDARY_IPV4" : "4.4.4.4"
|
||||
}
|
||||
},
|
||||
|
||||
"PCRF" :
|
||||
{
|
||||
"FD_CONF_PATH" : "pcrf.conf"
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue