Merge "Reorganize directories and switch libaries to using asn1c"
[it/test.git] / simulators / 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
23 options_t read_input_options_old(int argc, char* argv[])
24 {
25   options_t options;
26
27   options.server_ip         = (char*)DEFAULT_SCTP_IP;
28   options.server_port       = X2AP_SCTP_PORT;
29
30   // Parse command line options
31   static struct option long_options[] =
32     {
33       {"ipv4", required_argument, 0, 'i'},
34       {"ipv6", required_argument, 0, 'I'},
35       {"port", required_argument, 0, 'p'},
36       {"verbose", no_argument, 0, 'v'},
37     };
38
39     while(1)
40     {
41       int option_index = 0;
42
43       char c = getopt_long(argc, argv, "i:I:p:", long_options, &option_index);
44
45       if(c == -1)
46         break;
47
48       switch(c)
49       {
50         case 'i':
51           options.server_ip = optarg;
52           break;
53         case 'I':
54           break;
55         case 'p':
56           options.server_port = atoi(optarg);
57           if(options.server_port < 1 || options.server_port > 65535)
58           {
59             LOG_E("Invalid port number (%d). Valid values are between 1 and 65535.\n",
60                                                               options.server_port);
61             exit(1);
62           }
63           break;
64
65         default:
66           LOG_E("Error: unknown input option: %c\n", optopt);
67           exit(1);
68       }
69     }
70
71     return options;
72 }
73
74 options_t read_input_options(int argc, char *argv[])
75 {
76   options_t options;
77
78   options.server_ip         = (char*)DEFAULT_SCTP_IP;
79   options.server_port       = X2AP_SCTP_PORT;
80
81   if(argc == 3) //user provided IP and PORT
82   {
83     options.server_ip = argv[1];
84     options.server_port = atoi(argv[2]);
85     if(options.server_port < 1 || options.server_port > 65535) {
86       LOG_E("Invalid port number (%d). Valid values are between 1 and 65535.\n",
87                                   options.server_port);
88       exit(1);
89     }
90   }
91   else if(argc == 2) //user provided only IP
92   {
93     options.server_ip = argv[1];
94   }
95   else if(argc == 1)
96   {
97     options.server_ip = (char*)DEFAULT_SCTP_IP;
98   }
99   else
100   {
101     LOG_I("Unrecognized option.\n");
102     LOG_I("Usage: %s [SERVER IP ADDRESS] [SERVER PORT]\n", argv[0]);
103     exit(1);
104   }
105
106   return options;
107 }