INET Framework for OMNeT++/OMNEST
inet::TwoRateThreeColorMeter Class Reference

This class can be used as a meter in an ITrafficConditioner. More...

#include <TwoRateThreeColorMeter.h>

Inheritance diagram for inet::TwoRateThreeColorMeter:

Public Member Functions

 TwoRateThreeColorMeter ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void refreshDisplay () const override
 
virtual int meterPacket (cPacket *packet)
 

Protected Attributes

double PIR = NaN
 
long PBS = 0
 
double CIR = NaN
 
long CBS = 0
 
bool colorAwareMode = false
 
long Tp = 0
 
long Tc = 0
 
simtime_t lastUpdateTime
 
int numRcvd = 0
 
int numYellow = 0
 
int numRed = 0
 

Detailed Description

This class can be used as a meter in an ITrafficConditioner.

It marks the packets based on two rates, Peak Information Rate (PIR) and Committed Information Rate (CIR), and their associated burst sizes to be either green, yellow or red.

See RFC 2698.

Constructor & Destructor Documentation

inet::TwoRateThreeColorMeter::TwoRateThreeColorMeter ( )
inline
53 {}

Member Function Documentation

void inet::TwoRateThreeColorMeter::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
56 {
57  cPacket *packet = findIPDatagramInPacket(check_and_cast<cPacket *>(msg));
58  if (!packet)
59  throw cRuntimeError("TwoRateThreeColorMeter received a packet that does not encapsulate an IP datagram.");
60 
61  numRcvd++;
62  int color = meterPacket(packet);
63  switch (color) {
64  case GREEN:
65  send(packet, "greenOut");
66  break;
67 
68  case YELLOW:
69  numYellow++;
70  send(packet, "yellowOut");
71  break;
72 
73  case RED:
74  numRed++;
75  send(packet, "redOut");
76  break;
77  }
78 }
cPacket * findIPDatagramInPacket(cPacket *packet)
Returns the IP datagram encapsulated inside packet, or the packet itself if it is an IPv4/IPv6 datagr...
Definition: DiffservUtil.cc:199
Definition: DiffservUtil.h:30
virtual int meterPacket(cPacket *packet)
Definition: TwoRateThreeColorMeter.cc:92
Definition: DiffservUtil.h:30
int numYellow
Definition: TwoRateThreeColorMeter.h:49
int numRcvd
Definition: TwoRateThreeColorMeter.h:48
Definition: DiffservUtil.h:30
int numRed
Definition: TwoRateThreeColorMeter.h:50
void inet::TwoRateThreeColorMeter::initialize ( int  stage)
overrideprotectedvirtual
30 {
31  cSimpleModule::initialize(stage);
32 
33  if (stage == INITSTAGE_LOCAL) {
34  numRcvd = 0;
35  numYellow = 0;
36  numRed = 0;
37  WATCH(numRcvd);
38  WATCH(numYellow);
39  WATCH(numRed);
40 
41  PBS = 8 * (int)par("pbs");
42  CBS = 8 * (int)par("cbs");
43  colorAwareMode = par("colorAwareMode");
44  Tp = PBS;
45  Tc = CBS;
46  }
47  else if (stage == INITSTAGE_NETWORK_LAYER) {
48  IInterfaceTable *ift = findModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
49  PIR = parseInformationRate(par("pir"), "pir", ift, *this, 0);
50  CIR = parseInformationRate(par("cir"), "cir", ift, *this, 0);
51  lastUpdateTime = simTime();
52  }
53 }
long CBS
Definition: TwoRateThreeColorMeter.h:41
long Tp
Definition: TwoRateThreeColorMeter.h:44
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
bool colorAwareMode
Definition: TwoRateThreeColorMeter.h:42
long Tc
Definition: TwoRateThreeColorMeter.h:45
Local initializations.
Definition: InitStages.h:35
long PBS
Definition: TwoRateThreeColorMeter.h:39
double parseInformationRate(const char *attrValue, const char *attrName, IInterfaceTable *ift, cSimpleModule &owner, int defaultValue)
Parses the information rate parameter (bits/sec).
Definition: DiffservUtil.cc:51
simtime_t lastUpdateTime
Definition: TwoRateThreeColorMeter.h:46
int numYellow
Definition: TwoRateThreeColorMeter.h:49
double PIR
Definition: TwoRateThreeColorMeter.h:38
int numRcvd
Definition: TwoRateThreeColorMeter.h:48
int numRed
Definition: TwoRateThreeColorMeter.h:50
double CIR
Definition: TwoRateThreeColorMeter.h:40
int inet::TwoRateThreeColorMeter::meterPacket ( cPacket *  packet)
protectedvirtual
93 {
94  // update token buckets
95  simtime_t currentTime = simTime();
96  double elapsedTime = SIMTIME_DBL(currentTime - lastUpdateTime);
97  lastUpdateTime = currentTime;
98  long numTokens = (long)(elapsedTime * PIR);
99  if (Tp + numTokens <= PBS)
100  Tp += numTokens;
101  else
102  Tp = PBS;
103  numTokens = (long)(elapsedTime * CIR);
104  if (Tc + numTokens <= CBS)
105  Tc += numTokens;
106  else
107  Tc = CBS;
108 
109  // update meter state
110  int oldColor = colorAwareMode ? getColor(packet) : -1;
111  int newColor;
112  int packetSizeInBits = 8 * packet->getByteLength();
113  if (oldColor == RED || Tp - packetSizeInBits < 0) {
114  newColor = RED;
115  }
116  else if (oldColor == YELLOW || Tc - packetSizeInBits < 0) {
117  Tp -= packetSizeInBits;
118  newColor = YELLOW;
119  }
120  else {
121  Tp -= packetSizeInBits;
122  Tc -= packetSizeInBits;
123  newColor = GREEN;
124  }
125 
126  setColor(packet, newColor);
127  return newColor;
128 }
int getColor(cPacket *packet)
Returns the color of the packet.
Definition: DiffservUtil.cc:227
void setColor(cPacket *packet, int color)
Sets the color of the packet.
Definition: DiffservUtil.cc:233
Definition: DiffservUtil.h:30
long CBS
Definition: TwoRateThreeColorMeter.h:41
Definition: DiffservUtil.h:30
long Tp
Definition: TwoRateThreeColorMeter.h:44
bool colorAwareMode
Definition: TwoRateThreeColorMeter.h:42
long Tc
Definition: TwoRateThreeColorMeter.h:45
long PBS
Definition: TwoRateThreeColorMeter.h:39
simtime_t lastUpdateTime
Definition: TwoRateThreeColorMeter.h:46
double PIR
Definition: TwoRateThreeColorMeter.h:38
Definition: DiffservUtil.h:30
double CIR
Definition: TwoRateThreeColorMeter.h:40
virtual int inet::TwoRateThreeColorMeter::numInitStages ( ) const
inlineoverrideprotectedvirtual
56 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::TwoRateThreeColorMeter::refreshDisplay ( ) const
overrideprotectedvirtual
81 {
82  char buf[80] = "";
83  if (numRcvd > 0)
84  sprintf(buf + strlen(buf), "rcvd: %d ", numRcvd);
85  if (numYellow > 0)
86  sprintf(buf + strlen(buf), "yellow:%d ", numYellow);
87  if (numRed > 0)
88  sprintf(buf + strlen(buf), "red:%d ", numRed);
89  getDisplayString().setTagArg("t", 0, buf);
90 }
int numYellow
Definition: TwoRateThreeColorMeter.h:49
int numRcvd
Definition: TwoRateThreeColorMeter.h:48
int numRed
Definition: TwoRateThreeColorMeter.h:50

Member Data Documentation

long inet::TwoRateThreeColorMeter::CBS = 0
protected
double inet::TwoRateThreeColorMeter::CIR = NaN
protected
bool inet::TwoRateThreeColorMeter::colorAwareMode = false
protected
simtime_t inet::TwoRateThreeColorMeter::lastUpdateTime
protected
int inet::TwoRateThreeColorMeter::numRcvd = 0
protected
int inet::TwoRateThreeColorMeter::numRed = 0
protected
int inet::TwoRateThreeColorMeter::numYellow = 0
protected
long inet::TwoRateThreeColorMeter::PBS = 0
protected
double inet::TwoRateThreeColorMeter::PIR = NaN
protected
long inet::TwoRateThreeColorMeter::Tc = 0
protected
long inet::TwoRateThreeColorMeter::Tp = 0
protected

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