RINASim  October 2016
Documentation of framework for OMNeT++
RMTQueue.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "RMTQueue.h"
24 
25 const char* SIG_STAT_RMTQUEUE_LENGTH = "RMTQueue_Length";
26 const char* SIG_STAT_RMTQUEUE_DROP = "RMTQueue_Drop";
27 
29 
31 {
32  while (!queue.empty())
33  {
34  delete queue.front();
35  queue.pop_front();
36  }
37 }
38 
40 {
41  size_t pduCount = queue.size();
42  if (pduCount)
43  {
44  EV << "Queue " << getFullPath() << " still contains " << pduCount
45  << " unprocessed PDUs!" << endl;
46 
47  for (iterator it = begin(); it != end(); ++it)
48  {
49  cPacket* p = *it;
50  EV << p->getClassName() << " received at " << p->getArrivalTime() << endl;
51  }
52  }
53 }
54 
55 
57 {
58  outputGate = gate("outputGate");
59  inputGate = gate("inputGate");
60  // message retrieval signal handler
61  sigRMTPDUPreRcvd = registerSignal(SIG_RMT_QueuePDUPreRcvd);
62  // message retrieval signal handler
64  // message pre-departure signal handler
65  sigRMTPDUPreSend = registerSignal(SIG_RMT_QueuePDUPreSend);
66  // message departure signal handler
67  sigRMTPDUSent = registerSignal(SIG_RMT_QueuePDUSent);
68  // length for vector stats
70 
71  maxQLength = getModuleByPath("^.^")->par("defaultMaxQLength");
72  thresholdQLength = getModuleByPath("^.^")->par("defaultThreshQLength");
73  qTime = simTime();
74  redrawGUI();
75 
76  WATCH(thresholdQLength);
77  WATCH(maxQLength);
78  WATCH(qTime);
79 }
80 
82  flow = f;
83 }
84 const Flow* RMTQueue::getFlow() const{
85  return flow;
86 }
87 
88 
89 std::string RMTQueue::info() const
90 {
91  std::ostringstream os;
92 
93  os << "name: " << this->getFullName()
94  << "; type: " << ((this->type == INPUT) ? "input" : "output")
95  << "; saturation: " << getLength() << "/" << this->maxQLength;
96 
97  return os.str();
98 }
99 
100 std::ostream& operator <<(std::ostream& os, const RMTQueue& cte)
101 {
102  return os << cte.info();
103 }
104 
105 
107 {
108  if (!getEnvir()->isGUI())
109  {
110  return;
111  }
112 
113  int len = getLength();
114  cDisplayString& disp = getDisplayString();
115 
116  // change color to reflect queue saturation
117  if (len == 0)
118  {
119  disp.setTagArg("i", 1, "");
120  }
121  else if (len < thresholdQLength)
122  {
123  disp.setTagArg("i", 1, "#80FF80");
124  }
125  else if (len < maxQLength)
126  {
127  disp.setTagArg("i", 1, "#FF8000");
128  }
129  else
130  {
131  disp.setTagArg("i", 1, "#800000");
132  }
133 
134  // print current saturation in numbers
135  std::ostringstream desc;
136  desc << " " << len << "/" << maxQLength;
137  disp.setTagArg("t", 1, "l");
138  disp.setTagArg("t", 0, desc.str().c_str());
139 }
140 
141 void RMTQueue::handleMessage(cMessage* msg)
142 {
143  if (dynamic_cast<cPacket*>(msg) != nullptr)
144  {
145  enqueuePDU((cPacket*)msg);
146  }
147  else
148  {
149  EV << "handleMessage(): unsupported message type!" << endl;
150  }
151 }
152 
153 void RMTQueue::enqueuePDU(cPacket* pdu)
154 {
155  emit(sigRMTPDUPreRcvd, this);
156  queue.push_back(pdu);
157  emit(sigRMTPDUPostRcvd, this);
159  redrawGUI();
160 }
161 
163 {
164  Enter_Method("releasePDU()");
165 
166  if (this->getLength() > 0)
167  {
168  emit(sigRMTPDUPreSend, this);
169  cPacket* pdu = queue.front();
170  queue.pop_front();
171  send(pdu, outputGate);
172 
173  if (getLength() == 0)
174  {
175  qTime = simTime();
176  }
177 
178  emit(sigRMTPDUSent, this);
180  bubble("Releasing a PDU...");
181  redrawGUI();
182  }
183 }
184 
186 {
187  cPacket* dropped = queue.back();
188  bubble("Dropping a PDU...");
189  queue.pop_back();
190  redrawGUI();
191  return dropped;
192 }
193 
195 {
196  cPacket* msg = queue.back();
197 
198  if (dynamic_cast<PDU*>(msg) != nullptr)
199  {
200  PDU* pdu = (PDU*) msg;
201  pdu->setFlags(pdu->getFlags() | ECN_FLAG);
202  }
203  else
204  {
205  EV << "The message isn't a PDU, cannot apply marking!" << endl;
206  }
207 }
208 
209 
211 {
212  return queue.size();
213 }
214 
216 {
217  return maxQLength;
218 }
219 
220 
222 {
223  this->maxQLength = val;
224 }
225 
227 {
228  return thresholdQLength;
229 }
230 
232 {
233  this->thresholdQLength = val;
234 }
235 
236 simtime_t RMTQueue::getQTime() const
237 {
238  return qTime;
239 }
240 
242 {
243  return type;
244 }
245 
247 {
248  this->type = type;
249 }
250 
252 {
253  return rmtAccessGate;
254 }
255 
256 void RMTQueue::setRMTAccessGate(cGate* gate)
257 {
258  rmtAccessGate = gate;
259 }
260 
262 {
263  return outputGate;
264 }
265 
267 {
268  return inputGate;
269 }
270 
271 const cPacket* RMTQueue::getFirstPDU() const
272 {
273  return queue.front();
274 }
275 
276 const cPacket* RMTQueue::getLastPDU() const
277 {
278  return queue.back();
279 }
int maxQLength
Definition: RMTQueue.h:149
const char * SIG_RMT_QueuePDUPreRcvd
Definition: RINASignals.cc:131
Class representing flow object with attributes from specs.
Definition: Flow.h:45
void setFlow(Flow *)
Definition: RMTQueue.cc:81
queueType getType() const
Definition: RMTQueue.cc:241
int thresholdQLength
Definition: RMTQueue.h:150
cGate * inputGate
Definition: RMTQueue.h:156
simsignal_t sigRMTPDUPostRcvd
Definition: RMTQueue.h:173
cGate * getOutputGate() const
Definition: RMTQueue.cc:261
simsignal_t sigStatRMTQueueLength
Definition: RMTQueue.h:176
const char * SIG_STAT_RMTQUEUE_LENGTH
Definition: RMTQueue.cc:25
int getMaxLength() const
Definition: RMTQueue.cc:215
const char * SIG_RMT_QueuePDUPreSend
Definition: RINASignals.cc:133
const cPacket * getFirstPDU() const
Definition: RMTQueue.cc:271
simsignal_t sigRMTPDUSent
Definition: RMTQueue.h:175
std::deque< cPacket * > queue
Definition: RMTQueue.h:146
Flow * flow
Definition: RMTQueue.h:158
void releasePDU()
Definition: RMTQueue.cc:162
Define_Module(RMTQueue)
virtual ~RMTQueue()
Definition: RMTQueue.cc:30
simtime_t qTime
Definition: RMTQueue.h:152
void setMaxLength(int value)
Definition: RMTQueue.cc:221
void setThreshLength(int value)
Definition: RMTQueue.cc:231
void setRMTAccessGate(cGate *gate)
Definition: RMTQueue.cc:256
Definition: PDU.h:42
virtual void setFlags(int flags)
Definition: PDU_m.cc:361
cGate * rmtAccessGate
Definition: RMTQueue.h:154
cPacket * dropLast()
Definition: RMTQueue.cc:185
const char * SIG_RMT_QueuePDUSent
Definition: RINASignals.cc:134
virtual void handleMessage(cMessage *msg)
Definition: RMTQueue.cc:141
int getLength() const
Definition: RMTQueue.cc:210
const cPacket * getLastPDU() const
Definition: RMTQueue.cc:276
void redrawGUI()
Definition: RMTQueue.cc:106
const Flow * getFlow() const
Definition: RMTQueue.cc:84
const char * SIG_STAT_RMTQUEUE_DROP
Definition: RMTQueue.cc:26
int getThreshLength() const
Definition: RMTQueue.cc:226
cGate * outputGate
Definition: RMTQueue.h:155
const char * SIG_RMT_QueuePDUPostRcvd
Definition: RINASignals.cc:132
queueType type
Definition: RMTQueue.h:147
void setType(queueType type)
Definition: RMTQueue.cc:246
simtime_t getQTime() const
Definition: RMTQueue.cc:236
iterator begin()
Definition: RMTQueue.h:119
cGate * getInputGate() const
Definition: RMTQueue.cc:266
virtual void finish()
Definition: RMTQueue.cc:39
void markCongestionOnLast()
Definition: RMTQueue.cc:194
simsignal_t sigRMTPDUPreRcvd
Definition: RMTQueue.h:172
virtual int getFlags() const
Definition: PDU_m.cc:356
#define ECN_FLAG
Definition: PDU.h:37
virtual void initialize()
Definition: RMTQueue.cc:56
iterator end()
Definition: RMTQueue.h:120
std::deque< cPacket * >::iterator iterator
Definition: RMTQueue.h:117
simsignal_t sigRMTPDUPreSend
Definition: RMTQueue.h:174
cGate * getRMTAccessGate() const
Definition: RMTQueue.cc:251
void enqueuePDU(cPacket *pdu)
Definition: RMTQueue.cc:153
std::ostream & operator<<(std::ostream &os, const RMTQueue &cte)
Definition: RMTQueue.cc:100
std::string info() const
Definition: RMTQueue.cc:89