NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
face-uri.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
28 #ifndef NDN_NET_FACE_URI_HPP
29 #define NDN_NET_FACE_URI_HPP
30 
31 #include "ethernet.hpp"
32 #include "../util/time.hpp"
33 
34 #include <boost/asio/ip/tcp.hpp>
35 #include <boost/asio/ip/udp.hpp>
36 #include <boost/asio/local/stream_protocol.hpp>
37 
38 namespace ndn {
39 
43 class FaceUri
44 {
45 public:
46  class Error : public std::invalid_argument
47  {
48  public:
49  explicit
50  Error(const std::string& what)
51  : std::invalid_argument(what)
52  {
53  }
54  };
55 
56  FaceUri();
57 
63  explicit
64  FaceUri(const std::string& uri);
65 
66  // This overload is needed so that calls with string literal won't be
67  // resolved to boost::asio::local::stream_protocol::endpoint overload.
68  explicit
69  FaceUri(const char* uri);
70 
72  bool
73  parse(const std::string& uri);
74 
75 public: // scheme-specific construction
77  explicit
78  FaceUri(const boost::asio::ip::udp::endpoint& endpoint);
79 
81  explicit
82  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint);
83 
85  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme);
86 
87 #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
88  explicit
90  FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint);
91 #endif // BOOST_ASIO_HAS_LOCAL_SOCKETS
92 
94  static FaceUri
95  fromFd(int fd);
96 
98  explicit
99  FaceUri(const ethernet::Address& address);
100 
102  static FaceUri
103  fromDev(const std::string& ifname);
104 
106  static FaceUri
107  fromUdpDev(const boost::asio::ip::udp::endpoint& endpoint, const std::string& ifname);
108 
109 public: // getters
111  const std::string&
112  getScheme() const
113  {
114  return m_scheme;
115  }
116 
118  const std::string&
119  getHost() const
120  {
121  return m_host;
122  }
123 
125  const std::string&
126  getPort() const
127  {
128  return m_port;
129  }
130 
132  const std::string&
133  getPath() const
134  {
135  return m_path;
136  }
137 
139  std::string
140  toString() const;
141 
142 public: // EqualityComparable concept
143  bool
144  operator==(const FaceUri& rhs) const;
145 
146  bool
147  operator!=(const FaceUri& rhs) const;
148 
149 public: // canonical FaceUri
152  static bool
153  canCanonize(const std::string& scheme);
154 
160  bool
161  isCanonical() const;
162 
163  typedef function<void(const FaceUri&)> CanonizeSuccessCallback;
164  typedef function<void(const std::string& reason)> CanonizeFailureCallback;
165 
175  void
176  canonize(const CanonizeSuccessCallback& onSuccess,
177  const CanonizeFailureCallback& onFailure,
178  boost::asio::io_service& io,
179  time::nanoseconds timeout) const;
180 
181 private:
182  std::string m_scheme;
183  std::string m_host;
184  std::string m_port;
185  std::string m_path;
187  bool m_isV6;
188 
189  friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
190 };
191 
192 std::ostream&
193 operator<<(std::ostream& os, const FaceUri& uri);
194 
195 } // namespace ndn
196 
197 #endif // NDN_NET_FACE_URI_HPP
Copyright (c) 2011-2015 Regents of the University of California.
function< void(const std::string &reason)> CanonizeFailureCallback
Definition: face-uri.hpp:164
static FaceUri fromFd(int fd)
create fd FaceUri from file descriptor
Definition: face-uri.cpp:155
function< void(const FaceUri &)> CanonizeSuccessCallback
Definition: face-uri.hpp:163
static bool canCanonize(const std::string &scheme)
Definition: face-uri.cpp:635
Error(const std::string &what)
Definition: face-uri.hpp:50
STL namespace.
static FaceUri fromUdpDev(const boost::asio::ip::udp::endpoint &endpoint, const std::string &ifname)
create udp4 or udp6 NIC-associated FaceUri from endpoint and network device name
Definition: face-uri.cpp:180
bool operator!=(const FaceUri &rhs) const
Definition: face-uri.cpp:200
void canonize(const CanonizeSuccessCallback &onSuccess, const CanonizeFailureCallback &onFailure, boost::asio::io_service &io, time::nanoseconds timeout) const
asynchronously convert this FaceUri to canonical form
Definition: face-uri.cpp:652
bool parse(const std::string &uri)
exception-safe parsing
Definition: face-uri.cpp:64
std::string toString() const
write as a string
Definition: face-uri.cpp:206
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:43
represents an Ethernet hardware address
Definition: ethernet.hpp:52
bool isCanonical() const
determine whether this FaceUri is in canonical form
Definition: face-uri.cpp:641
bool operator==(const FaceUri &rhs) const
Definition: face-uri.cpp:190
const std::string & getScheme() const
get scheme (protocol)
Definition: face-uri.hpp:112
const std::string & getHost() const
get host (domain)
Definition: face-uri.hpp:119
const std::string & getPort() const
get port
Definition: face-uri.hpp:126
static FaceUri fromDev(const std::string &ifname)
create dev FaceUri from network device name
Definition: face-uri.cpp:171
const std::string & getPath() const
get path
Definition: face-uri.hpp:133
friend std::ostream & operator<<(std::ostream &os, const FaceUri &uri)
Definition: face-uri.cpp:214