Traffic control layer definition. More...
#include "traffic-control-layer.h"
Classes | |
struct | ProtocolHandlerEntry |
Protocol handler entry. More... | |
Public Types | |
typedef std::vector< Ptr< QueueDisc > > | QueueDiscVector |
Typedef for queue disc vector. More... | |
Public Member Functions | |
TrafficControlLayer () | |
Constructor. More... | |
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. More... | |
virtual TypeId | GetInstanceTypeId (void) const |
Get the type ID for the instance. More... | |
virtual Ptr< QueueDisc > | GetRootQueueDiscOnDevice (Ptr< NetDevice > device) |
This method can be used to get the root queue disc installed on a device. More... | |
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. More... | |
void | RegisterProtocolHandler (Node::ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device) |
Register an IN handler. More... | |
virtual void | Send (Ptr< NetDevice > device, Ptr< QueueDiscItem > item) |
Called from upper layer to queue a packet for the transmission. More... | |
void | SetNode (Ptr< Node > node) |
Set node associated with this stack. More... | |
virtual void | SetRootQueueDiscOnDevice (Ptr< NetDevice > device, Ptr< QueueDisc > qDisc) |
This method can be used to set the root queue disc installed on a device. More... | |
virtual void | SetupDevice (Ptr< NetDevice > device) |
Perform the operations that the traffic control layer needs to do when an IPv4/v6 interface is added to a device. More... | |
![]() | |
Object () | |
Constructor. More... | |
virtual | ~Object () |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose (void) |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator (void) const |
Get an iterator to the Objects aggregated to this one. More... | |
template<typename T > | |
Ptr< T > | GetObject (void) const |
Get a pointer to the requested aggregated Object. More... | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. More... | |
void | Initialize (void) |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
![]() | |
SimpleRefCount () | |
Constructor. More... | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount (void) const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment. More... | |
void | Ref (void) const |
Increment the reference count. More... | |
void | Unref (void) const |
Decrement the reference count. More... | |
![]() | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
Get the value of an attribute, raising fatal errors if unsuccessful. More... | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising erros. More... | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. More... | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. More... | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. More... | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. More... | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. More... | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. More... | |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
![]() | |
static TypeId | GetTypeId (void) |
Register this type. More... | |
![]() | |
static void | Cleanup (void) |
Noop. More... | |
![]() | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Protected Member Functions | |
virtual void | DoDispose (void) |
Destructor implementation. More... | |
virtual void | DoInitialize (void) |
Initialize() implementation. More... | |
virtual void | NotifyNewAggregate (void) |
Notify all Objects aggregated to this one of a new Object being aggregated. More... | |
![]() | |
Object (const Object &o) | |
Copy an Object. More... | |
![]() | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. More... | |
virtual void | NotifyConstructionCompleted (void) |
Notifier called once the ObjectBase is fully constructed. More... | |
Private Types | |
typedef std::pair< Ptr< NetDeviceQueueInterface >, QueueDiscVector > | NetDeviceInfo |
Typedef for queue disc vector. More... | |
typedef std::vector< struct ProtocolHandlerEntry > | ProtocolHandlerList |
Typedef for protocol handlers container. More... | |
Private Member Functions | |
TrafficControlLayer (TrafficControlLayer const &) | |
Copy constructor Disable default implementation to avoid misuse. More... | |
uint32_t | GetDeviceIndex (Ptr< NetDevice > device) |
Lookup a given Ptr<NetDevice> in the node's list of devices. More... | |
TrafficControlLayer & | operator= (TrafficControlLayer const &) |
Assignment operator Disable default implementation to avoid misuse. More... | |
Private Attributes | |
ProtocolHandlerList | m_handlers |
List of upper-layer handlers. More... | |
std::map< Ptr< NetDevice >, NetDeviceInfo > | m_netDeviceQueueToQueueDiscMap |
This map plays the role of the qdisc field of the netdev_queue struct in Linux. More... | |
Ptr< Node > | m_node |
The node this TrafficControlLayer object is aggregated to. More... | |
QueueDiscVector | m_rootQueueDiscs |
This vector stores the root queue discs installed on all the devices of the node. More... | |
Additional Inherited Members | |
![]() | |
static TypeId | GetObjectIid (void) |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
Traffic control layer definition.
Introspection did not find any typical Config paths.
This layer stays between NetDevices (L2) and any network protocol (e.g. IP). When enabled, it is responsible to analyze packets and to perform actions on them: the most common is scheduling.
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:
Ptr<TrafficControlLayer> tc = m_node->GetObject<TrafficControlLayer> (); NS_ASSERT (tc != 0); m_node->RegisterProtocolHandler (MakeCallback (&TrafficControlLayer::Receive, tc), Ipv4L3Protocol::PROT_NUMBER, device); m_node->RegisterProtocolHandler (MakeCallback (&TrafficControlLayer::Receive, tc), ArpL3Protocol::PROT_NUMBER, device); tc->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, this), Ipv4L3Protocol::PROT_NUMBER, device); tc->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (GetObject<ArpL3Protocol> ())), ArpL3Protocol::PROT_NUMBER, device);
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.
No TraceSources are defined for this type.
Size of this type is 136 bytes (on a 64-bit architecture).
Definition at line 83 of file traffic-control-layer.h.
|
private |
Typedef for queue disc vector.
Definition at line 222 of file traffic-control-layer.h.
|
private |
Typedef for protocol handlers container.
Definition at line 219 of file traffic-control-layer.h.
typedef std::vector<Ptr<QueueDisc> > ns3::TrafficControlLayer::QueueDiscVector |
Typedef for queue disc vector.
Definition at line 125 of file traffic-control-layer.h.
ns3::TrafficControlLayer::TrafficControlLayer | ( | ) |
Constructor.
Definition at line 53 of file traffic-control-layer.cc.
References NS_LOG_FUNCTION_NOARGS.
|
private |
Copy constructor Disable default implementation to avoid misuse.
This method can be used to remove the root queue disc (and associated filters, classes and queues) installed on a device.
device | the device on which the installed queue disc will be deleted |
Definition at line 195 of file traffic-control-layer.cc.
References GetDeviceIndex(), m_rootQueueDiscs, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
|
protectedvirtual |
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 overriden 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 60 of file traffic-control-layer.cc.
References ns3::Object::DoDispose(), m_handlers, m_netDeviceQueueToQueueDiscMap, m_node, m_rootQueueDiscs, and NS_LOG_FUNCTION.
|
protectedvirtual |
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 71 of file traffic-control-layer.cc.
References ns3::Object::DoInitialize(), ns3::Node::GetDevice(), m_netDeviceQueueToQueueDiscMap, m_node, m_rootQueueDiscs, ns3::MakeCallback(), NS_ASSERT, NS_ASSERT_MSG, NS_LOG_FUNCTION, ns3::QueueDisc::Run(), ns3::QueueDisc::WAKE_CHILD, and ns3::QueueDisc::WAKE_ROOT.
Lookup a given Ptr<NetDevice> in the node's list of devices.
device | the device to lookup |
Definition at line 235 of file traffic-control-layer.cc.
References ns3::Node::GetDevice(), ns3::Node::GetNDevices(), m_node, and NS_LOG_FUNCTION.
Referenced by DeleteRootQueueDiscOnDevice(), GetRootQueueDiscOnDevice(), and SetRootQueueDiscOnDevice().
|
virtual |
Get the type ID for the instance.
Reimplemented from ns3::Object.
Definition at line 48 of file traffic-control-layer.cc.
References GetTypeId().
|
virtual |
This method can be used to get the root queue disc installed on a device.
device | the device on which the requested root queue disc is installed |
Definition at line 180 of file traffic-control-layer.cc.
References GetDeviceIndex(), m_rootQueueDiscs, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 33 of file traffic-control-layer.cc.
References m_rootQueueDiscs, ns3::MakeObjectVectorAccessor(), and ns3::TypeId::SetParent().
Referenced by GetInstanceTypeId().
|
protectedvirtual |
Notify all Objects aggregated to this one of a new Object being aggregated.
This function must be implemented in the stack that needs to notify other stacks connected to the node of their presence in the node.
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 overriden 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 218 of file traffic-control-layer.cc.
References m_node, ns3::Object::NotifyNewAggregate(), NS_LOG_FUNCTION, and SetNode().
|
private |
Assignment operator Disable default implementation to avoid misuse.
|
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.
device | network device |
p | the packet |
protocol | next header value |
from | address of the correspondant |
to | address of the destination |
packetType | type of the packet |
Definition at line 244 of file traffic-control-layer.cc.
References m_handlers, NS_FATAL_ERROR, NS_LOG_DEBUG, and NS_LOG_FUNCTION.
Referenced by ns3::Ipv6L3Protocol::AddInterface(), and ns3::Ipv4L3Protocol::AddInterface().
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.
handler | the handler to register |
protocolType | the 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. |
device | the device attached to this handler. If the value is zero, the handler is attached to all devices. |
Definition at line 143 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.
|
virtual |
Called from upper layer to queue a packet for the transmission.
device | the device the packet must be sent to |
item | a queue item including a packet and additional information |
Definition at line 278 of file traffic-control-layer.cc.
References ns3::QueueDisc::Enqueue(), m_netDeviceQueueToQueueDiscMap, NS_ASSERT, NS_LOG_DEBUG, NS_LOG_FUNCTION, and ns3::QueueDisc::Run().
Set node associated with this stack.
node | node to set |
Definition at line 211 of file traffic-control-layer.cc.
References m_node, and NS_LOG_FUNCTION.
Referenced by NotifyNewAggregate().
|
virtual |
This method can be used to set the root queue disc installed on a device.
device | the device on which the provided queue disc will be installed |
qDisc | the queue disc to be installed as root queue disc on device |
Definition at line 161 of file traffic-control-layer.cc.
References GetDeviceIndex(), m_rootQueueDiscs, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
Perform the operations that the traffic control layer needs to do when an IPv4/v6 interface is added to a device.
device | the device which the IPv4/v6 interface has been added to |
This method creates a NetDeviceQueueInterface for the device
Definition at line 120 of file traffic-control-layer.cc.
References m_netDeviceQueueToQueueDiscMap, NS_ASSERT_MSG, NS_LOG_DEBUG, and NS_LOG_FUNCTION.
|
private |
List of upper-layer handlers.
Definition at line 239 of file traffic-control-layer.h.
Referenced by DoDispose(), Receive(), and RegisterProtocolHandler().
|
private |
This map plays the role of the qdisc field of the netdev_queue struct in Linux.
Definition at line 238 of file traffic-control-layer.h.
Referenced by DoDispose(), DoInitialize(), Send(), and SetupDevice().
The node this TrafficControlLayer object is aggregated to.
Definition at line 233 of file traffic-control-layer.h.
Referenced by DoDispose(), DoInitialize(), GetDeviceIndex(), NotifyNewAggregate(), and SetNode().
|
private |
This vector stores the root queue discs installed on all the devices of the node.
Devices are sorted as in Node::m_devices
Definition at line 236 of file traffic-control-layer.h.
Referenced by DeleteRootQueueDiscOnDevice(), DoDispose(), DoInitialize(), GetRootQueueDiscOnDevice(), GetTypeId(), and SetRootQueueDiscOnDevice().