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

Records a NetAnim trace. More...

#include <NetAnimTrace.h>

Inheritance diagram for inet::NetAnimTrace:

Protected Member Functions

virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual void dump ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual bool isRelevantModule (cModule *mod)
 
virtual void resolveNodeCoordinates (cModule *mod, double &x, double &y)
 
virtual void addNode (cModule *mod)
 
virtual void addLink (cGate *gate)
 

Protected Attributes

std::ofstream f
 

Static Protected Attributes

static simsignal_t messageSentSignal = registerSignal("messageSent")
 
static simsignal_t mobilityStateChangedSignal = registerSignal("mobilityStateChanged")
 

Detailed Description

Records a NetAnim trace.

See NED file for more information.

Author
andras

Member Function Documentation

void inet::NetAnimTrace::addLink ( cGate *  gate)
protectedvirtual

Referenced by dump(), and receiveSignal().

141 {
142  f << simTime() << " L " << gate->getOwnerModule()->getId() << " " << gate->getNextGate()->getOwnerModule()->getId() << "\n";
143 }
std::ofstream f
Definition: NetAnimTrace.h:36
void inet::NetAnimTrace::addNode ( cModule *  mod)
protectedvirtual

Referenced by dump(), and receiveSignal().

134 {
135  double x, y;
137  f << simTime() << " N " << mod->getId() << " " << x << " " << y << "\n";
138 }
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
virtual void resolveNodeCoordinates(cModule *mod, double &x, double &y)
Definition: NetAnimTrace.cc:156
std::ofstream f
Definition: NetAnimTrace.h:36
void inet::NetAnimTrace::dump ( )
protectedvirtual

Referenced by initialize().

61 {
62  cModule *parent = getSimulation()->getSystemModule();
63  for (cModule::SubmoduleIterator it(parent); !it.end(); it++)
64  if ((*it) != this)
65  addNode(*it);
66 
67  for (cModule::SubmoduleIterator it(parent); !it.end(); it++)
68  if ((*it) != this)
69  for (cModule::GateIterator ig(*it); !ig.end(); ig++)
70  if ((*ig)->getType() == cGate::OUTPUT && (*ig)->getNextGate())
71  addLink(*ig);
72 
73 }
virtual void addNode(cModule *mod)
Definition: NetAnimTrace.cc:133
virtual void addLink(cGate *gate)
Definition: NetAnimTrace.cc:140
void inet::NetAnimTrace::finish ( )
overrideprotectedvirtual
56 {
57  f.close();
58 }
std::ofstream f
Definition: NetAnimTrace.h:36
void inet::NetAnimTrace::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
51 {
52  throw cRuntimeError("This module does not handle messages");
53 }
void inet::NetAnimTrace::initialize ( )
overrideprotectedvirtual
34 {
35  if (!par("enabled").boolValue())
36  return;
37 
38  const char *filename = par("filename");
39  f.open(filename, std::ios::out | std::ios::trunc);
40  if (f.fail())
41  throw cRuntimeError("Cannot open file \"%s\" for writing", filename);
42 
43  dump();
44 
45  getSimulation()->getSystemModule()->subscribe(POST_MODEL_CHANGE, this);
46  getSimulation()->getSystemModule()->subscribe(messageSentSignal, this);
47  getSimulation()->getSystemModule()->subscribe(mobilityStateChangedSignal, this);
48 }
virtual void dump()
Definition: NetAnimTrace.cc:60
static simsignal_t mobilityStateChangedSignal
Definition: NetAnimTrace.h:35
static simsignal_t messageSentSignal
Definition: NetAnimTrace.h:34
std::ofstream f
Definition: NetAnimTrace.h:36
bool inet::NetAnimTrace::isRelevantModule ( cModule *  mod)
protectedvirtual

Referenced by receiveSignal().

129 {
130  return mod->getParentModule() == getSimulation()->getSystemModule();
131 }
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
void inet::NetAnimTrace::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual
76 {
77  if (signalID == messageSentSignal && !source->isModule()) {
78  // record a "packet sent" line
79  cChannel *channel = (cChannel *)source;
80  cModule *srcModule = channel->getSourceGate()->getOwnerModule();
81  if (isRelevantModule(srcModule)) {
82  cModule *destModule = channel->getSourceGate()->getNextGate()->getOwnerModule();
83  cITimestampedValue *v = check_and_cast<cITimestampedValue *>(obj);
84  if (dynamic_cast<cDatarateChannel *>(channel)) {
85  cDatarateChannel *datarateChannel = (cDatarateChannel *)channel;
86  cMessage *msg = check_and_cast<cMessage *>(v->objectValue(signalID));
87  simtime_t duration = msg->isPacket() ? ((cPacket *)msg)->getBitLength() / datarateChannel->getDatarate() : 0.0;
88  simtime_t delay = datarateChannel->getDelay();
89  simtime_t fbTx = v->getTimestamp(signalID);
90  simtime_t lbTx = fbTx + duration;
91  simtime_t fbRx = fbTx + delay;
92  simtime_t lbRx = lbTx + delay;
93  f << fbTx << " P " << srcModule->getId() << " " << destModule->getId() << " " << lbTx << " " << fbRx << " " << lbRx << "\n";
94  }
95  else if (dynamic_cast<cDelayChannel *>(channel)) {
96  cDelayChannel *delayChannel = (cDelayChannel *)channel;
97  simtime_t fbTx = v->getTimestamp(signalID);
98  simtime_t fbRx = fbTx + delayChannel->getDelay();
99  f << fbTx << " P " << srcModule->getId() << " " << destModule->getId() << " " << fbTx << " " << fbRx << " " << fbRx << "\n";
100  }
101  }
102  }
103  else if (signalID == mobilityStateChangedSignal) {
104  IMobility *mobility = dynamic_cast<IMobility *>(source);
105  if (mobility) {
106  Coord c = mobility->getCurrentPosition();
107  cModule *mod = findContainingNode(dynamic_cast<cModule *>(source));
108  if (mod && isRelevantModule(mod))
109  f << simTime() << " N " << mod->getId() << " " << c.x << " " << c.y << "\n";
110  }
111  }
112  else if (signalID == POST_MODEL_CHANGE) {
113  // record dynamic "node created" and "link created" lines.
114  // note: at the time of writing, NetAnim did not support "link removed" and "node removed" lines
115  if (dynamic_cast<cPostModuleAddNotification *>(obj)) {
116  cPostModuleAddNotification *notification = (cPostModuleAddNotification *)obj;
117  if (isRelevantModule(notification->module))
118  addNode(notification->module);
119  }
120  else if (dynamic_cast<cPostGateConnectNotification *>(obj)) {
121  cPostGateConnectNotification *notification = (cPostGateConnectNotification *)obj;
122  if (isRelevantModule(notification->gate->getOwnerModule()))
123  addLink(notification->gate);
124  }
125  }
126 }
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
virtual bool isRelevantModule(cModule *mod)
Definition: NetAnimTrace.cc:128
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
static simsignal_t mobilityStateChangedSignal
Definition: NetAnimTrace.h:35
static simsignal_t messageSentSignal
Definition: NetAnimTrace.h:34
virtual void addNode(cModule *mod)
Definition: NetAnimTrace.cc:133
virtual void addLink(cGate *gate)
Definition: NetAnimTrace.cc:140
std::ofstream f
Definition: NetAnimTrace.h:36
void inet::NetAnimTrace::resolveNodeCoordinates ( cModule *  mod,
double &  x,
double &  y 
)
protectedvirtual

Referenced by addNode().

157 {
158  // choose some defaults
159  x = 600 * dblrand();
160  y = 400 * dblrand();
161 
162  // and be content with them if there is no "p" tag in the display string
163  cDisplayString& ds = submod->getDisplayString();
164  if (!ds.containsTag("p"))
165  return;
166 
167  // the following code is based on Tkenv (modinsp.cc, getSubmoduleCoords())
168 
169  // read x,y coordinates from "p" tag
170  x = toDouble(ds.getTagArg("p", 0), x);
171  y = toDouble(ds.getTagArg("p", 1), y);
172 
173  double sx = 20;
174  double sy = 20;
175 
176  const char *layout = ds.getTagArg("p", 2); // matrix, row, column, ring, exact etc.
177 
178  // modify x,y using predefined layouts
179  if (!layout || !*layout) {
180  // we're happy
181  }
182  else if (!strcmp(layout, "e") || !strcmp(layout, "x") || !strcmp(layout, "exact")) {
183  int dx = toDouble(ds.getTagArg("p", 3), 0);
184  int dy = toDouble(ds.getTagArg("p", 4), 0);
185  x += dx;
186  y += dy;
187  }
188  else if (!strcmp(layout, "r") || !strcmp(layout, "row")) {
189  int dx = toDouble(ds.getTagArg("p", 3), 2 * sx);
190  x += submod->getIndex() * dx;
191  }
192  else if (!strcmp(layout, "c") || !strcmp(layout, "col") || !strcmp(layout, "column")) {
193  int dy = toDouble(ds.getTagArg("p", 3), 2 * sy);
194  y += submod->getIndex() * dy;
195  }
196  else if (!strcmp(layout, "m") || !strcmp(layout, "matrix")) {
197  int columns = toDouble(ds.getTagArg("p", 3), 5);
198  int dx = toDouble(ds.getTagArg("p", 4), 2 * sx);
199  int dy = toDouble(ds.getTagArg("p", 5), 2 * sy);
200  x += (submod->getIndex() % columns) * dx;
201  y += (submod->getIndex() / columns) * dy;
202  }
203  else if (!strcmp(layout, "i") || !strcmp(layout, "ri") || !strcmp(layout, "ring")) {
204  int rx = toDouble(ds.getTagArg("p", 3), (sx + sy) * submod->getVectorSize() / 4);
205  int ry = toDouble(ds.getTagArg("p", 4), rx);
206 
207  x += (int)floor(rx - rx * sin(submod->getIndex() * 2 * M_PI / submod->getVectorSize()));
208  y += (int)floor(ry - ry * cos(submod->getIndex() * 2 * M_PI / submod->getVectorSize()));
209  }
210  else {
211  throw cRuntimeError("Invalid layout `%s' in `p' tag of display string", layout);
212  }
213 }
Value cos(const value< Value, Unit > &angle)
Definition: Units.h:1201
uint32_t ds
Definition: TCP_NSC.cc:76
#define M_PI
Definition: PlotFigure.cc:27
Value sin(const value< Value, Unit > &angle)
Definition: Units.h:1195

Member Data Documentation

std::ofstream inet::NetAnimTrace::f
protected
simsignal_t inet::NetAnimTrace::messageSentSignal = registerSignal("messageSent")
staticprotected

Referenced by initialize(), and receiveSignal().

simsignal_t inet::NetAnimTrace::mobilityStateChangedSignal = registerSignal("mobilityStateChanged")
staticprotected

Referenced by initialize(), and receiveSignal().


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