OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
oper_dhcp_options.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_oper_dhcp_options_h_
6 #define vnsw_agent_oper_dhcp_options_h_
7 
8 #include <vnc_cfg_types.h>
9 
10 namespace autogen {
11  struct DhcpOptionType;
12  struct RouteType;
13 }
14 
15 // DHCP options coming from config
17 public:
18  typedef std::vector<autogen::DhcpOptionType> DhcpOptionsList;
19  typedef std::vector<autogen::RouteType> HostOptionsList;
20 
21  struct HostRoute {
23  uint32_t plen_;
25 
26  HostRoute() : prefix_(), plen_(0), gw_() {}
27  bool operator<(const HostRoute &rhs) const {
28  if (prefix_ != rhs.prefix_)
29  return prefix_ < rhs.prefix_;
30  if (plen_ != rhs.plen_)
31  return plen_ < rhs.plen_;
32  return gw_ < rhs.gw_;
33  }
34  bool operator==(const HostRoute &rhs) const {
35  return prefix_ == rhs.prefix_ && plen_ == rhs.plen_ &&
36  gw_ == rhs.gw_;
37  }
38  std::string ToString() const {
39  char len[32];
40  snprintf(len, sizeof(len), "%u", plen_);
41  return prefix_.to_string() + "/" + std::string(len) +
42  " -> " + gw_.to_string();
43  }
44  };
45 
48  dhcp_options_ = options.dhcp_options_;
49  host_routes_ = options.host_routes_;
50  }
51  virtual ~OperDhcpOptions() {}
52 
53  const DhcpOptionsList &dhcp_options() const { return dhcp_options_; }
54  const std::vector<HostRoute> &host_routes() const { return host_routes_; }
57  host_routes_.clear();
58  update_host_routes(host_routes);
59  }
61  host_routes_.clear();
62  for (unsigned int i = 0; i < host_routes.size(); ++i) {
63  HostRoute host_route;
64  boost::system::error_code ec = Ip4PrefixParse(host_routes[i].prefix,
65  &host_route.prefix_,
66  (int *)&host_route.plen_);
67  if (ec || host_route.plen_ > 32) {
68  continue;
69  }
70  host_route.gw_ = Ip4Address::from_string(host_routes[i].next_hop, ec);
71  if (ec) {
72  host_route.gw_ = Ip4Address();
73  }
74  host_routes_.push_back(host_route);
75  }
76  }
77 
78  bool are_dhcp_options_set() const {
79  return dhcp_options_.size() > 0;
80  }
81  bool are_host_routes_set() const {
82  return host_routes_.size() > 0;
83  }
84 
85 private:
87  std::vector<HostRoute> host_routes_;
88 };
89 
90 #endif // vnsw_agent_oper_dhcp_options_h_
bool are_host_routes_set() const
const std::vector< HostRoute > & host_routes() const
std::string ToString() const
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
Definition: address.cc:107
std::vector< HostRoute > host_routes_
const DhcpOptionsList & dhcp_options() const
bool are_dhcp_options_set() const
virtual ~OperDhcpOptions()
bool operator==(const HostRoute &rhs) const
static Options options
std::vector< autogen::RouteType > HostOptionsList
bool operator<(const HostRoute &rhs) const
DhcpOptionsList dhcp_options_
OperDhcpOptions(const OperDhcpOptions &options)
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
void set_host_routes(const HostOptionsList &host_routes)
void update_host_routes(const HostOptionsList &host_routes)
std::vector< autogen::DhcpOptionType > DhcpOptionsList
void set_options(const DhcpOptionsList &options)