2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
22 * Author: Ashwin Shridharan, Shraboni Jana
25 #include "xapp_config.hpp"
27 string& XappSettings::operator[](const SettingName& theName){
28 return theSettings[theName];
31 void XappSettings::loadCmdlineSettings(int argc, char **argv){
33 // Parse command line options to over ride
34 static struct option long_options[] =
36 {"xappname", required_argument, 0, 'n'},
37 {"xappid", required_argument, 0, 'x'},
38 {"port", required_argument, 0, 'p'},
39 {"threads", required_argument, 0, 't'},
40 {"a1-schema", required_argument, 0, 'a'},
41 {"ves-schema", required_argument, 0, 'v'},
42 {"ves-url", required_argument, 0, 'u'},
43 {"ves-interval", required_argument, 0, 'i'},
44 {"gNodeB", required_argument, 0, 'g'},
45 {"opmode", required_argument, 0, 'c'}
53 char c = getopt_long(argc, argv, "n:p:t:s:g:a:v:u:i:c:x:", long_options, &option_index);
63 theSettings[XAPP_NAME].assign(optarg);
67 theSettings[HW_PORTS].assign(optarg);
71 theSettings[THREADS].assign(optarg);
72 mdclog_write(MDCLOG_INFO, "Number of threads set to %s from command line e\n", theSettings[THREADS].c_str());
76 theSettings[A1_SCHEMA_FILE].assign(optarg);
77 mdclog_write(MDCLOG_INFO, "Schema file set to %s from command line ", theSettings[A1_SCHEMA_FILE].c_str());
81 theSettings[VES_SCHEMA_FILE].assign(optarg);
82 mdclog_write(MDCLOG_INFO, "VES Schema file set to %s from command line ", theSettings[VES_SCHEMA_FILE].c_str());
86 theSettings[OPERATING_MODE].assign(optarg);
87 mdclog_write(MDCLOG_INFO, "Operating mode set from command line to %s\n", theSettings[OPERATING_MODE].c_str());
91 theSettings[VES_COLLECTOR_URL].assign(optarg);
92 mdclog_write(MDCLOG_INFO, "VES collector url set to %s from command line ", theSettings[VES_COLLECTOR_URL].c_str());
96 theSettings[XAPP_ID].assign(optarg);
97 mdclog_write(MDCLOG_INFO, "XAPP ID set to %s from command line ", theSettings[XAPP_ID].c_str());
101 theSettings[VES_MEASUREMENT_INTERVAL].assign(optarg);
102 mdclog_write(MDCLOG_INFO, "Measurement interval set to %s from command line\n", theSettings[VES_MEASUREMENT_INTERVAL].c_str());
106 theSettings[GNODEB].assign(optarg);
107 mdclog_write(MDCLOG_INFO, "gNodeB List set to %s from command line ", theSettings[GNODEB].c_str());
122 void XappSettings::loadDefaultSettings(){
125 if(theSettings[XAPP_NAME].empty()){
126 theSettings[XAPP_NAME] = DEFAULT_PORT;
129 if(theSettings[XAPP_ID].empty()){
130 theSettings[XAPP_ID] = DEFAULT_PORT;
132 if(theSettings[LOG_LEVEL].empty()){
133 theSettings[LOG_LEVEL] = DEFAULT_LOG_LEVEL;
135 if(theSettings[HW_PORTS].empty()){
136 theSettings[HW_PORTS] = DEFAULT_PORT;
138 if(theSettings[MSG_MAX_BUFFER].empty()){
139 theSettings[MSG_MAX_BUFFER] = DEFAULT_BUFFER;
142 if(theSettings[A1_SCHEMA_FILE].empty()){
143 theSettings[A1_SCHEMA_FILE] = DEFAULT_A1_SCHEMA_FILE;
146 if(theSettings[VES_SCHEMA_FILE].empty()){
147 theSettings[VES_SCHEMA_FILE] = DEFAULT_VES_SCHEMA_FILE;
150 if(theSettings[VES_COLLECTOR_URL].empty()){
151 theSettings[VES_COLLECTOR_URL] = DEFAULT_VES_COLLECTOR_URL;
154 if(theSettings[VES_MEASUREMENT_INTERVAL].empty()){
155 theSettings[VES_MEASUREMENT_INTERVAL] = DEFAULT_VES_MEASUREMENT_INTERVAL;
158 if(theSettings[GNODEB].empty()){
159 theSettings[GNODEB] = DEFAULT_GNODEB;
162 if(theSettings[OPERATING_MODE].empty()){
163 theSettings[OPERATING_MODE] = DEFAULT_OPERATING_MODE;
168 void XappSettings::loadEnvVarSettings(){
170 if (const char *env_xname = std::getenv("XAPP_NAME")){
171 theSettings[XAPP_NAME].assign(env_xname);
172 mdclog_write(MDCLOG_INFO,"Xapp Name set to %s from environment variable", theSettings[XAPP_NAME].c_str());
174 if (const char *env_xid = std::getenv("XAPP_ID")){
175 theSettings[XAPP_ID].assign(env_xid);
176 mdclog_write(MDCLOG_INFO,"Xapp ID set to %s from environment variable", theSettings[XAPP_ID].c_str());
179 if (const char *env_ports = std::getenv("HW_PORTS")){
180 theSettings[HW_PORTS].assign(env_ports);
181 mdclog_write(MDCLOG_INFO,"Ports set to %s from environment variable", theSettings[HW_PORTS].c_str());
183 if (const char *env_ports = std::getenv("MSG_MAX_BUFFER")){
184 theSettings[MSG_MAX_BUFFER].assign(env_ports);
185 mdclog_write(MDCLOG_INFO,"Ports set to %s from environment variable", theSettings[MSG_MAX_BUFFER].c_str());
188 if (const char *env_schema = std::getenv("A1_SCHEMA_FILE")){
189 theSettings[A1_SCHEMA_FILE].assign(env_schema);
190 mdclog_write(MDCLOG_INFO, "A1 Schema file set to %s from environment variable", theSettings[A1_SCHEMA_FILE].c_str());
192 if (const char *env_schema = std::getenv("VES_SCHEMA_FILE")){
193 theSettings[VES_SCHEMA_FILE].assign(env_schema);
194 mdclog_write(MDCLOG_INFO, "VES Schema file set to %s from environment variable", theSettings[VES_SCHEMA_FILE].c_str());
196 if (const char *env_schema = std::getenv("VES_COLLECTOR_URL")){
197 theSettings[VES_COLLECTOR_URL].assign(env_schema);
198 mdclog_write(MDCLOG_INFO, "VES Collector url set to %s from environment variable", theSettings[VES_COLLECTOR_URL].c_str());
201 if (const char *env_schema = std::getenv("VES_MEASUREMENT_INTERVAL")){
202 theSettings[VES_MEASUREMENT_INTERVAL].assign(env_schema);
203 mdclog_write(MDCLOG_INFO, "VES Measurement Interval set to %s from environment variable", theSettings[VES_MEASUREMENT_INTERVAL].c_str());
206 if (char *env_gnodeb = std::getenv("GNODEB")){
207 theSettings[GNODEB].assign(env_gnodeb);
208 mdclog_write(MDCLOG_INFO, "GNODEB file set to %s from environment variable", theSettings[GNODEB].c_str());
214 void XappSettings::usage(char *command){
215 std::cout <<"Usage : " << command << " " << std::endl;
216 std::cout <<" --name[-n] xapp_instance_name "<< std::endl;
217 std::cout <<" --port[-p] port to listen on e.g tcp:4561 "<< std::endl;
218 std::cout << "--threads[-t] number of listener threads "<< std::endl ;
219 std::cout << "--a1-schema[-a] a1 schema file location" << std::endl;
220 std::cout << "--ves-schema[-v] ves schema file location" << std::endl;
221 std::cout << "--samples [-s] samples file location with samples for all jsons" << std::endl;
222 std::cout << "--ves-url [-u] ves collector url" << std::endl;
223 std::cout << "--gNodeB[][-g] gNodeB" << std::endl;
224 std::cout << "--interval[-i] measurement interval to send to ves collector (in seconds)" << std::endl;
225 std::cout << "--opmode [-c] type of operatoring mode : either REPORT or CONTROL. In REPORT, does not send a control message back to gNodeB" << std::endl;