Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NAMTraceWriter Class Reference

#include <NAMTraceWriter.h>

Inheritance diagram for NAMTraceWriter:

INotifiable List of all members.

Detailed Description

Writes a "nam" trace.


Protected Member Functions

void recordNodeEvent (char *state, char *shape)
void recordLinkEvent (int peernamid, double datarate, double delay, char *state)
void recordLinkEvent (InterfaceEntry *ie, char *state)
void recordPacketEvent (const char event, int peernamid, cMessage *msg)
virtual int numInitStages () const
virtual void initialize (int stage)
virtual void finish ()
virtual void receiveChangeNotification (int category, cPolymorphic *details)

Protected Attributes

int namid
NAMTracent


Member Function Documentation

void NAMTraceWriter::finish  )  [protected, virtual]
 

00100 {
00101     if (nt && nt->enabled())
00102     {
00103         recordNodeEvent("DOWN", "circle");
00104     }
00105 }

void NAMTraceWriter::initialize int  stage  )  [protected, virtual]
 

00033 {
00034     if (stage==1)  // let NAMTrace module initialize in stage 0
00035     {
00036         // get pointer to the NAMTrace module
00037         cModule *namMod = simulation.moduleByPath("nam");
00038         if (!namMod)
00039         {
00040             nt = NULL;
00041             EV << "NAMTraceWriter: nam module not found, no trace will be written\n";
00042             return;
00043         }
00044 
00045         // store ptr to namtrace module
00046         nt = check_and_cast<NAMTrace*>(namMod);
00047 
00048         // register given namid; -1 means autoconfigure
00049         int namid0 = par("namid");
00050         cModule *node = parentModule();  // the host or router
00051         namid = nt->assignNamId(node, namid0);
00052         if (namid0==-1)
00053             par("namid") = namid;  // let parameter reflect autoconfigured namid
00054 
00055         // write "node" entry to the trace
00056         if (nt->enabled())
00057             recordNodeEvent("UP", "circle");
00058 
00059         // subscribe to the interesting notifications
00060         NotificationBoard *nb = NotificationBoardAccess().get();
00061         nb->subscribe(this, NF_NODE_FAILURE);
00062         nb->subscribe(this, NF_NODE_RECOVERY);
00063         nb->subscribe(this, NF_PP_TX_BEGIN);
00064         nb->subscribe(this, NF_PP_RX_END);
00065         nb->subscribe(this, NF_L2_Q_DROP);
00066     }
00067     else if (stage==2 && nt!=NULL && nt->enabled())
00068     {
00069         // write "link" entries
00070         InterfaceTable *ift = InterfaceTableAccess().get();
00071         cModule *node = parentModule();  // the host or router
00072         for (int i=0; i<ift->numInterfaces(); i++)
00073         {
00074             // skip loopback interfaces
00075             InterfaceEntry *ie = ift->interfaceAt(i);
00076             if (ie->isLoopback()) continue;
00077             if (!ie->isPointToPoint()) continue; // consider pont-to-point links only
00078 
00079             // fill in peerNamIds in InterfaceEntries
00080             cGate *outgate = node->gate(ie->nodeOutputGateId());
00081             if (!outgate || !outgate->toGate()) continue;
00082             cModule *peernode = outgate->toGate()->ownerModule(); // FIXME not entirely correct: what if a subnet is "boxed"?
00083             cModule *peerwriter = peernode->submodule("namTrace");
00084             if (!peerwriter) error("module %s doesn't have a submodule named namTrace", peernode->fullPath().c_str());
00085             int peernamid = peerwriter->par("namid");
00086             ie->setPeerNamId(peernamid);
00087 
00088             // find delay
00089             double delay = 0;
00090             cSimpleChannel *chan = dynamic_cast<cSimpleChannel*>(outgate->channel());
00091             if (chan) delay = chan->delay();
00092 
00093             // write link entry into trace
00094             recordLinkEvent(peernamid, ie->datarate(), delay, "UP");
00095         }
00096     }
00097 }

virtual int NAMTraceWriter::numInitStages  )  const [inline, protected, virtual]
 

00049 {return 3;}

void NAMTraceWriter::receiveChangeNotification int  category,
cPolymorphic *  details
[protected, virtual]
 

Redefined INotifiable method. Called by NotificationBoard on changes.

Implements INotifiable.

00109 {
00110     // don't do anything if global NAMTrace module doesn't exist or does not have a file open
00111     if (!nt || !nt->enabled())
00112         return;
00113 
00114     // process notification
00115     if (category==NF_PP_TX_BEGIN || category==NF_PP_RX_END || category==NF_L2_Q_DROP)
00116     {
00117         TxNotifDetails *d = check_and_cast<TxNotifDetails *>(details);
00118         int peernamid = d->interfaceEntry()->peerNamId();
00119         cMessage *msg = d->message();
00120 
00121         switch(category)
00122         {
00123             case NF_PP_TX_BEGIN: recordPacketEvent('h', peernamid, msg); break;
00124             case NF_PP_RX_END:   recordPacketEvent('r', peernamid, msg); break;
00125             case NF_L2_Q_DROP:   recordPacketEvent('d', peernamid, msg); break;
00126         }
00127     }
00128     else
00129     {
00130         switch(category)
00131         {
00132             case NF_NODE_FAILURE: break; // TODO
00133             case NF_NODE_RECOVERY: break; // TODO
00134         }
00135     }
00136 }

void NAMTraceWriter::recordLinkEvent InterfaceEntry ie,
char *  state
[protected]
 

void NAMTraceWriter::recordLinkEvent int  peernamid,
double  datarate,
double  delay,
char *  state
[protected]
 

00151 {
00152     ASSERT(nt && nt->enabled());
00153     std::ostream& out = nt->out();
00154 
00155     // link entry (to be registered ON ONE END ONLY! This also means that
00156     // ns2 thinks that datarate and delay must be the same in both directions)
00157     if (namid < peernamid)
00158         out << "l -t * -s " << namid << " -d " << peernamid
00159             << " -S " << state << " -r " << (int)datarate << " -D " << delay << endl;
00160 
00161     // queue entry
00162     out << "q -t * -s " << namid << " -d " << peernamid << " -a 0 " << endl;
00163 }

void NAMTraceWriter::recordNodeEvent char *  state,
char *  shape
[protected]
 

00139 {
00140     ASSERT(nt && nt->enabled());
00141     std::ostream& out = nt->out();
00142     out << "n -t ";
00143     if (simTime() == 0.0)
00144         out << "*";
00145     else
00146         out << simTime();
00147     out << " -s " << namid << " -a " << namid << " -S " << state << " -v " << shape << endl;
00148 }

void NAMTraceWriter::recordPacketEvent const char  event,
int  peernamid,
cMessage *  msg
[protected]
 

00166 {
00167     ASSERT(nt && nt->enabled());
00168     std::ostream& out = nt->out();
00169 
00170     int size = msg->byteLength();
00171     int color = 0;
00172     for (cMessage *em = msg; em; em = em->encapsulatedMsg())
00173         if (em->hasPar("color"))
00174             {color = em->par("color").longValue(); break;}
00175 
00176     out << event << " -t " << simTime();
00177     if (event=='h')
00178         out << " -s " << namid << " -d " << peernamid;
00179     else
00180         out << " -s " << peernamid << " -d " << namid;
00181 
00182     out << " -e " << size << " -a " << color << endl;
00183 }


Member Data Documentation

int NAMTraceWriter::namid [protected]
 

NAMTrace* NAMTraceWriter::nt [protected]
 


The documentation for this class was generated from the following files:
Generated on Sat Apr 1 20:52:23 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.1