A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::TrafficControlLayer Class Reference

The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructure into ns-3. More...

#include "traffic-control-layer.h"

+ Inheritance diagram for ns3::TrafficControlLayer:
+ Collaboration diagram for ns3::TrafficControlLayer:

Classes

struct  NetDeviceInfo
 Information to store for each device. More...
 
struct  ProtocolHandlerEntry
 Protocol handler entry. More...
 

Public Types

typedef std::vector< Ptr< QueueDisc > > QueueDiscVector
 Typedef for queue disc vector.
 

Public Member Functions

 TrafficControlLayer ()
 Constructor.
 
 TrafficControlLayer (const TrafficControlLayer &)=delete
 
 ~TrafficControlLayer () override
 
virtual void DeleteRootQueueDiscOnDevice (Ptr< NetDevice > device)
 This method can be used to remove the root queue disc (and associated filters, classes and queues) installed on a device.
 
TypeId GetInstanceTypeId () const override
 Get the type ID for the instance.
 
virtual Ptr< QueueDiscGetRootQueueDiscOnDevice (Ptr< NetDevice > device) const
 This method can be used to get the root queue disc installed on a device.
 
TrafficControlLayeroperator= (const TrafficControlLayer &)=delete
 
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.
 
void RegisterProtocolHandler (Node::ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device)
 Register an IN handler.
 
virtual void ScanDevices ()
 Collect information needed to determine how to handle packets destined to each of the NetDevices of this node.
 
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 void SetRootQueueDiscOnDevice (Ptr< NetDevice > device, Ptr< QueueDisc > qDisc)
 This method can be used to set the root queue disc installed on a device.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Protected Member Functions

void DoDispose () override
 Destructor implementation.
 
void DoInitialize () override
 Initialize() implementation.
 
void NotifyNewAggregate () override
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Private Types

typedef std::vector< ProtocolHandlerEntryProtocolHandlerList
 Typedef for protocol handlers container.
 

Private Member Functions

uint32_t GetNDevices () const
 Required by the object map accessor.
 
Ptr< QueueDiscGetRootQueueDiscOnDeviceByIndex (uint32_t index) const
 Required by the object map accessor.
 

Private Attributes

TracedCallback< Ptr< const Packet > > m_dropped
 The trace source fired when the Traffic Control layer drops a packet because no queue disc is installed on the device, the device supports flow control and the device queue is stopped.
 
ProtocolHandlerList m_handlers
 List of upper-layer handlers.
 
std::map< Ptr< NetDevice >, NetDeviceInfom_netDevices
 Map storing the required information for each device with a queue disc installed.
 
Ptr< Nodem_node
 The node this TrafficControlLayer object is aggregated to.
 

Additional Inherited Members

Detailed Description

The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructure into ns-3.

Introspection did not find any typical Config paths.

The Traffic Control layer sits in between the NetDevices (L2) and any network protocol (e.g., IP). It is in charge of processing packets and performing actions on them: scheduling, dropping, marking, policing, etc.

Traffic control layer class

This object represents the main interface of the Traffic Control Module. Basically, we manage both IN and OUT directions (sometimes called RX and TX, respectively). The OUT direction is easy to follow, since it involves direct calls: upper layer (e.g. IP) calls the Send method on an instance of this class, which then calls the Enqueue method of the QueueDisc associated with the device. The Dequeue method of the QueueDisc finally calls the Send method of the NetDevice.

The IN direction uses a little trick to reduce dependencies between modules. In simple words, we use Callbacks to connect upper layer (which should register their Receive callback through RegisterProtocolHandler) and NetDevices.

An example of the IN connection between this layer and IP layer is the following:

NS_ASSERT(tc != nullptr);
device);
device);
tc->RegisterProtocolHandler(MakeCallback(&Ipv4L3Protocol::Receive, this),
device);
tc->RegisterProtocolHandler(
device);
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Lower layer calls this method after calling L3Demux::Lookup The ARP subclass needs to know from which...
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition node.cc:220
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructu...
Ptr< Node > m_node
The node this TrafficControlLayer object is aggregated to.
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.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:443
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...
Definition callback.h:684

On the node, for IPv4 and ARP packet, is registered the TrafficControlLayer::Receive callback. At the same time, on the TrafficControlLayer object, is registered the callbacks associated to the upper layers (IPv4 or ARP).

When the node receives an IPv4 or ARP packet, it calls the Receive method on TrafficControlLayer, that calls the right upper-layer callback once it finishes the operations on the packet received.

Discrimination through callbacks (in other words: what is the right upper-layer callback for this packet?) is done through checks over the device and the protocol number.


Attributes

TraceSources

  • TcDrop: Trace source indicating a packet has been dropped by the Traffic Control layer because no queue disc is installed on the device, the device supports flow control and the device queue is stopped

Group: TrafficControl

Size of this type is 160 bytes (on a 64-bit architecture).

Definition at line 87 of file traffic-control-layer.h.

Member Typedef Documentation

◆ ProtocolHandlerList

Typedef for protocol handlers container.

Definition at line 232 of file traffic-control-layer.h.

◆ QueueDiscVector

Typedef for queue disc vector.

Definition at line 135 of file traffic-control-layer.h.

Constructor & Destructor Documentation

◆ TrafficControlLayer() [1/2]

ns3::TrafficControlLayer::TrafficControlLayer ( )

Constructor.

Definition at line 57 of file traffic-control-layer.cc.

References NS_LOG_FUNCTION.

◆ ~TrafficControlLayer()

ns3::TrafficControlLayer::~TrafficControlLayer ( )
override

Definition at line 63 of file traffic-control-layer.cc.

References NS_LOG_FUNCTION.

◆ TrafficControlLayer() [2/2]

ns3::TrafficControlLayer::TrafficControlLayer ( const TrafficControlLayer & )
delete

Member Function Documentation

◆ DeleteRootQueueDiscOnDevice()

void ns3::TrafficControlLayer::DeleteRootQueueDiscOnDevice ( Ptr< NetDevice > device)
virtual

This method can be used to remove the root queue disc (and associated filters, classes and queues) installed on a device.

Parameters
devicethe device on which the installed queue disc will be deleted

Definition at line 253 of file traffic-control-layer.cc.

References m_netDevices, ns3::MakeNullCallback(), NS_ASSERT_MSG, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DoDispose()

void ns3::TrafficControlLayer::DoDispose ( )
overrideprotectedvirtual

Destructor implementation.

This method is called by Dispose() or by the Object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.

It is safe to call GetObject() from within this method.

Reimplemented from ns3::Object.

Definition at line 69 of file traffic-control-layer.cc.

References ns3::Object::DoDispose(), m_handlers, m_netDevices, m_node, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DoInitialize()

void ns3::TrafficControlLayer::DoInitialize ( )
overrideprotectedvirtual

Initialize() implementation.

This method is called only once by Initialize(). If the user calls Initialize() multiple times, DoInitialize() is called only the first time.

Subclasses are expected to override this method and chain up to their parent's implementation once they are done. It is safe to call GetObject() and AggregateObject() from within this method.

Reimplemented from ns3::Object.

Definition at line 79 of file traffic-control-layer.cc.

References ns3::Object::DoInitialize(), m_netDevices, NS_LOG_FUNCTION, and ScanDevices().

+ Here is the call graph for this function:

◆ GetInstanceTypeId()

TypeId ns3::TrafficControlLayer::GetInstanceTypeId ( ) const
overridevirtual

Get the type ID for the instance.

Returns
the instance TypeId

Reimplemented from ns3::Object.

Definition at line 52 of file traffic-control-layer.cc.

References GetTypeId().

+ Here is the call graph for this function:

◆ GetNDevices()

uint32_t ns3::TrafficControlLayer::GetNDevices ( ) const
private

Required by the object map accessor.

Returns
the number of devices in the m_netDevices map

Definition at line 312 of file traffic-control-layer.cc.

References ns3::Node::GetNDevices(), and m_node.

Referenced by GetTypeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRootQueueDiscOnDevice()

Ptr< QueueDisc > ns3::TrafficControlLayer::GetRootQueueDiscOnDevice ( Ptr< NetDevice > device) const
virtual

This method can be used to get the root queue disc installed on a device.

Parameters
devicethe device on which the requested root queue disc is installed
Returns
the root queue disc installed on the given device

Definition at line 232 of file traffic-control-layer.cc.

References m_netDevices, and NS_LOG_FUNCTION.

Referenced by GetRootQueueDiscOnDeviceByIndex().

+ Here is the caller graph for this function:

◆ GetRootQueueDiscOnDeviceByIndex()

Ptr< QueueDisc > ns3::TrafficControlLayer::GetRootQueueDiscOnDeviceByIndex ( uint32_t index) const
private

Required by the object map accessor.

Parameters
indexthe index of the device in the node's device list
Returns
the root queue disc installed on the specified device

Definition at line 246 of file traffic-control-layer.cc.

References ns3::Node::GetDevice(), GetRootQueueDiscOnDevice(), m_node, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::TrafficControlLayer::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 28 of file traffic-control-layer.cc.

References GetNDevices(), GetRootQueueDiscOnDeviceByIndex(), m_dropped, ns3::MakeObjectMapAccessor(), ns3::MakeObjectMapChecker(), ns3::MakeTraceSourceAccessor(), and ns3::TypeId::SetParent().

Referenced by GetInstanceTypeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NotifyNewAggregate()

void ns3::TrafficControlLayer::NotifyNewAggregate ( )
overrideprotectedvirtual

Notify all Objects aggregated to this one of a new Object being aggregated.

This method is invoked whenever two sets of Objects are aggregated together. It is invoked exactly once for each Object in both sets. This method can be overridden by subclasses who wish to be notified of aggregation events. These subclasses must chain up to their base class NotifyNewAggregate() method.

It is safe to call GetObject() and AggregateObject() from within this method.

Reimplemented from ns3::Object.

Definition at line 295 of file traffic-control-layer.cc.

References ns3::Object::GetObject(), m_node, ns3::Object::NotifyNewAggregate(), NS_LOG_FUNCTION, and SetNode().

+ Here is the call graph for this function:

◆ operator=()

TrafficControlLayer & ns3::TrafficControlLayer::operator= ( const TrafficControlLayer & )
delete

◆ Receive()

void ns3::TrafficControlLayer::Receive ( Ptr< NetDevice > device,
Ptr< const Packet > p,
uint16_t protocol,
const Address & from,
const Address & to,
NetDevice::PacketType packetType )
virtual

Called by NetDevices, incoming packet.

After analyses and scheduling, this method will call the right handler to pass the packet up in the stack.

Parameters
devicenetwork device
pthe packet
protocolnext header value
fromaddress of the correspondent
toaddress of the destination
packetTypetype of the packet

Definition at line 318 of file traffic-control-layer.cc.

References m_handlers, NS_ABORT_MSG_IF, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3Protocol::AddInterface(), ns3::Ipv6L3Protocol::AddInterface(), ns3::Ipv4Interface::Send(), and ns3::Ipv6Interface::Send().

+ Here is the caller graph for this function:

◆ RegisterProtocolHandler()

void ns3::TrafficControlLayer::RegisterProtocolHandler ( Node::ProtocolHandler handler,
uint16_t protocolType,
Ptr< NetDevice > device )

Register an IN handler.

The handler will be invoked when a packet is received to pass it to upper layers.

Parameters
handlerthe handler to register
protocolTypethe type of protocol this handler is interested in. This protocol type is a so-called EtherType, as registered here: http://standards.ieee.org/regauth/ethertype/eth.txt the value zero is interpreted as matching all protocols.
devicethe device attached to this handler. If the value is zero, the handler is attached to all devices.

Definition at line 98 of file traffic-control-layer.cc.

References ns3::TrafficControlLayer::ProtocolHandlerEntry::device, ns3::TrafficControlLayer::ProtocolHandlerEntry::handler, m_handlers, NS_LOG_DEBUG, NS_LOG_FUNCTION, ns3::TrafficControlLayer::ProtocolHandlerEntry::promiscuous, and ns3::TrafficControlLayer::ProtocolHandlerEntry::protocol.

◆ ScanDevices()

void ns3::TrafficControlLayer::ScanDevices ( )
virtual

Collect information needed to determine how to handle packets destined to each of the NetDevices of this node.

Checks whether a NetDeviceQueueInterface objects is aggregated to each of the NetDevices of this node and sets the required callbacks properly.

Definition at line 117 of file traffic-control-layer.cc.

References ns3::Node::GetDevice(), ns3::Node::GetId(), ns3::Node::GetNDevices(), m_netDevices, m_node, ns3::MakeCallback(), NS_ABORT_MSG, NS_ABORT_MSG_IF, NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_FUNCTION, ns3::QueueDisc::Run(), ns3::QueueDisc::WAKE_CHILD, and ns3::QueueDisc::WAKE_ROOT.

Referenced by DoInitialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Send()

void ns3::TrafficControlLayer::Send ( Ptr< NetDevice > device,
Ptr< QueueDiscItem > item )
virtual

Called from upper layer to queue a packet for the transmission.

Parameters
devicethe device the packet must be sent to
itema queue item including a packet and additional information

Definition at line 350 of file traffic-control-layer.cc.

References m_dropped, m_netDevices, NS_ASSERT, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

◆ SetNode()

void ns3::TrafficControlLayer::SetNode ( Ptr< Node > node)

Set node associated with this stack.

Parameters
nodenode to set

Definition at line 288 of file traffic-control-layer.cc.

References m_node, and NS_LOG_FUNCTION.

Referenced by NotifyNewAggregate().

+ Here is the caller graph for this function:

◆ SetRootQueueDiscOnDevice()

void ns3::TrafficControlLayer::SetRootQueueDiscOnDevice ( Ptr< NetDevice > device,
Ptr< QueueDisc > qDisc )
virtual

This method can be used to set the root queue disc installed on a device.

Parameters
devicethe device on which the provided queue disc will be installed
qDiscthe queue disc to be installed as root queue disc on device

Definition at line 210 of file traffic-control-layer.cc.

References m_netDevices, NS_ABORT_MSG_IF, and NS_LOG_FUNCTION.

Member Data Documentation

◆ m_dropped

TracedCallback<Ptr<const Packet> > ns3::TrafficControlLayer::m_dropped
private

The trace source fired when the Traffic Control layer drops a packet because no queue disc is installed on the device, the device supports flow control and the device queue is stopped.

Definition at line 257 of file traffic-control-layer.h.

Referenced by GetTypeId(), and Send().

◆ m_handlers

ProtocolHandlerList ns3::TrafficControlLayer::m_handlers
private

List of upper-layer handlers.

Definition at line 250 of file traffic-control-layer.h.

Referenced by DoDispose(), Receive(), and RegisterProtocolHandler().

◆ m_netDevices

std::map<Ptr<NetDevice>, NetDeviceInfo> ns3::TrafficControlLayer::m_netDevices
private

Map storing the required information for each device with a queue disc installed.

Definition at line 249 of file traffic-control-layer.h.

Referenced by DeleteRootQueueDiscOnDevice(), DoDispose(), DoInitialize(), GetRootQueueDiscOnDevice(), ScanDevices(), Send(), and SetRootQueueDiscOnDevice().

◆ m_node

Ptr<Node> ns3::TrafficControlLayer::m_node
private

The node this TrafficControlLayer object is aggregated to.

Definition at line 247 of file traffic-control-layer.h.

Referenced by DoDispose(), GetNDevices(), GetRootQueueDiscOnDeviceByIndex(), NotifyNewAggregate(), ScanDevices(), and SetNode().


The documentation for this class was generated from the following files: