13#include "ns3/net-device-queue-interface.h"
14#include "ns3/object-map.h"
15#include "ns3/packet.h"
16#include "ns3/socket.h"
31 TypeId(
"ns3::TrafficControlLayer")
33 .SetGroupName(
"TrafficControl")
37 "The list of root queue discs associated to this Traffic Control layer.",
42 .AddTraceSource(
"TcDrop",
43 "Trace source indicating a packet has been dropped by the Traffic "
44 "Control layer because no queue disc is installed on the device, the "
45 "device supports flow control and the device queue is stopped",
47 "ns3::Packet::TracedCallback");
88 if (ndi.second.m_rootQueueDisc)
90 ndi.second.m_rootQueueDisc->Initialize();
99 uint16_t protocolType,
112 NS_LOG_DEBUG(
"Handler for NetDevice: " << device <<
" registered for protocol " << protocolType
128 NS_LOG_DEBUG(
"Checking device " << i <<
" with pointer " << dev <<
" of type "
129 << dev->GetInstanceTypeId().GetName());
133 NS_LOG_DEBUG(
"Pointer to NetDeviceQueueInterface: " << ndqi);
139 NS_LOG_DEBUG(
"Device entry found; installing NetDeviceQueueInterface pointer "
140 << ndqi <<
" to internal map");
141 ndi->second.m_ndqi = ndqi;
150 NS_LOG_DEBUG(
"No device entry found; create entry for device and store pointer to "
151 "NetDeviceQueueInterface: "
158 if (ndi !=
m_netDevices.end() && ndi->second.m_rootQueueDisc)
160 NS_LOG_DEBUG(
"Setting the wake callbacks on NetDevice queues");
161 ndi->second.m_queueDiscsToWake.clear();
165 for (std::size_t i = 0; i < ndqi->GetNTxQueues(); i++)
171 qd = ndi->second.m_rootQueueDisc;
176 ndqi->GetNTxQueues(),
177 "The number of child queue discs does not match the number "
178 "of netdevice queues");
180 qd = ndi->second.m_rootQueueDisc->GetQueueDiscClass(i)->GetQueueDisc();
188 ndi->second.m_queueDiscsToWake.push_back(qd);
193 ndi->second.m_queueDiscsToWake.push_back(ndi->second.m_rootQueueDisc);
198 for (
auto& q : ndi->second.m_queueDiscsToWake)
200 q->SetNetDeviceQueueInterface(ndqi);
202 dev->Send(item->GetPacket(), item->GetAddress(), item->GetProtocol());
224 "Cannot install a root queue disc on a device already having one. "
225 "Delete the existing queue disc first.");
227 ndi->second.m_rootQueueDisc = qDisc;
242 return ndi->second.m_rootQueueDisc;
260 "No root queue disc installed on device " << device);
263 ndi->second.m_rootQueueDisc =
nullptr;
264 for (
auto& q : ndi->second.m_queueDiscsToWake)
266 q->SetNetDeviceQueueInterface(
nullptr);
267 q->SetSendCallback(
nullptr);
269 ndi->second.m_queueDiscsToWake.clear();
275 for (std::size_t i = 0; i < ndqi->GetNTxQueues(); i++)
325 NS_LOG_FUNCTION(
this << device << p << protocol << from << to << packetType);
331 if (!i->device || (i->device == device))
333 if (i->protocol == 0 || i->protocol == protocol)
335 NS_LOG_DEBUG(
"Found handler for packet " << p <<
", protocol " << protocol
336 <<
" and NetDevice " << device
337 <<
". Send packet up");
338 i->handler(device, p, protocol, from, to, packetType);
345 "Handler for protocol " << p <<
" and device " << device
346 <<
" not found. It isn't forwarded up; it dies here.");
354 NS_LOG_DEBUG(
"Send packet to device " << device <<
" protocol number " << item->GetProtocol());
361 devQueueIface = ndi->second.m_ndqi;
366 if (devQueueIface && devQueueIface->GetNTxQueues() > 1)
368 txq = devQueueIface->GetSelectQueueCallback()(item);
377 NS_ASSERT(!devQueueIface || txq < devQueueIface->GetNTxQueues());
379 if (ndi ==
m_netDevices.end() || !ndi->second.m_rootQueueDisc)
384 if (!devQueueIface || !devQueueIface->GetTxQueue(txq)->IsStopped())
387 if (!devQueueIface || devQueueIface->GetNTxQueues() == 1)
390 item->GetPacket()->RemovePacketTag(priorityTag);
392 device->Send(item->GetPacket(), item->GetAddress(), item->GetProtocol());
403 item->SetTxQueueIndex(txq);
407 qDisc->Enqueue(item);
a polymophic address class
PacketType
Packet types are used as they are in Linux.
Network device transmission queue interface.
uint32_t GetNDevices() const
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
A base class which provides memory management and object aggregation.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
virtual void DoInitialize()
Initialize() implementation.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
void Run()
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
indicates whether the socket has a priority set.
The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructu...
void NotifyNewAggregate() override
Notify all Objects aggregated to this one of a new Object being aggregated.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the type ID for the instance.
Ptr< QueueDisc > GetRootQueueDiscOnDeviceByIndex(uint32_t index) const
Required by the object map accessor.
void DoInitialize() override
Initialize() implementation.
void DoDispose() override
Destructor implementation.
TracedCallback< Ptr< const Packet > > m_dropped
The trace source fired when the Traffic Control layer drops a packet because no queue disc is install...
ProtocolHandlerList m_handlers
List of upper-layer handlers.
TrafficControlLayer()
Constructor.
Ptr< Node > m_node
The node this TrafficControlLayer object is aggregated to.
uint32_t GetNDevices() const
Required by the object map accessor.
std::map< Ptr< NetDevice >, NetDeviceInfo > m_netDevices
Map storing the required information for each device with a queue disc installed.
virtual void DeleteRootQueueDiscOnDevice(Ptr< NetDevice > device)
This method can be used to remove the root queue disc (and associated filters, classes and queues) in...
std::vector< Ptr< QueueDisc > > QueueDiscVector
Typedef for queue disc vector.
virtual void ScanDevices()
Collect information needed to determine how to handle packets destined to each of the NetDevices of t...
virtual void Send(Ptr< NetDevice > device, Ptr< QueueDiscItem > item)
Called from upper layer to queue a packet for the transmission.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
virtual Ptr< QueueDisc > GetRootQueueDiscOnDevice(Ptr< NetDevice > device) const
This method can be used to get the root queue disc installed on a device.
virtual void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called by NetDevices, incoming packet.
virtual void SetRootQueueDiscOnDevice(Ptr< NetDevice > device, Ptr< QueueDisc > qDisc)
This method can be used to set the root queue disc installed on a device.
void RegisterProtocolHandler(Node::ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device)
Register an IN handler.
~TrafficControlLayer() override
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeChecker > MakeObjectMapChecker()
Callback< R, Args... > MakeNullCallback()
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Node::ProtocolHandler handler
the protocol handler
bool promiscuous
true if it is a promiscuous handler
uint16_t protocol
the protocol number
Ptr< NetDevice > device
the NetDevice