OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
address.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef ctrlplane_address_h
6 #define ctrlplane_address_h
7 
8 #include <boost/asio/ip/address.hpp>
9 
10 //
11 // address types are POD types
12 //
13 typedef boost::asio::ip::address IpAddress;
14 typedef boost::asio::ip::address_v4 Ip4Address;
15 typedef boost::asio::ip::address_v6 Ip6Address;
16 
17 class Address {
18 public:
19  static const uint8_t kMaxV4Bytes = 4;
20  static const uint8_t kMaxV4PrefixLen = 32;
21  static const uint8_t kMaxV6Bytes = 16;
22  static const uint8_t kMaxV6PrefixLen = 128;
23 
24  enum Family {
25  UNSPEC = 0,
26  INET = 1,
27  INET6 = 2,
28  INETVPN = 3,
29  INET6VPN = 4,
30  RTARGET = 5,
31  EVPN = 6,
32  ERMVPN = 7,
33  MVPN = 8,
34  INETMPLS = 9,
36  };
37 
38  Address();
39 
40  static Family FamilyFromString(const std::string &family);
41  static std::string FamilyToString(Family fmly);
42  static std::string FamilyToTableString(Family family);
43  static Family VpnFamilyFromFamily(Family family);
44  static Ip4Address V4FromV4MappedV6(const Ip6Address &v6_address);
45  static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix,
46  uint16_t plen);
47  static Ip6Address GetIp6SubnetAddress(const Ip6Address &prefix,
48  uint16_t plen);
49 
50 private:
52 };
53 
54 boost::system::error_code Ip4PrefixParse(const std::string &str,
55  Ip4Address *addr, int *plen);
56 boost::system::error_code Ip4SubnetParse(const std::string &str,
57  Ip4Address *addr, int *plen);
58 boost::system::error_code Inet6PrefixParse(const std::string &str,
59  Ip6Address *addr, int *plen);
60 boost::system::error_code Inet6SubnetParse(const std::string &str,
61  Ip6Address *addr, int *plen);
62 
63 #endif
static Family VpnFamilyFromFamily(Family family)
Definition: address.cc:71
static const uint8_t kMaxV6PrefixLen
Definition: address.h:22
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
Definition: address.cc:107
Family
Definition: address.h:24
static Family FamilyFromString(const std::string &family)
Definition: address.cc:54
boost::asio::ip::address IpAddress
Definition: address.h:13
static const uint8_t kMaxV4PrefixLen
Definition: address.h:20
static std::string FamilyToTableString(Family family)
Definition: address.cc:67
static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix, uint16_t plen)
Definition: address.cc:179
static Ip6Address GetIp6SubnetAddress(const Ip6Address &prefix, uint16_t plen)
Definition: address.cc:200
static const uint8_t kMaxV4Bytes
Definition: address.h:19
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
static const uint8_t kMaxV6Bytes
Definition: address.h:21
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
boost::system::error_code Ip4SubnetParse(const string &str, Ip4Address *addr, int *plen)
Definition: address.cc:131
static std::string FamilyToString(Family fmly)
Definition: address.cc:63
boost::system::error_code Inet6PrefixParse(const string &str, Ip6Address *addr, int *plen)
Definition: address.cc:144
IpAddress addr_
Definition: address.h:51
Address()
Definition: address.cc:12
static Ip4Address V4FromV4MappedV6(const Ip6Address &v6_address)
Definition: address.cc:291
boost::system::error_code Inet6SubnetParse(const string &str, Ip6Address *addr, int *plen)
Definition: address.cc:162