-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathCommandLineOptionsParser.cpp
197 lines (159 loc) · 6.88 KB
/
CommandLineOptionsParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "CommandLineOptionsParser.h"
#include "meta/sai_serialize.h"
#include "swss/logger.h"
#include <getopt.h>
#include <iostream>
using namespace syncd;
std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
_In_ int argc,
_In_ char **argv)
{
SWSS_LOG_ENTER();
auto options = std::make_shared<CommandLineOptions>();
#ifdef SAITHRIFT
const char* const optstring = "dp:t:g:x:b:uSUCsz:lrm:h";
#else
const char* const optstring = "dp:t:g:x:b:uSUCsz:lh";
#endif // SAITHRIFT
while (true)
{
static struct option long_options[] =
{
{ "diag", no_argument, 0, 'd' },
{ "profile", required_argument, 0, 'p' },
{ "startType", required_argument, 0, 't' },
{ "useTempView", no_argument, 0, 'u' },
{ "disableExitSleep", no_argument, 0, 'S' },
{ "enableUnittests", no_argument, 0, 'U' },
{ "enableConsistencyCheck", no_argument, 0, 'C' },
{ "syncMode", no_argument, 0, 's' },
{ "redisCommunicationMode", required_argument, 0, 'z' },
{ "enableSaiBulkSupport", no_argument, 0, 'l' },
{ "globalContext", required_argument, 0, 'g' },
{ "contextContig", required_argument, 0, 'x' },
{ "breakConfig", required_argument, 0, 'b' },
#ifdef SAITHRIFT
{ "rpcserver", no_argument, 0, 'r' },
{ "portmap", required_argument, 0, 'm' },
#endif // SAITHRIFT
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
int option_index = 0;
int c = getopt_long(argc, argv, optstring, long_options, &option_index);
if (c == -1)
{
break;
}
switch (c)
{
case 'd':
options->m_enableDiagShell = true;
break;
case 'p':
options->m_profileMapFile = std::string(optarg);
break;
case 't':
options->m_startType = CommandLineOptions::startTypeStringToStartType(optarg);
if (options->m_startType == SAI_START_TYPE_UNKNOWN)
{
SWSS_LOG_ERROR("unknown start type '%s'", optarg);
exit(EXIT_FAILURE);
}
break;
case 'u':
options->m_enableTempView = true;
break;
case 'S':
options->m_disableExitSleep = true;
break;
case 'U':
options->m_enableUnittests = true;
break;
case 'C':
options->m_enableConsistencyCheck = true;
break;
case 's':
SWSS_LOG_WARN("param -s is depreacated, use -z");
options->m_enableSyncMode = true;
break;
case 'z':
sai_deserialize_redis_communication_mode(optarg, options->m_redisCommunicationMode);
break;
case 'l':
options->m_enableSaiBulkSupport = true;
break;
case 'g':
options->m_globalContext = (uint32_t)std::stoul(optarg);
break;
case 'x':
options->m_contextConfig = std::string(optarg);
break;
case 'b':
options->m_breakConfig = std::string(optarg);
break;
#ifdef SAITHRIFT
case 'r':
options->m_runRPCServer = true;
break;
case 'm':
options->m_portMapFile = std::string(optarg);
break;
#endif // SAITHRIFT
case 'h':
printUsage();
exit(EXIT_SUCCESS);
case '?':
SWSS_LOG_WARN("unknown option %c", optopt);
printUsage();
exit(EXIT_FAILURE);
default:
SWSS_LOG_ERROR("getopt_long failure");
exit(EXIT_FAILURE);
}
}
return options;
}
void CommandLineOptionsParser::printUsage()
{
SWSS_LOG_ENTER();
#ifdef SAITHRIFT
std::cout << "Usage: syncd [-d] [-p profile] [-t type] [-u] [-S] [-U] [-C] [-s] [-z mode] [-l] [-g idx] [-x contextConfig] [-b breakConfig] [-r] [-m portmap] [-h]" << std::endl;
#else
std::cout << "Usage: syncd [-d] [-p profile] [-t type] [-u] [-S] [-U] [-C] [-s] [-z mode] [-l] [-g idx] [-x contextConfig] [-b breakConfig] [-h]" << std::endl;
#endif // SAITHRIFT
std::cout << " -d --diag" << std::endl;
std::cout << " Enable diagnostic shell" << std::endl;
std::cout << " -p --profile profile" << std::endl;
std::cout << " Provide profile map file" << std::endl;
std::cout << " -t --startType type" << std::endl;
std::cout << " Specify start type (cold|warm|fast|fastfast) " << std::endl;
std::cout << " -u --useTempView" << std::endl;
std::cout << " Use temporary view between init and apply" << std::endl;
std::cout << " -S --disableExitSleep" << std::endl;
std::cout << " Disable sleep when syncd crashes" << std::endl;
std::cout << " -U --enableUnittests" << std::endl;
std::cout << " Metadata enable unittests" << std::endl;
std::cout << " -C --enableConsistencyCheck" << std::endl;
std::cout << " Enable consisteny check DB vs ASIC after comparison logic" << std::endl;
std::cout << " -s --syncMode" << std::endl;
std::cout << " Enable synchronous mode (depreacated, use -z)" << std::endl;
std::cout << " -z --redisCommunicationMode" << std::endl;
std::cout << " Redis communication mode (redis_async|redis_sync|zmq_sync), default: redis_async" << std::endl;
std::cout << " -l --enableBulk" << std::endl;
std::cout << " Enable SAI Bulk support" << std::endl;
std::cout << " -g --globalContext" << std::endl;
std::cout << " Global context index to load from context config file" << std::endl;
std::cout << " -x --contextConfig" << std::endl;
std::cout << " Context configuration file" << std::endl;
std::cout << " -b --breakConfig" << std::endl;
std::cout << " Comparison logic 'break before make' configuration file" << std::endl;
#ifdef SAITHRIFT
std::cout << " -r --rpcserver" << std::endl;
std::cout << " Enable rpcserver" << std::endl;
std::cout << " -m --portmap portmap" << std::endl;
std::cout << " Specify port map file" << std::endl;
#endif // SAITHRIFT
std::cout << " -h --help" << std::endl;
std::cout << " Print out this message" << std::endl;
}