OpenSDN source code
tor_agent_param.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 /*
7  * Parameters specific to ToR Agent
8  */
9 #include <cmn/agent_cmn.h>
11 
12 #include <string>
13 #include <base/options_util.h>
14 
15 using std::string;
16 
17 using boost::optional;
18 namespace boost_po = boost::program_options;
19 using namespace options::util;
20 
22  AgentParam(false, false, false, false) {
23 }
24 
26 }
27 
29  boost_po::options_description tor("ToR Agent options");
30  tor.add_options()
31  ("TOR.tor_ip", boost_po::value<string>()->default_value(""),
32  "IP Address of the ToR being managed")
33  ("TOR.tsn_ip", boost_po::value<string>()->default_value(""),
34  "IP Address of the ToR Service Node")
35  ("TOR.tor_id", boost_po::value<string>()->default_value(""),
36  "Identifier of the TOR")
37  ("TOR.tor_type", boost_po::value<string>()->default_value(""),
38  "ToR management scheme")
39  ("TOR.tor_ovs_protocol", boost_po::value<string>()->default_value(""),
40  "Protocol to be used for connection to TOR")
41  ("TOR.tor_ovs_port", boost_po::value<uint16_t>()->default_value(0),
42  "ToR OVS port")
43  ("TOR.ssl_cert", boost_po::value<string>()->default_value(""),
44  "SSL Certificate file to be used")
45  ("TOR.ssl_privkey", boost_po::value<string>()->default_value(""),
46  "SSL Private Key file to be used")
47  ("TOR.ssl_cacert", boost_po::value<string>()->default_value(""),
48  "SSL CA certificate file to be used for peer validations")
49  ("TOR.tor_keepalive_interval", boost_po::value<int>()->default_value(-1),
50  "Keepalive interval for TOR in milli seconds")
51  ("TOR.tor_ha_stale_route_interval",
52  boost_po::value<int>()->default_value(-1),
53  "Interval in millisecond for TOR Agent to hold unicast routes as HA Stale");
56 }
57 
59  // Parse common arguments
62 }
63 
65  // Parse ToR specific arguments
66  const boost::program_options::variables_map &vars = var_map();
67 
68  ParseIpArgument(vars, tor_info_.ip_, "TOR.tor_ip");
69  ParseIpArgument(vars, tor_info_.tsn_ip_, "TOR.tsn_ip");
70  GetOptValue<string>(vars, tor_info_.id_, "TOR.tor_id");
71  GetOptValue<string>(vars, tor_info_.type_, "TOR.tor_type");
72  GetOptValue<string>(vars, tor_info_.protocol_, "TOR.tor_ovs_protocol");
73  GetOptValue<uint16_t>(vars, tor_info_.port_, "TOR.tor_ovs_port");
74  GetOptValue<string>(vars, tor_info_.ssl_cert_,"TOR.ssl_cert");
75  GetOptValue<string>(vars, tor_info_.ssl_privkey_,"TOR.ssl_privkey");
76  GetOptValue<string>(vars, tor_info_.ssl_cacert_,"TOR.ssl_cacert");
77  GetOptValue<int>(vars, tor_info_.keepalive_interval_,
78  "TOR.tor_keepalive_interval");
79  GetOptValue<int>(vars, tor_info_.ha_stale_route_interval_,
80  "TOR.tor_ha_stale_route_interval");
81 }
82 
84  if (tor_info_.tsn_ip_ == Ip4Address::from_string("0.0.0.0")) {
85  LOG(ERROR, "Configuration error. TSN IP address not specified");
86  return (EINVAL);
87  }
88 
89  if (tor_info_.id_ == "") {
90  LOG(ERROR, "Configuration error. ToR ID not specified");
91  return (EINVAL);
92  }
93 
94  if (tor_info_.type_ != "ovs") {
95  LOG(ERROR, "Configuration error. Unsupported ToR type.");
96  LOG(ERROR, "Supported ToR types : <ovs>");
97  return (EINVAL);
98  }
99 
100  if (tor_info_.protocol_ == "tcp") {
101  if (tor_info_.ip_ == Ip4Address::from_string("0.0.0.0")) {
102  LOG(ERROR, "Configuration error. ToR IP address not specified");
103  return (EINVAL);
104  }
105  } else if (tor_info_.protocol_ == "pssl") {
106  if (tor_info_.ssl_cert_ == "") {
107  LOG(ERROR, "Configuration error. SSL Certificate not specified");
108  return (EINVAL);
109  }
110  if (tor_info_.ssl_privkey_ == "") {
111  LOG(ERROR, "Configuration error. SSL Private Key not specified");
112  return (EINVAL);
113  }
114  if (tor_info_.ssl_cacert_ == "") {
115  LOG(ERROR, "Configuration error. SSL CA certificate not specified");
116  return (EINVAL);
117  }
118  } else {
119  LOG(ERROR, "Configuration error. Unsupported ToR OVS Protocol.");
120  LOG(ERROR, "Supported ToR Protocol : <tcp>");
121  return (EINVAL);
122  }
123 
124  if (tor_info_.port_ == 0) {
125  LOG(ERROR, "Configuration error. ToR OVS Protocol Port not specified");
126  return (EINVAL);
127  }
128 
129  return 0;
130 }
void AddOptions(const boost::program_options::options_description &opt)
const boost::program_options::variables_map & var_map() const
Definition: agent_param.h:372
void ParseIpArgument(const boost::program_options::variables_map &var_map, Ip4Address &server, const std::string &key)
Definition: agent_param.cc:155
virtual void ProcessArguments()
Definition: agent_param.cc:955
void ConfigAddOptions(const boost::program_options::options_description &opt)
virtual int Validate()
virtual void ProcessArguments()
virtual void ParseTorArguments()
virtual ~TorAgentParam()
#define LOG(_Level, _Msg)
Definition: logging.h:35