INET Framework for OMNeT++/OMNEST
inet::LinkStateRouting Class Reference

Implements a minimalistic link state routing protocol that employs flooding. More...

#include <LinkStateRouting.h>

Inheritance diagram for inet::LinkStateRouting:

Public Member Functions

 LinkStateRouting ()
 
virtual ~LinkStateRouting ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void processLINK_STATE_MESSAGE (LinkStateMsg *msg, IPv4Address sender)
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual void sendToPeers (const std::vector< TELinkStateInfo > &list, bool req, IPv4Address exceptPeer)
 
virtual void sendToPeer (IPv4Address peer, const std::vector< TELinkStateInfo > &list, bool req)
 
virtual void sendToIP (LinkStateMsg *msg, IPv4Address destAddr)
 

Protected Attributes

TEDtedmod = nullptr
 
cMessage * announceMsg = nullptr
 
IPv4Address routerId
 
IPAddressVector peerIfAddrs
 

Detailed Description

Implements a minimalistic link state routing protocol that employs flooding.

Flooding works like this:

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.

Constructor & Destructor Documentation

inet::LinkStateRouting::LinkStateRouting ( )
34 {
35 }
inet::LinkStateRouting::~LinkStateRouting ( )
virtual
38 {
39  cancelAndDelete(announceMsg);
40 }

Member Function Documentation

void inet::LinkStateRouting::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
76 {
77  if (msg == announceMsg) {
78  delete announceMsg;
79  announceMsg = nullptr;
80  sendToPeers(tedmod->ted, true, IPv4Address());
81  }
82  else if (!strcmp(msg->getArrivalGate()->getName(), "ipIn")) {
83  EV_INFO << "Processing message from IPv4: " << msg << endl;
84  IPv4ControlInfo *controlInfo = check_and_cast<IPv4ControlInfo *>(msg->getControlInfo());
85  IPv4Address sender = controlInfo->getSrcAddr();
86  processLINK_STATE_MESSAGE(check_and_cast<LinkStateMsg *>(msg), sender);
87  }
88  else
89  ASSERT(false);
90 }
TELinkStateInfoVector ted
The link state database.
Definition: TED.h:64
void inet::LinkStateRouting::initialize ( int  stage)
overrideprotectedvirtual
43 {
44  cSimpleModule::initialize(stage);
45 
46  if (stage == INITSTAGE_ROUTING_PROTOCOLS) {
47  tedmod = getModuleFromPar<TED>(par("tedModule"), this);
48 
49  IIPv4RoutingTable *rt = getModuleFromPar<IIPv4RoutingTable>(par("routingTableModule"), this);
50  routerId = rt->getRouterId();
51 
52  // listen for TED modifications
53  cModule *host = getContainingNode(this);
54  host->subscribe(NF_TED_CHANGED, this);
55 
56  // peers are given as interface names in the "peers" module parameter;
57  // store corresponding interface addresses in peerIfAddrs[]
58  cStringTokenizer tokenizer(par("peers"));
59  IInterfaceTable *ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
60  const char *token;
61  while ((token = tokenizer.nextToken()) != nullptr) {
62  ASSERT(ift->getInterfaceByName(token));
63  peerIfAddrs.push_back(ift->getInterfaceByName(token)->ipv4Data()->getIPAddress());
64  }
65 
66  // schedule start of flooding link state info
67  announceMsg = new cMessage("announce");
68  scheduleAt(simTime() + exponential(0.01), announceMsg);
69 
70  IPSocket socket(gate("ipOut"));
71  socket.registerProtocol(IP_PROT_OSPF);
72  }
73 }
Initialization of routing protocols.
Definition: InitStages.h:101
Definition: IPProtocolId_m.h:89
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
simsignal_t NF_TED_CHANGED
Definition: NotifierConsts.cc:55
virtual int inet::LinkStateRouting::numInitStages ( ) const
inlineoverrideprotectedvirtual
70 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::LinkStateRouting::processLINK_STATE_MESSAGE ( LinkStateMsg msg,
IPv4Address  sender 
)
protectedvirtual

Referenced by handleMessage().

120 {
121  EV_INFO << "received LINK_STATE message from " << sender << endl;
122 
123  TELinkStateInfoVector forward;
124 
125  unsigned int n = msg->getLinkInfoArraySize();
126 
127  bool change = false; // in topology
128 
129  // loop through every link in the message
130  for (unsigned int i = 0; i < n; i++) {
131  const TELinkStateInfo& link = msg->getLinkInfo(i);
132 
133  TELinkStateInfo *match;
134 
135  // process link if we haven't seen this already and timestamp is newer
136  if (tedmod->checkLinkValidity(link, match)) {
137  ASSERT(link.sourceId == link.advrouter.getInt());
138 
139  EV_INFO << "new information found" << endl;
140 
141  if (!match) {
142  // and we have no info on this link so far, store it as it is
143  tedmod->ted.push_back(link);
144  change = true;
145  }
146  else {
147  // copy over the information from it
148  if (match->state != link.state) {
149  match->state = link.state;
150  change = true;
151  }
152  match->messageId = link.messageId;
153  match->sourceId = link.sourceId;
154  match->timestamp = link.timestamp;
155  for (int i = 0; i < 8; i++)
156  match->UnResvBandwidth[i] = link.UnResvBandwidth[i];
157  match->MaxBandwidth = link.MaxBandwidth;
158  match->metric = link.metric;
159  }
160 
161  forward.push_back(link);
162  }
163  }
164 
165  if (change)
167 
168  if (msg->getRequest()) {
169  sendToPeer(sender, tedmod->ted, false);
170  }
171 
172  if (forward.size() > 0) {
173  sendToPeers(forward, false, sender);
174  }
175 
176  delete msg;
177 }
virtual void rebuildRoutingTable()
Definition: TED.cc:230
virtual bool checkLinkValidity(TELinkStateInfo link, TELinkStateInfo *&match)
Definition: TED.cc:400
std::vector< struct TELinkStateInfo > TELinkStateInfoVector
Definition: TED_m.h:40
TELinkStateInfoVector ted
The link state database.
Definition: TED.h:64
void inet::LinkStateRouting::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual
93 {
94  Enter_Method_Silent();
95  printNotificationBanner(signalID, obj);
96 
97  ASSERT(signalID == NF_TED_CHANGED);
98 
99  EV_INFO << "TED changed\n";
100 
101  const TEDChangeInfo *d = check_and_cast<const TEDChangeInfo *>(obj);
102 
103  unsigned int k = d->getTedLinkIndicesArraySize();
104 
105  ASSERT(k > 0);
106 
107  // build linkinfo list
108  std::vector<TELinkStateInfo> links;
109  for (unsigned int i = 0; i < k; i++) {
110  unsigned int index = d->getTedLinkIndices(i);
111 
112  tedmod->updateTimestamp(&tedmod->ted[index]);
113  links.push_back(tedmod->ted[index]);
114  }
115 
116  sendToPeers(links, false, IPv4Address());
117 }
virtual void updateTimestamp(TELinkStateInfo *link)
Definition: TED.cc:458
simsignal_t NF_TED_CHANGED
Definition: NotifierConsts.cc:55
void printNotificationBanner(simsignal_t signalID, const cObject *obj)
Utility function.
Definition: NotifierConsts.cc:109
TELinkStateInfoVector ted
The link state database.
Definition: TED.h:64
const double k
Definition: QAM16Modulation.cc:24
void inet::LinkStateRouting::sendToIP ( LinkStateMsg msg,
IPv4Address  destAddr 
)
protectedvirtual

Referenced by sendToPeer().

218 {
219  // attach control info to packet
220  IPv4ControlInfo *controlInfo = new IPv4ControlInfo();
221  controlInfo->setDestAddr(destAddr);
222  controlInfo->setSrcAddr(routerId);
223  controlInfo->setProtocol(IP_PROT_OSPF);
224  msg->setControlInfo(controlInfo);
225 
226  int length = msg->getLinkInfoArraySize() * 72;
227  msg->setByteLength(length);
228 
229  msg->addPar("color") = TED_TRAFFIC;
230 
231  send(msg, "ipOut");
232 }
Definition: IPProtocolId_m.h:89
void inet::LinkStateRouting::sendToPeer ( IPv4Address  peer,
const std::vector< TELinkStateInfo > &  list,
bool  req 
)
protectedvirtual

Referenced by processLINK_STATE_MESSAGE(), and sendToPeers().

203 {
204  EV_INFO << "sending LINK_STATE message to " << peer << endl;
205 
206  LinkStateMsg *out = new LinkStateMsg("link state");
207 
208  out->setLinkInfoArraySize(list.size());
209  for (unsigned int j = 0; j < list.size(); j++)
210  out->setLinkInfo(j, list[j]);
211 
212  out->setRequest(req);
213 
214  sendToIP(out, peer);
215 }
void inet::LinkStateRouting::sendToPeers ( const std::vector< TELinkStateInfo > &  list,
bool  req,
IPv4Address  exceptPeer 
)
protectedvirtual

Referenced by handleMessage(), processLINK_STATE_MESSAGE(), and receiveSignal().

180 {
181  EV_INFO << "sending LINK_STATE message to peers" << endl;
182 
183  // send "list" to every peer (linkid in our ted[] entries???) in a LinkStateMsg
184  for (auto & elem : tedmod->ted) {
185  if (elem.advrouter != routerId)
186  continue;
187 
188  if (elem.linkid == exceptPeer)
189  continue;
190 
191  if (!elem.state)
192  continue;
193 
194  if (find(peerIfAddrs.begin(), peerIfAddrs.end(), elem.local) == peerIfAddrs.end())
195  continue;
196 
197  // send a copy
198  sendToPeer(elem.linkid, list, req);
199  }
200 }
TELinkStateInfoVector ted
The link state database.
Definition: TED.h:64
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48

Member Data Documentation

cMessage* inet::LinkStateRouting::announceMsg = nullptr
protected
IPAddressVector inet::LinkStateRouting::peerIfAddrs
protected

Referenced by initialize(), and sendToPeers().

IPv4Address inet::LinkStateRouting::routerId
protected

Referenced by initialize(), sendToIP(), and sendToPeers().

TED* inet::LinkStateRouting::tedmod = nullptr
protected

The documentation for this class was generated from the following files: