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

📄 dsr_route_discovery.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 3 页
字号:
	DsrT_Request_Orig_Entry*		route_request_orig_entry_ptr = OPC_NIL;	static Boolean					route_request_orig_entry_pmh_defined = OPC_FALSE;		/** Allocates pooled memory for the route	**/	/** request originating entry				**/	FIN (dsr_route_request_orig_entry_mem_alloc (void));		if (route_request_orig_entry_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route request	*/		/* option in the DSR packets if not already defined	*/		route_request_orig_entry_pmh = op_prg_pmo_define ("Route Request Originating Entry", sizeof (DsrT_Request_Orig_Entry), 32);		route_request_orig_entry_pmh_defined = OPC_TRUE;		}		/* Allocate the route request options from the pooled memory	*/	route_request_orig_entry_ptr = (DsrT_Request_Orig_Entry*) op_prg_pmo_alloc (route_request_orig_entry_pmh);	route_request_orig_entry_ptr->num_route_discoveries = 0;	route_request_orig_entry_ptr->last_route_req_time = 0.0;		FRET (route_request_orig_entry_ptr);	}static voiddsr_route_request_orig_entry_mem_free (DsrT_Request_Orig_Entry* route_request_orig_entry)	{	/** Frees the route request originating entry	**/	FIN (dsr_route_request_orig_entry_mem_free (<args>));		/* Cancel the retry timer	*/	if (op_ev_valid (route_request_orig_entry->retry_timer) && op_ev_pending (route_request_orig_entry->retry_timer))		op_ev_cancel (route_request_orig_entry->retry_timer);		/* Free the rout request originating entry	*/	op_prg_mem_free (route_request_orig_entry);		FOUT;	}static DsrT_Request_Forward_Entry*dsr_route_request_forward_entry_mem_alloc (void)	{	static Pmohandle				route_request_forward_entry_pmh;	DsrT_Request_Forward_Entry*		route_request_forward_entry_ptr = OPC_NIL;	static Boolean					route_request_forward_entry_pmh_defined = OPC_FALSE;		/** Allocates pooled memory for the route	**/	/** request forward entry					**/	FIN (dsr_route_request_forward_entry_mem_alloc (void));		if (route_request_forward_entry_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route request	*/		/* option in the DSR packets if not already defined	*/		route_request_forward_entry_pmh = op_prg_pmo_define ("Route Request Forward Entry", sizeof (DsrT_Request_Forward_Entry), 32);		route_request_forward_entry_pmh_defined = OPC_TRUE;		}		/* Allocate the route request options from the pooled memory	*/	route_request_forward_entry_ptr = (DsrT_Request_Forward_Entry*) op_prg_pmo_alloc (route_request_forward_entry_pmh);	route_request_forward_entry_ptr->route_request_id = OPC_INT_UNDEF;	route_request_forward_entry_ptr->last_used_time = OPC_DBL_INFINITY;		FRET (route_request_forward_entry_ptr);	}static voiddsr_route_request_forward_entry_mem_free (DsrT_Request_Forward_Entry* route_request_forward_entry)	{	/** Frees the route request forward entry	**/	FIN (dsr_route_request_forward_entry_mem_free (<args>));		/* Free the route request entry	*/	op_prg_mem_free (route_request_forward_entry);		FOUT;	}/**********************************************************//*********** "GRATUITOUS" ROUTE REPLY TABLE ***************//**********************************************************/DsrT_Route_Reply_Table*dsr_grat_reply_table_create (double grat_reply_holdoff_time)	{	DsrT_Route_Reply_Table*		route_reply_ptr = OPC_NIL;		/** Creates the gratuitous route reply table	**/	FIN (dsr_grat_reply_table_create (<args>));		route_reply_ptr = dsr_grat_reply_table_mem_alloc ();	route_reply_ptr->grat_reply_holdoff_time = grat_reply_holdoff_time;		FRET (route_reply_ptr);	}voiddsr_grat_reply_table_insert (DsrT_Route_Reply_Table* route_reply_ptr, 						InetT_Address dest_address, InetT_Address overheard_node_address)	{	char						dest_str [INETC_ADDR_STR_LEN];	List*						node_lptr = OPC_NIL;	DsrT_Route_Reply_Entry*		route_reply_entry_ptr = OPC_NIL;	void*						old_contents_ptr = OPC_NIL;		/** Inserts an entry into the gratuitous	**/	/** route reply table for a specific 		**/	/** destination address						**/	FIN (dsr_grat_reply_table_insert (<args>));		/* Delete all expired entries	*/	dsr_expired_grat_reply_entries_delete (route_reply_ptr);		/* Get the destination address as a */	/* string to index the hash table	*/	inet_address_print (dest_str, dest_address);		/* Check if there already exists an entry for the destination	*/	node_lptr = (List*) prg_string_hash_table_item_get (route_reply_ptr->grat_route_reply_table, dest_str);		if (route_reply_entry_ptr == OPC_NIL)		{		/* There does not exist an entry for this destination	*/		/* Create a list to store all entries from different	*/		/* overheard nodes to the same destination				*/		node_lptr = op_prg_list_create ();				/* Set the list in the gratuitous route reply table	*/		prg_string_hash_table_item_insert (route_reply_ptr->grat_route_reply_table, dest_str, node_lptr, &old_contents_ptr);		}		/* Create the memory to set overheard node address	*/	route_reply_entry_ptr = dsr_grat_reply_entry_mem_alloc ();	route_reply_entry_ptr->overheard_node_address = inet_address_copy (overheard_node_address);	route_reply_entry_ptr->insert_time = op_sim_time ();		/* Insert this entry into the list	*/	op_prg_list_insert (node_lptr, route_reply_entry_ptr, OPC_LISTPOS_TAIL);		FOUT;	}Booleandsr_grat_reply_entry_exists (DsrT_Route_Reply_Table* route_reply_ptr, InetT_Address dest_address, InetT_Address overheard_address)	{	char						dest_str [INETC_ADDR_STR_LEN];	List*						node_lptr = OPC_NIL;	int							count, num_entries;	DsrT_Route_Reply_Entry*		route_reply_entry_ptr = OPC_NIL;		/** Checks if there exists an entry for the	**/	/** specified destination address in the	**/	/** gratuitous route reply table			**/	FIN (dsr_grat_reply_entry_exists (<args>));		/* Delete all expired entries	*/	dsr_expired_grat_reply_entries_delete (route_reply_ptr);		/* Get the destination address as a */	/* string to index the hash table	*/	inet_address_print (dest_str, dest_address);		/* Check if there already exists an entry for the destination	*/	node_lptr = (List*) prg_string_hash_table_item_get (route_reply_ptr->grat_route_reply_table, dest_str);		if (node_lptr == OPC_NIL)		{		/* No entry exists for the destination	*/		FRET (OPC_FALSE);		}		/* Get the number of overheard entries	*/	num_entries = op_prg_list_size (node_lptr);		for (count = 0; count < num_entries; count++)		{		/* Get each element in the list and	*/		/* check if the entry exists		*/		route_reply_entry_ptr = (DsrT_Route_Reply_Entry*) op_prg_list_access (node_lptr, count);				if (inet_address_equal (route_reply_entry_ptr->overheard_node_address, overheard_address) == OPC_TRUE)			{			/* A match is found. An entry exists	*/			FRET (OPC_TRUE);			}		}	    FRET (OPC_FALSE);	}static voiddsr_expired_grat_reply_entries_delete (DsrT_Route_Reply_Table* route_reply_ptr)	{	double						current_time;	int							num_entries;	int							count;	int							num_nodes, size;	char*						key_str = OPC_NIL;	List*						keys_lptr = OPC_NIL;	List*						node_lptr = OPC_NIL;	DsrT_Route_Reply_Entry*		route_reply_entry_ptr = OPC_NIL;		/** Deletes all expired entries from the	**/	/** gratuitous route reply table			**/	FIN (dsr_expired_grat_reply_entries_delete (<args>));		/* Get the current time	*/	current_time = op_sim_time ();		/* Get the list of entries in the hash table	*/	keys_lptr = prg_string_hash_table_keys_get (route_reply_ptr->grat_route_reply_table);		/* Get the number of entries	*/	num_entries = op_prg_list_size (keys_lptr);		for (count = 0; count < num_entries; count ++)		{		/* Get each key and access the value from the	*/		/* gratuitous route reply table					*/		key_str = (char*) op_prg_list_access (keys_lptr, count);				node_lptr = (List*) prg_string_hash_table_item_get (route_reply_ptr->grat_route_reply_table, key_str);				num_nodes = op_prg_list_size (node_lptr);				for (size = 0; size < num_nodes; size++)			{			route_reply_entry_ptr = (DsrT_Route_Reply_Entry*) op_prg_list_access (node_lptr, size);					/* Check if the entry has expired	*/			if ((current_time - route_reply_entry_ptr->insert_time) >= route_reply_ptr->grat_reply_holdoff_time)				{				/* This entry has expired. Remove the	*/				/* entry from the hash table			*/				route_reply_entry_ptr = (DsrT_Route_Reply_Entry*) op_prg_list_remove (node_lptr, size);;							/* Free the memory for this entry	*/				dsr_grat_reply_entry_mem_free (route_reply_entry_ptr);								size--;				num_nodes--;				}			}				if (op_prg_list_size (node_lptr) == 0)			{			/* No more entries for this destination	*/			/* Remove it from the table				*/			node_lptr = (List*) prg_string_hash_table_item_remove (route_reply_ptr->grat_route_reply_table, key_str);			op_prg_mem_free (node_lptr);			}		}		/* Free the key list	*/	op_prg_list_free (keys_lptr);	op_prg_mem_free (keys_lptr);		FOUT;	}static DsrT_Route_Reply_Table*dsr_grat_reply_table_mem_alloc (void)	{	DsrT_Route_Reply_Table*		route_reply_table_ptr = OPC_NIL;		/** Allocates memory for the gratuitous route reply table	**/	FIN (dsr_grat_reply_table_mem_alloc (void));		route_reply_table_ptr = (DsrT_Route_Reply_Table*) op_prg_mem_alloc (sizeof (DsrT_Route_Reply_Table));	route_reply_table_ptr->grat_route_reply_table = (PrgT_String_Hash_Table*) prg_string_hash_table_create (10, 10);	route_reply_table_ptr->grat_reply_holdoff_time = 0.0;		FRET (route_reply_table_ptr);	}static DsrT_Route_Reply_Entry*dsr_grat_reply_entry_mem_alloc (void)	{	DsrT_Route_Reply_Entry*			route_reply_entry_ptr = OPC_NIL;		/** Allocates memory for an entry in the	**/	/** gratuitous route reply table			**/	FIN (dsr_grat_reply_entry_mem_alloc (void));		route_reply_entry_ptr = (DsrT_Route_Reply_Entry*) op_prg_mem_alloc (sizeof (DsrT_Route_Reply_Entry));	route_reply_entry_ptr->insert_time = 0.0;		FRET (route_reply_entry_ptr);	}static voiddsr_grat_reply_entry_mem_free (DsrT_Route_Reply_Entry* route_reply_entry_ptr)	{	/** Frees the memory allocated to an entry	**/	/** in the gratuitous route reply table		**/	FIN (dsr_grat_reply_entry_mem_free (<args>));		inet_address_destroy (route_reply_entry_ptr->overheard_node_address);	op_prg_mem_free (route_reply_entry_ptr);		FOUT;	}

⌨️ 快捷键说明

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