22 #include "../helper/ndn-stack-helper.hpp" 24 #include "../utils/ndn-ns3-packet-tag.hpp" 26 #include <ndn-cxx/encoding/block.hpp> 27 #include <ndn-cxx/interest.hpp> 28 #include <ndn-cxx/data.hpp> 30 #include "ns3/queue.h" 32 NS_LOG_COMPONENT_DEFINE(
"ndn.NetDeviceTransport");
38 const Ptr<NetDevice>& netDevice,
39 const std::string& localUri,
40 const std::string& remoteUri,
44 : m_netDevice(netDevice)
52 this->
setMtu(m_netDevice->GetMtu());
55 PointerValue txQueueAttribute;
56 if (m_netDevice->GetAttributeFailSafe(
"TxQueue", txQueueAttribute)) {
57 Ptr<ns3::QueueBase> txQueue = txQueueAttribute.Get<ns3::QueueBase>();
62 NS_LOG_FUNCTION(
this <<
"Creating an ndnSIM transport instance for netDevice with URI" 65 NS_ASSERT_MSG(m_netDevice != 0,
"NetDeviceFace needs to be assigned a valid NetDevice");
67 m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceTransport::receiveFromNetDevice,
this),
74 NS_LOG_FUNCTION_NOARGS();
80 PointerValue txQueueAttribute;
81 if (m_netDevice->GetAttributeFailSafe(
"TxQueue", txQueueAttribute)) {
82 Ptr<ns3::QueueBase> txQueue = txQueueAttribute.Get<ns3::QueueBase>();
83 return txQueue->GetNBytes();
91 NetDeviceTransport::doClose()
93 NS_LOG_FUNCTION(
this <<
"Closing transport for netDevice with URI" 101 NetDeviceTransport::doSend(Packet&& packet)
103 NS_LOG_FUNCTION(
this <<
"Sending packet from netDevice with URI" 107 BlockHeader header(packet);
109 Ptr<ns3::Packet> ns3Packet = Create<ns3::Packet>();
110 ns3Packet->AddHeader(header);
113 m_netDevice->Send(ns3Packet, m_netDevice->GetBroadcast(),
119 NetDeviceTransport::receiveFromNetDevice(Ptr<NetDevice> device,
120 Ptr<const ns3::Packet> p,
122 const Address& from,
const Address& to,
123 NetDevice::PacketType packetType)
125 NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
128 Ptr<ns3::Packet> packet = p->Copy();
131 packet->RemoveHeader(header);
133 auto nfdPacket = Packet(std::move(header.getBlock()));
135 this->
receive(std::move(nfdPacket));
const ssize_t QUEUE_UNSUPPORTED
indicates that the transport does not support reading the queue capacity/length
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Copyright (c) 2011-2015 Regents of the University of California.
static const uint16_t ETHERNET_FRAME_TYPE
Ethernet Frame Type of Ndn.
void setRemoteUri(const FaceUri &uri)
virtual ssize_t getSendQueueLength() final
void setLinkType(ndn::nfd::LinkType linkType)
void setScope(ndn::nfd::FaceScope scope)
NetDeviceTransport(Ptr< Node > node, const Ptr< NetDevice > &netDevice, const std::string &localUri, const std::string &remoteUri, ::ndn::nfd::FaceScope scope=::ndn::nfd::FACE_SCOPE_NON_LOCAL, ::ndn::nfd::FacePersistency persistency=::ndn::nfd::FACE_PERSISTENCY_PERSISTENT, ::ndn::nfd::LinkType linkType=::ndn::nfd::LINK_TYPE_POINT_TO_POINT)
FaceUri getLocalUri() const
the transport is closed, and can be safely deallocated
Copyright (c) 2011-2015 Regents of the University of California.
void setLocalUri(const FaceUri &uri)
Ptr< NetDevice > GetNetDevice() const
void setSendQueueCapacity(ssize_t sendQueueCapacity)
void setState(TransportState newState)
set transport state
void receive(Packet &&packet)
receive a link-layer packet