--- /dev/null
+/*\r
+==================================================================================\r
+\r
+ Copyright (c) 2018-2019 AT&T Intellectual Property.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================================\r
+*/\r
+\r
+#include "kpi-xapp.hpp"\r
+\r
+void get_environment_config(configuration & config_instance){\r
+\r
+ // Order of priority for setting variables\r
+ // So we start in reverse order\r
+ // -- command line \r
+ // -- environment variable\r
+ // -- default path \r
+ \r
+ if (char *env_gnodeb = std::getenv("GNODEB")){\r
+ config_instance.fill_gnodeb_list(env_gnodeb);\r
+ mdclog_write(MDCLOG_INFO, "gNodeB List set to %s from environment variable", env_gnodeb);\r
+ }\r
+ \r
+ if (const char *threads = std::getenv("THREADS")){\r
+ config_instance.num_threads = atoi(threads);\r
+ if ( config_instance.num_threads <= 0 or config_instance.num_threads > MAX_THREADS){\r
+ 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
+ exit(-1);\r
+ }\r
+ else{\r
+ mdclog_write(MDCLOG_INFO, "Number of threads set to %d from environment variable\n", config_instance.num_threads);\r
+ }\r
+ }\r
+\r
+ if (const char *log_env = std::getenv("LOG_LEVEL")){\r
+ if (!strcmp(log_env, "MDCLOG_INFO")){\r
+ config_instance.log_level = MDCLOG_INFO;\r
+ }\r
+ else if (!strcmp(log_env, "MDCLOG_WARN")){\r
+ config_instance.log_level = MDCLOG_WARN;\r
+ }\r
+ else if (!strcmp(log_env, "MDCLOG_ERR")){\r
+ config_instance.log_level = MDCLOG_ERR;\r
+ }\r
+ else if (!strcmp(log_env, "MDCLOG_DEBUG")){\r
+ config_instance.log_level = MDCLOG_DEBUG;\r
+ }\r
+ else{\r
+ config_instance.log_level = MDCLOG_WARN;\r
+ std::cerr <<"Error ! Illegal environment option for log level ignored. Setting log level to " << config_instance.log_level << std::endl;\r
+ }\r
+ }\r
+ \r
+}\r
+\r
+void get_command_line_config(int argc, char **argv, configuration &config_instance){\r
+\r
+ // Parse command line options to over ride\r
+ static struct option long_options[] = \r
+ {\r
+ /* Thse options require arguments */\r
+ {"name", required_argument, 0, 'n'},\r
+ {"port", required_argument, 0, 'p'},\r
+ {"redisport", required_argument,0, 'r'},\r
+ {"threads", required_argument, 0, 't'},\r
+ {"gNodeB", required_argument, 0, 'g'},\r
+ {"verbose", no_argument, &config_instance.log_level, MDCLOG_INFO},\r
+ };\r
+\r
+\r
+ while(1) {\r
+\r
+ int option_index = 0;\r
+ char c = getopt_long(argc, argv, "n:p:r:t:g:", long_options, &option_index);\r
+\r
+ if(c == -1){\r
+ break;\r
+ }\r
+\r
+ switch(c)\r
+ {\r
+\r
+ case 0:\r
+ /* An option flag was set. \r
+ Do nothing for now */\r
+ break;\r
+ \r
+ case 'n':\r
+ strcpy(config_instance.name, optarg);\r
+ break;\r
+ \r
+ case 'p':\r
+ strcpy(config_instance.port, optarg);\r
+ break;\r
+ \r
+ case 't':\r
+ config_instance.num_threads = atoi(optarg);\r
+ mdclog_write(MDCLOG_INFO, "Number of threads set to %d from command line e\n", config_instance.num_threads);\r
+ break;\r
+ \r
+ case 'g':\r
+ config_instance.fill_gnodeb_list(optarg);\r
+ mdclog_write(MDCLOG_INFO, "gNodeB List set to %s from command line ", optarg);\r
+ break;\r
+\r
+ case 'r':\r
+ config_instance.redis_port = atoi(optarg);\r
+ mdclog_write(MDCLOG_INFO, "Redis Port set to %d from command line e\n", config_instance.redis_port);\r
+ break;\r
+ \r
+ case 'h':\r
+ usage(argv[0]);\r
+ exit(0);\r
+ \r
+ default:\r
+ usage(argv[0]);\r
+ exit(1);\r
+ }\r
+ };\r
+\r
+}\r
+\r
+\r
+void usage(char *command){\r
+ std::cout <<"Usage : " << command << " " << std::endl;\r
+ std::cout <<" --name[-n] xapp_instance_name "<< std::endl;\r
+ std::cout <<" --port[-p] port to listen on e.g tcp:4561 "<< std::endl;\r
+ std::cout << "--threads[-t] number of listener threads "<< std::endl ;\r
+ std::cout <<"[--gNodeB[][-g] gNodeB" << std::endl;\r
+ std::cout <<"--redisport[-r] port to connect to redis DB eg., tcp:6379 "<<std::endl;\r
+}\r