NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
26 #ifndef NFD_DAEMON_FACE_UDP_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_UDP_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 
31 namespace nfd {
32 
33 namespace udp {
34 typedef boost::asio::ip::udp::endpoint Endpoint;
35 } // namespace udp
36 
37 class UdpFace;
38 
42 class UdpChannel : public Channel
43 {
44 public:
55  UdpChannel(const udp::Endpoint& localEndpoint,
56  const time::seconds& timeout);
57 
70  void
71  listen(const FaceCreatedCallback& onFaceCreated,
72  const ConnectFailedCallback& onReceiveFailed);
73 
79  void
80  connect(const udp::Endpoint& remoteEndpoint,
81  ndn::nfd::FacePersistency persistency,
82  const FaceCreatedCallback& onFaceCreated,
83  const ConnectFailedCallback& onConnectFailed);
84 
88  size_t
89  size() const;
90 
91  bool
92  isListening() const;
93 
94 private:
95  std::pair<bool, shared_ptr<UdpFace>>
96  createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency);
97 
102  void
103  handleNewPeer(const boost::system::error_code& error,
104  size_t nBytesReceived,
105  const FaceCreatedCallback& onFaceCreated,
106  const ConnectFailedCallback& onReceiveFailed);
107 
108 private:
109  std::map<udp::Endpoint, shared_ptr<UdpFace>> m_channelFaces;
110 
111  udp::Endpoint m_localEndpoint;
112 
116  udp::Endpoint m_remoteEndpoint;
117 
121  boost::asio::ip::udp::socket m_socket;
122 
126  time::seconds m_idleFaceTimeout;
127 
128  uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
129 };
130 
131 inline bool
133 {
134  return m_socket.is_open();
135 }
136 
137 } // namespace nfd
138 
139 #endif // NFD_DAEMON_FACE_UDP_CHANNEL_HPP
bool isListening() const
Class implementing UDP-based channel to create faces.
Definition: udp-channel.hpp:42
Implementation of Face abstraction that uses unicast UDP as underlying transport mechanism.
Definition: udp-face.hpp:38
UdpChannel
Definition: udp-channel.cpp:32
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
function< void(const std::string &reason)> ConnectFailedCallback
Prototype for the callback that is called when face is failed to get created.
Definition: channel.hpp:46
boost::asio::ip::udp::endpoint Endpoint
Definition: udp-channel.hpp:34
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback called when face is created (as a response to incoming connection or after...
Definition: channel.hpp:41
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
Definition: tlv.hpp:39