124 RouterID routerID = intf->parentArea->getRouter()->getRouterID();
125 DesignatedRouterID currentDesignatedRouter = intf->designatedRouter;
126 DesignatedRouterID currentBackupRouter = intf->backupDesignatedRouter;
128 unsigned int neighborCount = intf->neighboringRouters.size();
129 unsigned char repeatCount = 0;
132 DesignatedRouterID declaredBackup;
133 unsigned char declaredBackupPriority;
137 DesignatedRouterID declaredDesignatedRouter;
138 unsigned char declaredDesignatedRouterPriority;
139 RouterID declaredDesignatedRouterID;
140 bool designatedRouterDeclared;
145 declaredBackupPriority = 0;
147 backupDeclared =
false;
150 unsigned char highestPriority = 0;
153 for (i = 0; i < neighborCount; i++) {
154 Neighbor *neighbor = intf->neighboringRouters[i];
155 unsigned char neighborPriority = neighbor->getPriority();
160 if (neighborPriority == 0) {
164 RouterID neighborID = neighbor->getNeighborID();
165 DesignatedRouterID neighborsDesignatedRouter = neighbor->getDesignatedRouter();
166 DesignatedRouterID neighborsBackupDesignatedRouter = neighbor->getBackupDesignatedRouter();
168 if (neighborsDesignatedRouter.routerID != neighborID) {
169 if (neighborsBackupDesignatedRouter.routerID == neighborID) {
170 if ((neighborPriority > declaredBackupPriority) ||
171 ((neighborPriority == declaredBackupPriority) &&
172 (neighborID > declaredBackupID)))
174 declaredBackup = neighborsBackupDesignatedRouter;
175 declaredBackupPriority = neighborPriority;
176 declaredBackupID = neighborID;
177 backupDeclared =
true;
180 if (!backupDeclared) {
181 if ((neighborPriority > highestPriority) ||
182 ((neighborPriority == highestPriority) &&
183 (neighborID > highestID)))
185 highestRouter.routerID = neighborID;
186 highestRouter.ipInterfaceAddress = neighbor->getAddress();
187 highestPriority = neighborPriority;
188 highestID = neighborID;
194 if (intf->routerPriority > 0) {
195 if (currentDesignatedRouter.routerID != routerID) {
196 if (currentBackupRouter.routerID == routerID) {
197 if ((intf->routerPriority > declaredBackupPriority) ||
198 ((intf->routerPriority == declaredBackupPriority) &&
199 (routerID > declaredBackupID)))
201 declaredBackup.routerID = routerID;
202 declaredBackup.ipInterfaceAddress = intf->interfaceAddressRange.address;
203 declaredBackupPriority = intf->routerPriority;
204 declaredBackupID = routerID;
205 backupDeclared =
true;
208 if (!backupDeclared) {
209 if ((intf->routerPriority > highestPriority) ||
210 ((intf->routerPriority == highestPriority) &&
211 (routerID > highestID)))
213 declaredBackup.routerID = routerID;
214 declaredBackup.ipInterfaceAddress = intf->interfaceAddressRange.address;
215 declaredBackupPriority = intf->routerPriority;
216 declaredBackupID = routerID;
217 backupDeclared =
true;
220 declaredBackup = highestRouter;
221 declaredBackupPriority = highestPriority;
222 declaredBackupID = highestID;
223 backupDeclared =
true;
231 declaredDesignatedRouterPriority = 0;
233 designatedRouterDeclared =
false;
235 for (i = 0; i < neighborCount; i++) {
236 Neighbor *neighbor = intf->neighboringRouters[i];
237 unsigned char neighborPriority = neighbor->getPriority();
242 if (neighborPriority == 0) {
246 RouterID neighborID = neighbor->getNeighborID();
247 DesignatedRouterID neighborsDesignatedRouter = neighbor->getDesignatedRouter();
248 DesignatedRouterID neighborsBackupDesignatedRouter = neighbor->getBackupDesignatedRouter();
250 if (neighborsDesignatedRouter.routerID == neighborID) {
251 if ((neighborPriority > declaredDesignatedRouterPriority) ||
252 ((neighborPriority == declaredDesignatedRouterPriority) &&
253 (neighborID > declaredDesignatedRouterID)))
255 declaredDesignatedRouter = neighborsDesignatedRouter;
256 declaredDesignatedRouterPriority = neighborPriority;
257 declaredDesignatedRouterID = neighborID;
258 designatedRouterDeclared =
true;
263 if (intf->routerPriority > 0) {
264 if (currentDesignatedRouter.routerID == routerID) {
265 if ((intf->routerPriority > declaredDesignatedRouterPriority) ||
266 ((intf->routerPriority == declaredDesignatedRouterPriority) &&
267 (routerID > declaredDesignatedRouterID)))
269 declaredDesignatedRouter.routerID = routerID;
270 declaredDesignatedRouter.ipInterfaceAddress = intf->interfaceAddressRange.address;
271 declaredDesignatedRouterPriority = intf->routerPriority;
272 declaredDesignatedRouterID = routerID;
273 designatedRouterDeclared =
true;
277 if (!designatedRouterDeclared) {
278 declaredDesignatedRouter = declaredBackup;
279 declaredDesignatedRouterPriority = declaredBackupPriority;
280 declaredDesignatedRouterID = declaredBackupID;
281 designatedRouterDeclared =
true;
289 (currentDesignatedRouter.routerID == routerID) &&
290 (declaredDesignatedRouter.routerID != routerID)
293 (currentDesignatedRouter.routerID != routerID) &&
294 (declaredDesignatedRouter.routerID == routerID)
300 (currentBackupRouter.routerID == routerID) &&
301 (declaredBackup.routerID != routerID)
304 (currentBackupRouter.routerID != routerID) &&
305 (declaredBackup.routerID == routerID)
310 currentDesignatedRouter = declaredDesignatedRouter;
311 currentBackupRouter = declaredBackup;
317 }
while (repeatCount < 2);
319 RouterID routersOldDesignatedRouterID = intf->designatedRouter.routerID;
320 RouterID routersOldBackupID = intf->backupDesignatedRouter.routerID;
322 intf->designatedRouter = declaredDesignatedRouter;
323 intf->backupDesignatedRouter = declaredBackup;
325 bool wasBackupDesignatedRouter = (routersOldBackupID == routerID);
326 bool wasDesignatedRouter = (routersOldDesignatedRouterID == routerID);
328 bool wasWaiting = (!wasBackupDesignatedRouter && !wasDesignatedRouter && !wasOther);
329 bool isBackupDesignatedRouter = (declaredBackup.routerID == routerID);
330 bool isDesignatedRouter = (declaredDesignatedRouter.routerID == routerID);
331 bool isOther = (!isBackupDesignatedRouter && !isDesignatedRouter);
333 if (wasBackupDesignatedRouter) {
334 if (isDesignatedRouter) {
335 changeState(intf,
new InterfaceStateDesignatedRouter,
this);
338 changeState(intf,
new InterfaceStateNotDesignatedRouter,
this);
341 if (wasDesignatedRouter) {
342 if (isBackupDesignatedRouter) {
346 changeState(intf,
new InterfaceStateNotDesignatedRouter,
this);
350 if (isDesignatedRouter) {
351 changeState(intf,
new InterfaceStateDesignatedRouter,
this);
353 if (isBackupDesignatedRouter) {
358 if (isDesignatedRouter) {
359 changeState(intf,
new InterfaceStateDesignatedRouter,
this);
361 if (isBackupDesignatedRouter) {
365 changeState(intf,
new InterfaceStateNotDesignatedRouter,
this);
369 for (i = 0; i < neighborCount; i++) {
371 ((!wasBackupDesignatedRouter && isBackupDesignatedRouter) ||
372 (!wasDesignatedRouter && isDesignatedRouter)))
374 if (intf->neighboringRouters[i]->getPriority() == 0) {
378 if ((declaredDesignatedRouter.routerID != routersOldDesignatedRouterID) ||
379 (declaredBackup.routerID != routersOldBackupID))
Definition: OSPFNeighbor.h:65
Definition: OSPFInterface.h:58
const DesignatedRouterID NULL_DESIGNATEDROUTERID
Definition: OSPFcommon.h:164
Definition: OSPFNeighbor.h:43
void changeState(Interface *intf, InterfaceState *newState, InterfaceState *currentState)
Definition: OSPFInterfaceState.cc:33
const RouterID NULL_ROUTERID(0, 0, 0, 0)
Definition: OSPFNeighbor.h:49
IPv4Address RouterID
Definition: OSPFcommon.h:137
Definition: OSPFInterface.h:68