NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
udp-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_UDP_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_UDP_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "udp-protocol.hpp"
31 
32 #include <array>
33 
34 namespace nfd {
35 namespace face {
36 
40 class UdpChannel : public Channel
41 {
42 public:
50  UdpChannel(const udp::Endpoint& localEndpoint,
51  time::nanoseconds idleTimeout);
52 
53  bool
54  isListening() const override
55  {
56  return m_socket.is_open();
57  }
58 
59  size_t
60  size() const override
61  {
62  return m_channelFaces.size();
63  }
64 
74  void
75  connect(const udp::Endpoint& remoteEndpoint,
76  ndn::nfd::FacePersistency persistency,
77  bool wantLpReliability,
78  const FaceCreatedCallback& onFaceCreated,
79  const FaceCreationFailedCallback& onConnectFailed);
80 
92  void
93  listen(const FaceCreatedCallback& onFaceCreated,
94  const FaceCreationFailedCallback& onFaceCreationFailed);
95 
96 private:
97  void
98  waitForNewPeer(const FaceCreatedCallback& onFaceCreated,
99  const FaceCreationFailedCallback& onReceiveFailed);
100 
105  void
106  handleNewPeer(const boost::system::error_code& error,
107  size_t nBytesReceived,
108  const FaceCreatedCallback& onFaceCreated,
109  const FaceCreationFailedCallback& onReceiveFailed);
110 
111  std::pair<bool, shared_ptr<Face>>
112  createFace(const udp::Endpoint& remoteEndpoint,
113  ndn::nfd::FacePersistency persistency,
114  bool wantLpReliability);
115 
116 private:
117  const udp::Endpoint m_localEndpoint;
118  udp::Endpoint m_remoteEndpoint;
120  std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
121  std::map<udp::Endpoint, shared_ptr<Face>> m_channelFaces;
122  const time::nanoseconds m_idleFaceTimeout;
123 };
124 
125 } // namespace face
126 } // namespace nfd
127 
128 #endif // NFD_DAEMON_FACE_UDP_CHANNEL_HPP
bool isListening() const override
Returns whether the channel is listening.
Definition: udp-channel.hpp:54
size_t size() const override
Returns the number of faces in the channel.
Definition: udp-channel.hpp:60
represent a channel that communicates on a local endpoint
Definition: channel.hpp:52
void connect(const udp::Endpoint &remoteEndpoint, ndn::nfd::FacePersistency persistency, bool wantLpReliability, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast UDP face toward remoteEndpoint.
Definition: udp-channel.cpp:49
UdpChannel(const udp::Endpoint &localEndpoint, time::nanoseconds idleTimeout)
Create a UDP channel on the given localEndpoint.
Definition: udp-channel.cpp:38
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
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
boost::asio::ip::udp::endpoint Endpoint
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
Definition: udp-channel.cpp:72
Catch-all error for socket component errors that don&#39;t fit in other categories.
Definition: base.hpp:83
Class implementing UDP-based channel to create faces.
Definition: udp-channel.hpp:40
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