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

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

#include <SingleRateThreeColorMeter.h>

Inheritance diagram for inet::SingleRateThreeColorMeter:

Public Member Functions

 SingleRateThreeColorMeter ()
 

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 CIR = NaN
 
long CBS = 0
 
long EBS = 0
 
bool colorAwareMode = false
 
long Tc = 0
 
long Te = 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 according to three parameters, Committed Information Rate (CIR), Committed Burst Size (CBS), and Excess Burst Size (EBS), to be either green, yellow or red.

See RFC 2697.

Constructor & Destructor Documentation

inet::SingleRateThreeColorMeter::SingleRateThreeColorMeter ( )
inline
52 {}

Member Function Documentation

void inet::SingleRateThreeColorMeter::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
56 {
57  cPacket *packet = findIPDatagramInPacket(check_and_cast<cPacket *>(msg));
58  if (!packet)
59  throw cRuntimeError("SingleRateThreeColorMeter 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
int numRcvd
Definition: SingleRateThreeColorMeter.h:47
int numRed
Definition: SingleRateThreeColorMeter.h:49
Definition: DiffservUtil.h:30
int numYellow
Definition: SingleRateThreeColorMeter.h:48
virtual int meterPacket(cPacket *packet)
Definition: SingleRateThreeColorMeter.cc:92
Definition: DiffservUtil.h:30
void inet::SingleRateThreeColorMeter::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  CBS = 8 * (int)par("cbs");
42  EBS = 8 * (int)par("ebs");
43  colorAwareMode = par("colorAwareMode");
44  Tc = CBS;
45  Te = EBS;
46  }
47  else if (stage == INITSTAGE_NETWORK_LAYER) {
48  const char *cirStr = par("cir");
49  IInterfaceTable *ift = findModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
50  CIR = parseInformationRate(cirStr, "cir", ift, *this, 0);
51  lastUpdateTime = simTime();
52  }
53 }
bool colorAwareMode
Definition: SingleRateThreeColorMeter.h:41
double CIR
Definition: SingleRateThreeColorMeter.h:38
int numRcvd
Definition: SingleRateThreeColorMeter.h:47
int numRed
Definition: SingleRateThreeColorMeter.h:49
long CBS
Definition: SingleRateThreeColorMeter.h:39
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
Local initializations.
Definition: InitStages.h:35
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
int numYellow
Definition: SingleRateThreeColorMeter.h:48
long Te
Definition: SingleRateThreeColorMeter.h:44
simtime_t lastUpdateTime
Definition: SingleRateThreeColorMeter.h:45
long Tc
Definition: SingleRateThreeColorMeter.h:43
long EBS
Definition: SingleRateThreeColorMeter.h:40
int inet::SingleRateThreeColorMeter::meterPacket ( cPacket *  packet)
protectedvirtual
93 {
94  // update token buckets
95  simtime_t currentTime = simTime();
96  long numTokens = (long)(SIMTIME_DBL(currentTime - lastUpdateTime) * CIR);
97  lastUpdateTime = currentTime;
98  if (Tc + numTokens <= CBS)
99  Tc += numTokens;
100  else {
101  long excessTokens = Tc + numTokens - CBS;
102  Tc = CBS;
103  if (Te + excessTokens <= EBS)
104  Te += excessTokens;
105  else
106  Te = EBS;
107  }
108 
109  // update meter state
110  int oldColor = colorAwareMode ? getColor(packet) : -1;
111  int newColor;
112  int packetSizeInBits = packet->getBitLength();
113  if (oldColor <= GREEN && Tc - packetSizeInBits >= 0) {
114  Tc -= packetSizeInBits;
115  newColor = GREEN;
116  }
117  else if (oldColor <= YELLOW && Te - packetSizeInBits >= 0) {
118  Te -= packetSizeInBits;
119  newColor = YELLOW;
120  }
121  else
122  newColor = RED;
123 
124  setColor(packet, newColor);
125  return newColor;
126 }
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
bool colorAwareMode
Definition: SingleRateThreeColorMeter.h:41
double CIR
Definition: SingleRateThreeColorMeter.h:38
Definition: DiffservUtil.h:30
Definition: DiffservUtil.h:30
long CBS
Definition: SingleRateThreeColorMeter.h:39
long Te
Definition: SingleRateThreeColorMeter.h:44
simtime_t lastUpdateTime
Definition: SingleRateThreeColorMeter.h:45
Definition: DiffservUtil.h:30
long Tc
Definition: SingleRateThreeColorMeter.h:43
long EBS
Definition: SingleRateThreeColorMeter.h:40
virtual int inet::SingleRateThreeColorMeter::numInitStages ( ) const
inlineoverrideprotectedvirtual
55 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::SingleRateThreeColorMeter::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 numRcvd
Definition: SingleRateThreeColorMeter.h:47
int numRed
Definition: SingleRateThreeColorMeter.h:49
int numYellow
Definition: SingleRateThreeColorMeter.h:48

Member Data Documentation

long inet::SingleRateThreeColorMeter::CBS = 0
protected
double inet::SingleRateThreeColorMeter::CIR = NaN
protected
bool inet::SingleRateThreeColorMeter::colorAwareMode = false
protected
long inet::SingleRateThreeColorMeter::EBS = 0
protected
simtime_t inet::SingleRateThreeColorMeter::lastUpdateTime
protected
int inet::SingleRateThreeColorMeter::numRcvd = 0
protected
int inet::SingleRateThreeColorMeter::numRed = 0
protected
int inet::SingleRateThreeColorMeter::numYellow = 0
protected
long inet::SingleRateThreeColorMeter::Tc = 0
protected
long inet::SingleRateThreeColorMeter::Te = 0
protected

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