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

📄 aodv_route_table.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/* aodv_route_table.ex.c *//* C file for AODV Route Table APIs *//****************************************//*		Copyright (c) 1987-2005			*//*		by OPNET Technologies, Inc.		*//*		(A Delaware Corporation)		*//*	7255 Woodmont Av., Suite 250  		*//*     Bethesda, MD 20814, U.S.A.       *//*			All Rights Reserved.		*//****************************************//***** Includes *****/#include <opnet.h>#include <stdarg.h>#include <aodv.h>#include <aodv_pkt_support.h>#include <aodv_ptypes.h>#include <ip_addr_v4.h>#include <ip_cmn_rte_table.h>/***** Prototypes *****/static AodvT_Route_Entry*		aodv_route_table_entry_mem_alloc (void);static void						aodv_route_table_entry_mem_free (AodvT_Route_Entry*);extern void						aodv_rte_entry_expiry_handle (void*, int);AodvT_Route_Table*aodv_route_table_create (IpT_Cmn_Rte_Table* cmn_rte_table_ptr, IpT_Rte_Proc_Id proto_id, double expiry_time, 							double delete_period, AodvT_Local_Stathandles* local_stat_ptr)	{	AodvT_Route_Table*		route_table_ptr;		/** Creates and allocates memory for	**/	/** the AODV route table				**/	FIN (aodv_route_table_create (void));		route_table_ptr = (AodvT_Route_Table*) op_prg_mem_alloc (sizeof (AodvT_Route_Table));	route_table_ptr->route_table = (PrgT_String_Hash_Table*) prg_string_hash_table_create (100, 15);	route_table_ptr->ip_cmn_rte_table_ptr = cmn_rte_table_ptr;	route_table_ptr->aodv_protocol_id = proto_id;	route_table_ptr->route_expiry_time = expiry_time;	route_table_ptr->delete_period = delete_period;	route_table_ptr->stat_handles_ptr = local_stat_ptr;	route_table_ptr->current_size = 0;		FRET (route_table_ptr);	}voidaodv_route_table_entry_create (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, InetT_Subnet_Mask subnet_mask,	InetT_Address next_hop_addr, IpT_Port_Info out_port_info, int num_hops, int dest_seq_num, double expiry_time)	{	AodvT_Route_Entry*			route_entry_ptr;	AodvT_Global_Stathandles*	global_stathandle_ptr;	char						dest_addr_str [INETC_ADDR_STR_LEN];	void*						old_contents_ptr;	InetT_Address*				dest_addr_ptr;		/** Adds a new route table entry	**/	/** in the route table				**/	FIN (aodv_route_table_entry_create (<args>));	/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);	dest_addr_ptr = inet_address_create_dynamic (dest_addr);		/* Allocate memory for the route entry	*/	route_entry_ptr = aodv_route_table_entry_mem_alloc ();	route_entry_ptr->dest_prefix = ip_cmn_rte_table_dest_prefix_create (dest_addr, subnet_mask);	route_entry_ptr->dest_seq_num = dest_seq_num;		if (dest_seq_num != AODVC_DEST_SEQ_NUM_INVALID)		route_entry_ptr->valid_dest_sequence_number_flag = OPC_TRUE;	else		route_entry_ptr->valid_dest_sequence_number_flag = OPC_FALSE;		route_entry_ptr->route_entry_state = AodvC_Valid_Route;	route_entry_ptr->next_hop_addr = inet_address_copy (next_hop_addr);	route_entry_ptr->next_hop_port_info = out_port_info;	route_entry_ptr->hop_count = num_hops;	route_entry_ptr->route_expiry_time = op_sim_time () + expiry_time;		/* Installing event state */	/* This event will be processed by aodv_rte_entry_expiry_handle */	/* function when the timer expires.								*/	op_ev_state_install (dest_addr_ptr, OPC_NIL);	route_entry_ptr->route_expiry_evhandle = op_intrpt_schedule_call(route_entry_ptr->route_expiry_time,		AODVC_ROUTE_ENTRY_INVALID,	aodv_rte_entry_expiry_handle, dest_addr_ptr);	op_ev_state_install (OPC_NIL, OPC_NIL);		/* Set the route entry for this destination	*/	/* in the route table						*/	prg_string_hash_table_item_insert (route_table_ptr->route_table, dest_addr_str, route_entry_ptr, &old_contents_ptr);		/* Insert the route in the IP common route table	*/	Inet_Cmn_Rte_Table_Entry_Add_Options (route_table_ptr->ip_cmn_rte_table_ptr, OPC_NIL, route_entry_ptr->dest_prefix, 		route_entry_ptr->next_hop_addr, route_entry_ptr->next_hop_port_info, route_entry_ptr->hop_count, 		route_table_ptr->aodv_protocol_id, 1, IPC_CMN_RTE_TABLE_ENTRY_ADD_INDIRECT_NEXTHOP_OPTION);		/* Update the size of the route table	*/	route_table_ptr->current_size++;	/* Update the route table size statistic	*/	op_stat_write (route_table_ptr->stat_handles_ptr->route_table_size_shandle, route_table_ptr->current_size);		/* Update the statistic for the number of hops	*/	op_stat_write (route_table_ptr->stat_handles_ptr->num_hops_shandle, route_entry_ptr->hop_count);			/* Get a handle to the global statistics	*/	global_stathandle_ptr = aodv_support_global_stat_handles_obtain ();		/* Update the global statistic for the number of hops	*/	op_stat_write (global_stathandle_ptr->num_hops_global_shandle, route_entry_ptr->hop_count);	FOUT;	}AodvT_Route_Entry*aodv_route_table_entry_get (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];			/** Determines whether an entry exists	**/	/** in the route table for a destination**/	FIN (aodv_route_table_entry_get (<args>));		/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);				/* Get the entry for this destination	*/	route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, dest_addr_str);		if(route_entry_ptr == OPC_NIL)		{		FRET (OPC_NIL);		}	else		{		FRET(route_entry_ptr);		}	}Compcodeaodv_route_table_entry_param_get (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, int param, void* value_ptr)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];	int*						int_value_ptr;	double*						dbl_value_ptr;	Boolean*					bool_value_ptr;	AodvC_Route_Entry_State*	route_state_ptr;	InetT_Address*				ip_addr_ptr;	List**						list_pptr;	IpT_Port_Info*				port_info_ptr;		/** Access any field in the route table entry	**/	FIN (aodv_route_table_entry_param_get (<args>));		/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);		/* Get the entry for this destination	*/	route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, dest_addr_str);		if (route_entry_ptr == OPC_NIL)		{				FRET (OPC_COMPCODE_FAILURE);		}		/* Based on the input parameter, return	*/	/* the appropriate parameter			*/	switch (param)		{		case (AODVC_ROUTE_ENTRY_DEST_SEQ_NUM):			{			int_value_ptr = (int*) value_ptr;			*int_value_ptr = route_entry_ptr->dest_seq_num;			break;			}					case (AODVC_ROUTE_ENTRY_VALID_SEQ_NUM_FLAG):			{			bool_value_ptr = (Boolean*) value_ptr;			*bool_value_ptr = route_entry_ptr->valid_dest_sequence_number_flag;			break;			}					case (AODVC_ROUTE_ENTRY_ROUTE_ENTRY_STATE):			{			route_state_ptr = (AodvC_Route_Entry_State*) value_ptr;			*route_state_ptr = route_entry_ptr->route_entry_state;			break;			}					case (AODVC_ROUTE_ENTRY_NEXT_HOP_ADDR):			{			ip_addr_ptr = (InetT_Address*) value_ptr;			*ip_addr_ptr = route_entry_ptr->next_hop_addr;			break;			}					case (AODVC_ROUTE_ENTRY_OUT_PORT_INFO):			{			port_info_ptr = (IpT_Port_Info*) value_ptr;			*port_info_ptr = route_entry_ptr->next_hop_port_info;			break;			}		   		case (AODVC_ROUTE_ENTRY_HOP_COUNT):			{			int_value_ptr = (int*) value_ptr;			*int_value_ptr = route_entry_ptr->hop_count;			break;			}					case (AODVC_ROUTE_ENTRY_PRECURSOR_LIST):			{			list_pptr = (List**) value_ptr;			*list_pptr = route_entry_ptr->precursor_lptr;			break;			}					case (AODVC_ROUTE_ENTRY_EXPIRY_TIME):			{			dbl_value_ptr = (double*) value_ptr;			*dbl_value_ptr = route_entry_ptr->route_expiry_time;			break;			}				default :			{			/* Unknown input parameter	*/			FRET (OPC_COMPCODE_FAILURE);			}		}			FRET (OPC_COMPCODE_SUCCESS);	}			Compcodeaodv_route_table_entry_param_set (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, int param, ...)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];	va_list						arg_list;		/** Set the fields of the route table entry	**/	FIN (aodv_route_table_entry_param_set (<args>));		/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);		/* Get the entry for this destination	*/	route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, dest_addr_str);		if (route_entry_ptr == OPC_NIL)		FRET (OPC_COMPCODE_FAILURE);		/* Initialize the list of arguments. Though a list arguments may	*/    /* not always be passed this approach will help us identify the		*/    /* data type of the parameters and appropriately cast it.			*/    va_start (arg_list, param);		/* Based on the input parameter, set	*/	/* the appropriate parameter			*/	switch (param)		{		case (AODVC_ROUTE_ENTRY_DEST_SEQ_NUM):			{			route_entry_ptr->dest_seq_num = va_arg (arg_list, int);			break;			}					case (AODVC_ROUTE_ENTRY_VALID_SEQ_NUM_FLAG):			{			route_entry_ptr->valid_dest_sequence_number_flag = va_arg (arg_list, Boolean);			break;			}					default :			{			/* Unknown input parameter	*/			FRET (OPC_COMPCODE_FAILURE);			}		}		FRET (OPC_COMPCODE_SUCCESS);	}Compcodeaodv_route_table_precursor_add (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, 								InetT_Address precursor_addr)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];	InetT_Address*				precursor_addr_ptr;	InetT_Address*				pre_addr_ptr;	InetT_Address				existing_precursor_addr;	int 						num, size;	Boolean						FOUND;		/** Adds a percursor node to the entry in	**/	/** the route table for a destination		**/	FIN (aodv_route_table_precursor_add (<args>));		/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);		/* Get the entry for this destination	*/	route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, dest_addr_str);	

⌨️ 快捷键说明

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