NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ethernet-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-2022, 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_ETHERNET_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "ethernet-protocol.hpp"
31 #include "pcap-helper.hpp"
32 
34 
35 namespace nfd {
36 namespace face {
37 
41 class EthernetChannel final : public Channel
42 {
43 public:
47  class Error : public std::runtime_error
48  {
49  public:
50  explicit
51  Error(const std::string& what)
52  : std::runtime_error(what)
53  {
54  }
55  };
56 
63  EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
64  time::nanoseconds idleTimeout);
65 
66  bool
67  isListening() const final
68  {
69  return m_isListening;
70  }
71 
72  size_t
73  size() const final
74  {
75  return m_channelFaces.size();
76  }
77 
81  void
82  connect(const ethernet::Address& remoteEndpoint,
83  const FaceParams& params,
84  const FaceCreatedCallback& onFaceCreated,
85  const FaceCreationFailedCallback& onConnectFailed);
86 
99  void
100  listen(const FaceCreatedCallback& onFaceCreated,
101  const FaceCreationFailedCallback& onFaceCreationFailed);
102 
103 private:
104  void
105  asyncRead(const FaceCreatedCallback& onFaceCreated,
106  const FaceCreationFailedCallback& onReceiveFailed);
107 
108  void
109  handleRead(const boost::system::error_code& error,
110  const FaceCreatedCallback& onFaceCreated,
111  const FaceCreationFailedCallback& onReceiveFailed);
112 
113  void
114  processIncomingPacket(span<const uint8_t> packet,
115  const ethernet::Address& sender,
116  const FaceCreatedCallback& onFaceCreated,
117  const FaceCreationFailedCallback& onReceiveFailed);
118 
119  std::pair<bool, shared_ptr<Face>>
120  createFace(const ethernet::Address& remoteEndpoint,
121  const FaceParams& params);
122 
123  void
124  updateFilter();
125 
126 private:
127  shared_ptr<const ndn::net::NetworkInterface> m_localEndpoint;
128  bool m_isListening;
129  boost::asio::posix::stream_descriptor m_socket;
130  PcapHelper m_pcap;
131  std::map<ethernet::Address, shared_ptr<Face>> m_channelFaces;
132  const time::nanoseconds m_idleFaceTimeout;
133 
134 #ifdef _DEBUG
135  size_t m_nDropped;
137 #endif
138 };
139 
140 } // namespace face
141 } // namespace nfd
142 
143 #endif // NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
void connect(const ethernet::Address &remoteEndpoint, const FaceParams &params, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast Ethernet face toward remoteEndpoint.
Represents a channel that listens on a local endpoint.
Definition: channel.hpp:41
Helper class for dealing with libpcap handles.
Definition: pcap-helper.hpp:45
STL namespace.
std::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:90
Class implementing Ethernet-based channel to create faces.
EthernetChannel-related error.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
bool isListening() const final
Returns whether the channel is listening.
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
Error(const std::string &what)
represents an Ethernet hardware address
Definition: ethernet.hpp:52
EthernetChannel(shared_ptr< const ndn::net::NetworkInterface > localEndpoint, time::nanoseconds idleTimeout)
Create an Ethernet channel on the given localEndpoint (network interface)
size_t size() const final
Returns the number of faces in the channel.
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
Definition: channel.hpp:86
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
Parameters used to set Transport properties or LinkService options on a newly created face...
Definition: face-common.hpp:78