#include <LinkStateRouting.h>
Inheritance diagram for LinkStateRouting:
When a router receives a link state packet, it merges the packet contents into its own link state database (ted). If the packet contained new information (ted got updated), the router broadcasts the ted contents to all its other neighbours; otherwise (when the packet didn't contain any new info), nothing happens.
Also: when the announceMsg timer expires, LinkStateRouting sends out an initial link state message. (Currently this happens only once, at the beginning of the simulation). The "request" bit in the message is set then, asking neighbours to send back their link state databases. (FIXME why's this? redundant messaging: same msg is often sent twice: both as reply and as voluntary "announce").
TODO discover peers by "hello". Peers are those from which the router has received a Hello in the last X seconds. Link info to all peers are maintained; links to ex-peers (those haven't heard of for more than X seconds) are assumed to be down.
See NED file for more info.
Public Member Functions | |
LinkStateRouting () | |
virtual | ~LinkStateRouting () |
Protected Member Functions | |
virtual void | initialize (int stage) |
virtual int | numInitStages () const |
virtual void | handleMessage (cMessage *msg) |
void | processLINK_STATE_MESSAGE (LinkStateMsg *msg, IPAddress sender) |
virtual void | receiveChangeNotification (int category, cPolymorphic *details) |
void | sendToPeers (const std::vector< TELinkStateInfo > &list, bool req, IPAddress exceptPeer) |
void | sendToPeer (IPAddress peer, const std::vector< TELinkStateInfo > &list, bool req) |
void | sendToIP (LinkStateMsg *msg, IPAddress destAddr) |
Protected Attributes | |
TED * | tedmod |
cMessage * | announceMsg |
IPAddress | routerId |
IPAddressVector | peerIfAddrs |
|
00031 { 00032 announceMsg = NULL; 00033 }
|
|
00036 { 00037 cancelAndDelete(announceMsg); 00038 }
|
|
00072 { 00073 if (msg == announceMsg) 00074 { 00075 delete announceMsg; 00076 announceMsg = NULL; 00077 sendToPeers(tedmod->ted, true, IPAddress()); 00078 } 00079 else if (!strcmp(msg->arrivalGate()->name(), "from_ip")) 00080 { 00081 EV << "Processing message from IP: " << msg << endl; 00082 IPControlInfo *controlInfo = check_and_cast<IPControlInfo *>(msg->controlInfo()); 00083 IPAddress sender = controlInfo->srcAddr(); 00084 processLINK_STATE_MESSAGE(check_and_cast<LinkStateMsg*>(msg), sender); 00085 } 00086 else 00087 ASSERT(false); 00088 }
|
|
00041 { 00042 // we have to wait until routerId gets assigned in stage 3 00043 if (stage==4) 00044 { 00045 tedmod = TEDAccess().get(); 00046 00047 RoutingTable *rt = RoutingTableAccess().get(); 00048 routerId = rt->routerId(); 00049 00050 // listen for TED modifications 00051 NotificationBoard *nb = NotificationBoardAccess().get(); 00052 nb->subscribe(this, NF_TED_CHANGED); 00053 00054 // peers are given as interface names in the "peers" module parameter; 00055 // store corresponding interface addresses in peerIfAddrs[] 00056 cStringTokenizer tokenizer(par("peers")); 00057 InterfaceTable *ift = InterfaceTableAccess().get(); 00058 const char *token; 00059 while ((token = tokenizer.nextToken())!=NULL) 00060 { 00061 ASSERT(ift->interfaceByName(token)); 00062 peerIfAddrs.push_back(ift->interfaceByName(token)->ipv4()->inetAddress()); 00063 } 00064 00065 // schedule start of flooding link state info 00066 announceMsg = new cMessage("announce"); 00067 scheduleAt(simTime() + exponential(0.01), announceMsg); 00068 } 00069 }
|
|
00071 {return 5;}
|
|
00118 { 00119 EV << "received LINK_STATE message from " << sender << endl; 00120 00121 TELinkStateInfoVector forward; 00122 00123 unsigned int n = msg->getLinkInfoArraySize(); 00124 00125 bool change = false; // in topology 00126 00127 // loop through every link in the message 00128 for (unsigned int i = 0; i < n; i++) 00129 { 00130 const TELinkStateInfo& link = msg->getLinkInfo(i); 00131 00132 TELinkStateInfo *match; 00133 00134 // process link if we haven't seen this already and timestamp is newer 00135 if(tedmod->checkLinkValidity(link, match)) 00136 { 00137 ASSERT(link.sourceId == link.advrouter.getInt()); 00138 00139 EV << "new information found" << endl; 00140 00141 if(!match) 00142 { 00143 // and we have no info on this link so far, store it as it is 00144 tedmod->ted.push_back(link); 00145 change = true; 00146 } 00147 else 00148 { 00149 // copy over the information from it 00150 if(match->state != link.state) 00151 { 00152 match->state = link.state; 00153 change = true; 00154 } 00155 match->messageId = link.messageId; 00156 match->sourceId = link.sourceId; 00157 match->timestamp = link.timestamp; 00158 for(int i = 0; i < 8; i++) 00159 match->UnResvBandwidth[i] = link.UnResvBandwidth[i]; 00160 match->MaxBandwidth = link.MaxBandwidth; 00161 match->metric = link.metric; 00162 } 00163 00164 forward.push_back(link); 00165 } 00166 } 00167 00168 if(change) 00169 tedmod->rebuildRoutingTable(); 00170 00171 if(msg->getRequest()) 00172 { 00173 sendToPeer(sender, tedmod->ted, false); 00174 } 00175 00176 if(forward.size() > 0) 00177 { 00178 sendToPeers(forward, false, sender); 00179 } 00180 00181 delete msg; 00182 }
|
|
Called by the NotificationBoard whenever a change of a category occurs to which this client has subscribed. Implements INotifiable. 00091 { 00092 Enter_Method_Silent(); 00093 00094 ASSERT(category == NF_TED_CHANGED); 00095 00096 EV << "received NF_TED_CHANGED notification\n" << endl; 00097 00098 TEDChangeInfo *d = check_and_cast<TEDChangeInfo *>(details); 00099 00100 unsigned int k = d->getTedLinkIndicesArraySize(); 00101 00102 ASSERT(k > 0); 00103 00104 // build linkinfo list 00105 std::vector<TELinkStateInfo> links; 00106 for (unsigned int i = 0; i < k; i++) 00107 { 00108 unsigned int index = d->getTedLinkIndices(i); 00109 00110 tedmod->updateTimestamp(&tedmod->ted[index]); 00111 links.push_back(tedmod->ted[index]); 00112 } 00113 00114 sendToPeers(links, false, IPAddress()); 00115 }
|
|
00224 { 00225 // attach control info to packet 00226 IPControlInfo *controlInfo = new IPControlInfo(); 00227 controlInfo->setDestAddr(destAddr); 00228 controlInfo->setSrcAddr(routerId); 00229 controlInfo->setProtocol(IP_PROT_OSPF); 00230 msg->setControlInfo(controlInfo); 00231 00232 int length = msg->getLinkInfoArraySize() * 72; 00233 msg->setByteLength(length); 00234 00235 msg->addPar("color") = TED_TRAFFIC; 00236 00237 send(msg, "to_ip"); 00238 }
|
|
00209 { 00210 EV << "sending LINK_STATE message to " << peer << endl; 00211 00212 LinkStateMsg *out = new LinkStateMsg("link state"); 00213 00214 out->setLinkInfoArraySize(list.size()); 00215 for (unsigned int j = 0; j < list.size(); j++) 00216 out->setLinkInfo(j, list[j]); 00217 00218 out->setRequest(req); 00219 00220 sendToIP(out, peer); 00221 }
|
|
00185 { 00186 EV << "sending LINK_STATE message to peers" << endl; 00187 00188 // send "list" to every peer (linkid in our ted[] entries???) in a LinkStateMsg 00189 for (unsigned int i = 0; i < tedmod->ted.size(); i++) 00190 { 00191 if(tedmod->ted[i].advrouter != routerId) 00192 continue; 00193 00194 if(tedmod->ted[i].linkid == exceptPeer) 00195 continue; 00196 00197 if(!tedmod->ted[i].state) 00198 continue; 00199 00200 if(find(peerIfAddrs.begin(), peerIfAddrs.end(), tedmod->ted[i].local) == peerIfAddrs.end()) 00201 continue; 00202 00203 // send a copy 00204 sendToPeer(tedmod->ted[i].linkid, list, req); 00205 } 00206 }
|
|
|
|
|
|
|
|
|