NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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-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 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  TcpChannel(const tcp::Endpoint& localEndpoint, bool wantCongestionMarking);
57 
58  bool
59  isListening() const override
60  {
61  return m_acceptor.is_open();
62  }
63 
64  size_t
65  size() const override
66  {
67  return m_channelFaces.size();
68  }
69 
79  void
80  listen(const FaceCreatedCallback& onFaceCreated,
81  const FaceCreationFailedCallback& onAcceptFailed,
82  int backlog = boost::asio::ip::tcp::acceptor::max_connections);
83 
87  void
88  connect(const tcp::Endpoint& remoteEndpoint,
89  const FaceParams& params,
90  const FaceCreatedCallback& onFaceCreated,
91  const FaceCreationFailedCallback& onConnectFailed,
92  time::nanoseconds timeout = 8_s);
93 
94 private:
95  void
96  createFace(boost::asio::ip::tcp::socket&& socket,
97  const FaceParams& params,
98  const FaceCreatedCallback& onFaceCreated);
99 
100  void
101  accept(const FaceCreatedCallback& onFaceCreated,
102  const FaceCreationFailedCallback& onAcceptFailed);
103 
104  void
105  handleAccept(const boost::system::error_code& error,
106  const FaceCreatedCallback& onFaceCreated,
107  const FaceCreationFailedCallback& onAcceptFailed);
108 
109  void
110  handleConnect(const boost::system::error_code& error,
111  const tcp::Endpoint& remoteEndpoint,
112  const shared_ptr<boost::asio::ip::tcp::socket>& socket,
113  const FaceParams& params,
114  const scheduler::EventId& connectTimeoutEvent,
115  const FaceCreatedCallback& onFaceCreated,
116  const FaceCreationFailedCallback& onConnectFailed);
117 
118  void
119  handleConnectTimeout(const tcp::Endpoint& remoteEndpoint,
120  const shared_ptr<boost::asio::ip::tcp::socket>& socket,
121  const FaceCreationFailedCallback& onConnectFailed);
122 
123 private:
124  const tcp::Endpoint m_localEndpoint;
125  boost::asio::ip::tcp::acceptor m_acceptor;
126  boost::asio::ip::tcp::socket m_socket;
127  std::map<tcp::Endpoint, shared_ptr<Face>> m_channelFaces;
128  bool m_wantCongestionMarking;
129 };
130 
131 } // namespace face
132 } // namespace nfd
133 
134 #endif // NFD_DAEMON_FACE_TCP_CHANNEL_HPP
TcpChannel(const tcp::Endpoint &localEndpoint, bool wantCongestionMarking)
Create TCP channel for the local endpoint.
Definition: tcp-channel.cpp:38
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:59
function< void(const shared_ptr< Face > &face)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
Definition: channel.hpp:40
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onAcceptFailed, int backlog=boost::asio::ip::tcp::acceptor::max_connections)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
Definition: tcp-channel.cpp:49
size_t size() const override
Returns the number of faces in the channel.
Definition: tcp-channel.hpp:65
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
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:51
Parameters used to set Transport properties or LinkService options on a newly created face...
Definition: channel.hpp:87
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
void connect(const tcp::Endpoint &remoteEndpoint, const FaceParams &params, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed, time::nanoseconds timeout=8_s)
Create a face by establishing a TCP connection to remoteEndpoint.
Definition: tcp-channel.cpp:71
Class implementing TCP-based channel to create faces.
Definition: tcp-channel.hpp:47