33 #include <boost/range/adaptor/map.hpp> 34 #include <pcap/pcap.h> 43 : m_localEndpoint(
std::
move(localEndpoint))
44 , m_isListening(false)
46 , m_pcap(m_localEndpoint->getName())
47 , m_idleFaceTimeout(idleTimeout)
62 shared_ptr<Face> face;
64 face = createFace(remoteEndpoint, params).second;
66 catch (
const boost::system::system_error& e) {
69 onConnectFailed(504,
"Face creation failed: "s + e.what());
90 m_socket.assign(m_pcap.
getFd());
97 asyncRead(onFaceCreated, onFaceCreationFailed);
105 m_socket.async_read_some(boost::asio::null_buffers(),
106 [=] (
const auto& e,
auto) { this->handleRead(e, onFaceCreated, onReceiveFailed); });
110 EthernetChannel::handleRead(
const boost::system::error_code& error,
118 onReceiveFailed(500,
"Receive failed: " + error.message());
123 span<const uint8_t> pkt;
131 const ether_header* eh;
133 m_localEndpoint->getEthernetAddress());
140 processIncomingPacket(pkt, sender, onFaceCreated, onReceiveFailed);
146 if (nDropped - m_nDropped > 0)
148 m_nDropped = nDropped;
151 asyncRead(onFaceCreated, onReceiveFailed);
155 EthernetChannel::processIncomingPacket(span<const uint8_t> packet,
162 bool isCreated =
false;
163 shared_ptr<Face> face;
167 std::tie(isCreated, face) = createFace(sender, params);
172 onReceiveFailed(504,
"Face creation failed: "s + e.what());
186 std::pair<bool, shared_ptr<Face>>
190 auto it = m_channelFaces.find(remoteEndpoint);
191 if (it != m_channelFaces.end()) {
194 return {
false, it->second};
198 GenericLinkService::Options options;
199 options.allowFragmentation =
true;
200 options.allowReassembly =
true;
203 options.overrideMtu = *params.
mtu;
206 auto linkService = make_unique<GenericLinkService>(options);
207 auto transport = make_unique<UnicastEthernetTransport>(*m_localEndpoint, remoteEndpoint,
210 face->setChannel(shared_from_this());
212 m_channelFaces[remoteEndpoint] = face;
214 m_channelFaces.erase(remoteEndpoint);
223 EthernetChannel::updateFilter()
229 ") && (ether dst " + m_localEndpoint->getEthernetAddress().toString() +
")";
230 for (
const auto& addr : m_channelFaces | boost::adaptors::map_keys) {
231 filter +=
" && (not ether src " + addr.toString() +
")";
235 filter +=
" && (not vlan)";
#define NDN_THROW_NESTED(e)
void connect(const ethernet::Address &remoteEndpoint, const FaceParams ¶ms, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast Ethernet face toward remoteEndpoint.
void setUri(const FaceUri &uri)
#define NFD_LOG_INIT(name)
std::string to_string(const T &val)
void activate(int dlt)
Start capturing packets.
ndn::nfd::FacePersistency persistency
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
std::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 setPacketFilter(const char *filter) const
Install a BPF filter on the receiving socket.
Class implementing Ethernet-based channel to create faces.
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a face is closed.
#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.
std::tuple< const ether_header *, std::string > checkFrameHeader(span< const uint8_t > packet, const Address &localAddr, const Address &destAddr)
#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)
bool isListening() const final
Returns whether the channel is listening.
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
const uint16_t ETHERTYPE_NDN
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)
int getFd() const
Obtain a file descriptor that can be used in calls such as select(2) and poll(2). ...
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
size_t getNDropped() const
Get the number of packets dropped by the kernel, as reported by libpcap.
void receivePayload(span< const uint8_t > payload, const ethernet::Address &sender)
Processes the payload of an incoming frame.
std::tuple< span< const uint8_t >, std::string > readNextPacket() const noexcept
Read the next packet captured on the interface.
A unicast Transport that uses raw Ethernet II frames.
static FaceUri fromDev(const std::string &ifname)
create dev FaceUri from network device name
boost::chrono::nanoseconds nanoseconds
Parameters used to set Transport properties or LinkService options on a newly created face...