TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QueueBuffer.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "QueueBuffer.h"
17 
18 namespace TTEthernetModel {
19 
20 simsignal_t QueueBuffer::queueLengthSignal = SIMSIGNAL_NULL;
21 simsignal_t QueueBuffer::ctDroppedSignal = SIMSIGNAL_NULL;
22 
24 {
26 }
27 
29 {
30  frames.clear();
31 }
32 
34 {
35  queueLengthSignal = registerSignal("queueLength");
36  ctDroppedSignal = registerSignal("ctDropped");
37  frames.setName("frames");
38 }
39 
40 void QueueBuffer::enqueue(EtherFrame *newFrame)
41 {
42  int size = par("size").longValue();
43  if(size>=0 && frames.length()>=size){
44  emit(ctDroppedSignal, 1);
45  if(ev.isGUI()){
46  bubble("buffer overflow - dropping frame");
47  getDisplayString().setTagArg("i2", 0, "status/excl3");
48  getDisplayString().setTagArg("tt", 0, "WARNING: buffer overflow");
49  getParentModule()->getDisplayString().setTagArg("i2", 0, "status/excl3");
50  getParentModule()->getDisplayString().setTagArg("tt", 0, "WARNING: buffer overflow");
51  }
52  if(par("drop_new").boolValue())
53  {
54  delete newFrame;
55  return;
56  }
57  else
58  {
59  EtherFrame *oldFrame = (EtherFrame *)frames.pop();
60  delete oldFrame;
61  }
62  }
63  frames.insert(newFrame);
64  setIsEmpty(frames.length() == 0);
65  emit(queueLengthSignal, frames.length());
66 }
67 
68 EtherFrame * QueueBuffer::dequeue()
69 {
70  if (frames.length() > 0)
71  {
72  setIsEmpty(frames.length() - 1 == 0);
73  emit(queueLengthSignal, frames.length() - 1);
74  return (EtherFrame*) frames.pop();
75  }
76  else
77  return NULL;
78 }
79 
80 } //namespace