beef up the AI/ML framework tests by adding InfluxDB as data source and populate...
[it/test.git] / ric_benchmarking / e2-interface / e2sim / src / DEF / e2sim_defs.cpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 # Copyright 2019 Nokia                                                       *
5 #                                                                            *
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                                    *
9 #                                                                            *
10 #      http://www.apache.org/licenses/LICENSE-2.0                            *
11 #                                                                            *
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 #                                                                            *
18 ******************************************************************************/
19
20 #include "e2sim_defs.h"
21 #include <getopt.h>
22 #include <sys/time.h>
23 #include <time.h>
24
25 char* time_stamp(void)
26 {
27   timeval curTime;
28   gettimeofday(&curTime, NULL);
29   int milli = curTime.tv_usec / 1000;
30
31   char buffer [80];
32   strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec));
33
34   const int time_buffer_len = 84;
35   static char currentTime[time_buffer_len] = "";
36   snprintf(currentTime, time_buffer_len, "%s:%03d", buffer, milli);
37
38   return currentTime;
39 }
40
41 options_t read_input_options_old(int argc, char* argv[])
42 {
43   options_t options;
44
45   options.server_ip         = (char*)DEFAULT_SCTP_IP;
46   options.server_port       = X2AP_SCTP_PORT;
47
48   // Parse command line options
49   static struct option long_options[] =
50     {
51       {"ipv4", required_argument, 0, 'i'},
52       {"ipv6", required_argument, 0, 'I'},
53       {"port", required_argument, 0, 'p'},
54       {"verbose", no_argument, 0, 'v'},
55     };
56
57     while(1)
58     {
59       int option_index = 0;
60
61       char c = getopt_long(argc, argv, "i:I:p:", long_options, &option_index);
62
63       if(c == -1)
64         break;
65
66       switch(c)
67       {
68         case 'i':
69           options.server_ip = optarg;
70           break;
71         case 'I':
72           break;
73         case 'p':
74           options.server_port = atoi(optarg);
75           if(options.server_port < 1 || options.server_port > 65535)
76           {
77             LOG_E("Invalid port number (%d). Valid values are between 1 and 65535.\n",
78                                                               options.server_port);
79             exit(1);
80           }
81           break;
82
83         default:
84           LOG_E("Error: unknown input option: %c\n", optopt);
85           exit(1);
86       }
87     }
88
89     return options;
90 }
91
92 options_t read_input_options(int argc, char *argv[])
93 {
94   options_t options;
95
96   options.server_ip         = (char*)DEFAULT_SCTP_IP;
97   options.server_port       = X2AP_SCTP_PORT;
98   options.num_of_e2sim      = 1;
99
100   if(argc == 4) //user provided IP, PORT and number of e2sim
101   {
102     options.server_ip    = argv[1];
103     options.server_port  = atoi(argv[2]);
104     options.num_of_e2sim = atoi(argv[3]);
105     printf("options.server_ip:%s\n", options.server_ip);
106     if(options.server_port < 1 || options.server_port > 65535) {
107       LOG_E("Invalid port number (%d). Valid values are between 1 and 65535.\n",
108                                   options.server_port);
109       exit(1);
110     }
111   }
112   else if(argc == 3) //user provided IP and PORT
113   {
114     options.server_ip = argv[1];
115     options.server_port = atoi(argv[2]);
116     printf("options.server_ip:%s\n", options.server_ip);
117     
118     if(options.server_port < 1 || options.server_port > 65535) {
119       LOG_E("Invalid port number (%d). Valid values are between 1 and 65535.\n",
120                                   options.server_port);
121       exit(1);
122     }
123   }
124   else if(argc == 2) //user provided only IP
125   {
126     options.server_ip = argv[1];
127   }
128   else if(argc == 1)
129   {
130     options.server_ip = (char*)DEFAULT_SCTP_IP;
131   }
132   else
133   {
134     LOG_I("Unrecognized option.\n");
135     LOG_I("Usage: %s [SERVER IP ADDRESS] [SERVER PORT]\n", argv[0]);
136     exit(1);
137   }
138
139   return options;
140 }