NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
12  *
13  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU Lesser General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any later version.
16  *
17  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20  *
21  * You should have received copies of the GNU General Public License and GNU Lesser
22  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26  */
27 
28 #ifndef NDN_NET_FACE_URI_HPP
29 #define NDN_NET_FACE_URI_HPP
30 
32 #include "ndn-cxx/net/ethernet.hpp"
33 #include "ndn-cxx/util/time.hpp"
34 
35 #include <boost/asio/ip/tcp.hpp>
36 #include <boost/asio/ip/udp.hpp>
37 #include <boost/asio/local/stream_protocol.hpp>
38 
39 namespace ndn {
40 
44 class FaceUri
45 {
46 public:
47  class Error : public std::invalid_argument
48  {
49  public:
50  explicit
51  Error(const std::string& what)
52  : std::invalid_argument(what)
53  {
54  }
55  };
56 
57  FaceUri();
58 
64  explicit
65  FaceUri(const std::string& uri);
66 
67  // This overload is needed so that calls with string literal won't be
68  // resolved to boost::asio::local::stream_protocol::endpoint overload.
69  explicit
70  FaceUri(const char* uri);
71 
73  bool
74  parse(const std::string& uri);
75 
76 public: // scheme-specific construction
78  explicit
79  FaceUri(const boost::asio::ip::udp::endpoint& endpoint);
80 
82  explicit
83  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint);
84 
86  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme);
87 
88 #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
89  explicit
91  FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint);
92 #endif // BOOST_ASIO_HAS_LOCAL_SOCKETS
93 
95  static FaceUri
96  fromFd(int fd);
97 
99  explicit
100  FaceUri(const ethernet::Address& address);
101 
103  static FaceUri
104  fromDev(const std::string& ifname);
105 
107  static FaceUri
108  fromUdpDev(const boost::asio::ip::udp::endpoint& endpoint, const std::string& ifname);
109 
110 public: // getters
112  const std::string&
113  getScheme() const
114  {
115  return m_scheme;
116  }
117 
119  const std::string&
120  getHost() const
121  {
122  return m_host;
123  }
124 
126  const std::string&
127  getPort() const
128  {
129  return m_port;
130  }
131 
133  const std::string&
134  getPath() const
135  {
136  return m_path;
137  }
138 
140  std::string
141  toString() const;
142 
143 public: // EqualityComparable concept
144  bool
145  operator==(const FaceUri& rhs) const;
146 
147  bool
148  operator!=(const FaceUri& rhs) const;
149 
150 public: // canonical FaceUri
153  static bool
154  canCanonize(const std::string& scheme);
155 
161  bool
162  isCanonical() const;
163 
164  typedef function<void(const FaceUri&)> CanonizeSuccessCallback;
165  typedef function<void(const std::string& reason)> CanonizeFailureCallback;
166 
175  void
176  canonize(const CanonizeSuccessCallback& onSuccess,
177  const CanonizeFailureCallback& onFailure,
178  time::nanoseconds timeout) const;
179 
180 private:
181  std::string m_scheme;
182  std::string m_host;
183  std::string m_port;
184  std::string m_path;
186  bool m_isV6;
187 
188  friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
189 };
190 
191 std::ostream&
192 operator<<(std::ostream& os, const FaceUri& uri);
193 
194 } // namespace ndn
195 
196 #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:165
static FaceUri fromFd(int fd)
create fd FaceUri from file descriptor
Definition: face-uri.cpp:153
const std::string & getHost() const
get host (domain)
Definition: face-uri.hpp:120
bool operator!=(const FaceUri &rhs) const
Definition: face-uri.cpp:198
function< void(const FaceUri &)> CanonizeSuccessCallback
Definition: face-uri.hpp:164
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
static bool canCanonize(const std::string &scheme)
Definition: face-uri.cpp:630
Error(const std::string &what)
Definition: face-uri.hpp:51
std::string toString() const
write as a string
Definition: face-uri.cpp:204
void canonize(const CanonizeSuccessCallback &onSuccess, const CanonizeFailureCallback &onFailure, time::nanoseconds timeout) const
asynchronously convert this FaceUri to canonical form
Definition: face-uri.cpp:647
const std::string & getPort() const
get port
Definition: face-uri.hpp:127
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:178
bool parse(const std::string &uri)
exception-safe parsing
Definition: face-uri.cpp:63
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
represents an Ethernet hardware address
Definition: ethernet.hpp:52
const std::string & getScheme() const
get scheme (protocol)
Definition: face-uri.hpp:113
bool operator==(const FaceUri &rhs) const
Definition: face-uri.cpp:188
bool isCanonical() const
determine whether this FaceUri is in canonical form
Definition: face-uri.cpp:636
const std::string & getPath() const
get path
Definition: face-uri.hpp:134
static FaceUri fromDev(const std::string &ifname)
create dev FaceUri from network device name
Definition: face-uri.cpp:169
friend std::ostream & operator<<(std::ostream &os, const FaceUri &uri)
Definition: face-uri.cpp:212