NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
tcp-channel.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2017, 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 NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_DAEMON_FACE_TCP_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_TCP_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "core/scheduler.hpp"
31 
32 namespace nfd {
33 
34 namespace tcp {
35 typedef boost::asio::ip::tcp::endpoint Endpoint;
36 } // namespace tcp
37 
38 namespace face {
39 
47 class TcpChannel : public Channel
48 {
49 public:
56  explicit
57  TcpChannel(const tcp::Endpoint& localEndpoint);
58 
59  bool
60  isListening() const override
61  {
62  return m_acceptor.is_open();
63  }
64 
65  size_t
66  size() const override
67  {
68  return m_channelFaces.size();
69  }
70 
80  void
81  listen(const FaceCreatedCallback& onFaceCreated,
82  const FaceCreationFailedCallback& onAcceptFailed,
83  int backlog = boost::asio::ip::tcp::acceptor::max_connections);
84 
88  void
89  connect(const tcp::Endpoint& remoteEndpoint,
90  ndn::nfd::FacePersistency persistency,
91  bool wantLocalFields,
92  bool wantLpReliability,
93  const FaceCreatedCallback& onFaceCreated,
94  const FaceCreationFailedCallback& onConnectFailed,
95  time::nanoseconds timeout = time::seconds(4));
96 
97 private:
98  struct ConnectParams
99  {
100  ndn::nfd::FacePersistency persistency;
101  bool wantLocalFields;
102  bool wantLpReliability;
103  };
104 
105 private:
106  void
108  ndn::nfd::FacePersistency persistency,
109  bool wantLocalFields,
110  bool wantLpReliability,
111  const FaceCreatedCallback& onFaceCreated);
112 
113  void
114  accept(const FaceCreatedCallback& onFaceCreated,
115  const FaceCreationFailedCallback& onAcceptFailed);
116 
117  void
118  handleAccept(const boost::system::error_code& error,
119  const FaceCreatedCallback& onFaceCreated,
120  const FaceCreationFailedCallback& onAcceptFailed);
121 
122  void
123  handleConnect(const boost::system::error_code& error,
124  const tcp::Endpoint& remoteEndpoint,
125  const shared_ptr<boost::asio::ip::tcp::socket>& socket,
126  ConnectParams params,
127  const scheduler::EventId& connectTimeoutEvent,
128  const FaceCreatedCallback& onFaceCreated,
129  const FaceCreationFailedCallback& onConnectFailed);
130 
131  void
132  handleConnectTimeout(const tcp::Endpoint& remoteEndpoint,
133  const shared_ptr<boost::asio::ip::tcp::socket>& socket,
134  const FaceCreationFailedCallback& onConnectFailed);
135 
136 private:
137  const tcp::Endpoint m_localEndpoint;
138  boost::asio::ip::tcp::acceptor m_acceptor;
140  std::map<tcp::Endpoint, shared_ptr<Face>> m_channelFaces;
141 };
142 
143 } // namespace face
144 } // namespace nfd
145 
146 #endif // NFD_DAEMON_FACE_TCP_CHANNEL_HPP
represent a channel that communicates on a local endpoint
Definition: channel.hpp:52
bool isListening() const override
Returns whether the channel is listening.
Definition: tcp-channel.hpp:60
Accept any value the remote endpoint offers.
Definition: enabled.hpp:194
size_t size() const override
Returns the number of faces in the channel.
Definition: tcp-channel.hpp:66
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:48
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp-channel.hpp:35
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
Definition: channel.hpp:44
Catch-all error for socket component errors that don&#39;t fit in other categories.
Definition: base.hpp:83
Class implementing TCP-based channel to create faces.
Definition: tcp-channel.hpp:47
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
Definition: channel.hpp:35