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> ())
88 if (ndi.second.m_rootQueueDisc)
90 ndi.second.m_rootQueueDisc->Initialize ();
111 NS_LOG_DEBUG (
"Handler for NetDevice: " << device <<
" registered for protocol " <<
112 protocolType <<
".");
133 ndi->second.m_ndqi = ndqi;
147 if (ndi !=
m_netDevices.end () && ndi->second.m_rootQueueDisc)
149 ndi->second.m_queueDiscsToWake.clear ();
153 for (uint16_t i = 0; i < ndqi->GetNTxQueues (); i++)
159 qd = ndi->second.m_rootQueueDisc;
163 NS_ABORT_MSG_IF (ndi->second.m_rootQueueDisc->GetNQueueDiscClasses () != ndqi->GetNTxQueues (),
164 "The number of child queue discs does not match the number of netdevice queues");
174 ndi->second.m_queueDiscsToWake.push_back (qd);
179 ndi->second.m_queueDiscsToWake.push_back (ndi->second.m_rootQueueDisc);
184 for (
auto& q : ndi->second.m_queueDiscsToWake)
186 q->SetNetDeviceQueueInterface (ndqi);
188 { dev->Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ()); });
209 "Cannot install a root queue disc on a device already having one. " 210 "Delete the existing queue disc first.");
212 ndi->second.m_rootQueueDisc = qDisc;
227 return ndi->second.m_rootQueueDisc;
245 "No root queue disc installed on device " << device);
248 ndi->second.m_rootQueueDisc = 0;
249 for (
auto& q : ndi->second.m_queueDiscsToWake)
251 q->SetNetDeviceQueueInterface (
nullptr);
252 q->SetSendCallback (
nullptr);
254 ndi->second.m_queueDiscsToWake.clear ();
260 for (uint16_t i = 0; i < ndqi->GetNTxQueues (); i++)
262 ndqi->GetTxQueue (i)->SetWakeCallback (MakeNullCallback <void> ());
285 Ptr<Node> node = this->GetObject<Node> ();
308 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
312 for (ProtocolHandlerList::iterator i =
m_handlers.begin ();
316 || (i->device != 0 && i->device == device))
319 || i->protocol == protocol)
321 NS_LOG_DEBUG (
"Found handler for packet " << p <<
", protocol " <<
322 protocol <<
" and NetDevice " << device <<
324 i->handler (device, p, protocol, from, to, packetType);
330 NS_ABORT_MSG_IF (!found,
"Handler for protocol " << p <<
" and device " << device <<
331 " not found. It isn't forwarded up; it dies here.");
339 NS_LOG_DEBUG (
"Send packet to device " << device <<
" protocol number " <<
340 item->GetProtocol ());
347 devQueueIface = ndi->second.m_ndqi;
352 if (devQueueIface && devQueueIface->GetNTxQueues () > 1)
354 txq = devQueueIface->GetSelectQueueCallback () (item);
363 NS_ASSERT (!devQueueIface || txq < devQueueIface->GetNTxQueues ());
365 if (ndi ==
m_netDevices.end () || ndi->second.m_rootQueueDisc == 0)
369 if (!devQueueIface || !devQueueIface->GetTxQueue (txq)->IsStopped ())
373 if (!devQueueIface || devQueueIface->GetNTxQueues () == 1)
376 item->GetPacket ()->RemovePacketTag (priorityTag);
378 device->Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ());
385 item->SetTxQueueIndex (txq);
virtual void DeleteRootQueueDiscOnDevice(Ptr< NetDevice > device)
This method can be used to remove the root queue disc (and associated filters, classes and queues) in...
virtual void DoInitialize(void)
Initialize() implementation.
uint32_t GetNDevices(void) const
Required by the object map accessor.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void SetRootQueueDiscOnDevice(Ptr< NetDevice > device, Ptr< QueueDisc > qDisc)
This method can be used to set the root queue disc installed on a device.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Introspection did not find any typical Config paths.
ProtocolHandlerList m_handlers
List of upper-layer handlers.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
bool promiscuous
true if it is a promiscuous handler
virtual void DoInitialize(void)
Initialize() implementation.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void DoDispose(void)
Destructor implementation.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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.
uint16_t protocol
the protocol number
a polymophic address class
void SetNode(Ptr< Node > node)
Set node associated with this stack.
indicates whether the socket has a priority set.
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets...
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Network device transmission queue interface.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
std::vector< Ptr< QueueDisc > > QueueDiscVector
Typedef for queue disc vector.
virtual ~TrafficControlLayer()
Ptr< NetDevice > device
the NetDevice
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID for the instance.
static TypeId GetTypeId(void)
Get the type ID.
virtual void Send(Ptr< NetDevice > device, Ptr< QueueDiscItem > item)
Called from upper layer to queue a packet for the transmission.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
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. ...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Information to store for each device.
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< QueueDisc > GetRootQueueDiscOnDeviceByIndex(uint32_t index) const
Required by the object map accessor.
Node::ProtocolHandler handler
the protocol handler
A base class which provides memory management and object aggregation.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
PacketType
Packet types are used as they are in Linux.
Container for a set of ns3::Object pointers.
virtual void DoDispose(void)
Destructor implementation.
TrafficControlLayer()
Constructor.
a unique identifier for an interface.
void RegisterProtocolHandler(Node::ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device)
Register an IN handler.
virtual Ptr< QueueDisc > GetRootQueueDiscOnDevice(Ptr< NetDevice > device) const
This method can be used to get the root queue disc installed on a device.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual void ScanDevices(void)
Collect information needed to determine how to handle packets destined to each of the NetDevices of t...
uint32_t GetNDevices(void) const