#include <NAMTraceWriter.h>
List of all members.
Detailed Description
Constructor & Destructor Documentation
NAMTraceWriter::~NAMTraceWriter |
( |
| ) |
[protected, virtual] |
Member Function Documentation
void NAMTraceWriter::initialize |
( |
int |
stage | ) |
[protected, virtual] |
{
if (stage==1)
{
cModule *namMod = simulation.getModuleByPath("nam");
if (!namMod)
{
nt = NULL;
EV << "NAMTraceWriter: nam module not found, no trace will be written\n";
return;
}
nt = check_and_cast<NAMTrace*>(namMod);
int namid0 = par("namid");
cModule *node = getParentModule();
namid = nt->assignNamId(node, namid0);
if (namid0==-1)
par("namid") = namid;
if (nt->isEnabled())
recordNodeEvent("UP", "circle");
NotificationBoard *nb = NotificationBoardAccess().get();
nb->subscribe(this, NF_NODE_FAILURE);
nb->subscribe(this, NF_NODE_RECOVERY);
nb->subscribe(this, NF_PP_TX_BEGIN);
nb->subscribe(this, NF_PP_RX_END);
nb->subscribe(this, NF_L2_Q_DROP);
}
else if (stage==2 && nt!=NULL && nt->isEnabled())
{
IInterfaceTable *ift = InterfaceTableAccess().get();
cModule *node = getParentModule();
for (int i=0; i<ift->getNumInterfaces(); i++)
{
InterfaceEntry *ie = ift->getInterface(i);
if (ie->isLoopback()) continue;
if (!ie->isPointToPoint()) continue;
cGate *outgate = node->gate(ie->getNodeOutputGateId());
if (!outgate || !outgate->getNextGate()) continue;
cModule *peernode = outgate->getNextGate()->getOwnerModule();
cModule *peerwriter = peernode->getSubmodule("namTrace");
if (!peerwriter) error("module %s doesn't have a submodule named namTrace", peernode->getFullPath().c_str());
int peernamid = peerwriter->par("namid");
ie->setPeerNamId(peernamid);
simtime_t delay = 0;
cDatarateChannel *chan = dynamic_cast<cDatarateChannel*>(outgate->getChannel());
if (chan) delay = chan->getDelay();
recordLinkEvent(peernamid, ie->getDatarate(), delay, "UP");
}
}
}
virtual int NAMTraceWriter::numInitStages |
( |
| ) |
const [inline, protected, virtual] |
void NAMTraceWriter::receiveChangeNotification |
( |
int |
category, |
|
|
const cPolymorphic * |
details |
|
) |
| [protected, virtual] |
void NAMTraceWriter::recordLinkEvent |
( |
int |
peernamid, |
|
|
double |
datarate, |
|
|
simtime_t |
delay, |
|
|
const char * |
state |
|
) |
| [protected, virtual] |
Referenced by initialize().
{
ASSERT(nt && nt->isEnabled());
std::ostream& out = nt->out();
if (namid < peernamid)
out << "l -t * -s " << namid << " -d " << peernamid
<< " -S " << state << " -r " << (int)datarate << " -D " << delay << endl;
out << "q -t * -s " << namid << " -d " << peernamid << " -a 0 " << endl;
}
void NAMTraceWriter::recordNodeEvent |
( |
const char * |
state, |
|
|
const char * |
shape |
|
) |
| [protected, virtual] |
Referenced by initialize().
{
ASSERT(nt && nt->isEnabled());
std::ostream& out = nt->out();
out << "n -t ";
if (simTime() == 0.0)
out << "*";
else
out << simTime();
out << " -s " << namid << " -a " << namid << " -S " << state << " -v " << shape << endl;
}
void NAMTraceWriter::recordPacketEvent |
( |
char |
event, |
|
|
int |
peernamid, |
|
|
cPacket * |
msg |
|
) |
| [protected, virtual] |
Referenced by receiveChangeNotification().
{
ASSERT(nt && nt->isEnabled());
std::ostream& out = nt->out();
int size = msg->getByteLength();
int color = 0;
for (cPacket *em = msg; em; em = em->getEncapsulatedPacket())
if (em->hasPar("color"))
{color = em->par("color").longValue(); break;}
out << event << " -t " << simTime();
if (event=='h')
out << " -s " << namid << " -d " << peernamid;
else
out << " -s " << peernamid << " -d " << namid;
out << " -e " << size << " -a " << color << endl;
}
Member Data Documentation
The documentation for this class was generated from the following files: