36 OSPFHelloPacket *helloPacket = check_and_cast<OSPFHelloPacket *>(packet);
37 bool shouldRebuildRoutingTable =
false;
45 if ((intf->getHelloInterval() == helloPacket->getHelloInterval()) &&
46 (intf->getRouterDeadInterval() == helloPacket->getRouterDeadInterval()))
55 (intf->getAddressRange().mask != helloPacket->getNetworkMask())
62 if (intf->getArea()->getExternalRoutingCapability() == helloPacket->getOptions().E_ExternalRoutingCapability) {
63 INetworkProtocolControlInfo *controlInfo = check_and_cast<INetworkProtocolControlInfo *>(helloPacket->getControlInfo());
64 IPv4Address srcAddress = controlInfo->getSourceAddress().toIPv4();
65 bool neighborChanged =
false;
66 bool neighborsDRStateChanged =
false;
67 bool drChanged =
false;
68 bool backupSeen =
false;
79 neighbor = intf->getNeighborByAddress(srcAddress);
85 neighbor = intf->getNeighborByID(helloPacket->getRouterID());
88 if (neighbor !=
nullptr) {
91 IPv4Address designatedAddress = neighbor->getDesignatedRouter().ipInterfaceAddress;
92 IPv4Address backupAddress = neighbor->getBackupDesignatedRouter().ipInterfaceAddress;
93 char newPriority = helloPacket->getRouterPriority();
94 IPv4Address source = controlInfo->getSourceAddress().toIPv4();
95 IPv4Address newDesignatedRouter = helloPacket->getDesignatedRouter();
96 IPv4Address newBackupRouter = helloPacket->getBackupDesignatedRouter();
97 DesignatedRouterID dRouterID;
102 neighbor->setPriority(helloPacket->getRouterPriority());
103 neighbor->setRouterDeadInterval(helloPacket->getRouterDeadInterval());
110 if (neighbor->getPriority() != newPriority) {
111 neighborChanged =
true;
121 if ((newDesignatedRouter == source) &&
134 if (((newDesignatedRouter == source) &&
135 (newDesignatedRouter != designatedAddress)) ||
136 ((newDesignatedRouter != source) &&
137 (source == designatedAddress)))
139 neighborChanged =
true;
140 neighborsDRStateChanged =
true;
150 if ((newBackupRouter == source) &&
162 if (((newBackupRouter == source) &&
163 (newBackupRouter != backupAddress)) ||
164 ((newBackupRouter != source) &&
165 (source == backupAddress)))
167 neighborChanged =
true;
171 neighbor->setNeighborID(helloPacket->getRouterID());
172 neighbor->setPriority(newPriority);
173 neighbor->setAddress(srcAddress);
174 dRouterID.routerID = newDesignatedRouter;
175 dRouterID.ipInterfaceAddress = newDesignatedRouter;
176 if (newDesignatedRouter != designatedAddress) {
177 designatedAddress = dRouterID.ipInterfaceAddress;
180 neighbor->setDesignatedRouter(dRouterID);
181 dRouterID.routerID = newBackupRouter;
182 dRouterID.ipInterfaceAddress = newBackupRouter;
183 if (newBackupRouter != backupAddress) {
184 backupAddress = dRouterID.ipInterfaceAddress;
187 neighbor->setBackupDesignatedRouter(dRouterID);
189 neighbor->setupDesignatedRouters(
false);
196 if (!neighbor->designatedRoutersAreSetUp()) {
197 Neighbor *designated = intf->getNeighborByAddress(designatedAddress);
198 Neighbor *backup = intf->getNeighborByAddress(backupAddress);
200 if (designated !=
nullptr) {
201 dRouterID.routerID = designated->getNeighborID();
202 dRouterID.ipInterfaceAddress = designated->getAddress();
203 neighbor->setDesignatedRouter(dRouterID);
205 if (backup !=
nullptr) {
206 dRouterID.routerID = backup->getNeighborID();
207 dRouterID.ipInterfaceAddress = backup->getAddress();
208 neighbor->setBackupDesignatedRouter(dRouterID);
210 if ((designated !=
nullptr) && (backup !=
nullptr)) {
211 neighbor->setupDesignatedRouters(
true);
216 DesignatedRouterID dRouterID;
217 bool designatedSetUp =
false;
218 bool backupSetUp =
false;
220 neighbor =
new Neighbor(helloPacket->getRouterID());
221 neighbor->setPriority(helloPacket->getRouterPriority());
222 neighbor->setAddress(srcAddress);
223 neighbor->setRouterDeadInterval(helloPacket->getRouterDeadInterval());
227 dRouterID.routerID = helloPacket->getDesignatedRouter();
228 dRouterID.ipInterfaceAddress = dRouterID.routerID;
230 Neighbor *designated = intf->getNeighborByAddress(dRouterID.ipInterfaceAddress);
233 if (designated !=
nullptr) {
234 if (designated->getNeighborID() != dRouterID.routerID) {
235 dRouterID.routerID = designated->getNeighborID();
237 designatedSetUp =
true;
239 neighbor->setDesignatedRouter(dRouterID);
241 dRouterID.routerID = helloPacket->getBackupDesignatedRouter();
242 dRouterID.ipInterfaceAddress = dRouterID.routerID;
244 Neighbor *backup = intf->getNeighborByAddress(dRouterID.ipInterfaceAddress);
247 if (backup !=
nullptr) {
248 if (backup->getNeighborID() != dRouterID.routerID) {
249 dRouterID.routerID = backup->getNeighborID();
253 neighbor->setBackupDesignatedRouter(dRouterID);
254 if (designatedSetUp && backupSetUp) {
255 neighbor->setupDesignatedRouters(
true);
257 intf->addNeighbor(neighbor);
262 (intf->getRouterPriority() == 0) &&
265 intf->sendHelloPacket(neighbor->getAddress());
268 IPv4Address interfaceAddress = intf->getAddressRange().address;
269 unsigned int neighborsNeighborCount = helloPacket->getNeighborArraySize();
275 for (i = 0; i < neighborsNeighborCount; i++) {
276 if (helloPacket->getNeighbor(i) == interfaceAddress) {
285 if (i == neighborsNeighborCount) {
289 if (neighborChanged) {
301 unsigned int neighborCount = intf->getNeighborCount();
302 for (i = 0; i < neighborCount; i++) {
303 Neighbor *stuckNeighbor = intf->getNeighbor(i);
309 if (neighborsDRStateChanged) {
312 if (routerLSA !=
nullptr) {
313 long sequenceNumber = routerLSA->getHeader().getLsSequenceNumber();
315 routerLSA->getHeader().setLsAge(
MAX_AGE);
316 intf->getArea()->floodLSA(routerLSA);
317 routerLSA->incrementInstallTime();
320 RouterLSA *newLSA = intf->getArea()->originateRouterLSA();
322 newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1);
323 shouldRebuildRoutingTable |= routerLSA->update(newLSA);
326 intf->getArea()->floodLSA(routerLSA);
339 if (shouldRebuildRoutingTable) {
Definition: OSPFNeighbor.h:64
Definition: OSPFNeighbor.h:65
void printEvent(const char *eventString, const Interface *onInterface=nullptr, const Neighbor *forNeighbor=nullptr) const
Definition: MessageHandler.cc:377
const IPv4Address NULL_IPV4ADDRESS(0, 0, 0, 0)
Definition: OSPFInterface.h:60
Definition: OSPFNeighbor.h:62
Definition: OSPFNeighbor.h:51
Definition: OSPFNeighbor.h:42
Definition: OSPFInterface.h:66
Router * router
Definition: IMessageHandler.h:35
Definition: OSPFInterface.h:47
Definition: OSPFInterface.h:48
Definition: OSPFNeighbor.h:44
Definition: OSPFInterface.h:56
RouterID getRouterID() const
Definition: OSPFRouter.h:72
Definition: OSPFInterface.h:58
#define MAX_SEQUENCE_NUMBER
Definition: OSPFcommon.h:43
Definition: OSPFInterface.h:57
Definition: OSPFInterface.h:59
#define MAX_AGE
Definition: OSPFcommon.h:36
Definition: OSPFNeighbor.h:49
MessageHandler * getMessageHandler()
Definition: OSPFRouter.h:77
OSPFInterfaceType
Definition: OSPFInterface.h:54
void rebuildRoutingTable()
Rebuilds the routing table from scratch(based on the LSA database).
Definition: OSPFRouter.cc:704