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

📄 macbrspn.c

📁 以太网交换机协议平台stp协议的设计与实现源代码。
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * $Log:: /OEM Source Code/Spantree/macbrsp $
 * 
 * 1     12/04/98 2:36p Release Engineer
 * code cleanup, bug fixes, code style
 * changes, linted, system level test
 * STP v4.3.0
 * 
 * 1     2/06/96 11:06p Ross
 * Adding new version control
*/
/*	$Modname: macbrspn.c$  $version: 1.30$      $date: 03/31/95$   */
/*
* 	$lgb$
1.0 01/05/92 ross
1.1 01/25/92 ross
1.2 04/22/92 ross
1.3 07/30/92 ross
1.4 07/30/92 ross
1.5 07/30/92 ross
1.6 07/31/92 ross
1.7 08/05/92 ross
1.8 08/21/92 ross
1.9 08/22/92 ross Added support for multiple instances of stp_class
1.10 08/22/92 ross made as many functions as possible static
1.11 11/23/92 ross changed ETHERNET_ADDRESS to MAC_ADDRESS to appear more generic (cosmetic)
1.12 01/15/93 ross changed 1992 to 1993.
1.13 01/29/93 ross changed get_nvram port parameters to use port_number - 1.
1.14 01/29/93 ross fixed nvram problem with port parameters.
1.15 02/28/93 ross deleted reference to vlibstr.h
1.16 07/16/93 ross added some mib statistics
1.17 07/18/93 ross added check for token ring boolean in the initialize data structures routine.
1.18 07/18/93 ross fixed another occurance of token ring bug.
1.19 07/23/93 ross small modification to sptr_mac_address.
1.20 10/28/93 ross delete nvram header
1.21 10/28/93 ross delete end-of-file symbol.
1.22 01/13/94 ross added setting the filtering database aging time when a topology change occurs.  Courtesy of Helen.
1.23 02/02/94 ross took out frame relay header and fixed big endian problems.  Courtesy of Rick.
1.24 03/07/94 ross removed external references to mac_address, function used instead.
1.25 05/09/94 ross added changes for configuring forwarding state for SRT
1.26 06/15/94 ross cosmetic changes and snmp access routines.
1.27 07/21/94 ross fixed bug with topology change.  Courtesy of sanjeev.
1.28 07/29/94 ross record_port_infor... add 1 to root path cost.  Courtesy of Sanjeev.
1.29 08/25/94 ross Added an enum cast for some compiler warnings.
1.30 03/31/95 ross Changes for new rwutils library.
* 	$lge$
*/
/************************************************************************/
/*	Copyright (C) 1989-1998 RouterWare, Inc. 										*/
/*	Unpublished - rights reserved under the Copyright Laws of the			*/
/*	United States.  Use, duplication, or disclosure by the 					*/
/*	Government is subject to restrictions as set forth in 					*/
/*	subparagraph (c)(1)(ii) of the Rights in Technical Data and 			*/
/*	Computer Software clause at 252.227-7013.										*/
/*	RouterWare, Inc., 3961 MacArthur Blvd. Suite 212, Newport Beach Ca   */
/************************************************************************/
#include "macbridg.h"
/****************************************************************************/
static void setup_this_bridge_values (void);
static void initialize_mac_bridge_data_structures (USHORT port_number);
static void record_configuration_port_information (USHORT port_number,BRIDGE_CONFIGURATION_BPDU *sptr_bridge_configuration_BPDU);
static void record_hello_timeout_values (BRIDGE_CONFIGURATION_BPDU *sptr_bridge_configuration_BPDU);
static void reply (USHORT port_number);
static void root_selection (void);
static void designated_port_selection (void);
static void make_forwarding (USHORT port_number);
static void make_blocking (USHORT port_number);
static void topology_change_acknowledgement (void);
static void acknowledge_topology_change (USHORT port_number);
static enum BOOLEAN supercedes_port_info (USHORT port_number,BRIDGE_CONFIGURATION_BPDU *sptr_bridge_configuration_BPDU);
static enum BOOLEAN check_for_invalid_bpdu_parameters (BRIDGE_CONFIGURATION_BPDU *sptr_bridge_configuration_BPDU);/*AOS*/
static void set_stp_port_default_values (USHORT port_number);
/****************************************************************************/
void initialize_bridge_spanning_tree (void)
{
	BYTE	port_number;

	stp_printf (STP_ALGORITHM_PRINTF,"STP: initialize bridge \n\r");

	add_bridge_addresses_to_static_forwarding_table ();

	setup_this_bridge_values ();

	set_timer (&stp_class.topology_change_notification_timer,STOP_TIMER);
	set_timer (&stp_class.topology_change_timer,STOP_TIMER);

	for (port_number = 0x01; port_number <= stp_class.number_of_spanning_tree_ports ; port_number += (BYTE) 1)
		{
		initialize_port (port_number);

		initialize_mac_bridge_data_structures (port_number);
		}

	port_state_selection ();

	configuration_BPDU_generation ();

	set_timer (&stp_class.hello_timer,START_TIMER);
}
/****************************************************************************/
static void setup_this_bridge_values (void)
{
	stp_class.stp_algorithm_enabled = TRUE;

	stp_class.this_bridge.aging_time_for_fd = AGEING_TIME_FOR_FILTERING_DATABASE;

	lsl_control (GET_MAC_ADDRESS,0x0000,stp_class.stack_id,&stp_class.this_bridge.bridge_id.address);

	stp_class.this_bridge.bridge_id.priority = BRIDGE_PRIORITY;

	stp_class.this_bridge.bridge_max_age = MAXIMUM_AGE;
	stp_class.this_bridge.bridge_hello_time = HELLO_TIME;
	stp_class.this_bridge.bridge_forward_delay = FORWARD_DELAY_TIME;

	lsl_control (GET_MAC_ADDRESS,0x0000,stp_class.stack_id,&stp_class.this_bridge.root_id.address);

	stp_class.this_bridge.root_id.priority = BRIDGE_PRIORITY;

	stp_class.this_bridge.root_path_cost = 0x00000000L;

	stp_class.this_bridge.root_port_id.priority = PORT_PRIORITY;
	stp_class.this_bridge.root_port_id.number = 0x00;

	stp_class.this_bridge.max_age = stp_class.this_bridge.bridge_max_age; 
	stp_class.this_bridge.hello_time = stp_class.this_bridge.bridge_hello_time; 
	stp_class.this_bridge.forward_delay = stp_class.this_bridge.bridge_forward_delay; 

	stp_class.this_bridge.topology_change_detected = FALSE;
	stp_class.this_bridge.topology_change = FALSE;
	stp_class.this_bridge.topology_change_time = MAXIMUM_AGE + FORWARD_DELAY_TIME;

	stp_class.this_bridge.hold_time = HOLD_TIME;

/*	set_nvram_configuration (STP_THIS_BRIDGE_VALUES,&stp_class.this_bridge,NULL); */
}
/****************************************************************************/
void initialize_port (USHORT port_number)
{
/*	if (get_nvram_configuration (STP_PORT_VALUES,&stp_class.port[port_number],port_number - 1) == FALSE) */

	if (stp_class.port[port_number].path_cost == 0x0000)
		{
		stp_class.port[port_number].path_cost = ETHERNET_PATH_COST;
		}

	if (stp_class.port[port_number].message_age.value == 0x0000)
		{
		stp_class.port[port_number].message_age.value = MAXIMUM_AGE;
		}

	if (stp_class.port[port_number].hold_time.value == 0x0000)
		{
		stp_class.port[port_number].hold_time.value = HOLD_TIME;
		}

	if (stp_class.port[port_number].forward_delay.value == 0x0000)
		{
		stp_class.port[port_number].forward_delay.value = FORWARD_DELAY_TIME;
		}

	if (stp_class.port[port_number].port_id.priority == 0x0000)
		{
		stp_class.port[port_number].port_id.priority = PORT_PRIORITY;
		}

	set_stp_port_default_values (port_number); /* Set default values */

/*	stp_class.port[port_number].state = BLOCKING; */
	stp_class.port[port_number].topology_change_acknowledgement = FALSE;
	stp_class.port[port_number].configuration_pending = FALSE;
	stp_class.port[port_number].port_id.number = (BYTE) port_number;

/*	set_nvram_configuration (STP_PORT_VALUES,&stp_class.port[port_number],port_number - 1);
*/
	become_designated_port (port_number);

	set_timer (&stp_class.port[port_number].message_age,STOP_TIMER);
	set_timer (&stp_class.port[port_number].forward_delay,STOP_TIMER);
	set_timer (&stp_class.port[port_number].hold_time,STOP_TIMER);

   /* snmp parameters  */
   stp_class.port[port_number].dot1dBasePort = port_number;
   stp_class.port[port_number].dot1dBasePortIfIndex = port_number;

}
/****************************************************************************/
static void initialize_mac_bridge_data_structures (USHORT port_number)
{
	if (stp_class.port[port_number].token_ring == TRUE)
		{
		stp_class.bridge_configuration_BPDU[port_number].mac_header.destination_address = token_ring_bridge_group_address;
		}
	else
		{
		stp_class.bridge_configuration_BPDU[port_number].mac_header.destination_address = bridge_group_address;
		}

	lsl_control (GET_MAC_ADDRESS,port_number - 1,stp_class.stack_id,&stp_class.port[port_number].mac_address);

	stp_class.bridge_configuration_BPDU[port_number].mac_header.source_address = stp_class.port[port_number].mac_address;

	stp_class.bridge_configuration_BPDU[port_number].mac_header.length =
		swap (sizeof (BRIDGE_CONFIGURATION_BPDU) - sizeof (ETHERNET_HEADER));

	stp_class.bridge_configuration_BPDU[port_number].LLC_header.destination_address_DSAP =
		LSAP_BRIDGE_SPANNING_TREE_PROTOCOL;
	stp_class.bridge_configuration_BPDU[port_number].LLC_header.source_address_SSAP =
		LSAP_BRIDGE_SPANNING_TREE_PROTOCOL;
	stp_class.bridge_configuration_BPDU[port_number].LLC_header.llc_frame_type = (enum LLC_FRAME_TYPE) UNNUMBERED_INFORMATION;

	stp_class.bridge_configuration_BPDU[port_number].type = CONFIGURATION;
	stp_class.bridge_configuration_BPDU[port_number].protocol_version_ID = VERSION_ID;

	if (stp_class.port[port_number].token_ring == TRUE)
		convert_ethernet_header_to_token_ring ((ETHERNET_HEADER *) &stp_class.bridge_configuration_BPDU[port_number].mac_header);

	if (stp_class.port[port_number].token_ring == TRUE)
		{
		stp_class.bridge_topology_change_notification[port_number].mac_header.destination_address =
			token_ring_bridge_group_address;
		}
	else
		{
		stp_class.bridge_topology_change_notification[port_number].mac_header.destination_address =
			bridge_group_address;
		}

	lsl_control (GET_MAC_ADDRESS,port_number - 1,stp_class.stack_id,
		&stp_class.bridge_topology_change_notification[port_number].mac_header.source_address);

	stp_class.bridge_topology_change_notification[port_number].mac_header.length =
		swap (sizeof (BRIDGE_TOPOLOGY_CHANGE_NOTIFICATION) - sizeof (ETHERNET_HEADER));

	stp_class.bridge_topology_change_notification[port_number].LLC_header.destination_address_DSAP =
		LSAP_BRIDGE_SPANNING_TREE_PROTOCOL;

	stp_class.bridge_topology_change_notification[port_number].LLC_header.source_address_SSAP =
		LSAP_BRIDGE_SPANNING_TREE_PROTOCOL;

	stp_class.bridge_topology_change_notification[port_number].LLC_header.llc_frame_type = UNNUMBERED_INFORMATION;
	stp_class.bridge_topology_change_notification[port_number].type = (enum BPDU_TYPE) TOPOLOGY_CHANGE;
	stp_class.bridge_topology_change_notification[port_number].protocol_version_ID = VERSION_ID;

	if (stp_class.port[port_number].token_ring == TRUE)
		{
		convert_ethernet_header_to_token_ring ((ETHERNET_HEADER *) 
			&stp_class.bridge_topology_change_notification[port_number].mac_header);
		}
}
/****************************************************************************/
void transmit_configuration (USHORT port_number)
{
	if (stp_class.port[port_number].hold_time.active == START_TIMER)
		{
		stp_class.port[port_number].configuration_pending = TRUE;
		}
	else
		{
		stp_class.bridge_configuration_BPDU[port_number].root_id = stp_class.this_bridge.root_id;
		stp_class.bridge_configuration_BPDU[port_number].root_path_cost = stp_class.this_bridge.root_path_cost;
		stp_class.bridge_configuration_BPDU[port_number].bridge_id = stp_class.this_bridge.bridge_id;
		stp_class.bridge_configuration_BPDU[port_number].port_id =
			stp_class.port[port_number].port_id;

		if (root_bridge () == TRUE)
			{
			stp_class.bridge_configuration_BPDU[port_number].message_age = 0x0000;
			}
		else
			{
			stp_class.bridge_configuration_BPDU[port_number].message_age = (USHORT) 
				(stp_class.port[stp_class.this_bridge.root_port_id.number].message_age.value + MESSAGE_AGE_INCREMENT);
			}

		stp_class.bridge_configuration_BPDU[port_number].max_age = (USHORT) stp_class.this_bridge.max_age;
		stp_class.bridge_configuration_BPDU[port_number].hello_time = (USHORT) stp_class.this_bridge.hello_time;
		stp_class.bridge_configuration_BPDU[port_number].forward_delay = (USHORT) stp_class.this_bridge.forward_delay;

		stp_class.bridge_configuration_BPDU[port_number].flags.topology_change_acknowledgement =
			(BYTE) stp_class.port[port_number].topology_change_acknowledgement;

		stp_class.port[port_number].topology_change_acknowledgement = FALSE;

		stp_class.bridge_configuration_BPDU[port_number].flags.topology_change = (BYTE) stp_class.this_bridge.topology_change;

		send_mac_bridge_PDU (port_number,&stp_class.bridge_configuration_BPDU[port_number],sizeof (BRIDGE_CONFIGURATION_BPDU));

⌨️ 快捷键说明

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