NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ethernet-transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
27 #define NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
28 
29 #include "core/common.hpp"
30 #include "transport.hpp"
32 
33 #ifndef HAVE_LIBPCAP
34 #error "Cannot include this file when libpcap is not available"
35 #endif
36 
37 // forward declarations
38 struct pcap;
39 typedef pcap pcap_t;
40 struct pcap_pkthdr;
41 
42 namespace nfd {
43 namespace face {
44 
48 class EthernetTransport final : public Transport
49 {
50 public:
51  class Error : public std::runtime_error
52  {
53  public:
54  explicit
55  Error(const std::string& what)
56  : std::runtime_error(what)
57  {
58  }
59  };
60 
64  EthernetTransport(const NetworkInterfaceInfo& interface,
65  const ethernet::Address& mcastAddress);
66 
67 protected:
68  virtual void
70 
71  virtual void
72  doClose() final;
73 
74 private:
75  virtual void
76  doSend(Transport::Packet&& packet) final;
77 
81  void
82  pcapInit();
83 
89  void
90  setPacketFilter(const char* filterString);
91 
97  bool
98  joinMulticastGroup();
99 
103  void
104  sendPacket(const ndn::Block& block);
105 
109  void
110  handleRead(const boost::system::error_code& error, size_t nBytesRead);
111 
119  void
120  processIncomingPacket(const pcap_pkthdr* header, const uint8_t* packet);
121 
122 private:
126  void
127  processErrorCode(const boost::system::error_code& error);
128 
132  size_t
133  getInterfaceMtu();
134 
135 private:
136  unique_ptr<pcap_t, void(*)(pcap_t*)> m_pcap;
137  boost::asio::posix::stream_descriptor m_socket;
138 
139  ethernet::Address m_srcAddress;
140  ethernet::Address m_destAddress;
141  std::string m_interfaceName;
142 #if defined(__linux__)
143  int m_interfaceIndex;
144 #endif
145 
146 #ifdef _DEBUG
147  unsigned int m_nDropped;
149 #endif
150 };
151 
152 } // namespace face
153 } // namespace nfd
154 
155 #endif // NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
represents an Ethernet hardware address
Definition: ethernet.hpp:53
stores a packet along with the remote endpoint
Definition: transport.hpp:113
contains information about a network interface
EthernetTransport(const NetworkInterfaceInfo &interface, const ethernet::Address &mcastAddress)
Creates an Ethernet-based transport for multicast communication.
STL namespace.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
virtual void doClose() final
performs Transport specific operations to close the transport
pcap pcap_t
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
A multicast Transport that uses raw Ethernet II frames.
the lower part of a Face
Definition: transport.hpp:104
virtual void beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) final
invoked before persistency is changed