Protected Member Functions | Protected Attributes

ThruputMeter Class Reference

#include <ThruputMeter.h>

List of all members.

Protected Member Functions

virtual void updateStats (simtime_t now, unsigned long bits)
virtual void beginNewInterval (simtime_t now)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void finish ()

Protected Attributes

simtime_t startTime
unsigned int batchSize
simtime_t maxInterval
unsigned long numPackets
unsigned long numBits
simtime_t intvlStartTime
simtime_t intvlLastPkTime
unsigned long intvlNumPackets
unsigned long intvlNumBits
cOutVector bitpersecVector
cOutVector pkpersecVector

Detailed Description

Measures and records network thruput

Definition at line 31 of file ThruputMeter.h.


Member Function Documentation

void ThruputMeter::beginNewInterval ( simtime_t  now  )  [protected, virtual]

Definition at line 67 of file ThruputMeter.cc.

Referenced by updateStats().

{
    simtime_t duration = now - intvlStartTime;

    // record measurements
    double bitpersec = intvlNumBits/duration.dbl();
    double pkpersec = intvlNumPackets/duration.dbl();

    bitpersecVector.recordWithTimestamp(intvlStartTime, bitpersec);
    pkpersecVector.recordWithTimestamp(intvlStartTime, pkpersec);

    // restart counters
    intvlStartTime = now;  // FIXME this should be *beginning* of tx of this packet, not end!
    intvlNumPackets = intvlNumBits = 0;
}

void ThruputMeter::finish (  )  [protected, virtual]

Definition at line 83 of file ThruputMeter.cc.

{
    simtime_t duration = simTime() - startTime;

    recordScalar("duration", duration);
    recordScalar("total packets", numPackets);
    recordScalar("total bits", numBits);

    recordScalar("avg throughput (bit/s)", numBits/duration.dbl());
    recordScalar("avg packets/s", numPackets/duration.dbl());
}

void ThruputMeter::handleMessage ( cMessage *  msg  )  [protected, virtual]

Definition at line 47 of file ThruputMeter.cc.

{
    updateStats(simTime(), PK(msg)->getBitLength());
    send(msg, "out");
}

void ThruputMeter::initialize (  )  [protected, virtual]

Definition at line 24 of file ThruputMeter.cc.

{
    startTime = par("startTime");
    long _batchSize = par("batchSize");
    if((_batchSize < 0) || (((long)(unsigned int)_batchSize) != _batchSize))
        throw cRuntimeError("invalid 'batchSize=%ld' parameter at '%s' module",_batchSize, getFullPath().c_str());
    batchSize = (unsigned int)_batchSize;
    maxInterval = par("maxInterval");

    numPackets = numBits = 0;
    intvlStartTime = intvlLastPkTime = 0;
    intvlNumPackets = intvlNumBits = 0;

    WATCH(numPackets);
    WATCH(numBits);
    WATCH(intvlStartTime);
    WATCH(intvlNumPackets);
    WATCH(intvlNumBits);

    bitpersecVector.setName("thruput (bit/sec)");
    pkpersecVector.setName("packet/sec");
}

void ThruputMeter::updateStats ( simtime_t  now,
unsigned long  bits 
) [protected, virtual]

Definition at line 53 of file ThruputMeter.cc.

Referenced by handleMessage().

{
    numPackets++;
    numBits += bits;

    // packet should be counted to new interval
    if (intvlNumPackets >= batchSize || now-intvlStartTime >= maxInterval)
        beginNewInterval(now);

    intvlNumPackets++;
    intvlNumBits += bits;
    intvlLastPkTime = now;
}


Member Data Documentation

unsigned int ThruputMeter::batchSize [protected]

Definition at line 36 of file ThruputMeter.h.

Referenced by initialize(), and updateStats().

cOutVector ThruputMeter::bitpersecVector [protected]

Definition at line 52 of file ThruputMeter.h.

Referenced by beginNewInterval(), and initialize().

simtime_t ThruputMeter::intvlLastPkTime [protected]

Definition at line 47 of file ThruputMeter.h.

Referenced by initialize(), and updateStats().

unsigned long ThruputMeter::intvlNumBits [protected]

Definition at line 49 of file ThruputMeter.h.

Referenced by beginNewInterval(), initialize(), and updateStats().

unsigned long ThruputMeter::intvlNumPackets [protected]

Definition at line 48 of file ThruputMeter.h.

Referenced by beginNewInterval(), initialize(), and updateStats().

simtime_t ThruputMeter::intvlStartTime [protected]

Definition at line 46 of file ThruputMeter.h.

Referenced by beginNewInterval(), initialize(), and updateStats().

simtime_t ThruputMeter::maxInterval [protected]

Definition at line 37 of file ThruputMeter.h.

Referenced by initialize(), and updateStats().

unsigned long ThruputMeter::numBits [protected]

Definition at line 43 of file ThruputMeter.h.

Referenced by finish(), initialize(), and updateStats().

unsigned long ThruputMeter::numPackets [protected]

Definition at line 42 of file ThruputMeter.h.

Referenced by finish(), initialize(), and updateStats().

cOutVector ThruputMeter::pkpersecVector [protected]

Definition at line 53 of file ThruputMeter.h.

Referenced by beginNewInterval(), and initialize().

simtime_t ThruputMeter::startTime [protected]

Definition at line 35 of file ThruputMeter.h.

Referenced by finish(), and initialize().


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