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)
51 setUri(FaceUri::fromDev(m_localEndpoint->getName()));
61 shared_ptr<Face> face;
63 face = createFace(remoteEndpoint, params).second;
65 catch (
const boost::system::system_error& e) {
68 onConnectFailed(504, std::string(
"Face creation failed: ") + e.what());
89 m_socket.assign(m_pcap.
getFd());
92 BOOST_THROW_EXCEPTION(
Error(e.what()));
96 asyncRead(onFaceCreated, onFaceCreationFailed);
104 m_socket.async_read_some(boost::asio::null_buffers(),
105 bind(&EthernetChannel::handleRead,
this,
106 boost::asio::placeholders::error,
107 onFaceCreated, onReceiveFailed));
111 EthernetChannel::handleRead(
const boost::system::error_code& error,
116 if (error != boost::asio::error::operation_aborted) {
119 onReceiveFailed(500,
"Receive failed: " + error.message());
129 if (pkt ==
nullptr) {
133 const ether_header* eh;
135 m_localEndpoint->getEthernetAddress());
140 ethernet::Address sender(eh->ether_shost);
141 pkt += ethernet::HDR_LEN;
142 len -= ethernet::HDR_LEN;
143 processIncomingPacket(pkt, len, sender, onFaceCreated, onReceiveFailed);
149 if (nDropped - m_nDropped > 0)
151 m_nDropped = nDropped;
154 asyncRead(onFaceCreated, onReceiveFailed);
158 EthernetChannel::processIncomingPacket(
const uint8_t* packet,
size_t length,
159 const ethernet::Address& sender,
165 bool isCreated =
false;
166 shared_ptr<Face> face;
169 params.
persistency = ndn::nfd::FACE_PERSISTENCY_ON_DEMAND;
170 std::tie(isCreated, face) = createFace(sender, params);
175 onReceiveFailed(504, std::string(
"Face creation failed: ") + e.what());
189 std::pair<bool, shared_ptr<Face>>
190 EthernetChannel::createFace(
const ethernet::Address& remoteEndpoint,
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,
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()
227 std::string filter =
"(ether proto " + to_string(ethernet::ETHERTYPE_NDN) +
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)";
Parameters used to set Transport properties or LinkService options on a newly created face...
function< void(const shared_ptr< Face > &face)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
bool allowFragmentation
enables fragmentation
bool isEnabled
enables link-layer reliability
ndn::nfd::FacePersistency persistency
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
EthernetChannel-related error.
size_t getNDropped() const
Get the number of packets dropped by the kernel, as reported by libpcap.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void receivePayload(const uint8_t *payload, size_t length, const ethernet::Address &sender)
Processes the payload of an incoming frame.
EthernetChannel(shared_ptr< const ndn::net::NetworkInterface > localEndpoint, time::nanoseconds idleTimeout)
Create an Ethernet channel on the given localEndpoint (network interface)
std::tuple< const uint8_t *, size_t, std::string > readNextPacket() const
Read the next packet captured on the interface.
LpReliability::Options reliabilityOptions
options for reliability
std::pair< const ether_header *, std::string > checkFrameHeader(const uint8_t *packet, size_t length, const Address &localAddr, const Address &destAddr)
void activate(int dlt)
Start capturing packets.
void setUri(const FaceUri &uri)
int getFd() const
Obtain a file descriptor that can be used in calls such as select(2) and poll(2). ...
A unicast Transport that uses raw Ethernet II frames.
Options that control the behavior of GenericLinkService.
#define NFD_LOG_INIT(name)
void connect(const ethernet::Address &remoteEndpoint, const FaceParams ¶ms, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast Ethernet face toward remoteEndpoint.
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
bool isListening() const override
Returns whether the channel is listening.
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
bool allowReassembly
enables reassembly
void setPacketFilter(const char *filter) const
Install a BPF filter on the receiving socket.
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
boost::asio::io_service & getGlobalIoService()