/
agent_param.h
410 lines (376 loc) · 15.6 KB
/
agent_param.h
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_param_hpp
#define vnsw_agent_param_hpp
#include <boost/property_tree/ptree.hpp>
#include <boost/program_options.hpp>
#include <cmn/agent_cmn.h>
class Agent;
class VirtualGatewayConfigTable;
// Class handling agent configuration parameters from config file and
// arguments
class AgentParam {
public:
static const uint32_t kAgentStatsInterval = (30 * 1000); // time in millisecs
static const uint32_t kFlowStatsInterval = (1000); // time in milliseconds
static const uint32_t kVrouterStatsInterval = (30 * 1000); //time-millisecs
typedef std::vector<Ip4Address> AddressList;
// Agent mode we are running in
enum AgentMode {
VROUTER_AGENT,
TSN_AGENT,
TOR_AGENT,
};
// Hypervisor mode we are working on
enum HypervisorMode {
MODE_INVALID,
MODE_KVM,
MODE_XEN,
MODE_VMWARE,
MODE_DOCKER,
};
enum VmwareMode {
ESXI_NEUTRON,
VCENTER
};
enum Platform {
VROUTER_ON_HOST,
VROUTER_ON_HOST_DPDK,
VROUTER_ON_NIC
};
struct PortInfo {
PortInfo() :
name_(""), vrf_(""), addr_(0), prefix_(0), plen_(0), gw_(0) {}
~PortInfo() { };
std::string name_;
std::string vrf_;
Ip4Address addr_;
Ip4Address prefix_;
int plen_;
Ip4Address gw_;
};
AgentParam(Agent *agent, bool enable_flow_options = true,
bool enable_vhost_options = true,
bool enable_hypervisor_options = true,
bool enable_service_options = true,
AgentMode agent_mode = VROUTER_AGENT);
virtual ~AgentParam();
virtual int Validate();
bool IsVHostConfigured() {
return vhost_.addr_.to_ulong() != 0? true : false;
}
const std::string &vhost_name() const { return vhost_.name_; }
const Ip4Address &vhost_addr() const { return vhost_.addr_; }
const Ip4Address &vhost_prefix() const { return vhost_.prefix_; }
const int vhost_plen() const { return vhost_.plen_; }
const Ip4Address &vhost_gw() const { return vhost_.gw_; }
const std::string &xen_ll_name() const { return xen_ll_.name_; }
const void set_xen_ll_name(const std::string &name) {
xen_ll_.name_ = name;
}
const Ip4Address &xen_ll_addr() const { return xen_ll_.addr_; }
const Ip4Address &xen_ll_prefix() const { return xen_ll_.prefix_; }
const int xen_ll_plen() const { return xen_ll_.plen_; }
const Ip4Address &xen_ll_gw() const { return xen_ll_.gw_; }
const std::string &agent_name() const { return agent_name_; }
const std::string ð_port() const { return eth_port_; }
const bool ð_port_no_arp() const { return eth_port_no_arp_; }
const std::string ð_port_encap_type() const { return eth_port_encap_type_; }
const Ip4Address &xmpp_server_1() const { return xmpp_server_1_; }
const Ip4Address &xmpp_server_2() const { return xmpp_server_2_; }
const Ip4Address &dns_server_1() const { return dns_server_1_; }
const Ip4Address &dns_server_2() const { return dns_server_2_; }
const uint16_t dns_port_1() const { return dns_port_1_; }
const uint16_t dns_port_2() const { return dns_port_2_; }
const std::string &discovery_server() const { return dss_server_; }
const Ip4Address &mgmt_ip() const { return mgmt_ip_; }
const int xmpp_instance_count() const { return xmpp_instance_count_; }
const std::string &tunnel_type() const { return tunnel_type_; }
const std::string &metadata_shared_secret() const { return metadata_shared_secret_; }
float max_vm_flows() const { return max_vm_flows_; }
uint32_t linklocal_system_flows() const { return linklocal_system_flows_; }
uint32_t linklocal_vm_flows() const { return linklocal_vm_flows_; }
uint32_t flow_cache_timeout() const {return flow_cache_timeout_;}
bool headless_mode() const {return headless_mode_;}
bool dhcp_relay_mode() const {return dhcp_relay_mode_;}
bool xmpp_auth_enabled() const {return xmpp_auth_enable_;}
std::string xmpp_server_cert() const { return xmpp_server_cert_;}
bool simulate_evpn_tor() const {return simulate_evpn_tor_;}
std::string si_netns_command() const {return si_netns_command_;}
std::string si_docker_command() const {return si_docker_command_;}
const int si_netns_workers() const {return si_netns_workers_;}
const int si_netns_timeout() const {return si_netns_timeout_;}
std::string si_lb_ssl_cert_path() const {
return si_lb_ssl_cert_path_;
}
std::string si_lb_keystone_auth_conf_path() const {
return si_lb_keystone_auth_conf_path_;
}
std::string nexthop_server_endpoint() const {
return nexthop_server_endpoint_;
}
const std::string &config_file() const { return config_file_; }
const std::string &program_name() const { return program_name_;}
const std::string log_file() const { return log_file_; }
const int log_files_count() const { return log_files_count_; }
const long log_file_size() const { return log_file_size_; }
bool log_local() const { return log_local_; }
bool log_flow() const { return log_flow_; }
bool disable_flow_collection() const { return disable_flow_collection_; }
const std::string &log_level() const { return log_level_; }
const std::string &log_category() const { return log_category_; }
const std::string &log_property_file() const { return log_property_file_; }
const bool use_syslog() const { return use_syslog_; }
const std::string syslog_facility() const { return syslog_facility_; }
const std::vector<std::string> collector_server_list() const {
return collector_server_list_;
}
uint16_t http_server_port() const { return http_server_port_; }
const std::string &host_name() const { return host_name_; }
int agent_stats_interval() const { return agent_stats_interval_; }
int flow_stats_interval() const { return flow_stats_interval_; }
int vrouter_stats_interval() const { return vrouter_stats_interval_; }
void set_agent_stats_interval(int val) { agent_stats_interval_ = val; }
void set_flow_stats_interval(int val) { flow_stats_interval_ = val; }
void set_vrouter_stats_interval(int val) { vrouter_stats_interval_ = val; }
VirtualGatewayConfigTable *vgw_config_table() const {
return vgw_config_table_.get();
}
const std::string &vmware_physical_port() const {
return vmware_physical_port_;
}
bool debug() const { return debug_; }
HypervisorMode mode() const { return hypervisor_mode_; }
bool isXenMode() const { return hypervisor_mode_ == MODE_XEN; }
bool isKvmMode() const { return hypervisor_mode_ == MODE_KVM; }
bool isDockerMode() const { return hypervisor_mode_ == MODE_DOCKER; }
bool isVmwareMode() const { return hypervisor_mode_ == MODE_VMWARE; }
bool isVmwareVcenterMode() const { return vmware_mode_ == VCENTER; }
VmwareMode vmware_mode() const { return vmware_mode_; }
Platform platform() const { return platform_; }
bool vrouter_on_nic_mode() const {
return platform_ == VROUTER_ON_NIC;
}
bool vrouter_on_host_dpdk() const {
return platform_ == VROUTER_ON_HOST_DPDK;
}
bool vrouter_on_host() const {
return platform_ == VROUTER_ON_HOST;
}
void Init(const std::string &config_file,
const std::string &program_name);
void LogConfig() const;
void PostValidateLogConfig() const;
void InitVhostAndXenLLPrefix();
void InitPlatform();
void set_test_mode(bool mode);
bool test_mode() const { return test_mode_; }
void AddOptions(const boost::program_options::options_description &opt);
void ParseArguments(int argc, char *argv[]);
const boost::program_options::variables_map &var_map() const {
return var_map_;
}
boost::program_options::options_description options() const {
return options_;
}
AgentMode agent_mode() const { return agent_mode_; }
bool isTsnAgent() const { return agent_mode_ == TSN_AGENT; }
bool isTorAgent() const { return agent_mode_ == TOR_AGENT; }
const AddressList &compute_node_address_list() const {
return compute_node_address_list_;
}
void BuildAddressList(const std::string &val);
std::string exception_packet_interface() const {
return exception_packet_interface_;
}
std::string physical_interface_pci_addr() const {
return physical_interface_pci_addr_;
}
std::string physical_interface_mac_addr() const {
return physical_interface_mac_addr_;
}
std::string agent_base_dir() const { return agent_base_dir_; }
protected:
void set_hypervisor_mode(HypervisorMode m) { hypervisor_mode_ = m; }
virtual void InitFromSystem();
virtual void InitFromConfig();
virtual void InitFromArguments();
boost::property_tree::ptree &tree() { return tree_; }
template <typename ValueType>
bool GetOptValue(const boost::program_options::variables_map &var_map,
ValueType &var, const std::string &val) {
return GetOptValueImpl(var_map, var, val,
static_cast<ValueType *>(0));
}
// Implementation overloads
template <typename ValueType>
bool GetOptValueImpl(const boost::program_options::variables_map &var_map,
ValueType &var, const std::string &val, ValueType*) {
// Check if the value is present.
if (var_map.count(val) && !var_map[val].defaulted()) {
var = var_map[val].as<ValueType>();
return true;
}
return false;
}
template <typename ElementType>
bool GetOptValueImpl(const boost::program_options::variables_map &var_map,
std::vector<ElementType> &var, const std::string &val,
std::vector<ElementType> *);
template <typename ValueType>
bool GetValueFromTree(ValueType &var, const std::string &val) {
boost::optional<ValueType> opt;
if (opt = tree_.get_optional<ValueType>(val)) {
var = opt.get();
return true;
}
return false;
}
bool GetIpAddress(const std::string &str, Ip4Address *addr);
bool ParseIp(const std::string &key, Ip4Address *server);
bool ParseServerList(const std::string &key, Ip4Address *s1, Ip4Address *s2);
bool ParseAddress(const std::string &addr_string,
Ip4Address *server, uint16_t *port);
bool ParseServerList(const std::string &key, Ip4Address *server1,
uint16_t *port1, Ip4Address *server2, uint16_t *port2);
void ParseIpArgument(const boost::program_options::variables_map &var_map,
Ip4Address &server, const std::string &key);
bool ParseServerListArguments
(const boost::program_options::variables_map &var_map, Ip4Address &server1,
Ip4Address &server2, const std::string &key);
bool ParseServerListArguments
(const boost::program_options::variables_map &var_map, Ip4Address *server1,
uint16_t *port1, Ip4Address *server2, uint16_t *port2,
const std::string &key);
private:
friend class AgentParamTest;
void ComputeFlowLimits();
void ParseCollector();
void ParseVirtualHost();
void ParseDiscovery();
void ParseNetworks();
void ParseHypervisor();
void ParseDefaultSection();
void ParseMetadataProxy();
void ParseFlows();
void ParseHeadlessMode();
void ParseDhcpRelayMode();
void ParseSimulateEvpnTor();
void ParseServiceInstance();
void ParseAgentInfo();
void ParseNexthopServer();
void ParsePlatform();
void set_agent_mode(const std::string &mode);
void ParseCollectorArguments
(const boost::program_options::variables_map &v);
void ParseVirtualHostArguments
(const boost::program_options::variables_map &v);
void ParseDiscoveryArguments
(const boost::program_options::variables_map &v);
void ParseNetworksArguments
(const boost::program_options::variables_map &v);
void ParseHypervisorArguments
(const boost::program_options::variables_map &v);
void ParseDefaultSectionArguments
(const boost::program_options::variables_map &v);
void ParseMetadataProxyArguments
(const boost::program_options::variables_map &v);
void ParseFlowArguments
(const boost::program_options::variables_map &v);
void ParseHeadlessModeArguments
(const boost::program_options::variables_map &v);
void ParseDhcpRelayModeArguments
(const boost::program_options::variables_map &var_map);
void ParseServiceInstanceArguments
(const boost::program_options::variables_map &v);
void ParseAgentInfoArguments
(const boost::program_options::variables_map &v);
void ParseNexthopServerArguments
(const boost::program_options::variables_map &v);
void ParsePlatformArguments
(const boost::program_options::variables_map &v);
boost::program_options::variables_map var_map_;
boost::program_options::options_description options_;
bool enable_flow_options_;
bool enable_vhost_options_;
bool enable_hypervisor_options_;
bool enable_service_options_;
AgentMode agent_mode_;
Agent *agent_;
PortInfo vhost_;
std::string agent_name_;
std::string eth_port_;
bool eth_port_no_arp_;
std::string eth_port_encap_type_;
uint16_t xmpp_instance_count_;
Ip4Address xmpp_server_1_;
Ip4Address xmpp_server_2_;
Ip4Address dns_server_1_;
Ip4Address dns_server_2_;
uint16_t dns_port_1_;
uint16_t dns_port_2_;
std::string dss_server_;
uint16_t dss_port_;
Ip4Address mgmt_ip_;
HypervisorMode hypervisor_mode_;
PortInfo xen_ll_;
std::string tunnel_type_;
std::string metadata_shared_secret_;
float max_vm_flows_;
uint16_t linklocal_system_flows_;
uint16_t linklocal_vm_flows_;
uint16_t flow_cache_timeout_;
// Parameters configured from command line arguments only (for now)
std::string config_file_;
std::string program_name_;
std::string log_file_;
int log_files_count_;
long log_file_size_;
std::string log_property_file_;
bool log_local_;
bool log_flow_;
bool disable_flow_collection_;
std::string log_level_;
std::string log_category_;
bool use_syslog_;
std::string syslog_facility_;
std::vector<std::string> collector_server_list_;
uint16_t http_server_port_;
std::string host_name_;
int agent_stats_interval_;
int flow_stats_interval_;
int vrouter_stats_interval_;
std::string vmware_physical_port_;
bool test_mode_;
bool debug_;
boost::property_tree::ptree tree_;
std::auto_ptr<VirtualGatewayConfigTable> vgw_config_table_;
bool headless_mode_;
bool dhcp_relay_mode_;
bool xmpp_auth_enable_;
std::string xmpp_server_cert_;
//Simulate EVPN TOR mode moves agent into L2 mode. This mode is required
//only for testing where MX and bare metal are simulated. VM on the
//simulated compute node behaves as bare metal.
bool simulate_evpn_tor_;
std::string si_netns_command_;
std::string si_docker_command_;
int si_netns_workers_;
int si_netns_timeout_;
std::string si_lb_ssl_cert_path_;
std::string si_lb_keystone_auth_conf_path_;
VmwareMode vmware_mode_;
// List of IP addresses on the compute node.
AddressList compute_node_address_list_;
std::string nexthop_server_endpoint_;
bool nexthop_server_add_pid_;
bool vrouter_on_nic_mode_;
std::string exception_packet_interface_;
Platform platform_;
std::string physical_interface_pci_addr_;
std::string physical_interface_mac_addr_;
std::string agent_base_dir_;
DISALLOW_COPY_AND_ASSIGN(AgentParam);
};
#endif // vnsw_agent_param_hpp