30 #include <pcap/pcap.h> 32 #include <arpa/inet.h> 43 , m_pcap(localEndpoint.getName())
44 , m_srcAddress(localEndpoint.getEthernetAddress())
45 , m_destAddress(remoteEndpoint)
46 , m_interfaceName(localEndpoint.getName())
47 , m_hasRecentlyReceived(false)
57 BOOST_THROW_EXCEPTION(
Error(e.what()));
71 boost::system::error_code error;
89 sendPacket(packet.packet);
93 EthernetTransport::sendPacket(
const ndn::Block& block)
105 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ðertype),
ethernet::TYPE_LEN);
110 int sent = pcap_inject(
m_pcap, buffer.buf(), buffer.size());
113 else if (static_cast<size_t>(sent) < buffer.size())
114 handleError(
"Failed to send the full frame: size=" +
to_string(buffer.size()) +
122 EthernetTransport::asyncRead()
124 m_socket.async_read_some(boost::asio::null_buffers(),
125 bind(&EthernetTransport::handleRead,
this,
126 boost::asio::placeholders::error));
130 EthernetTransport::handleRead(
const boost::system::error_code& error)
135 if (error != boost::asio::error::operation_aborted &&
139 handleError(
"Receive operation failed: " + error.message());
149 if (pkt ==
nullptr) {
153 const ether_header* eh;
160 ethernet::Address sender(eh->ether_shost);
169 if (nDropped - m_nDropped > 0)
171 m_nDropped = nDropped;
191 m_hasRecentlyReceived =
true;
195 "Transport::Packet::remoteEndpoint is too small");
203 EthernetTransport::handleError(
const std::string& errorMessage)
const size_t MIN_DATA_LEN
Min octets in Ethernet payload (assuming no 802.1Q tag)
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to parse Block from a wire buffer.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void activate(int dlt)
Start capturing packets.
const size_t ADDR_LEN
Octets in one Ethernet address.
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
stores a packet along with the remote endpoint
EthernetTransport(const ndn::net::NetworkInterface &localEndpoint, const ethernet::Address &remoteEndpoint)
detail::SimulatorIo & getGlobalIoService()
Represents a TLV element of NDN packet format.
void receivePayload(const uint8_t *payload, size_t length, const ethernet::Address &sender)
Processes the payload of an incoming frame.
the transport is being closed due to a failure
void doClose() final
performs Transport specific operations to close the transport
Represents one network interface attached to the host.
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
size_t size() const
Get size of encoded wire, including Type-Length-Value.
TransportState getState() const
Copyright (c) 2011-2015 Regents of the University of California.
EndpointId remoteEndpoint
identifies the remote endpoint
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
const size_t HDR_LEN
Total octets in Ethernet header (without 802.1Q tag)
boost::asio::posix::stream_descriptor m_socket
ethernet::Address m_destAddress
const size_t TYPE_LEN
Octets in Ethertype field.
const uint16_t ETHERTYPE_NDN
the transport is being closed gracefully, either by the peer or by a call to close() ...
std::string getLastError() const
Get last error message.
std::pair< const ether_header *, std::string > checkFrameHeader(const uint8_t *packet, size_t length, const Address &localAddr, const Address &destAddr)
void close()
Stop capturing and close the handle.
bool isMulticast() const
True if this is a multicast address.
represents an Ethernet hardware address
ndn::nfd::FacePersistency getPersistency() const
int getFd() const
Obtain a file descriptor that can be used in calls such as select(2) and poll(2). ...
size_t getNDropped() const
Get the number of packets dropped by the kernel, as reported by libpcap.
std::string to_string(const V &v)
std::tuple< const uint8_t *, size_t, std::string > readNextPacket() const
Read the next packet captured on the interface.
void setState(TransportState newState)
set transport state
void receive(Packet &&packet)
receive a link-layer packet
#define NFD_LOG_INIT(name)
EncodingImpl< EncoderTag > EncodingBuffer
ethernet::Address m_srcAddress
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.