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

📄 aodv_route_table.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (route_entry_ptr == OPC_NIL)		FRET (OPC_COMPCODE_FAILURE);		FOUND = OPC_FALSE;		/* Insert this precursor node in the list					*/	/* Here we need to check and insert the precursor addr		*/	/* First check if the precursor addr is already in the list,*/	/* if yes, then don't insert, if no then insert.			*/		size = op_prg_list_size (route_entry_ptr->precursor_lptr);	for(num = 0; num < size; num++)		{		pre_addr_ptr = (InetT_Address*) op_prg_list_access (route_entry_ptr->precursor_lptr, num);		existing_precursor_addr = *pre_addr_ptr;				if(inet_address_equal (precursor_addr, existing_precursor_addr))			FOUND = OPC_TRUE;				}		   	if(FOUND == OPC_FALSE)		{				precursor_addr_ptr = inet_address_create_dynamic (precursor_addr);		op_prg_list_insert (route_entry_ptr->precursor_lptr, precursor_addr_ptr, OPC_LISTPOS_TAIL);		}		FRET (OPC_COMPCODE_SUCCESS);	}Compcodeaodv_route_table_entry_next_hop_update (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, 	InetT_Address new_next_hop_addr, int new_hop_count, IpT_Port_Info new_out_port_info)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];	AodvC_Route_Entry_State 	route_entry_state;		/** Updates the route table entry with the new	**/	/** next hop parameters and metric				**/	FIN (aodv_route_table_entry_next_hop_update (<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);		route_entry_state = route_entry_ptr->route_entry_state;		if (route_entry_state == AodvC_Valid_Route)		{		/* Update the common route table with the new information	*/		Inet_Cmn_Rte_Table_Entry_Update (route_table_ptr->ip_cmn_rte_table_ptr, route_entry_ptr->dest_prefix,			route_entry_ptr->next_hop_addr, route_table_ptr->aodv_protocol_id, new_next_hop_addr, new_out_port_info,			new_hop_count, OPC_NIL);		}	/* Free the old information	*/	inet_address_destroy (route_entry_ptr->next_hop_addr);		/* Set the new information	*/	route_entry_ptr->next_hop_addr = new_next_hop_addr;		FRET (OPC_COMPCODE_SUCCESS);	}Compcodeaodv_route_table_entry_state_set (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, 								AodvC_Route_Entry_State route_entry_state)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];		/** This function changes the state of a route table	**/	/** entry. It can either set it to be a valid route or	**/	/** and invalid route. The function appropriately 		**/	/** handles the necessary functions with these states	**/	FIN (aodv_route_table_entry_state_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);		if (route_entry_state == AodvC_Valid_Route)		{		/* The route entry that already exists is	*/		/* being set back to a valid route. Insert	*/		/* this route back into 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);				/* Set the state of the route to valid	*/		route_entry_ptr->route_entry_state = AodvC_Valid_Route;				/* Update the size of the route table	*/		/* The size indicates the number of 	*/		/* active routes that are present		*/		route_table_ptr->current_size++;		}	else		{		/* The route entry is become invalid. Delete	*/		/* the route from the common route table. Set	*/		/* the state of the route to invalid in the		*/		/* AODV route table. Do not delete it from the	*/		/* AODV route table as it is still needed to 	*/		/* keep information about the soft state		*/		Inet_Cmn_Rte_Table_Route_Delete (route_table_ptr->ip_cmn_rte_table_ptr, route_entry_ptr->dest_prefix, 											route_table_ptr->aodv_protocol_id);				/* Set the state of the route to valid	*/		route_entry_ptr->route_entry_state = AodvC_Invalid_Route;				/* Increament the dest seq num for the expired entry */		route_entry_ptr->dest_seq_num++;						/* Update the expiry time of the route to be delete period	*/		aodv_route_table_entry_expiry_time_update (route_table_ptr, dest_addr, route_table_ptr->delete_period, 													AODVC_ROUTE_ENTRY_EXPIRED);				/* Update the size of the route table	*/		/* The size indicates the number of 	*/		/* active routes that are present		*/		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);		FRET (OPC_COMPCODE_SUCCESS);	}	Compcodeaodv_route_table_entry_delete (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];		/** Deletes an entry from the AODV route table	**/	/** If an entry is deleted from the AODV table,	**/	/** it should have already been removed from 	**/	/** the IP common route table when the entry 	**/	/** was set to invalid							**/	FIN (aodv_route_table_entry_delete (<args>));		/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);		/* Remove the entry from the AODV route table	*/	route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_remove (route_table_ptr->route_table, dest_addr_str);		if (route_entry_ptr == OPC_NIL)		FRET (OPC_COMPCODE_FAILURE);		/* Free the memory for thie route table entry	*/	aodv_route_table_entry_mem_free (route_entry_ptr);		FRET (OPC_COMPCODE_SUCCESS);	}voidaodv_route_table_entry_expiry_time_update (AodvT_Route_Table* route_table_ptr, InetT_Address dest_addr, 											double timeout, int code)	{	AodvT_Route_Entry*			route_entry_ptr = OPC_NIL;	char						dest_addr_str [INETC_ADDR_STR_LEN];	InetT_Address*				dest_addr_ptr;	InetT_Address*				dest_addr_ptr_tmp;			/** Update the expiry time for a route in the route table	**/	FIN (aodv_route_table_entry_expiry_time_update (<args>));		/* Create the destination address string	*/	inet_address_print (dest_addr_str, dest_addr);	dest_addr_ptr = inet_address_create_dynamic (dest_addr);			/* Get the entry from the AODV route table	*/	route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, dest_addr_str);		/* Cancel the previously scheduled event	*/	if (op_ev_valid (route_entry_ptr->route_expiry_evhandle) && op_ev_pending (route_entry_ptr->route_expiry_evhandle))		{		dest_addr_ptr_tmp = (InetT_Address *) op_ev_state (route_entry_ptr->route_expiry_evhandle);		inet_address_destroy_dynamic (dest_addr_ptr_tmp);		op_ev_cancel (route_entry_ptr->route_expiry_evhandle);		}		/* Update the expiry time for this route entry	*/	route_entry_ptr->route_expiry_time = op_sim_time () + timeout;		/* 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, code, 		aodv_rte_entry_expiry_handle, dest_addr_ptr);	op_ev_state_install (OPC_NIL, OPC_NIL);		FOUT;	}intaodv_route_table_num_active_routes_get (AodvT_Route_Table* route_table_ptr)    {    List*                   keys_lptr;    int                     num_routes, count;    int                     num_valid_routes = 0;    char*                   key_ptr;    AodvT_Route_Entry*      route_entry_ptr;    /** Returns the number of active routes in the route table  **/    FIN (aodv_route_table_num_active_routes_get (<args>));    /* Get the number of routes in the route table  */    keys_lptr = (List*) prg_string_hash_table_keys_get (route_table_ptr->route_table);    num_routes = op_prg_list_size (keys_lptr);    for (count = 0; count < num_routes; count++)        {        /* For each route entry check if the route is valid */        key_ptr = (char*) op_prg_list_access (keys_lptr, count);        route_entry_ptr = (AodvT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, key_ptr);        if (route_entry_ptr->route_entry_state == AodvC_Valid_Route)            num_valid_routes++;        }    /* Free the keys    */    op_prg_list_free (keys_lptr);    op_prg_mem_free (keys_lptr);    FRET (num_valid_routes);    }static AodvT_Route_Entry*aodv_route_table_entry_mem_alloc (void)	{	static Pmohandle		route_table_entry_pmh;	AodvT_Route_Entry*		route_table_entry_ptr = OPC_NIL;	static Boolean			route_table_entry_pmh_defined = OPC_FALSE;		/** Allocates pooled memory for a route table entry	**/	FIN (aodv_route_table_entry_mem_alloc (void));		if (route_table_entry_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route table entry	*/		route_table_entry_pmh = op_prg_pmo_define ("Route Table Entry", sizeof (AodvT_Route_Entry), 32);		route_table_entry_pmh_defined = OPC_TRUE;		}		/* Allocate the route table entry from the pooled memory	*/	route_table_entry_ptr = (AodvT_Route_Entry*) op_prg_pmo_alloc (route_table_entry_pmh);		/* Initailize the components of the structure	*/	route_table_entry_ptr->valid_dest_sequence_number_flag = OPC_FALSE;	route_table_entry_ptr->route_entry_state = AodvC_Undef_Route;	route_table_entry_ptr->precursor_lptr = op_prg_list_create ();		FRET (route_table_entry_ptr);	}static voidaodv_route_table_entry_mem_free (AodvT_Route_Entry* route_entry_ptr)	{	int					num_elements;	InetT_Address*		precursor_addr_ptr;		/** Frees the memory for the route table entry	**/	FIN (aodv_route_table_entry_mem_free (<args>));		/* Free the next hop address	*/	inet_address_destroy (route_entry_ptr->next_hop_addr);		/* Get the size of the precursor list	*/	num_elements = op_prg_list_size (route_entry_ptr->precursor_lptr);		/* Free the elements of the list	*/	while (num_elements > 0)		{		precursor_addr_ptr = (InetT_Address*) op_prg_list_remove (route_entry_ptr->precursor_lptr, OPC_LISTPOS_HEAD);		inet_address_destroy_dynamic (precursor_addr_ptr);		num_elements--;		}		/* Free the list	*/	op_prg_mem_free (route_entry_ptr->precursor_lptr);		/* Cancel any pending event	*/	if (op_ev_valid (route_entry_ptr->route_expiry_evhandle) && op_ev_pending (route_entry_ptr->route_expiry_evhandle))		op_ev_cancel (route_entry_ptr->route_expiry_evhandle);		/* Free the destination prefix	*/	ip_cmn_rte_table_dest_prefix_destroy (route_entry_ptr->dest_prefix);			/* Free the route entry	*/	op_prg_mem_free (route_entry_ptr);		FOUT;	}

⌨️ 快捷键说明

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