|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
30 #include <pcap/pcap.h>
34 #include <boost/endian/conversion.hpp>
44 , m_pcap(localEndpoint.getName())
45 , m_srcAddress(localEndpoint.getEthernetAddress())
46 , m_destAddress(remoteEndpoint)
47 , m_interfaceName(localEndpoint.getName())
48 , m_hasRecentlyReceived(false)
63 handleNetifStateChange(newState);
77 boost::system::error_code error;
105 EthernetTransport::doSend(
const Block& packet,
const EndpointId&)
113 EthernetTransport::sendPacket(
const ndn::Block& block)
125 buffer.prependByteArray(
reinterpret_cast<const uint8_t*
>(ðertype),
ethernet::TYPE_LEN);
130 int sent = pcap_inject(
m_pcap, buffer.buf(), buffer.size());
133 else if (
static_cast<size_t>(sent) < buffer.size())
134 handleError(
"Failed to send the full frame: size=" +
to_string(buffer.size()) +
142 EthernetTransport::asyncRead()
144 m_socket.async_read_some(boost::asio::null_buffers(),
145 [
this] (
const auto& e,
auto) { this->handleRead(e); });
149 EthernetTransport::handleRead(
const boost::system::error_code& error)
154 if (error != boost::asio::error::operation_aborted &&
158 handleError(
"Receive operation failed: " + error.message());
168 if (pkt ==
nullptr) {
172 const ether_header* eh;
179 ethernet::Address sender(eh->ether_shost);
188 if (nDropped - m_nDropped > 0)
190 m_nDropped = nDropped;
210 m_hasRecentlyReceived =
true;
215 std::memcpy(&endpoint, sender.data(), sender.size());
218 this->
receive(element, endpoint);
222 EthernetTransport::handleError(
const std::string& errorMessage)
void receivePayload(const uint8_t *payload, size_t length, const ethernet::Address &sender)
Processes the payload of an incoming frame.
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
boost::asio::posix::stream_descriptor m_socket
@ CLOSED
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
ethernet::Address m_destAddress
int getFd() const
Obtain a file descriptor that can be used in calls such as select(2) and poll(2).
Represents one network interface attached to the host.
@ FACE_PERSISTENCY_PERMANENT
face is permanent
represents an Ethernet hardware address
void setState(TransportState newState)
set transport state
const uint16_t ETHERTYPE_NDN
ethernet::Address m_srcAddress
@ DOWN
the transport is temporarily down, and is being recovered
EthernetTransport(const ndn::net::NetworkInterface &localEndpoint, const ethernet::Address &remoteEndpoint)
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
ndn::nfd::FacePersistency getPersistency() const
#define NDN_THROW_NESTED(e)
void close()
Stop capturing and close the handle.
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
std::tuple< const uint8_t *, size_t, std::string > readNextPacket() const
Read the next packet captured on the interface.
@ CLOSING
the transport is being closed gracefully, either by the peer or by a call to close()
Copyright (c) 2011-2015 Regents of the University of California.
static NDN_CXX_NODISCARD std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to parse Block from a wire buffer.
util::Signal< NetworkInterface, InterfaceState, InterfaceState > onStateChanged
Fires when interface state changes.
const size_t TYPE_LEN
Octets in Ethertype field.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
const size_t HDR_LEN
Total octets in Ethernet header (without 802.1Q tag)
std::string getLastError() const
Get last error message.
InterfaceState
Indicates the state of a network interface.
const size_t MIN_DATA_LEN
Min octets in Ethernet payload (assuming no 802.1Q tag)
void activate(int dlt)
Start capturing packets.
Base class for Ethernet-based Transports.
@ UP
the transport is up and can transmit packets
const size_t ADDR_LEN
Octets in one Ethernet address.
Represents a TLV element of NDN packet format.
size_t size() const
Return the size of the encoded wire, i.e.
std::string to_string(const T &val)
@ FAILED
the transport is being closed due to a failure
size_t getNDropped() const
Get the number of packets dropped by the kernel, as reported by libpcap.
TransportState getState() const
uint64_t EndpointId
Identifies a remote endpoint on the link.
void receive(const Block &packet, const EndpointId &endpoint=0)
Pass a received link-layer packet to the upper layer for further processing.
bool isMulticast() const
True if this is a multicast address.
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
@ RUNNING
interface can be used to send and receive packets
std::pair< const ether_header *, std::string > checkFrameHeader(const uint8_t *packet, size_t length, const Address &localAddr, const Address &destAddr)
#define NFD_LOG_INIT(name)
EncodingImpl< EncoderTag > EncodingBuffer
void doClose() final
performs Transport specific operations to close the transport