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

Ordinal Based Dropper module. More...

#include <OrdinalBasedDropper.h>

Inheritance diagram for inet::OrdinalBasedDropper:

Protected Member Functions

virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void parseVector (const char *vector)
 
virtual void finish () override
 

Protected Attributes

unsigned int numPackets
 
unsigned int numDropped
 
bool generateFurtherDrops
 
std::vector< unsigned int > dropsVector
 

Static Protected Attributes

static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 
static simsignal_t sentPkSignal = registerSignal("sentPk")
 
static simsignal_t dropPkSignal = registerSignal("dropPk")
 

Detailed Description

Ordinal Based Dropper module.

Member Function Documentation

void inet::OrdinalBasedDropper::finish ( )
overrideprotectedvirtual
105 {
106 }
void inet::OrdinalBasedDropper::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
51 {
52  numPackets++;
53  emit(rcvdPkSignal, msg);
54 
56  if (numPackets == dropsVector[0]) {
57  EV << "DropsGenerator: Dropping packet number " << numPackets << " " << msg << endl;
58  emit(dropPkSignal, msg);
59  delete msg;
60  numDropped++;
61  dropsVector.erase(dropsVector.begin());
62  if (dropsVector.size() == 0) {
63  EV << "DropsGenerator: End of dropsVector reached." << endl;
64  generateFurtherDrops = false;
65  }
66  return; // drop message
67  }
68  }
69  emit(sentPkSignal, msg);
70  send(msg, "out");
71 }
static simsignal_t dropPkSignal
Definition: OrdinalBasedDropper.h:38
bool generateFurtherDrops
Definition: OrdinalBasedDropper.h:40
unsigned int numDropped
Definition: OrdinalBasedDropper.h:34
unsigned int numPackets
Definition: OrdinalBasedDropper.h:33
static simsignal_t sentPkSignal
Definition: OrdinalBasedDropper.h:37
static simsignal_t rcvdPkSignal
Definition: OrdinalBasedDropper.h:36
std::vector< unsigned int > dropsVector
Definition: OrdinalBasedDropper.h:41
void inet::OrdinalBasedDropper::initialize ( )
overrideprotectedvirtual
29 {
30  numPackets = 0;
31  numDropped = 0;
32  generateFurtherDrops = false;
33 
34  WATCH(numPackets);
35  WATCH(numDropped);
36  WATCH(generateFurtherDrops);
37 
38  const char *vector = par("dropsVector");
39  parseVector(vector);
40 
41  if (dropsVector.size() == 0) {
42  EV << "DropsGenerator: Empty dropsVector" << endl;
43  }
44  else {
45  EV << "DropsGenerator: dropsVector=" << vector << endl;
46  generateFurtherDrops = true;
47  }
48 }
virtual void parseVector(const char *vector)
Definition: OrdinalBasedDropper.cc:73
bool generateFurtherDrops
Definition: OrdinalBasedDropper.h:40
unsigned int numDropped
Definition: OrdinalBasedDropper.h:34
unsigned int numPackets
Definition: OrdinalBasedDropper.h:33
std::vector< unsigned int > dropsVector
Definition: OrdinalBasedDropper.h:41
void inet::OrdinalBasedDropper::parseVector ( const char *  vector)
protectedvirtual

Referenced by initialize().

74 {
75  const char *v = vector;
76  while (*v) {
77  // parse packet numbers
78  while (isspace(*v))
79  v++;
80  if (!*v || *v == ';')
81  break;
82  if (!isdigit(*v))
83  throw cRuntimeError("Syntax error in dropsVector: packet number expected");
84  if (dropsVector.size() > 0 && dropsVector.back() >= (unsigned int)atoi(v))
85  throw cRuntimeError("Syntax error in dropsVector: packet numbers in ascending order expected");
86 
87  dropsVector.push_back(atoi(v));
88  while (isdigit(*v))
89  v++;
90 
91  // skip delimiter
92  while (isspace(*v))
93  v++;
94  if (!*v)
95  break;
96  if (*v != ';')
97  throw cRuntimeError("Syntax error in dropsVector: separator ';' missing");
98  v++;
99  while (isspace(*v))
100  v++;
101  }
102 }
std::vector< unsigned int > dropsVector
Definition: OrdinalBasedDropper.h:41

Member Data Documentation

simsignal_t inet::OrdinalBasedDropper::dropPkSignal = registerSignal("dropPk")
staticprotected

Referenced by handleMessage().

std::vector<unsigned int> inet::OrdinalBasedDropper::dropsVector
protected
bool inet::OrdinalBasedDropper::generateFurtherDrops
protected

Referenced by handleMessage(), and initialize().

unsigned int inet::OrdinalBasedDropper::numDropped
protected

Referenced by handleMessage(), and initialize().

unsigned int inet::OrdinalBasedDropper::numPackets
protected

Referenced by handleMessage(), and initialize().

simsignal_t inet::OrdinalBasedDropper::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by handleMessage().

simsignal_t inet::OrdinalBasedDropper::sentPkSignal = registerSignal("sentPk")
staticprotected

Referenced by handleMessage().


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