32 #include <boost/range/adaptor/map.hpp> 33 #include <pcap/pcap.h> 41 time::nanoseconds idleTimeout)
42 : m_localEndpoint(
std::move(localEndpoint))
43 , m_isListening(false)
45 , m_pcap(m_localEndpoint->getName())
46 , m_idleFaceTimeout(idleTimeout)
58 bool wantLpReliability,
62 shared_ptr<Face>
face;
64 face = createFace(remoteEndpoint, persistency, wantLpReliability).second;
66 catch (
const boost::system::system_error& e) {
69 onConnectFailed(504, std::string(
"Face creation failed: ") + e.what());
90 m_socket.assign(m_pcap.
getFd());
93 BOOST_THROW_EXCEPTION(
Error(e.what()));
97 asyncRead(onFaceCreated, onFaceCreationFailed);
105 m_socket.async_read_some(boost::asio::null_buffers(),
106 bind(&EthernetChannel::handleRead,
this,
107 boost::asio::placeholders::error,
108 onFaceCreated, onReceiveFailed));
112 EthernetChannel::handleRead(
const boost::system::error_code& error,
120 onReceiveFailed(500,
"Receive failed: " + error.message());
130 if (pkt ==
nullptr) {
134 const ether_header* eh;
136 m_localEndpoint->getEthernetAddress());
144 processIncomingPacket(pkt, len, sender, onFaceCreated, onReceiveFailed);
150 if (nDropped - m_nDropped > 0)
152 m_nDropped = nDropped;
155 asyncRead(onFaceCreated, onReceiveFailed);
159 EthernetChannel::processIncomingPacket(
const uint8_t* packet,
size_t length,
166 bool isCreated =
false;
167 shared_ptr<Face>
face;
174 onReceiveFailed(504, std::string(
"Face creation failed: ") + e.what());
188 std::pair<bool, shared_ptr<Face>>
191 bool wantLpReliability)
193 auto it = m_channelFaces.find(remoteEndpoint);
194 if (it != m_channelFaces.end()) {
197 return {
false, it->second};
206 auto linkService = make_unique<GenericLinkService>(options);
207 auto transport = make_unique<UnicastEthernetTransport>(*m_localEndpoint, remoteEndpoint,
208 persistency, m_idleFaceTimeout);
209 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
211 m_channelFaces[remoteEndpoint] = face;
213 m_channelFaces.erase(remoteEndpoint);
222 EthernetChannel::updateFilter()
228 ") && (ether dst " + m_localEndpoint->getEthernetAddress().toString() +
")";
229 for (
const auto& addr : m_channelFaces | boost::adaptors::map_keys) {
230 filter +=
" && (not ether src " + addr.toString() +
")";
234 filter +=
" && (not vlan)";
bool allowReassembly
enables reassembly
void setUri(const FaceUri &uri)
void setPacketFilter(const char *filter) const
Install a BPF filter on the receiving socket.
void activate(int dlt)
Start capturing packets.
LpReliability::Options reliabilityOptions
options for reliability
detail::SimulatorIo & getGlobalIoService()
bool isListening() const override
Returns whether the channel is listening.
void receivePayload(const uint8_t *payload, size_t length, const ethernet::Address &sender)
Processes the payload of an incoming frame.
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
bool isEnabled
enables link-layer reliability
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
EthernetChannel-related error.
Copyright (c) 2011-2015 Regents of the University of California.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
const size_t HDR_LEN
Total octets in Ethernet header (without 802.1Q tag)
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
const uint16_t ETHERTYPE_NDN
std::pair< const ether_header *, std::string > checkFrameHeader(const uint8_t *packet, size_t length, const Address &localAddr, const Address &destAddr)
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.
std::tuple< const uint8_t *, size_t, std::string > readNextPacket() const
Read the next packet captured on the interface.
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
represents an Ethernet hardware address
EthernetChannel(shared_ptr< const ndn::net::NetworkInterface > localEndpoint, time::nanoseconds idleTimeout)
Create an Ethernet channel on the given localEndpoint (network interface)
Options that control the behavior of GenericLinkService.
int getFd() const
Obtain a file descriptor that can be used in calls such as select(2) and poll(2). ...
std::string to_string(const V &v)
size_t getNDropped() const
Get the number of packets dropped by the kernel, as reported by libpcap.
#define NFD_LOG_INIT(name)
A unicast Transport that uses raw Ethernet II frames.
static FaceUri fromDev(const std::string &ifname)
create dev FaceUri from network device name
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...
bool allowFragmentation
enables fragmentation