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 <<
".");
127 NS_LOG_DEBUG (
"Checking device " << i <<
" with pointer " << dev <<
" of type " << dev->GetInstanceTypeId ().GetName ());
131 NS_LOG_DEBUG (
"Pointer to NetDeviceQueueInterface: " << ndqi);
137 NS_LOG_DEBUG (
"Device entry found; installing NetDeviceQueueInterface pointer " << ndqi <<
" to internal map");
138 ndi->second.m_ndqi = ndqi;
147 NS_LOG_DEBUG (
"No device entry found; create entry for device and store pointer to NetDeviceQueueInterface: " << ndqi);
153 if (ndi !=
m_netDevices.end () && ndi->second.m_rootQueueDisc)
155 NS_LOG_DEBUG (
"Setting the wake callbacks on NetDevice queues");
156 ndi->second.m_queueDiscsToWake.clear ();
160 for (uint16_t i = 0; i < ndqi->GetNTxQueues (); i++)
166 qd = ndi->second.m_rootQueueDisc;
170 NS_ABORT_MSG_IF (ndi->second.m_rootQueueDisc->GetNQueueDiscClasses () != ndqi->GetNTxQueues (),
171 "The number of child queue discs does not match the number of netdevice queues");
173 qd = ndi->second.m_rootQueueDisc->GetQueueDiscClass (i)->GetQueueDisc ();
181 ndi->second.m_queueDiscsToWake.push_back (qd);
186 ndi->second.m_queueDiscsToWake.push_back (ndi->second.m_rootQueueDisc);
191 for (
auto& q : ndi->second.m_queueDiscsToWake)
193 q->SetNetDeviceQueueInterface (ndqi);
195 { dev->Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ()); });
216 "Cannot install a root queue disc on a device already having one. " 217 "Delete the existing queue disc first.");
219 ndi->second.m_rootQueueDisc = qDisc;
234 return ndi->second.m_rootQueueDisc;
252 "No root queue disc installed on device " << device);
255 ndi->second.m_rootQueueDisc = 0;
256 for (
auto& q : ndi->second.m_queueDiscsToWake)
258 q->SetNetDeviceQueueInterface (
nullptr);
259 q->SetSendCallback (
nullptr);
261 ndi->second.m_queueDiscsToWake.clear ();
267 for (uint16_t i = 0; i < ndqi->GetNTxQueues (); i++)
269 ndqi->GetTxQueue (i)->SetWakeCallback (MakeNullCallback <void> ());
292 Ptr<Node> node = this->GetObject<Node> ();
315 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
319 for (ProtocolHandlerList::iterator i =
m_handlers.begin ();
323 || (i->device != 0 && i->device == device))
326 || i->protocol == protocol)
328 NS_LOG_DEBUG (
"Found handler for packet " << p <<
", protocol " <<
329 protocol <<
" and NetDevice " << device <<
331 i->handler (device, p, protocol, from, to, packetType);
337 NS_ABORT_MSG_IF (!found,
"Handler for protocol " << p <<
" and device " << device <<
338 " not found. It isn't forwarded up; it dies here.");
346 NS_LOG_DEBUG (
"Send packet to device " << device <<
" protocol number " <<
347 item->GetProtocol ());
354 devQueueIface = ndi->second.m_ndqi;
359 if (devQueueIface && devQueueIface->GetNTxQueues () > 1)
361 txq = devQueueIface->GetSelectQueueCallback () (item);
370 NS_ASSERT (!devQueueIface || txq < devQueueIface->GetNTxQueues ());
372 if (ndi ==
m_netDevices.end () || ndi->second.m_rootQueueDisc == 0)
376 if (!devQueueIface || !devQueueIface->GetTxQueue (txq)->IsStopped ())
380 if (!devQueueIface || devQueueIface->GetNTxQueues () == 1)
383 item->GetPacket ()->RemovePacketTag (priorityTag);
385 device->Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ());
392 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.
uint32_t GetId(void) const
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.
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...
Network device transmission queue interface.
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...
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...
uint32_t GetNDevices(void) const