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