forked from acouzens/open5gs
update it
This commit is contained in:
parent
7c0efed3f8
commit
2e33ece64f
|
@ -15,7 +15,6 @@ status_t context_init()
|
|||
d_assert(context_initialized == 0, return CORE_ERROR,
|
||||
"Context already has been context_initialized");
|
||||
|
||||
/* Initialize context */
|
||||
memset(&self, 0, sizeof(context_t));
|
||||
|
||||
context_initialized = 1;
|
||||
|
@ -23,6 +22,77 @@ status_t context_init()
|
|||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t context_parse_config()
|
||||
{
|
||||
config_t *config = &self.config;
|
||||
|
||||
char *json = config->json;
|
||||
jsmntok_t *token = config->token;
|
||||
|
||||
typedef enum { START, ROOT, SKIP, STOP } parse_state;
|
||||
parse_state state = START;
|
||||
|
||||
size_t root_tokens = 0;
|
||||
size_t skip_tokens = 0;
|
||||
size_t i = 0, j = 1;
|
||||
|
||||
for (i = 0, j = 1; j > 0; i++, j--)
|
||||
{
|
||||
jsmntok_t *t = &token[i];
|
||||
|
||||
j += t->size;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case START:
|
||||
{
|
||||
state = ROOT;
|
||||
root_tokens = t->size;
|
||||
|
||||
break;
|
||||
}
|
||||
case ROOT:
|
||||
{
|
||||
root_tokens--;
|
||||
|
||||
if (jsmntok_equal(json, t, "DB_URI") == 0)
|
||||
self.db_uri = jsmntok_to_string(json, t+1);
|
||||
else if (jsmntok_equal(json, t, "LOG_PATH") == 0)
|
||||
self.log_path = jsmntok_to_string(json, t+1);
|
||||
|
||||
state = SKIP;
|
||||
skip_tokens = t->size;
|
||||
|
||||
if (root_tokens == 0) state = STOP;
|
||||
|
||||
break;
|
||||
}
|
||||
case SKIP:
|
||||
{
|
||||
skip_tokens--;
|
||||
skip_tokens += t->size;
|
||||
|
||||
if (skip_tokens == 0) state = ROOT;
|
||||
|
||||
break;
|
||||
}
|
||||
case STOP:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
d_error("Failed to parse configuration in the state(%u)",
|
||||
state);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t context_final()
|
||||
{
|
||||
d_assert(context_initialized == 1, return CORE_ERROR,
|
||||
|
@ -40,10 +110,15 @@ context_t* context_self()
|
|||
|
||||
status_t context_read_file(char *file_path)
|
||||
{
|
||||
char buf[MAX_ERROR_STRING_LEN];
|
||||
config_t *config = &self.config;
|
||||
status_t rv;
|
||||
file_t *file;
|
||||
|
||||
jsmn_parser parser;
|
||||
size_t json_len;
|
||||
int result;
|
||||
|
||||
char *path = file_path;
|
||||
if (path == NULL) path = DEFAULT_CONFIG_FILE_PATH;
|
||||
|
||||
|
@ -51,63 +126,39 @@ status_t context_read_file(char *file_path)
|
|||
if (rv != CORE_OK)
|
||||
{
|
||||
d_fatal("Can't open configuration file '%s' (errno = %d, %s)",
|
||||
path, rv, core_strerror(rv, config->json, MAX_CONFIG_FILE_SIZE));
|
||||
path, rv, core_strerror(rv, buf, MAX_ERROR_STRING_LEN));
|
||||
return rv;
|
||||
}
|
||||
|
||||
config->json_len = MAX_CONFIG_FILE_SIZE;
|
||||
rv = file_read(file, config->json, &config->json_len);
|
||||
json_len = MAX_CONFIG_FILE_SIZE;
|
||||
rv = file_read(file, config->json, &json_len);
|
||||
if (rv != CORE_OK)
|
||||
{
|
||||
d_fatal("Can't read configuration file '%s' (errno = %d, %s)",
|
||||
path, rv, core_strerror(rv, config->json, MAX_CONFIG_FILE_SIZE));
|
||||
path, rv, core_strerror(rv, buf, MAX_ERROR_STRING_LEN));
|
||||
return rv;
|
||||
}
|
||||
file_close(file);
|
||||
|
||||
jsmn_init(&config->parser);
|
||||
config->num_of_token = jsmn_parse(
|
||||
&config->parser, config->json, strlen(config->json),
|
||||
jsmn_init(&parser);
|
||||
result = jsmn_parse(&parser, config->json, strlen(config->json),
|
||||
config->token, sizeof(config->token)/sizeof(config->token[0]));
|
||||
if (config->num_of_token < 0)
|
||||
if (result < 0)
|
||||
{
|
||||
d_fatal("Failed to parse configuration '%s' (jsmnerr = %d)",
|
||||
config->json, config->num_of_token);
|
||||
d_fatal("Failed to parse configuration file '%s' (jsmnerr = %d)",
|
||||
path, result);
|
||||
return CORE_ERROR;
|
||||
}
|
||||
|
||||
if (config->num_of_token < 1 || config->token[0].type != JSMN_OBJECT)
|
||||
if (result < 1 || config->token[0].type != JSMN_OBJECT)
|
||||
{
|
||||
d_fatal("Failed to parse configuration file '%s' (OBJECT expected)",
|
||||
path);
|
||||
return CORE_ERROR;
|
||||
}
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t context_parse_config()
|
||||
{
|
||||
int i;
|
||||
config_t *config = &self.config;
|
||||
|
||||
char *json = config->json;
|
||||
int num_of_token = config->num_of_token;
|
||||
jsmntok_t *token = config->token;
|
||||
|
||||
for (i = 0; i < num_of_token; i++)
|
||||
{
|
||||
if (jsmntok_equal(json, &token[i], "DB_URI") == 0)
|
||||
{
|
||||
self.db_uri = jsmntok_to_string(json, &token[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if (jsmntok_equal(json, &token[i], "LOG_PATH") == 0)
|
||||
{
|
||||
self.log_path = jsmntok_to_string(json, &token[i+1]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
d_print(" Config '%s'\n", path);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,16 +9,11 @@
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MAX_CONFIG_FILE_SIZE 1024
|
||||
#define MAX_CONFIG_FILE_SIZE 2048
|
||||
#define MAX_NUM_OF_CONFIG_TOKEN 256
|
||||
|
||||
typedef struct _config_t {
|
||||
char json[MAX_CONFIG_FILE_SIZE+1];
|
||||
size_t json_len;
|
||||
|
||||
jsmn_parser parser;
|
||||
|
||||
int num_of_token;
|
||||
jsmntok_t token[MAX_NUM_OF_CONFIG_TOKEN];
|
||||
} config_t;
|
||||
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
#define MAX_NUM_OF_FILE 256
|
||||
#define MAX_FILENAME_SIZE 256
|
||||
#define MAX_DIRNAME_SIZE 256
|
||||
#define MAX_FILEPATH_LEN 256
|
||||
|
||||
#define MAX_NUM_OF_TIMER 1024
|
||||
|
||||
#define MAX_SIG_DESC_SIZE 256
|
||||
|
||||
#define MAX_FILEPATH_LEN 256
|
||||
#define MAX_ERROR_STRING_LEN 1024
|
||||
|
||||
#endif /* ! __CORE_PARAM_H__ */
|
||||
|
|
|
@ -258,6 +258,7 @@ int logger_start(const char *path)
|
|||
core_signal(SIGINT, check_signal);
|
||||
core_signal(SIGTERM, check_signal);
|
||||
|
||||
d_print(" Logging '%s'\n", path);
|
||||
ret = logger_start_internal(path);
|
||||
d_assert(ret == 0, _exit(EXIT_FAILURE), "logger_start() failed");
|
||||
|
||||
|
|
5
main.c
5
main.c
|
@ -145,13 +145,16 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
}
|
||||
|
||||
show_version();
|
||||
d_print("\n");
|
||||
|
||||
if (app_initialize(config_path, log_path) != CORE_OK)
|
||||
{
|
||||
d_fatal("NextEPC initialization failed. Aborted");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
show_version();
|
||||
d_print("\n\n");
|
||||
d_info("NextEPC daemon start");
|
||||
signal_thread(check_signal);
|
||||
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
{
|
||||
#
|
||||
DB_URI : "mongodb://localhost/nextepc"
|
||||
LOG_PATH : "@prefix@/var/log/nextepc.log"
|
||||
DB_URI : "mongodb://localhost/nextepc",
|
||||
LOG_PATH : "@prefix@/var/log/nextepc.log",
|
||||
|
||||
HSS :
|
||||
{
|
||||
S6A_CONFIG_PATH : "@prefix@/hss_fd.conf"
|
||||
},
|
||||
S6A_CONFIG_PATH : "/Users/acetcom/Documents/git/nextepc/install/hss_fd.conf"
|
||||
}
|
||||
|
||||
MME :
|
||||
{
|
||||
S6A_CONFIG_PATH : "@prefix@/mme_fd.conf"
|
||||
S6A_CONFIG_PATH : "/Users/acetcom/Documents/git/nextepc/install/mme_fd.conf",
|
||||
|
||||
DEFAULT_PAGING_DRX : "v64",
|
||||
RELATIVE_CAPACITY : 0xff,
|
||||
RELATIVE_CAPACITY : 255,
|
||||
|
||||
NETWORK :
|
||||
{
|
||||
|
@ -21,16 +20,16 @@
|
|||
#S1AP_PORT : 36412,
|
||||
#S11_ADDR: "10.1.35.215",
|
||||
#S11_PORT: 2123
|
||||
},
|
||||
}
|
||||
GUMMEI:
|
||||
[
|
||||
{
|
||||
MCC : "001",
|
||||
MNC : "01"
|
||||
MNC : "01",
|
||||
MME_GID : 2,
|
||||
MME_CODE : 1
|
||||
}
|
||||
],
|
||||
]
|
||||
TAI:
|
||||
[
|
||||
{
|
||||
|
@ -38,13 +37,13 @@
|
|||
MNC: "01",
|
||||
TAC: 12345
|
||||
}
|
||||
],
|
||||
]
|
||||
SECURITY :
|
||||
{
|
||||
INTEGRITY_ORDER : [ "EIA1", "EIA2", "EIA0" ],
|
||||
INTEGRITY_ORDER : [ "EIA1", "EIA2", "EIA0" ]
|
||||
CIPHERING_ORDER : [ "EEA0", "EEA1", "EEA2" ]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
SGW :
|
||||
{
|
||||
|
@ -59,11 +58,10 @@
|
|||
S5C_ADDR: "10.1.35.217",
|
||||
#S5C_PORT: 2123,
|
||||
#S5U_ADDR: "10.1.35.217",
|
||||
#S5U_PORT: 2125,
|
||||
#S5U_PORT: 2125
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
PGW :
|
||||
{
|
||||
|
@ -72,8 +70,8 @@
|
|||
S5C_ADDR: "10.1.35.219",
|
||||
#S5C_PORT: 2123,
|
||||
#S5U_ADDR: "10.1.35.219",
|
||||
#S5U_PORT: 2125,
|
||||
},
|
||||
#S5U_PORT: 2125
|
||||
}
|
||||
|
||||
DNS :
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue