A Discrete-Event Network Simulator
API
ofswitch13-priority-queue.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 University of Campinas (Unicamp)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Luciano Jerez Chaves <ljerezchaves@gmail.com>
18  */
19 
21 
22 #include "ns3/log.h"
23 #include "ns3/string.h"
24 
25 #undef NS_LOG_APPEND_CONTEXT
26 #define NS_LOG_APPEND_CONTEXT \
27  std::clog << "[dp " << m_dpId << " port " << m_portNo << "] ";
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("OFSwitch13PriorityQueue");
33 NS_OBJECT_ENSURE_REGISTERED(OFSwitch13PriorityQueue);
34 
35 static ObjectFactory
37 {
38  // Setting default internal queue configuration.
39  ObjectFactory queueFactory;
40  queueFactory.SetTypeId("ns3::DropTailQueue<Packet>");
41  queueFactory.Set("MaxSize", StringValue("100p"));
42  return queueFactory;
43 }
44 
45 TypeId
47 {
48  static TypeId tid =
49  TypeId("ns3::OFSwitch13PriorityQueue")
51  .SetGroupName("OFSwitch13")
52  .AddConstructor<OFSwitch13PriorityQueue>()
53  .AddAttribute(
54  "NumQueues",
55  "The number of internal priority queues.",
57  UintegerValue(1),
59  MakeUintegerChecker<int>(1, PORT_MAX_QUEUES))
60  .AddAttribute("QueueFactory",
61  "The object factory for internal priority queues.",
67  return tid;
68 }
69 
71  : OFSwitch13Queue(),
72  NS_LOG_TEMPLATE_DEFINE("OFSwitch13PriorityQueue")
73 {
74  NS_LOG_FUNCTION(this);
75 }
76 
78 {
79  NS_LOG_FUNCTION(this);
80 }
81 
84 {
85  NS_LOG_FUNCTION(this);
86 
87  int queueId = GetNonEmptyQueue();
88  if (queueId >= 0)
89  {
90  NS_LOG_DEBUG("Packet to be dequeued from queue " << queueId);
91  Ptr<Packet> packet = GetQueue(queueId)->Dequeue();
92  NotifyDequeue(packet);
93  return packet;
94  }
95 
96  NS_LOG_DEBUG("Queue empty");
97  return nullptr;
98 }
99 
102 {
103  NS_LOG_FUNCTION(this);
104 
105  int queueId = GetNonEmptyQueue();
106  if (queueId >= 0)
107  {
108  NS_LOG_DEBUG("Packet to be removed from queue " << queueId);
109  Ptr<Packet> packet = GetQueue(queueId)->Remove();
110  NotifyRemove(packet);
111  return packet;
112  }
113 
114  NS_LOG_DEBUG("Queue empty");
115  return nullptr;
116 }
117 
120 {
121  NS_LOG_FUNCTION(this);
122 
123  int queueId = GetNonEmptyQueue();
124  if (queueId >= 0)
125  {
126  NS_LOG_DEBUG("Packet to be peeked from queue " << queueId);
127  return GetQueue(queueId)->Peek();
128  }
129 
130  NS_LOG_DEBUG("Queue empty");
131  return nullptr;
132 }
133 
134 void
136 {
137  NS_LOG_FUNCTION(this);
138 
139  // Creating the internal priority queues.
140  for (int queueId = 0; queueId < m_numQueues; queueId++)
141  {
143  }
144 
145  // Chain up.
147 }
148 
149 int
151 {
152  NS_LOG_FUNCTION(this);
153 
154  for (int queueId = 0; queueId < GetNQueues(); queueId++)
155  {
156  if (GetQueue(queueId)->IsEmpty() == false)
157  {
158  return queueId;
159  }
160  }
161 
162  NS_LOG_DEBUG("All internal queues are empty.");
163  return -1;
164 }
165 
166 } // namespace ns3
This class implements the priority queuing discipline for OpenFlow queue.
Ptr< const Packet > Peek() const override
ObjectFactory m_facQueues
Factory for internal queues.
~OFSwitch13PriorityQueue() override
Dummy destructor, see DoDispose.
static TypeId GetTypeId()
Register this type.
int m_numQueues
Number of internal queues.
OFSwitch13PriorityQueue()
Default constructor.
int GetNonEmptyQueue() const
Identify the highest-priority non-empty queue.
The OpenFlow 1.3 queue interface.
void NotifyRemove(Ptr< Packet > packet)
Notify the parent class of a packet removed from any internal queue.
uint32_t AddQueue(Ptr< Queue< Packet >> queue)
Add a new internal queue to this OpenFlow queue interface.
void NotifyDequeue(Ptr< Packet > packet)
Notify the parent class of a packet dequeued from any internal queue.
Ptr< Queue< Packet > > GetQueue(int queueId) const
Get a pointer to internal queue with specific id.
int GetNQueues() const
Get the number of internal queues.
void DoInitialize() override
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
AttributeValue implementation for ObjectFactory.
Hold variables of type string.
Definition: string.h:56
a unique identifier for an interface.
Definition: type-id.h:60
@ ATTR_GET
The attribute can be read.
Definition: type-id.h:65
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
Definition: type-id.h:67
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Hold an unsigned integer type.
Definition: uinteger.h:45
Ptr< const AttributeChecker > MakeObjectFactoryChecker()
Ptr< const AttributeAccessor > MakeObjectFactoryAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:46
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition: log.h:236
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static ObjectFactory GetDefaultQueueFactory()