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     printNotificationBanner(category, details);
00115 
00116     // process notification
00117     if (category==NF_PP_TX_BEGIN || category==NF_PP_RX_END || category==NF_L2_Q_DROP)
00118     {
00119         TxNotifDetails *d = check_and_cast<TxNotifDetails *>(details);
00120         int peernamid = d->interfaceEntry()->peerNamId();
00121         cMessage *msg = d->message();
00122 
00123         switch(category)
00124         {
00125             case NF_PP_TX_BEGIN: recordPacketEvent('h', peernamid, msg); break;
00126             case NF_PP_RX_END:   recordPacketEvent('r', peernamid, msg); break;
00127             case NF_L2_Q_DROP:   recordPacketEvent('d', peernamid, msg); break;
00128         }
00129     }
00130     else
00131     {
00132         switch(category)
00133         {
00134             case NF_NODE_FAILURE: break; // TODO
00135             case NF_NODE_RECOVERY: break; // TODO
00136         }
00137     }
00138 }

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

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

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

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

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

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

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


Member Data Documentation

int NAMTraceWriter::namid [protected]
 

NAMTrace* NAMTraceWriter::nt [protected]
 


The documentation for this class was generated from the following files:
Generated on Thu Oct 19 18:22:27 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.0