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

A cDatarateChannel extended with throughput calculation. More...

#include <ThruputMeteringChannel.h>

Inheritance diagram for inet::ThruputMeteringChannel:

Public Member Functions

 ThruputMeteringChannel (const char *name=nullptr)
 Constructor. More...
 
virtual ~ThruputMeteringChannel ()
 Copy constructor. More...
 
virtual void initialize () override
 Assignment. More...
 
virtual void processMessage (cMessage *msg, simtime_t t, result_t &result) override
 Adds statistics and live display to the channel. More...
 

Protected Member Functions

virtual void beginNewInterval (simtime_t now)
 
virtual void refreshDisplay () const override
 

Protected Attributes

const char * fmt
 
unsigned int batchSize
 
simtime_t maxInterval
 
long numPackets
 
double numBits
 
simtime_t intvlStartTime
 
simtime_t intvlLastPkTime
 
unsigned long intvlNumPackets
 
unsigned long intvlNumBits
 
double currentBitPerSec
 
double currentPkPerSec
 

Detailed Description

A cDatarateChannel extended with throughput calculation.

Values get displayed on the link, using the connection's "t=" display string tag.

The display can be customized with the "format" attribute. In the format string, the following characters will get expanded:

  • 'N': number of packets
  • 'V': volume (in bytes)
  • 'p': current packet/sec
  • 'b': current bandwidth
  • 'u': current channel utilization (%)
  • 'P': average packet/sec on [0,now)
  • 'B': average bandwidth on [0,now)
  • 'U': average channel utilization (%) on [0,now) Other characters are copied verbatim.

"Current" actually means the last measurement interval, which is 10 packets or 0.1s, whichever comes first.

PROBLEM: display only gets updated if there's traffic! (For example, a high pk/sec value might stay displayed even when the link becomes idle!)

Constructor & Destructor Documentation

inet::ThruputMeteringChannel::ThruputMeteringChannel ( const char *  name = nullptr)
explicit

Constructor.

24  : cDatarateChannel(name)
25 {
26  fmt = nullptr;
27  batchSize = 10; // packets
28  maxInterval = 0.1; // seconds
29 
30  numPackets = 0;
31  numBits = 0;
32 
35 
37 }
simtime_t maxInterval
Definition: ThruputMeteringChannel.h:54
unsigned long intvlNumPackets
Definition: ThruputMeteringChannel.h:65
double currentPkPerSec
Definition: ThruputMeteringChannel.h:70
simtime_t intvlLastPkTime
Definition: ThruputMeteringChannel.h:64
simtime_t intvlStartTime
Definition: ThruputMeteringChannel.h:63
double numBits
Definition: ThruputMeteringChannel.h:60
double currentBitPerSec
Definition: ThruputMeteringChannel.h:69
unsigned long intvlNumBits
Definition: ThruputMeteringChannel.h:66
unsigned int batchSize
Definition: ThruputMeteringChannel.h:53
const char * fmt
Definition: ThruputMeteringChannel.h:52
long numPackets
Definition: ThruputMeteringChannel.h:59
inet::ThruputMeteringChannel::~ThruputMeteringChannel ( )
virtual

Copy constructor.

Destructor.

40 {
41 }

Member Function Documentation

void inet::ThruputMeteringChannel::beginNewInterval ( simtime_t  now)
protectedvirtual

Referenced by processMessage().

82 {
83  simtime_t duration = now - intvlStartTime;
84 
85  // record measurements
86  currentBitPerSec = intvlNumBits / duration;
87  currentPkPerSec = intvlNumPackets / duration;
88 
89  // restart counters
90  intvlStartTime = now;
92 }
unsigned long intvlNumPackets
Definition: ThruputMeteringChannel.h:65
double currentPkPerSec
Definition: ThruputMeteringChannel.h:70
simtime_t intvlStartTime
Definition: ThruputMeteringChannel.h:63
double currentBitPerSec
Definition: ThruputMeteringChannel.h:69
unsigned long intvlNumBits
Definition: ThruputMeteringChannel.h:66
void inet::ThruputMeteringChannel::initialize ( )
overridevirtual

Assignment.

Creates and returns an exact copy of this object. See cObject for more details. Add parameters and initialize the stat variables

54 {
55  cDatarateChannel::initialize();
56  fmt = par("thruputDisplayFormat");
57 }
const char * fmt
Definition: ThruputMeteringChannel.h:52
void inet::ThruputMeteringChannel::processMessage ( cMessage *  msg,
simtime_t  t,
result_t &  result 
)
overridevirtual

Adds statistics and live display to the channel.

60 {
61  cDatarateChannel::processMessage(msg, t, result);
62 
63  cPacket *pkt = dynamic_cast<cPacket *>(msg);
64  // TODO handle disabled state (show with different style?/color? or print "disabled"?)
65  if (!pkt || !fmt || *fmt == 0 || result.discard)
66  return;
67 
68  // count packets and bits
69  numPackets++;
70  numBits += pkt->getBitLength();
71 
72  // packet should be counted to new interval
75 
77  intvlNumBits += pkt->getBitLength();
78  intvlLastPkTime = t;
79 }
simtime_t maxInterval
Definition: ThruputMeteringChannel.h:54
unsigned long intvlNumPackets
Definition: ThruputMeteringChannel.h:65
virtual void beginNewInterval(simtime_t now)
Definition: ThruputMeteringChannel.cc:81
simtime_t intvlLastPkTime
Definition: ThruputMeteringChannel.h:64
simtime_t intvlStartTime
Definition: ThruputMeteringChannel.h:63
double numBits
Definition: ThruputMeteringChannel.h:60
unsigned long intvlNumBits
Definition: ThruputMeteringChannel.h:66
unsigned int batchSize
Definition: ThruputMeteringChannel.h:53
const char * fmt
Definition: ThruputMeteringChannel.h:52
long numPackets
Definition: ThruputMeteringChannel.h:59
void inet::ThruputMeteringChannel::refreshDisplay ( ) const
overrideprotectedvirtual
95 {
96  // produce label, based on format string
97  char buf[200];
98  char *p = buf;
99  simtime_t tt = getTransmissionFinishTime();
100  if (tt == 0)
101  tt = simTime();
102  double bps = (tt == 0) ? 0 : numBits / tt;
103  double bytes;
104  for (const char *fp = fmt; *fp && buf + 200 - p > 20; fp++) {
105  switch (*fp) {
106  case 'N': // number of packets
107  p += sprintf(p, "%ld", numPackets);
108  break;
109 
110  case 'V': // volume (in bytes)
111  bytes = floor(numBits / 8);
112  if (bytes < 1024)
113  p += sprintf(p, "%gB", bytes);
114  else if (bytes < 1024 * 1024)
115  p += sprintf(p, "%.3gKiB", bytes / 1024);
116  else
117  p += sprintf(p, "%.3gMiB", bytes / 1024 / 1024);
118  break;
119 
120  case 'p': // current packet/sec
121  p += sprintf(p, "%.3gpps", currentPkPerSec);
122  break;
123 
124  case 'b': // current bandwidth
125  if (currentBitPerSec < 1000000)
126  p += sprintf(p, "%.3gk", currentBitPerSec / 1000);
127  else
128  p += sprintf(p, "%.3gM", currentBitPerSec / 1000000);
129  break;
130 
131  case 'u': // current channel utilization (%)
132  if (getDatarate() == 0)
133  p += sprintf(p, "n/a");
134  else
135  p += sprintf(p, "%.3g%%", currentBitPerSec / getDatarate() * 100.0);
136  break;
137 
138  case 'P': // average packet/sec on [0,now)
139  p += sprintf(p, "%.3gpps", tt == 0 ? 0 : numPackets / tt);
140  break;
141 
142  case 'B': // average bandwidth on [0,now)
143  if (bps < 1000000)
144  p += sprintf(p, "%.3gk", bps / 1000);
145  else
146  p += sprintf(p, "%.3gM", bps / 1000000);
147  break;
148 
149  case 'U': // average channel utilization (%) on [0,now)
150  if (getDatarate() == 0)
151  p += sprintf(p, "n/a");
152  else
153  p += sprintf(p, "%.3g%%", bps / getDatarate() * 100.0);
154  break;
155 
156  default:
157  *p++ = *fp;
158  break;
159  }
160  }
161  *p = '\0';
162 
163  // display label
164  getSourceGate()->getDisplayString().setTagArg("t", 0, buf);
165 }
double currentPkPerSec
Definition: ThruputMeteringChannel.h:70
compose< b, pow< s,-1 > > bps
Definition: Units.h:985
double numBits
Definition: ThruputMeteringChannel.h:60
double currentBitPerSec
Definition: ThruputMeteringChannel.h:69
const char * fmt
Definition: ThruputMeteringChannel.h:52
long numPackets
Definition: ThruputMeteringChannel.h:59

Member Data Documentation

unsigned int inet::ThruputMeteringChannel::batchSize
protected
double inet::ThruputMeteringChannel::currentBitPerSec
protected
double inet::ThruputMeteringChannel::currentPkPerSec
protected
const char* inet::ThruputMeteringChannel::fmt
protected
simtime_t inet::ThruputMeteringChannel::intvlLastPkTime
protected
unsigned long inet::ThruputMeteringChannel::intvlNumBits
protected
unsigned long inet::ThruputMeteringChannel::intvlNumPackets
protected
simtime_t inet::ThruputMeteringChannel::intvlStartTime
protected
simtime_t inet::ThruputMeteringChannel::maxInterval
protected
double inet::ThruputMeteringChannel::numBits
protected
long inet::ThruputMeteringChannel::numPackets
protected

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