#include <DropsGenerator.h>
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | parseVector (const char *vector) |
virtual void | finish () |
Protected Attributes | |
unsigned int | numPackets |
unsigned int | numDropped |
bool | generateFurtherDrops |
std::vector< unsigned int > | dropsVector |
Drops generator.
Definition at line 30 of file DropsGenerator.h.
void DropsGenerator::finish | ( | ) | [protected, virtual] |
Definition at line 95 of file DropsGenerator.cc.
{ recordScalar("total packets", numPackets); recordScalar("total dropped", numDropped); }
void DropsGenerator::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 44 of file DropsGenerator.cc.
{ numPackets++; if (generateFurtherDrops) { if (numPackets==dropsVector[0]) { EV << "DropsGenerator: Dropping packet number " << numPackets << " " << msg << endl; delete msg; numDropped++; dropsVector.erase(dropsVector.begin()); if (dropsVector.size()==0) { EV << "DropsGenerator: End of dropsVector reached." << endl; generateFurtherDrops = false; } } else {send(msg, "out");} } else {send(msg, "out");} }
void DropsGenerator::initialize | ( | ) | [protected, virtual] |
Definition at line 22 of file DropsGenerator.cc.
{ numPackets = 0; numDropped = 0; generateFurtherDrops = false; WATCH(numPackets); WATCH(numDropped); WATCH(generateFurtherDrops); const char *vector = par("dropsVector"); parseVector(vector); if (dropsVector.size()==0) {EV << "DropsGenerator: Empty dropsVector" << endl;} else { EV << "DropsGenerator: dropsVector=" << vector << endl; generateFurtherDrops = true; } }
void DropsGenerator::parseVector | ( | const char * | vector | ) | [protected, virtual] |
Definition at line 69 of file DropsGenerator.cc.
Referenced by initialize().
{ const char *v = vector; while (*v) { // parse packet numbers while (isspace(*v)) v++; if (!*v || *v==';') break; if (!isdigit(*v)) throw cRuntimeError("syntax error in dropsVector: packet number expected"); if (dropsVector.size()>0 && dropsVector.back() >= (unsigned int)atoi(v)) throw cRuntimeError("syntax error in dropsVector: packet numbers in ascending order expected"); dropsVector.push_back(atoi(v)); while (isdigit(*v)) v++; // skip delimiter while (isspace(*v)) v++; if (!*v) break; if (*v!=';') throw cRuntimeError("syntax error in dropsVector: separator ';' missing"); v++; while (isspace(*v)) v++; } }
std::vector<unsigned int> DropsGenerator::dropsVector [protected] |
Definition at line 36 of file DropsGenerator.h.
Referenced by handleMessage(), initialize(), and parseVector().
bool DropsGenerator::generateFurtherDrops [protected] |
Definition at line 35 of file DropsGenerator.h.
Referenced by handleMessage(), and initialize().
unsigned int DropsGenerator::numDropped [protected] |
Definition at line 34 of file DropsGenerator.h.
Referenced by finish(), handleMessage(), and initialize().
unsigned int DropsGenerator::numPackets [protected] |
Definition at line 33 of file DropsGenerator.h.
Referenced by finish(), handleMessage(), and initialize().