21 #include "ns3/net-device-queue-interface.h"
23 #include "ns3/object-map.h"
24 #include "ns3/packet.h"
25 #include "ns3/socket.h"
26 #include "ns3/queue-disc.h"
40 .SetGroupName (
"TrafficControl")
42 .AddAttribute (
"RootQueueDiscList",
"The list of root queue discs associated to this Traffic Control layer.",
46 MakeObjectMapChecker<QueueDisc> ())
47 .AddTraceSource (
"TcDrop",
48 "Trace source indicating a packet has been dropped by the Traffic "
49 "Control layer because no queue disc is installed on the device, the "
50 "device supports flow control and the device queue is stopped",
52 "ns3::Packet::TracedCallback")
94 if (ndi.second.m_rootQueueDisc)
96 ndi.second.m_rootQueueDisc->Initialize ();
117 NS_LOG_DEBUG (
"Handler for NetDevice: " << device <<
" registered for protocol " <<
118 protocolType <<
".");
137 NS_LOG_DEBUG (
"Pointer to NetDeviceQueueInterface: " << ndqi);
143 NS_LOG_DEBUG (
"Device entry found; installing NetDeviceQueueInterface pointer " << ndqi <<
" to internal map");
144 ndi->second.m_ndqi = ndqi;
153 NS_LOG_DEBUG (
"No device entry found; create entry for device and store pointer to NetDeviceQueueInterface: " << ndqi);
159 if (ndi !=
m_netDevices.end () && ndi->second.m_rootQueueDisc)
161 NS_LOG_DEBUG (
"Setting the wake callbacks on NetDevice queues");
162 ndi->second.m_queueDiscsToWake.clear ();
166 for (uint16_t i = 0; i < ndqi->GetNTxQueues (); i++)
172 qd = ndi->second.m_rootQueueDisc;
176 NS_ABORT_MSG_IF (ndi->second.m_rootQueueDisc->GetNQueueDiscClasses () != ndqi->GetNTxQueues (),
177 "The number of child queue discs does not match the number of netdevice queues");
187 ndi->second.m_queueDiscsToWake.push_back (qd);
192 ndi->second.m_queueDiscsToWake.push_back (ndi->second.m_rootQueueDisc);
197 for (
auto& q : ndi->second.m_queueDiscsToWake)
199 q->SetNetDeviceQueueInterface (ndqi);
201 { dev->
Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ()); });
222 "Cannot install a root queue disc on a device already having one. "
223 "Delete the existing queue disc first.");
225 ndi->second.m_rootQueueDisc = qDisc;
240 return ndi->second.m_rootQueueDisc;
258 "No root queue disc installed on device " << device);
261 ndi->second.m_rootQueueDisc = 0;
262 for (
auto& q : ndi->second.m_queueDiscsToWake)
264 q->SetNetDeviceQueueInterface (
nullptr);
265 q->SetSendCallback (
nullptr);
267 ndi->second.m_queueDiscsToWake.clear ();
273 for (uint16_t i = 0; i < ndqi->GetNTxQueues (); i++)
275 ndqi->GetTxQueue (i)->SetWakeCallback (MakeNullCallback <void> ());
298 Ptr<Node> node = this->GetObject<Node> ();
321 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
325 for (ProtocolHandlerList::iterator i =
m_handlers.begin ();
329 || (i->device != 0 && i->device == device))
332 || i->protocol == protocol)
334 NS_LOG_DEBUG (
"Found handler for packet " << p <<
", protocol " <<
335 protocol <<
" and NetDevice " << device <<
337 i->handler (device, p, protocol, from, to, packetType);
343 NS_ABORT_MSG_IF (!found,
"Handler for protocol " << p <<
" and device " << device <<
344 " not found. It isn't forwarded up; it dies here.");
352 NS_LOG_DEBUG (
"Send packet to device " << device <<
" protocol number " <<
353 item->GetProtocol ());
360 devQueueIface = ndi->second.m_ndqi;
365 if (devQueueIface && devQueueIface->GetNTxQueues () > 1)
367 txq = devQueueIface->GetSelectQueueCallback () (item);
376 NS_ASSERT (!devQueueIface || txq < devQueueIface->GetNTxQueues ());
378 if (ndi ==
m_netDevices.end () || ndi->second.m_rootQueueDisc == 0)
383 if (!devQueueIface || !devQueueIface->GetTxQueue (txq)->IsStopped ())
386 if (!devQueueIface || devQueueIface->GetNTxQueues () == 1)
389 item->GetPacket ()->RemovePacketTag (priorityTag);
391 device->
Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ());
402 item->SetTxQueueIndex (txq);
a polymophic address class
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
PacketType
Packet types are used as they are in Linux.
Network device transmission queue interface.
uint32_t GetId(void) const
uint32_t GetNDevices(void) 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 TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual void DoDispose(void)
Destructor implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
virtual void DoInitialize(void)
Initialize() implementation.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Container for a set of ns3::Object pointers.
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
indicates whether the socket has a priority set.
Introspection did not find any typical Config paths.
Ptr< QueueDisc > GetRootQueueDiscOnDeviceByIndex(uint32_t index) const
Required by the object map accessor.
virtual void ScanDevices(void)
Collect information needed to determine how to handle packets destined to each of the NetDevices of t...
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID for the instance.
TrafficControlLayer()
Constructor.
uint32_t GetNDevices(void) const
Required by the object map accessor.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< Node > m_node
The node this TrafficControlLayer object is aggregated to.
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 ~TrafficControlLayer()
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 DoDispose(void)
Destructor implementation.
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 NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
virtual void DoInitialize(void)
Initialize() implementation.
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.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName(void) const
Get the name.
#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...
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
#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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Information to store for each device.
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