2 ==================================================================================
\r
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
\r
6 Licensed under the Apache License, Version 2.0 (the "License");
\r
7 you may not use this file except in compliance with the License.
\r
8 You may obtain a copy of the License at
\r
10 http://www.apache.org/licenses/LICENSE-2.0
\r
12 Unless required by applicable law or agreed to in writing, software
\r
13 distributed under the License is distributed on an "AS IS" BASIS,
\r
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 See the License for the specific language governing permissions and
\r
16 limitations under the License.
\r
17 ==================================================================================
\r
20 #include "kpi-xapp.hpp"
\r
22 void get_environment_config(configuration & config_instance){
\r
24 // Order of priority for setting variables
\r
25 // So we start in reverse order
\r
27 // -- environment variable
\r
30 if (char *env_gnodeb = std::getenv("GNODEB")){
\r
31 config_instance.fill_gnodeb_list(env_gnodeb);
\r
32 mdclog_write(MDCLOG_INFO, "gNodeB List set to %s from environment variable", env_gnodeb);
\r
35 if (const char *threads = std::getenv("THREADS")){
\r
36 config_instance.num_threads = atoi(threads);
\r
37 if ( config_instance.num_threads <= 0 or config_instance.num_threads > MAX_THREADS){
\r
38 mdclog_write(MDCLOG_ERR, "Error :: %s, %d :: Must specify numnber of threads between [1 and %d]. Specified = %d\n", __FILE__, __LINE__, MAX_THREADS, config_instance.num_threads);
\r
42 mdclog_write(MDCLOG_INFO, "Number of threads set to %d from environment variable\n", config_instance.num_threads);
\r
46 if (const char *log_env = std::getenv("LOG_LEVEL")){
\r
47 if (!strcmp(log_env, "MDCLOG_INFO")){
\r
48 config_instance.log_level = MDCLOG_INFO;
\r
50 else if (!strcmp(log_env, "MDCLOG_WARN")){
\r
51 config_instance.log_level = MDCLOG_WARN;
\r
53 else if (!strcmp(log_env, "MDCLOG_ERR")){
\r
54 config_instance.log_level = MDCLOG_ERR;
\r
56 else if (!strcmp(log_env, "MDCLOG_DEBUG")){
\r
57 config_instance.log_level = MDCLOG_DEBUG;
\r
60 config_instance.log_level = MDCLOG_WARN;
\r
61 std::cerr <<"Error ! Illegal environment option for log level ignored. Setting log level to " << config_instance.log_level << std::endl;
\r
67 void get_command_line_config(int argc, char **argv, configuration &config_instance){
\r
69 // Parse command line options to over ride
\r
70 static struct option long_options[] =
\r
72 /* Thse options require arguments */
\r
73 {"name", required_argument, 0, 'n'},
\r
74 {"port", required_argument, 0, 'p'},
\r
75 {"redisport", required_argument,0, 'r'},
\r
76 {"threads", required_argument, 0, 't'},
\r
77 {"gNodeB", required_argument, 0, 'g'},
\r
78 {"verbose", no_argument, &config_instance.log_level, MDCLOG_INFO},
\r
84 int option_index = 0;
\r
85 char c = getopt_long(argc, argv, "n:p:r:t:g:", long_options, &option_index);
\r
95 /* An option flag was set.
\r
96 Do nothing for now */
\r
100 strcpy(config_instance.name, optarg);
\r
104 strcpy(config_instance.port, optarg);
\r
108 config_instance.num_threads = atoi(optarg);
\r
109 mdclog_write(MDCLOG_INFO, "Number of threads set to %d from command line e\n", config_instance.num_threads);
\r
113 config_instance.fill_gnodeb_list(optarg);
\r
114 mdclog_write(MDCLOG_INFO, "gNodeB List set to %s from command line ", optarg);
\r
118 config_instance.redis_port = atoi(optarg);
\r
119 mdclog_write(MDCLOG_INFO, "Redis Port set to %d from command line e\n", config_instance.redis_port);
\r
135 void usage(char *command){
\r
136 std::cout <<"Usage : " << command << " " << std::endl;
\r
137 std::cout <<" --name[-n] xapp_instance_name "<< std::endl;
\r
138 std::cout <<" --port[-p] port to listen on e.g tcp:4561 "<< std::endl;
\r
139 std::cout << "--threads[-t] number of listener threads "<< std::endl ;
\r
140 std::cout <<"[--gNodeB[][-g] gNodeB" << std::endl;
\r
141 std::cout <<"--redisport[-r] port to connect to redis DB eg., tcp:6379 "<<std::endl;
\r