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-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_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 #include <ndn-cxx/net/network-interface.hpp>
33 
34 namespace nfd {
35 namespace face {
36 
40 class EthernetChannel : public Channel
41 {
42 public:
46  class Error : public std::runtime_error
47  {
48  public:
49  explicit
50  Error(const std::string& what)
51  : std::runtime_error(what)
52  {
53  }
54  };
55 
62  EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
63  time::nanoseconds idleTimeout);
64 
65  bool
66  isListening() const override
67  {
68  return m_isListening;
69  }
70 
71  size_t
72  size() const override
73  {
74  return m_channelFaces.size();
75  }
76 
86  void
87  connect(const ethernet::Address& remoteEndpoint,
88  ndn::nfd::FacePersistency persistency,
89  bool wantLpReliability,
90  const FaceCreatedCallback& onFaceCreated,
91  const FaceCreationFailedCallback& onConnectFailed);
92 
105  void
106  listen(const FaceCreatedCallback& onFaceCreated,
107  const FaceCreationFailedCallback& onFaceCreationFailed);
108 
109 private:
110  void
111  asyncRead(const FaceCreatedCallback& onFaceCreated,
112  const FaceCreationFailedCallback& onReceiveFailed);
113 
114  void
115  handleRead(const boost::system::error_code& error,
116  const FaceCreatedCallback& onFaceCreated,
117  const FaceCreationFailedCallback& onReceiveFailed);
118 
119  void
120  processIncomingPacket(const uint8_t* packet, size_t length,
121  const ethernet::Address& sender,
122  const FaceCreatedCallback& onFaceCreated,
123  const FaceCreationFailedCallback& onReceiveFailed);
124 
125  std::pair<bool, shared_ptr<Face>>
126  createFace(const ethernet::Address& remoteEndpoint,
127  ndn::nfd::FacePersistency persistency,
128  bool wantLpReliability);
129 
130  void
131  updateFilter();
132 
133 private:
134  shared_ptr<const ndn::net::NetworkInterface> m_localEndpoint;
135  bool m_isListening;
136  boost::asio::posix::stream_descriptor m_socket;
137  PcapHelper m_pcap;
138  std::map<ethernet::Address, shared_ptr<Face>> m_channelFaces;
139  const time::nanoseconds m_idleFaceTimeout;
140 
141 #ifdef _DEBUG
142  size_t m_nDropped;
144 #endif
145 };
146 
147 } // namespace face
148 } // namespace nfd
149 
150 #endif // NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
void connect(const ethernet::Address &remoteEndpoint, ndn::nfd::FacePersistency persistency, bool wantLpReliability, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast Ethernet face toward remoteEndpoint.
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
STL namespace.
size_t size() const override
Returns the number of faces in the channel.
EthernetChannel-related error.
Class implementing Ethernet-based channel to create faces.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
EthernetChannel(shared_ptr< const ndn::net::NetworkInterface > localEndpoint, time::nanoseconds idleTimeout)
Create an Ethernet channel on the given localEndpoint (network interface)
Error(const std::string &what)
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
represent a channel that communicates on a local endpoint
Definition: channel.hpp:52
bool isListening() const override
Returns whether the channel is listening.
Helper class for dealing with libpcap handles.
Definition: pcap-helper.hpp:45
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