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

📄 dsr_route_cache.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 3 页
字号:
				{				/* The route has this hop	*/				/* Delete the route			*/				path_ptr = (DsrT_Path_Info*) op_prg_list_remove (dest_routes_lptr, size);				dsr_route_cache_entry_mem_free (path_ptr);				route_cache_ptr->current_cache_size -= 1;				num_paths--;				route_deleted = OPC_TRUE;				}						if (!route_deleted)				size++;			} /* For each route to a destination */				/* Get the number of remaining paths to the destination	*/		num_paths = op_prg_list_size (dest_routes_lptr);				if (num_paths == 0)			{			/* All paths to the destination node were deleted	*/			/* Remove this node entry from the route cache		*/			dest_routes_lptr = (List*) prg_string_hash_table_item_remove (route_cache_ptr->route_cache_table, key_str);			op_prg_mem_free (dest_routes_lptr);			}		} /* For each destination node */		/* Update the size of the route cache_statistic	*/	dsr_route_cache_size_stat_update (route_cache_ptr);		op_prg_list_free (keys_lptr);	op_prg_mem_free (keys_lptr);		FOUT;	}voiddsr_route_cache_export (DsrT_Route_Cache* route_cache_ptr, int PRG_ARG_UNUSED (code))	{	static Boolean			log_handle_initialized = OPC_FALSE;	static Log_Handle		route_cache_log_handle;	List*					dest_keys_lptr = OPC_NIL;	int						num_dest, count, size, num_routes;	char*					dest_key_ptr;	List*					dest_routes_lptr = OPC_NIL;	char					message_str [10000] = "";	char					final_str [100000] = "";	DsrT_Path_Info*			path_ptr = OPC_NIL;	char					first_hop_str [8];	char					last_hop_str [8];	char					temp_str [1000] = "";	char*					route_str;		/** This function exports the route cache	**/	/** to a simulation log message				**/	FIN (dsr_route_cache_export (<args>));		if (log_handle_initialized == OPC_FALSE)		{		/* Initailize the log handle	*/		route_cache_log_handle = op_prg_log_handle_create (OpC_Log_Category_Results, "DSR", "Route Cache", 100);		log_handle_initialized = OPC_TRUE;		}		/* Get the number of destinations in the route cache	*/	dest_keys_lptr = prg_string_hash_table_keys_get (route_cache_ptr->route_cache_table);		num_dest = op_prg_list_size (dest_keys_lptr);		for (count = 0; count < num_dest; count++)		{		dest_key_ptr = (char*) op_prg_list_access (dest_keys_lptr, count);				/* Get the list of route to this destination	*/		dest_routes_lptr = (List*) prg_string_hash_table_item_get (route_cache_ptr->route_cache_table, dest_key_ptr);				if (dest_routes_lptr == OPC_NIL)			continue;				/* Get the number of routes	*/		num_routes = op_prg_list_size (dest_routes_lptr);				for (size = 0; size < num_routes; size++)			{			path_ptr = (DsrT_Path_Info*) op_prg_list_access (dest_routes_lptr, size);						if (path_ptr->first_hop_external == OPC_TRUE)				sprintf (first_hop_str, "TRUE");			else				sprintf (first_hop_str, "FALSE");						if (path_ptr->last_hop_external == OPC_TRUE)				sprintf (last_hop_str, "TRUE");			else				sprintf (last_hop_str, "FALSE");						route_str = dsr_support_route_print (path_ptr->path_hops_lptr);						if (size == 0)				sprintf (temp_str, "\t\t\t%-18.2f%-22s%-21s%s\n", path_ptr->installed_time, first_hop_str, last_hop_str, route_str);			else				sprintf (temp_str, "\t\t\t\t\t%-18.2f%-22s%-21s%s\n", path_ptr->installed_time, first_hop_str, last_hop_str, route_str);						strcat (message_str, temp_str);						/* Free the memory	*/			op_prg_mem_free (route_str);			}				strcpy (temp_str, "-----------------------------------------------------------------------------------------------------\n");		strcat (message_str, temp_str);		strcat (final_str , message_str);		}		op_prg_log_entry_write (route_cache_log_handle, 		"ROUTE CACHE INFORMATION at time %f \n"		"\n"		"========================================================================================================================\n"		"-                                                   ROUTE CACHE                                                        -\n"		"========================================================================================================================\n"		"Destination Node    Time Installed    First Hop External    Last Hop External    Route(s)\n"		"----------------    --------------    ------------------    -----------------    --------\n"		"%s\n", op_sim_time (), final_str);		/* Free the keys	*/	op_prg_list_free (dest_keys_lptr);	op_prg_mem_free (dest_keys_lptr);			FOUT;	}	voiddsr_route_cache_export_to_ot_initialize (void)	{	/** Initialize the OT package	**/		FIN (dsr_route_cache_export_to_ot_initialize (void));		/* Open the OT file	*/	Oms_Ot_File_Open ();		FOUT;	}voiddsr_route_cache_export_to_ot_close (void* route_cache_ptr1, int PRG_ARG_UNUSED (code))	{	DsrT_Route_Cache* 	route_cache_ptr;		/** Close the OT package	**/	FIN (dsr_route_cache_export_to_ot_close (void));		route_cache_ptr = (DsrT_Route_Cache*) route_cache_ptr1;		/* Close the file	*/	Oms_Ot_File_Close ();		FOUT;	}voiddsr_route_cache_export_to_ot (void* route_cache_ptr1, int PRG_ARG_UNUSED (code))	{	OmaT_Ot_Writer* 			ot_writer_ptr = OPC_NIL;	static OmaT_Ot_Template 	*ot_route_cache_table_template = OPC_NIL;	OmaT_Ot_Table       		*ot_route_cache_table = OPC_NIL;	char						table_name [512] = "";	List*						dest_keys_lptr;	int							num_dest, count, size, num_routes, hop_index;	int							num_hops, hop_count;	char*						dest_key_ptr;	List*						dest_routes_lptr = OPC_NIL;	DsrT_Path_Info*				path_ptr = OPC_NIL;	char						first_hop_str [8];	char						last_hop_str [8];	char						temp_str [1000] = "";	char						node_name [OMSC_HNAME_MAX_LEN];	char						hop_addr_str [INETC_ADDR_STR_LEN];	InetT_Address*				hop_address_ptr;	InetT_Address				dest_addr;	DsrT_Route_Cache* 			route_cache_ptr;		/** Export the route cache on a node to the	**/	/** OT package at various times				**/	FIN (dsr_route_cache_export_to_ot (<args>));		route_cache_ptr = (DsrT_Route_Cache* ) route_cache_ptr1;		/* Get the number of destinations in the route cache	*/	dest_keys_lptr = prg_string_hash_table_keys_get (route_cache_ptr->route_cache_table);		num_dest = op_prg_list_size (dest_keys_lptr);		if (num_dest == 0)		FOUT;		/* Get the source node name	*/	for (count = 0; count < num_dest; count++)		{		/* Access the first route	*/		dest_key_ptr = (char*) op_prg_list_access (dest_keys_lptr, OPC_LISTPOS_HEAD);				/* Get the list of route to this destination	*/		dest_routes_lptr = (List*) prg_string_hash_table_item_get (route_cache_ptr->route_cache_table, dest_key_ptr);				if (dest_routes_lptr == OPC_NIL)			continue;				if (op_prg_list_size (dest_routes_lptr) > 0)			{			path_ptr = (DsrT_Path_Info*) op_prg_list_access (				dest_routes_lptr, OPC_LISTPOS_HEAD);					/* Get the first node address	*/			if (op_prg_list_size (path_ptr->path_hops_lptr) > 0)					{				hop_address_ptr = (InetT_Address*) op_prg_list_access (					path_ptr->path_hops_lptr, OPC_LISTPOS_HEAD);							break;				}			}		}		/* Get the hierarchical name of the node	*/	inet_address_to_hname (*hop_address_ptr, node_name);		/* Get the OT file to write into	*/	ot_writer_ptr =	Oms_Ot_File_Get ();		/* If the OT writer couild not be obtained then exit the function	*/	if (ot_writer_ptr == OPC_NIL)		FOUT;		/* If do not yet have the tamplate then	*/	/* get the template for this table		*/			if (ot_route_cache_table_template == OPC_NIL)		ot_route_cache_table_template = Oms_Ot_Template_Create (routes_cache_columns_name_array, routes_cache_columns_name_array_size);		/* Create the table name */	sprintf (table_name, "DSR.Route Cache at %d seconds", (int) op_sim_time ());		/* Create the Route Cache table for this node	*/	ot_route_cache_table = Oma_Ot_Writer_Table_Add (ot_writer_ptr, OmaC_Table_Type_Site,								"", node_name, table_name, ot_route_cache_table_template);		for (count = 0; count < num_dest; count++)		{		dest_key_ptr = (char*) op_prg_list_access (dest_keys_lptr, count);				/* Get the list of route to this destination	*/		dest_routes_lptr = (List*) prg_string_hash_table_item_get (route_cache_ptr->route_cache_table, dest_key_ptr);				if (dest_routes_lptr == OPC_NIL)			continue;				/* Create the IP address from the string	*/		dest_addr = inet_address_create (dest_key_ptr, InetC_Addr_Family_Unknown);				/* Get the node name	*/		inet_address_to_hname (dest_addr, node_name);				/* Append the two	*/		sprintf (temp_str, "%s (%s)", dest_key_ptr, node_name);				/* Free the address	*/		inet_address_destroy (dest_addr);				/* Write out the destination address */		Oma_Ot_Table_Cell_Value_Set (ot_route_cache_table, routes_cache_columns_name_array [0], temp_str);				/* Get the number of routes	*/		num_routes = op_prg_list_size (dest_routes_lptr);				for (size = 0; size < num_routes; size++)			{			path_ptr = (DsrT_Path_Info*) op_prg_list_access (dest_routes_lptr, size);						/* Write out the installed time */			sprintf (temp_str, "%0.2f", path_ptr->installed_time);			Oma_Ot_Table_Cell_Value_Set (ot_route_cache_table, routes_cache_columns_name_array [1], temp_str);						if (path_ptr->first_hop_external == OPC_TRUE)				sprintf (first_hop_str, "TRUE");			else				sprintf (first_hop_str, "FALSE");						if (path_ptr->last_hop_external == OPC_TRUE)				sprintf (last_hop_str, "TRUE");			else				sprintf (last_hop_str, "FALSE");						/* Write out the first and last hop external */			Oma_Ot_Table_Cell_Value_Set (ot_route_cache_table, routes_cache_columns_name_array [2], first_hop_str);			Oma_Ot_Table_Cell_Value_Set (ot_route_cache_table, routes_cache_columns_name_array [3], last_hop_str);						/* Get the number of hops	*/			num_hops = op_prg_list_size (path_ptr->path_hops_lptr);			hop_count = num_hops - 1;						/* Write out the hop count	*/			sprintf (temp_str, "%d", hop_count);			Oma_Ot_Table_Cell_Value_Set (ot_route_cache_table, routes_cache_columns_name_array [4], temp_str);				for (hop_index = 0; hop_index < num_hops; hop_index++)				{				/* Get each hop from the route	*/				hop_address_ptr = (InetT_Address*) op_prg_list_access (path_ptr->path_hops_lptr, hop_index);						/* Get the IP address string	*/				inet_address_ptr_print (hop_addr_str, hop_address_ptr);						/* Get the name of the node	*/				inet_address_to_hname (*hop_address_ptr, node_name);						sprintf (temp_str, "%s (%s)", hop_addr_str, node_name);								/* Write out each hop	*/				Oma_Ot_Table_Cell_Value_Set (ot_route_cache_table, routes_cache_columns_name_array [5], temp_str);								/* Write out the rows constructed to each corresponding table		*/				Oma_Ot_Table_Row_Write (ot_route_cache_table);				}						/* Write out a blank row */			Oma_Ot_Table_Row_Write (ot_route_cache_table);			}				/* Write out a blank row */		Oma_Ot_Table_Row_Write (ot_route_cache_table);		}	/* Free the keys	*/	op_prg_list_free (dest_keys_lptr);	op_prg_mem_free (dest_keys_lptr);		/* Destroy the table	*/	if (ot_route_cache_table != OPC_NIL)		Oma_Ot_Table_Destroy (ot_route_cache_table);		FOUT;	}	/******************* INTERNAL FUNCTIONS *******************/static DsrT_Path_Info*dsr_route_cache_entry_create (List* path_lptr, Boolean first_hop_external, Boolean last_hop_external)	{	DsrT_Path_Info*			route_entry_ptr = OPC_NIL;	InetT_Address*			hop_address_ptr;	InetT_Address*			copy_address_ptr;	int						num_hops;	int						hop_count;		/** Creates a route entry to insert into the route	**/	/** cache for a specific route from a source node	**/	/** to a destination node.							**/	FIN (dsr_route_cache_entry_create (<args>));		/* Allocate memory for the route entry	*/	route_entry_ptr = dsr_route_cache_entry_mem_alloc ();		/* Get the number of hops	*/	num_hops = op_prg_list_size (path_lptr);		/* Copy each hop into the array	*/	for (hop_count = 0; hop_count < num_hops; hop_count++)		{		hop_address_ptr = (InetT_Address*) op_prg_list_access (path_lptr, hop_count);		copy_address_ptr = inet_address_copy_dynamic (hop_address_ptr);		op_prg_list_insert (route_entry_ptr->path_hops_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);		}		/* Set the rest of the variables associated with a route entry	*/	route_entry_ptr->first_hop_external = first_hop_external;	route_entry_ptr->last_hop_external = last_hop_external;	route_entry_ptr->num_hops = num_hops;	route_entry_ptr->last_access_time = op_sim_time ();	route_entry_ptr->installed_time = op_sim_time ();		FRET (route_entry_ptr);	}static Booleandsr_route_cache_route_exists (List* dest_routes_lptr, List* new_path_lptr)	{	int					num_routes, count, size;	int					exist_num_hops, new_num_hops;	DsrT_Path_Info*		path_info_ptr = OPC_NIL;	InetT_Address*		exist_hop_address_ptr;	InetT_Address*		new_hop_address_ptr;		/** Goes through all routes to a destination	**/	/** and checks if the route to be inserted into	**/	/** the route cache exists already				**/	FIN (dsr_route_cache_route_exists (<args>));		/* Get the number of routes to the destination	*/	num_routes = op_prg_list_size (dest_routes_lptr);	new_num_hops = op_prg_list_size (new_path_lptr);		for (count = 0; count < num_routes; count++)		{		/* Get each route that exists	*/		path_info_ptr = (DsrT_Path_Info*) op_prg_list_access (dest_routes_lptr, count);				/* If the size of the two paths are not	*/		/* the same, then they are different	*/		exist_num_hops = op_prg_list_size (path_info_ptr->path_hops_lptr);					if (exist_num_hops != new_num_hops)			{			/* This route does not match	*/			/* the new incoming route		*/			continue;			}				for (size = 0; size < exist_num_hops; size++)			{			/* Access each hop and compare	*/			/* that they are the same		*/			exist_hop_address_ptr = (InetT_Address*) op_prg_list_access (path_info_ptr->path_hops_lptr, size);			new_hop_address_ptr = (InetT_Address*) op_prg_list_access (new_path_lptr, size);						if (inet_address_ptr_equal (exist_hop_address_ptr, new_hop_address_ptr) == OPC_FALSE)				{				/* The hops do not match	*/				break;				}			}				if (size == exist_num_hops)			{			/* A matching route is found	*/			/* in the route cache			*/

⌨️ 快捷键说明

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