24 #include "ns3/net-device-queue-interface.h"
25 #include "ns3/object-map.h"
26 #include "ns3/packet.h"
27 #include "ns3/socket.h"
42 TypeId(
"ns3::TrafficControlLayer")
44 .SetGroupName(
"TrafficControl")
48 "The list of root queue discs associated to this Traffic Control layer.",
52 MakeObjectMapChecker<QueueDisc>())
53 .AddTraceSource(
"TcDrop",
54 "Trace source indicating a packet has been dropped by the Traffic "
55 "Control layer because no queue disc is installed on the device, the "
56 "device supports flow control and the device queue is stopped",
58 "ns3::Packet::TracedCallback");
99 if (ndi.second.m_rootQueueDisc)
101 ndi.second.m_rootQueueDisc->Initialize();
110 uint16_t protocolType,
123 NS_LOG_DEBUG(
"Handler for NetDevice: " << device <<
" registered for protocol " << protocolType
139 NS_LOG_DEBUG(
"Checking device " << i <<
" with pointer " << dev <<
" of type "
140 << dev->GetInstanceTypeId().GetName());
144 NS_LOG_DEBUG(
"Pointer to NetDeviceQueueInterface: " << ndqi);
150 NS_LOG_DEBUG(
"Device entry found; installing NetDeviceQueueInterface pointer "
151 << ndqi <<
" to internal map");
152 ndi->second.m_ndqi = ndqi;
161 NS_LOG_DEBUG(
"No device entry found; create entry for device and store pointer to "
162 "NetDeviceQueueInterface: "
169 if (ndi !=
m_netDevices.end() && ndi->second.m_rootQueueDisc)
171 NS_LOG_DEBUG(
"Setting the wake callbacks on NetDevice queues");
172 ndi->second.m_queueDiscsToWake.clear();
176 for (std::size_t i = 0; i < ndqi->GetNTxQueues(); i++)
182 qd = ndi->second.m_rootQueueDisc;
187 ndqi->GetNTxQueues(),
188 "The number of child queue discs does not match the number "
189 "of netdevice queues");
199 ndi->second.m_queueDiscsToWake.push_back(qd);
204 ndi->second.m_queueDiscsToWake.push_back(ndi->second.m_rootQueueDisc);
209 for (
auto& q : ndi->second.m_queueDiscsToWake)
211 q->SetNetDeviceQueueInterface(ndqi);
213 dev->Send(item->GetPacket(), item->GetAddress(), item->GetProtocol());
235 "Cannot install a root queue disc on a device already having one. "
236 "Delete the existing queue disc first.");
238 ndi->second.m_rootQueueDisc = qDisc;
253 return ndi->second.m_rootQueueDisc;
271 "No root queue disc installed on device " << device);
274 ndi->second.m_rootQueueDisc =
nullptr;
275 for (
auto& q : ndi->second.m_queueDiscsToWake)
277 q->SetNetDeviceQueueInterface(
nullptr);
278 q->SetSendCallback(
nullptr);
280 ndi->second.m_queueDiscsToWake.clear();
286 for (std::size_t i = 0; i < ndqi->GetNTxQueues(); i++)
288 ndqi->GetTxQueue(i)->SetWakeCallback(MakeNullCallback<void>());
311 Ptr<Node> node = this->GetObject<Node>();
336 NS_LOG_FUNCTION(
this << device << p << protocol << from << to << packetType);
342 if (!i->device || (i->device == device))
344 if (i->protocol == 0 || i->protocol == protocol)
346 NS_LOG_DEBUG(
"Found handler for packet " << p <<
", protocol " << protocol
347 <<
" and NetDevice " << device
348 <<
". Send packet up");
349 i->handler(device, p, protocol, from, to, packetType);
356 "Handler for protocol " << p <<
" and device " << device
357 <<
" not found. It isn't forwarded up; it dies here.");
365 NS_LOG_DEBUG(
"Send packet to device " << device <<
" protocol number " << item->GetProtocol());
372 devQueueIface = ndi->second.m_ndqi;
377 if (devQueueIface && devQueueIface->GetNTxQueues() > 1)
379 txq = devQueueIface->GetSelectQueueCallback()(item);
388 NS_ASSERT(!devQueueIface || txq < devQueueIface->GetNTxQueues());
390 if (ndi ==
m_netDevices.end() || !ndi->second.m_rootQueueDisc)
395 if (!devQueueIface || !devQueueIface->GetTxQueue(txq)->IsStopped())
398 if (!devQueueIface || devQueueIface->GetNTxQueues() == 1)
401 item->GetPacket()->RemovePacketTag(priorityTag);
403 device->Send(item->GetPacket(), item->GetAddress(), item->GetProtocol());
414 item->SetTxQueueIndex(txq);
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.
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,...
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.
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...
#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...
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
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