22 #include "ns3/object-map.h"
23 #include "ns3/packet.h"
24 #include "ns3/queue-disc.h"
37 .SetGroupName (
"TrafficControl")
39 .AddAttribute (
"RootQueueDiscList",
"The list of root queue discs associated to this Traffic Control layer.",
43 MakeObjectMapChecker<QueueDisc> ())
77 if (ndi->second.rootQueueDisc)
82 ndi->first->Initialize ();
90 for (uint32_t i = 0; i < devQueueIface->GetTxQueuesN (); i++)
93 ndi->second.queueDiscsToWake.push_back (ndi->second.rootQueueDisc);
98 NS_ASSERT_MSG (ndi->second.rootQueueDisc->GetNQueueDiscClasses () == devQueueIface->GetTxQueuesN (),
99 "The number of child queue discs does not match the number of netdevice queues");
100 for (uint32_t i = 0; i < devQueueIface->GetTxQueuesN (); i++)
103 ndi->second.rootQueueDisc->GetQueueDiscClass (i)->GetQueueDisc ()));
104 ndi->second.queueDiscsToWake.push_back (ndi->second.rootQueueDisc->GetQueueDiscClass (i)->GetQueueDisc ());
109 ndi->second.rootQueueDisc->Initialize ();
125 NS_LOG_DEBUG (
"The setup for this device has been already done.");
131 device->AggregateObject (devQueueIface);
145 NS_ASSERT_MSG (ndi->second.ndqi == 0,
"This is a bug, there is no netdevice queue interface "
146 <<
"aggregated to the device but the pointer is not null.");
147 ndi->second.ndqi = devQueueIface;
165 NS_LOG_DEBUG (
"Handler for NetDevice: " << device <<
" registered for protocol " <<
166 protocolType <<
".");
185 NS_ASSERT_MSG (ndi->second.rootQueueDisc == 0,
"Cannot install a root queue disc on a "
186 <<
"device already having one. Delete the existing queue disc first.");
187 ndi->second.rootQueueDisc = qDisc;
200 NS_LOG_WARN (
"GetRootQueueDiscOnDevice should not be called before the "
201 <<
"device is setup or a queue disc is installed on the device.");
204 return ndi->second.rootQueueDisc;
222 <<
" installed on device " << device);
225 ndi->second.rootQueueDisc = 0;
226 ndi->second.queueDiscsToWake.clear ();
242 Ptr<Node> node = this->GetObject<Node> ();
265 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
269 for (ProtocolHandlerList::iterator i =
m_handlers.begin ();
273 || (i->device != 0 && i->device == device))
276 || i->protocol == protocol)
278 NS_LOG_DEBUG (
"Found handler for packet " << p <<
", protocol " <<
279 protocol <<
" and NetDevice " << device <<
281 i->handler (device, p, protocol, from, to, packetType);
289 NS_FATAL_ERROR (
"Handler for protocol " << p <<
" and device " << device <<
290 " not found. It isn't forwarded up; it dies here.");
299 NS_LOG_DEBUG (
"Send packet to device " << device <<
" protocol number " <<
300 item->GetProtocol ());
308 uint8_t txq = devQueueIface->GetSelectedQueue (item);
309 NS_ASSERT (txq < devQueueIface->GetTxQueuesN ());
311 if (ndi->second.rootQueueDisc == 0)
315 if (!devQueueIface->GetTxQueue (txq)->IsStopped ())
318 device->Send (item->GetPacket (), item->GetAddress (), item->GetProtocol ());
325 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.
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.
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.
Traffic control layer definition.
ProtocolHandlerList m_handlers
List of upper-layer handlers.
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.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
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.
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets...
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Network device transmission queue interface.
std::vector< Ptr< QueueDisc > > QueueDiscVector
Typedef for queue disc vector.
Ptr< NetDevice > device
the NetDevice
static TypeId GetTypeId(void)
Get the type ID.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual void Send(Ptr< NetDevice > device, Ptr< QueueDiscItem > item)
Called from upper layer to queue a packet for the transmission.
Ptr< Node > m_node
The node this TrafficControlLayer object is aggregated to.
virtual Ptr< QueueDisc > GetRootQueueDiscOnDevice(Ptr< NetDevice > device) const
This method can be used to get the root queue disc installed on a device.
std::map< Ptr< NetDevice >, NetDeviceInfo > m_netDevices
Map storing the required information for each device with a queue disc installed. ...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
virtual void SetupDevice(Ptr< NetDevice > device)
Perform the operations that the traffic control layer needs to do when an IPv4/v6 interface is added ...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
uint32_t GetNDevices(void) const
Required by the object map accessor.
Information to store for each device.
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID for the instance.
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.
Ptr< QueueDisc > GetRootQueueDiscOnDeviceByIndex(uint32_t index) const
Required by the object map accessor.
TypeId SetParent(TypeId tid)
Set the parent TypeId.