#include <LinkMon.h>
Protected Member Functions | |
virtual void | initialize (int stage) |
virtual int | numInitStages () const |
virtual void | handleMessage (cMessage *msg) |
virtual void | report () |
Protected Attributes | |
double | pollInt |
Interval between polling for statistics. | |
double | reportInt |
The interval of sending report to the Topology Manager. | |
LinkTable | links |
All the monitored links. | |
FwTable * | fwt |
Pointer to the Forwarding Table of the Router. | |
TMInterface * | tm |
Pointer to the Topology Manager for sending messages. |
The Link Monitor application. Reports in random intervals to the Topology Manager information about the link status.
void LinkMon::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
This module is not supposed to receive any messages. It also deal with self messages for internal functions.
Reimplemented from cSimpleModule.
00119 { 00120 if (msg->isSelfMessage()) 00121 { 00122 //Self message to create or delete a new publication 00123 if(strcmp(msg->getFullName(),"LinkUpdate")==0) { 00124 00125 // For each link... update... 00126 for (unsigned int i=0; i<links.size(); i++){ 00127 // Finally do the job 00128 links[i].update(); 00129 } 00130 00131 //Reschedule message 00132 scheduleAt(simTime()+pollInt, msg); 00133 } 00134 else if(strcmp(msg->getFullName(),"LSReport")==0) { 00135 00136 //Report to the TM 00137 report(); 00138 00139 //Reschedule reporting 00140 scheduleAt(simTime()+reportInt, msg); 00141 } 00142 } 00143 }
void LinkMon::initialize | ( | int | stage | ) | [protected, virtual] |
Initialized the parameters of the class.
Reimplemented from cComponent.
00027 { 00028 if(stage==1) { 00029 reportInt=this->par("reportInt").doubleValue(); 00030 00031 //Access Interface and Forwarding Table 00032 fwt = FwTableAccess().get(); 00033 00034 //For all interface in Forwarding Table, initialize Link Table 00035 for (int i=0; i<fwt->getNumRoutes(); i++) { 00036 Link l; 00037 l.lid=fwt->getLID(i); 00038 00039 //l.cap = this->getParentModule()->getParentModule()->par("Datarate").doubleValue(); 00040 l.nettype = NT_ETH; 00041 00042 //Get Interface Name 00043 string name=fwt->getInterfaceName(i); 00044 00045 //Look for the position of the first number in the string 00046 size_t pos=name.find_first_of("0123456789"); 00047 00048 //If the interface has indeed an index number 00049 if(pos!=string::npos){ 00050 00051 //Create interface name 00052 stringstream fullname; 00053 fullname << name.substr(0,pos) << "[" << name.substr(pos,name.size()) << "]"; 00054 00055 // Find the gate according to the interface number and get the channel datarate! 00056 for (cModule::GateIterator i(this->getParentModule()); !i.end(); i++) { 00057 cGate *gate = i(); 00058 //If this is an output gate 00059 if( strcmp(cGate::getTypeName(gate->getType()),"output")==0 ) { 00060 //If the gate index is the same as the interface index 00061 if(atoi(name.substr(pos,name.size()).c_str()) == gate->getIndex()) { 00062 cDatarateChannel *mychannel = check_and_cast<cDatarateChannel *>(gate->getTransmissionChannel()); 00063 //Set the capacity in Mbps 00064 l.cap = mychannel->getDatarate()/pow(10,6); 00065 } 00066 } 00067 } 00068 00069 //Find correct interface 00070 cModule *m = findModuleWhereverInNode(fullname.str().c_str(), this->getParentModule()); 00071 00072 //Access the throughput meter and submodules of the network interface 00073 l.thr = check_and_cast<ThrPutMeter *>(m->getSubmodule("thruputMeter")); 00074 //If the is a problem with the throughput meter 00075 if(!l.thr) { 00076 ev << "Interface " << name << " of module " << this->getParentModule()->getFullName() << " doesn't have a throughput meter!" << endl; 00077 } 00078 00079 //Access the queue submodule of the network interface 00080 l.queue = check_and_cast<ReportDTQueue *>(m->getSubmodule("queue")); 00081 //If the is a problem with the throughput meter 00082 if(!l.queue) { 00083 ev << "Interface " << name << " of module " << this->getParentModule()->getFullName() << " doesn't have a readable queue!" << endl; 00084 } 00085 00086 //Access the forwarding entry of the network interface 00087 l.FwEntry = fwt->getFwRoute(l.lid); 00088 //If the is a problem with the throughput meter 00089 if(!l.FwEntry) { 00090 ev << "FwTable of module " << this->getParentModule()->getFullName() << " doesn't have the requested entry!" << endl; 00091 } 00092 00093 //Adding link to the link monitoring table 00094 links.push_back(l); 00095 } 00096 //Otherwise print an error 00097 else 00098 opp_error("Erroneous interface given to Link Monitor module as input."); 00099 } 00100 WATCH_VECTOR(links); 00101 00102 //Generate self message for updating the link status 00103 pollInt = par("pollInt").doubleValue(); 00104 cMessage *linkUpdate = new cMessage("LinkUpdate"); 00105 scheduleAt(simTime()+pollInt, linkUpdate); 00106 00107 //Generate self message for reporting to the TM 00108 reportInt = par("reportInt").doubleValue(); 00109 cMessage *linkReport = new cMessage("LSReport"); 00110 scheduleAt(simTime()+reportInt, linkReport); 00111 } 00112 if(stage==2) { 00113 //Set pointer to the topology manager module 00114 tm = check_and_cast<TMInterface *>(simulation.getModuleByPath("tm")); 00115 } 00116 }
virtual int LinkMon::numInitStages | ( | ) | const [inline, protected, virtual] |
void LinkMon::report | ( | ) | [protected, virtual] |
Reports the acquired QoS statistics from each link to the Topology Manager. It's being call by the handleMessage() function, whenever the correct self messages arives.
00146 { 00147 00148 //If there are no link to report, do nothing 00149 if (links.size()==0){ 00150 ev << "LinkMon: No Links on this router!!!" << endl; 00151 return; 00152 } 00153 00154 //Create report message 00155 LSMPacket *lsmPacket = new LSMPacket("LSMPacket"); 00156 00157 //Set data 00158 lsmPacket->setType(QoS_REPORT); 00159 lsmPacket->setNodeID(this->getParentModule()->getName()); 00160 00161 //Set the report length 00162 lsmPacket->setRepLen(links.size()); 00163 00164 //Fix the array sizes 00165 lsmPacket->setLinkStatusArraySize(links.size()); 00166 lsmPacket->setLidArraySize(links.size()); 00167 00168 // For each link append status and LID 00169 for (unsigned int i=0; i<links.size(); i++){ 00170 lsmPacket->setLid(i,links[i].lid.c_str()); 00171 lsmPacket->setLinkStatus(i,links[i].status); 00172 } 00173 00174 this->sendDirect(lsmPacket, tm, tm->findGate("TMin")); 00175 }
FwTable* LinkMon::fwt [protected] |
Pointer to the Forwarding Table of the Router.
LinkTable LinkMon::links [protected] |
All the monitored links.
double LinkMon::pollInt [protected] |
Interval between polling for statistics.
double LinkMon::reportInt [protected] |
The interval of sending report to the Topology Manager.
TMInterface* LinkMon::tm [protected] |
Pointer to the Topology Manager for sending messages.