?? ospf_designated_router_election.c
字號:
/* ospf_designated_router_election.c - Executes the designated router election process *//* Copyright 1998 - 2002 Wind River Systems, Inc. *//*modification history-------------------- 18,30may03,htm Fix SPR 88272, memcmp was failing due to sizeof(OSPF_DESIGNATED_ROUTER_NODE) returns 16 bytes instead of 14 bytes (the actual size). 17,11january02,jkw Fix TSR 72091, neighbors not being added. 16,26september00,reshma Added WindRiver CopyRight 15,25september00,reshma RFC-1587 implementation for OSPF NSSA Option, also tested against ANVL. 14,07july00,reshma Unix compatibility related changes. 13,04april00,reshma Added some MIB support (Read only).Passed all important ANVL OSPF tests. 12,23december99,reshma Compatibility with VxWorks-IP and VxWorks RTM-interface 11,28december98,jack Compiled and added some comments 10,11november98,jack Config changes, linted and big endian changes 09,30october98,jack Incorporate changes for compilation on Vxworks 08,23august98,jack ANVL tested OSPF with PATRICIA tree route table and no recursion 07,10august98,jack PATRICIA Route Table Based OSPF Code Base 06,04june98,jack Integration with RTM and BGP 05,24april98,jack RTM changes 04,10july97,cindy Pre-release v1.52b 03,02october97,cindy Release Version 1.52 02,22october96,cindy Release Version 1.50 01,05june96,cindy First Beta Release*//*DESCRIPTIONospf_designated_router_election.c is used for selecting the designated and backup designated router.This file is used whenever OSPF comes up on a broadcast or NBMA network.*/#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)#include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ *//*******************************************************************************************************************************/static void ospf_calculate_backup_designated_router (OSPF_INTERFACE *sptr_interface);static void ospf_calculate_designated_router (OSPF_INTERFACE *sptr_interface);static void ospf_select_best_router (OSPF_DESIGNATED_ROUTER_NODE *sptr_candidate_1, OSPF_NEIGHBOR *sptr_candidate_2);static void ospf_check_if_dr_is_down_and_assign_bdr_as_dr (OSPF_INTERFACE *sptr_interface);/****************************************************************************************//* section 9.4 of OSPF specification *//**************************************************************************************** ospf_run_designated_router_election - calculates the designated router and backup designated router** This routine calculates the designated router and the backup designated router.* This routine determines the designated router by comparing the router's interface* priority, current designated router and backup designated router with its * neighbors and their current priority, designated router and backup designated router.** <sptr_interface> OSPF interface ** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ospf_run_designated_router_election (OSPF_INTERFACE *sptr_interface){ enum OSPF_INTERFACE_STATE old_state; OSPF_NEIGHBOR *sptr_neighbor = NULL; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_DESIGNATED_ROUTER_NODE old_designated_router; OSPF_DESIGNATED_ROUTER_NODE old_backup_designated_router; char print_buffer[PRINT_BUFFER_SIZE]; char print_buffer_1[PRINT_BUFFER_SIZE]; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_run_designated_router_election\r\n"); old_state = sptr_interface->state; memcpy ((void *) &old_designated_router, (const void *) &sptr_interface->designated_router, /* step (1) */ (size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE)); memcpy ((void *) &old_backup_designated_router, (const void *) &sptr_interface->backup_designated_router, (size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE)); ospf_check_if_dr_is_down_and_assign_bdr_as_dr (sptr_interface); ospf_calculate_backup_designated_router (sptr_interface); /* step (2) */ ospf_calculate_designated_router (sptr_interface); /* step (3) */ if (((old_designated_router.address != sptr_interface->designated_router.address) && /* step (4) - repeat steps (2) and (3) if necessary */ ((old_designated_router.id == ospf.router_id) || (sptr_interface->designated_router.id == ospf.router_id))) || ((old_backup_designated_router.address != sptr_interface->backup_designated_router.address) && ((old_backup_designated_router.id == ospf.router_id) || (sptr_interface->backup_designated_router.id == ospf.router_id)))) { ospf_calculate_backup_designated_router (sptr_interface); ospf_calculate_designated_router (sptr_interface); } /* * Step (4) may not be carried out always. It's only assurances that a router won't declare itself as DR as well as BDR * But a router can declared another router to be both. In that case Step (4) is may not be carried out * So if DR and BDR are one and the same make the BDR NULL */ /* SPR 88272 - begin */ /* memcmp is no longer needed since ospf_calculate_backup_designated_router() was modified to prevent ospf.router_id from being both DR & BDR. */ /*if ( memcmp ( (const void *) &(sptr_interface->designated_router), (const void *) &(sptr_interface->backup_designated_router), (size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE)) == (int) 0 ) { memset ( (void *) (&(sptr_interface->backup_designated_router)), 0x00, (size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE) ); }*/ /* SPR 88272 - end */ /* SPR 88272 - begin */ /* Put all comparisons between (), otherwise it might fail on diab */ if ((sptr_interface->designated_router.id) == (ospf.router_id)) /* step (5) */ { sptr_interface->state = OSPF_INTERFACE_DESIGNATED_ROUTER; /* this router is designated router */ } else if ((sptr_interface->backup_designated_router.id) == (ospf.router_id)) { sptr_interface->state = OSPF_INTERFACE_BACKUP_DESIGNATED_ROUTER; /* this router is backup designated router */ } else { sptr_interface->state = OSPF_INTERFACE_DESIGNATED_ROUTER_OTHER; /* this router is neither designated nor backup designated router */ } /* SPR 88272 - end */ /* Removed ospf_multicast_alldesignated_router () calls from here. Joined All-SPF group already - Reshma*/ if ((sptr_interface->type == OSPF_NBMA) && /* step (6) */ (((sptr_interface->state == OSPF_INTERFACE_DESIGNATED_ROUTER ) && (old_state != OSPF_INTERFACE_DESIGNATED_ROUTER )) || ((sptr_interface->state == OSPF_INTERFACE_BACKUP_DESIGNATED_ROUTER) && (old_state != OSPF_INTERFACE_BACKUP_DESIGNATED_ROUTER)))) { for (sptr_neighbor = sptr_interface->sptr_neighbor; sptr_neighbor != NULL; sptr_neighbor = sptr_next_neighbor) { sptr_next_neighbor = sptr_neighbor->sptr_forward_link; if ((sptr_neighbor->priority == 0x0000) && (sptr_neighbor->state < OSPF_NEIGHBOR_2_WAY)) { ospf_execute_neighbor_state_machine (OSPF_START, sptr_neighbor->state, sptr_interface, sptr_neighbor); } } } if ((sptr_interface->designated_router.address != old_designated_router.address) || /* step (7) */ (sptr_interface->backup_designated_router.address != old_backup_designated_router.address)) { for (sptr_neighbor = sptr_interface->sptr_neighbor; sptr_neighbor != NULL; sptr_neighbor = sptr_next_neighbor) { sptr_next_neighbor = sptr_neighbor->sptr_forward_link; if (sptr_neighbor->state >= OSPF_NEIGHBOR_2_WAY) { ospf_execute_neighbor_state_machine (OSPF_ADJACENCY_OK, sptr_neighbor->state, sptr_interface, sptr_neighbor); } } } if (sptr_interface->state == OSPF_INTERFACE_DESIGNATED_ROUTER) { OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Set build_network on interface with address (HEX)%lx to TRUE , DR Election\r\n",sptr_interface->address); sptr_interface->flags._bit.build_network = TRUE; } OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer, sptr_interface->designated_router.id); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer_1, sptr_interface->designated_router.address); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: elected designated router: Router ID = %s, IP interface address = %s\r\n", print_buffer, print_buffer_1); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer, sptr_interface->backup_designated_router.id); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer_1, sptr_interface->backup_designated_router.address); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: elected backup designated router: Router ID = %s, IP interface address = %s\r\n", print_buffer, print_buffer_1); return;}/**************************************************************************************** ospf_calculate_backup_designated_router - calculates the backup designated router** This routine calculates the the backup designated router. This routine checks if its* priority is not 0 and if any other router has declared itself as the backup designated* router. If the interface is eligible to become the backup designated router it will* check to see if the neighbor has declared itself to be the backup designated router.* It will then determine whether or not to become the backup designated router.** <sptr_interface> OSPF interface ** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/static void ospf_calculate_backup_designated_router (OSPF_INTERFACE *sptr_interface){ OSPF_NEIGHBOR *sptr_neighbor = NULL; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_DESIGNATED_ROUTER_NODE best_backup_designated_router; enum BOOLEAN found_a_declared_backup_designated_router; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_calculate_backup_designated_router\r\n"); best_backup_designated_router.address = 0x00000000L; /* SPR 88272 - begin */ /* If ospf.router_id is DR then it can't be BDR, rfc 2328 s9.4. */ if ((sptr_interface->priority == 0x0000) || (sptr_interface->designated_router.id == ospf.router_id)) /* SPR 88272 - end */ { memset ((void *) &best_backup_designated_router, 0x00, (size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE)); } else { best_backup_designated_router.id = ospf.router_id; best_backup_designated_router.address = sptr_interface->address; best_backup_designated_router.state = OSPF_NEIGHBOR_FULL; best_backup_designated_router.priority = sptr_interface->priority; } found_a_declared_backup_designated_router = FALSE; for (sptr_neighbor = sptr_interface->sptr_neighbor; sptr_neighbor != NULL; sptr_neighbor = sptr_next_neighbor) { sptr_next_neighbor = sptr_neighbor->sptr_forward_link; if (sptr_neighbor->state < OSPF_NEIGHBOR_2_WAY) { continue; /* skip this neighbor since it hasn't established bidirectional communication with this router */ } if (sptr_neighbor->priority == 0x0000) { continue; /* skip this neighbor since it is not eligible to become designated router */ } if ((sptr_neighbor->designated_router == sptr_neighbor->address)) { continue; /* skip this neighbor since it has declared itself to be the designated router */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -