⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospf_designated_router_election.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
			}		if (sptr_neighbor->backup_designated_router == sptr_neighbor->address)			{			/* neighbor has already declared itself to be backup designated router */			if (found_a_declared_backup_designated_router == FALSE)				{				best_backup_designated_router.id = sptr_neighbor->id;				best_backup_designated_router.address = sptr_neighbor->address;				best_backup_designated_router.state = sptr_neighbor->state;				best_backup_designated_router.priority = sptr_neighbor->priority;				found_a_declared_backup_designated_router = TRUE;				}			else				{				ospf_select_best_router (&best_backup_designated_router, sptr_neighbor);				}			}		else			{         /* neighbor has not declared itself to be backup designated router */			if (found_a_declared_backup_designated_router == TRUE)				{				continue;		/* can't compete, skip it */				}			else if (best_backup_designated_router.address == 0x00000000L)				{				best_backup_designated_router.id = sptr_neighbor->id;				best_backup_designated_router.address = sptr_neighbor->address;				best_backup_designated_router.state = sptr_neighbor->state;				best_backup_designated_router.priority = sptr_neighbor->priority;				}			else				{				ospf_select_best_router (&best_backup_designated_router, sptr_neighbor);				}			}		}	memcpy ((void *) &sptr_interface->backup_designated_router, (const void *) &best_backup_designated_router,		(size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE));	return;}/**************************************************************************************** ospf_calculate_designated_router - calculates the designated router** This routine calculates the the designated router.  This routine checks if its* priority is not 0 and if any other router has declared itself as the designated* router.  If the interface is eligible to become the designated router it will* check to see if the neighbor has declared itself to be the designated router.* It will then determine whether or not to become the designated router.** <sptr_interface> OSPF interface ** RETURNS: 	N/A** ERRNO: N/A** NOMANUAL*/static void ospf_calculate_designated_router (OSPF_INTERFACE *sptr_interface){	OSPF_NEIGHBOR *sptr_neighbor = NULL;	OSPF_NEIGHBOR *sptr_next_neighbor = NULL;	OSPF_DESIGNATED_ROUTER_NODE best_designated_router;	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_calculate_designated_router\r\n");	best_designated_router.address = 0x00000000L;	if ((sptr_interface->priority != 0x0000) &&		((sptr_interface->designated_router.id == ospf.router_id) && (sptr_interface->designated_router.address == sptr_interface->address)))		{		best_designated_router.id = ospf.router_id;		best_designated_router.address = sptr_interface->address;		best_designated_router.state = OSPF_NEIGHBOR_FULL;		best_designated_router.priority = sptr_interface->priority;		}	else		{		memset ((void *) &best_designated_router, 0x00, (size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE));		}	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))    {			/* neighbor has already declared itself to be designated router */			if (best_designated_router.address == 0x00000000L)				{				best_designated_router.id = sptr_neighbor->id;				best_designated_router.address = sptr_neighbor->address;				best_designated_router.state = sptr_neighbor->state;				best_designated_router.priority = sptr_neighbor->priority;				}			else				{				ospf_select_best_router (&best_designated_router, sptr_neighbor);				}			} 		else if (sptr_neighbor->designated_router == sptr_interface->address) /* someone else's timer expired before mine and declared me as DR, guess I am the right candidate */			{			best_designated_router.id = ospf.router_id;   					  /* #$-NOTE:note3-$#*/			best_designated_router.address = sptr_interface->address;			best_designated_router.state = OSPF_NEIGHBOR_FULL;			best_designated_router.priority = sptr_interface->priority;			}		else			{         /* neighbor has not declared itself to be designated router */			continue;			}		}	if (best_designated_router.address != 0x00000000L)		{		memcpy ((void *) &sptr_interface->designated_router, (const void *) &best_designated_router,			(size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE));		}	else if (sptr_interface->backup_designated_router.address != 0x00000000L)		{		/* assign the designated router to be the same as the newly elected backup designated router */		memcpy ((void *) &sptr_interface->designated_router, (const void *) &sptr_interface->backup_designated_router,			(size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE));		}	return;}/**************************************************************************************** ospf_select_best_router - selects the best router to become designated route or backup designated router** This routine calculates the the best designated router or backup designated router* between itself and its neighbor.  ** <sptr_candidate_1> Its own designated router or backup designated router** <sptr_candidate_2> Neighbors designated router or backup designated router** RETURNS: 	N/A** ERRNO: N/A** NOMANUAL*/static void ospf_select_best_router (OSPF_DESIGNATED_ROUTER_NODE *sptr_candidate_1, OSPF_NEIGHBOR *sptr_candidate_2){	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_select_best_router\r\n");	if (sptr_candidate_1->priority > sptr_candidate_2->priority)		{		return;		}	else if (sptr_candidate_2->priority > sptr_candidate_1->priority)	  	{		sptr_candidate_1->id = sptr_candidate_2->id;		sptr_candidate_1->address = sptr_candidate_2->address;		sptr_candidate_1->state = sptr_candidate_2->state;		sptr_candidate_1->priority = sptr_candidate_2->priority;		return;	  	}	else		{		if (sptr_candidate_1->id > sptr_candidate_2->id)			{			return;			}		else			{			sptr_candidate_1->id = sptr_candidate_2->id;			sptr_candidate_1->address = sptr_candidate_2->address;			sptr_candidate_1->state = sptr_candidate_2->state;			sptr_candidate_1->priority = sptr_candidate_2->priority;			return;			}		}}/**************************************************************************************** ospf_check_if_dr_is_down_and_assign_bdr_as_dr - assigns backup designated router to designated router** This routine checks to see if the designated router is down.  If it is then * assign the backup designated router to become the designated router.** <sptr_interface> OSPF interface ** RETURNS: 	N/A** ERRNO: N/A** NOMANUAL*/static void ospf_check_if_dr_is_down_and_assign_bdr_as_dr (OSPF_INTERFACE *sptr_interface){	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_check_if_dr_is_down_and_assign_bdr_as_dr\r\n");	/*	 * If the neighbor's address is same as that of the DRs, on neighbor down event, DR's state is set	 * in the function ospf_process_neighbor_down_event.	 */	if ( (sptr_interface->designated_router.address != 0x0) && (sptr_interface->designated_router.state == OSPF_NEIGHBOR_DOWN) )		{		/*		 * make the bdr the dr		 */		if ( (sptr_interface->backup_designated_router.address != 0x0) && (sptr_interface->backup_designated_router.state > OSPF_NEIGHBOR_DOWN) )			{			memcpy ( (void*) &sptr_interface->designated_router, (void*) &sptr_interface->backup_designated_router,				(size_t) sizeof (OSPF_DESIGNATED_ROUTER_NODE) );			}	  	}	return ;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -