22 #include "../helper/ndn-stack-helper.hpp"
24 #include "../utils/ndn-ns3-packet-tag.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>();
60 auto size = txQueue->GetMaxSize();
61 if (size.GetUnit() == BYTES) {
70 NS_LOG_FUNCTION(
this <<
"Creating an ndnSIM transport instance for netDevice with URI"
73 NS_ASSERT_MSG(m_netDevice != 0,
"NetDeviceFace needs to be assigned a valid NetDevice");
75 m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceTransport::receiveFromNetDevice,
this),
82 NS_LOG_FUNCTION_NOARGS();
88 PointerValue txQueueAttribute;
89 if (m_netDevice->GetAttributeFailSafe(
"TxQueue", txQueueAttribute)) {
90 Ptr<ns3::QueueBase> txQueue = txQueueAttribute.Get<ns3::QueueBase>();
91 return txQueue->GetNBytes();
99 NetDeviceTransport::doClose()
101 NS_LOG_FUNCTION(
this <<
"Closing transport for netDevice with URI"
109 NetDeviceTransport::doSend(
const Block& packet,
const nfd::EndpointId& endpoint)
111 NS_LOG_FUNCTION(
this <<
"Sending packet from netDevice with URI"
115 BlockHeader header(packet);
117 Ptr<ns3::Packet> ns3Packet = Create<ns3::Packet>();
118 ns3Packet->AddHeader(header);
121 m_netDevice->Send(ns3Packet, m_netDevice->GetBroadcast(),
127 NetDeviceTransport::receiveFromNetDevice(Ptr<NetDevice> device,
128 Ptr<const ns3::Packet> p,
130 const Address& from,
const Address& to,
131 NetDevice::PacketType packetType)
133 NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
136 Ptr<ns3::Packet> packet = p->Copy();
139 packet->RemoveHeader(header);