NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
ethernet-face.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_FACE_HPP
27 #define NFD_DAEMON_FACE_ETHERNET_FACE_HPP
28 
29 #include "common.hpp"
30 #include "face.hpp"
32 #include "ndnlp-slicer.hpp"
34 
35 #include <unordered_map>
36 
37 #ifndef HAVE_LIBPCAP
38 #error "Cannot include this file when libpcap is not available"
39 #endif
40 
41 // forward declarations
42 struct pcap;
43 typedef pcap pcap_t;
44 struct pcap_pkthdr;
45 
46 namespace nfd {
47 
52 class EthernetFace : public Face
53 {
54 public:
58  struct Error : public Face::Error
59  {
60  Error(const std::string& what) : Face::Error(what) {}
61  };
62 
63  EthernetFace(boost::asio::posix::stream_descriptor socket,
64  const NetworkInterfaceInfo& interface,
65  const ethernet::Address& address);
66 
68  void
69  sendInterest(const Interest& interest) DECL_OVERRIDE;
70 
72  void
73  sendData(const Data& data) DECL_OVERRIDE;
74 
80  void
82 
83 private:
87  void
88  pcapInit();
89 
95  void
96  setPacketFilter(const char* filterString);
97 
103  bool
104  joinMulticastGroup();
105 
109  void
110  sendPacket(const ndn::Block& block);
111 
115  void
116  handleRead(const boost::system::error_code& error, size_t nBytesRead);
117 
125  void
126  processIncomingPacket(const pcap_pkthdr* header, const uint8_t* packet);
127 
128 private:
132  void
133  processErrorCode(const boost::system::error_code& error);
134 
138  size_t
139  getInterfaceMtu();
140 
141 private:
142  struct Reassembler
143  {
144  unique_ptr<ndnlp::PartialMessageStore> pms;
145  scheduler::EventId expireEvent;
146  };
147 
148  unique_ptr<pcap_t, void(*)(pcap_t*)> m_pcap;
149  boost::asio::posix::stream_descriptor m_socket;
150 
151 #if defined(__linux__)
152  int m_interfaceIndex;
153 #endif
154  std::string m_interfaceName;
155  ethernet::Address m_srcAddress;
156  ethernet::Address m_destAddress;
157 
158  size_t m_interfaceMtu;
159  unique_ptr<ndnlp::Slicer> m_slicer;
160  std::unordered_map<ethernet::Address, Reassembler> m_reassemblers;
161  static const time::nanoseconds REASSEMBLER_LIFETIME;
162 
163 #ifdef _DEBUG
164  unsigned int m_nDropped;
166 #endif
167 };
168 
169 } // namespace nfd
170 
171 #endif // NFD_DAEMON_FACE_ETHERNET_FACE_HPP
Face-related error.
Definition: face.hpp:63
represents an Ethernet hardware address
Definition: ethernet.hpp:53
contains information about a network interface
EthernetFace(boost::asio::posix::stream_descriptor socket, const NetworkInterfaceInfo &interface, const ethernet::Address &address)
void sendData(const Data &data) 1
send a Data
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
#define DECL_OVERRIDE
expands to &#39;override&#39; if compiler supports this feature, otherwise expands to nothing ...
Definition: common.hpp:49
void sendInterest(const Interest &interest) 1
send an Interest
Implementation of Face abstraction that uses raw Ethernet frames as underlying transport mechanism...
represents a face
Definition: face.hpp:57
EthernetFace-related error.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void close() 1
Closes the face.
pcap pcap_t
Error(const std::string &what)
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
represents a Data packet
Definition: data.hpp:39