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

📄 dsr_support.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 3 页
字号:
/* dsr_support.ex.c *//* C support file for DSR support functions *//****************************************//*		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 <string.h>#include <dsr.h>#include <dsr_pkt_support.h>#include <dsr_ptypes.h>#include <ip_addr_v4.h>#include <ip_support.h>#include <manet.h>#include <oms_ot_support.h>/* These arrays hold the names of the different columns					*//* in the respective table. The arrays will be used for column names	*//* while creating the templates, and will also be used as column tags	*//* while wrting into the tables											*/int			routes_export_columns_name_array_size = 5;const char*	routes_export_columns_name_array [] 	= {"Time",		"Source Node Name", 	"Destination Node Name", 														"Hop Count", 	"Route Taken"};/* Global static variables	*/static OmaT_Ot_Table       		*ot_routes_report_table = OPC_NIL;char*dsr_support_route_print (List* route_lptr)	{	char			return_str [100000] = "";	char*			final_return_str = OPC_NIL;	char			node_name [OMSC_HNAME_MAX_LEN];	char			hop_addr_str [INETC_ADDR_STR_LEN];	char			temp_str [512];	InetT_Address*	hop_address_ptr;	int				num_hops, count;		/** Returns a print of the route list passed	**/	FIN (dsr_support_route_print (<args>));		/* Get the number of hops	*/	num_hops = op_prg_list_size (route_lptr);		for (count = 0; count < num_hops; count++)		{		/* Get each hop from the route	*/		hop_address_ptr = (InetT_Address*) op_prg_list_access (route_lptr, count);				/* 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);				/* Set the return string	*/		strcat (return_str, temp_str);				if (count != (num_hops - 1))			strcat (return_str, "--> ");		}		/* Allocate memory for the return string	*/	final_return_str = (char*) op_prg_mem_alloc (sizeof (char) * (strlen (return_str) + 1));	strcpy (final_return_str, return_str);		FRET (final_return_str);	}char*dsr_support_option_route_print (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Route_Request_Option*		route_request_option_ptr;	DsrT_Route_Reply_Option*		route_reply_option_ptr;	DsrT_Source_Route_Option*		source_route_option_ptr;	char*							return_str = OPC_NIL;		/** Prints the route in an option	**/	FIN (dsr_support_option_route_print (<args>));		switch (dsr_tlv_ptr->option_type)		{		case (DSRC_ROUTE_REQUEST):			{			/* Print the route request option route	*/			route_request_option_ptr = (DsrT_Route_Request_Option*) dsr_tlv_ptr->dsr_option_ptr;			return_str = dsr_support_route_print (route_request_option_ptr->route_lptr);			break;			}		case (DSRC_ROUTE_REPLY):			{			/* Print the route reply option route	*/			route_reply_option_ptr = (DsrT_Route_Reply_Option*) dsr_tlv_ptr->dsr_option_ptr;			return_str = dsr_support_route_print (route_reply_option_ptr->route_lptr);			break;			}		case (DSRC_SOURCE_ROUTE):			{			/* Print the source route option route	*/			source_route_option_ptr = (DsrT_Source_Route_Option*) dsr_tlv_ptr->dsr_option_ptr;			return_str = dsr_support_route_print (source_route_option_ptr->route_lptr);			break;			}		}		FRET (return_str);	}char*dsr_support_route_cache_print_to_string (DsrT_Route_Cache* route_cache_ptr)	{	List*					dest_keys_lptr 		= OPC_NIL;	int						num_dest, count, size, num_routes;	char*					dest_key_ptr		= OPC_NIL;	List*					dest_routes_lptr 	= OPC_NIL;	char					message_str [10000] = "";	char*					final_str			= OPC_NIL;	DsrT_Path_Info*			path_ptr 			= OPC_NIL;	char					first_hop_str [8];	char					last_hop_str [8];	char					temp_str [1000] 	= "";	char*					route_str			= OPC_NIL;	int						current_elements, add_elements;		/** Prints the route cache on a node to a string	**/	FIN (dsr_support_route_cache_print_to_string (<args>));		sprintf (message_str, 		"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", op_sim_time ());		/* Get the size of each string	*/	add_elements = strlen (message_str);			/* Append the new string to the return string	*/	final_str = (char*) dsr_array_elements_add (final_str, 0, (add_elements + 1), sizeof (char));	strcat (final_str, message_str);		/* 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;				sprintf (message_str, "%s", dest_key_ptr);				/* 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);				/* Get the size of each string	*/		current_elements = strlen (final_str);		add_elements = strlen (message_str);				/* Append the new string to the return string	*/		final_str = (char*) dsr_array_elements_add (final_str, current_elements, (add_elements + 1), sizeof (char));		strcat (final_str, message_str);		}		/* Free the keys	*/	op_prg_list_free (dest_keys_lptr);	op_prg_mem_free (dest_keys_lptr);			FRET (final_str);	}voiddsr_support_route_print_to_file (IpT_Dgram_Fields* ip_dgram_fd_ptr, List* intermediate_route_lptr)	{	static OmsT_Ext_File_Handle		ext_file_handle = OPC_NIL;	InetT_Address*					hop_address_ptr;	int								num_intermediate_nodes; 	int								total_intermediate_hops, total_hops, count;	char							temp_str [10000];	char							src_addr_str [INETC_ADDR_STR_LEN];	char							src_node_name [OMSC_HNAME_MAX_LEN];	char							dest_addr_str [INETC_ADDR_STR_LEN];	char							dest_node_name [OMSC_HNAME_MAX_LEN];	char							hop_addr_str [INETC_ADDR_STR_LEN];	char							hop_node_name [OMSC_HNAME_MAX_LEN];	char							src_str [512];	char							dest_str [512];	char							hop_str [512];	/** Prints the route taken by each source	**/	/** route packet to a file					**/	FIN (dsr_support_route_print_to_file (<args>));		/* Determine the total number of hops in the route	*/	num_intermediate_nodes = op_prg_list_size (intermediate_route_lptr);	total_intermediate_hops = num_intermediate_nodes - 1;		/* Add the source and destination node hops	*/	total_hops = total_intermediate_hops + 2;		/* Check if we have file in which to write data	*/	if (ext_file_handle == OPC_NIL)		{		ext_file_handle = Oms_Ext_File_Handle_Get (OMSC_EXT_FILE_PROJ_SCEN_NAME, "dsr_routes", OMSC_EXT_FILE_GDF);				/* Add the header to the file	*/		strcpy (temp_str, "DSR Routes Report\n");		Oms_Ext_File_Info_Append (ext_file_handle, temp_str);		strcpy (temp_str, "-----------------\n\n\n");		Oms_Ext_File_Info_Append (ext_file_handle, temp_str);		strcpy (temp_str, "TIME        SOURCE NODE NAME                        DESTINATION NODE NAME                       HOP COUNT       ROUTE TAKEN\n");		Oms_Ext_File_Info_Append (ext_file_handle, temp_str);		strcpy (temp_str, "----        ----------------                        ---------------------                       ----------      -----------\n");		Oms_Ext_File_Info_Append (ext_file_handle, temp_str);		}		/* Get the source node and destination node names	*/		/* If the source address is invalid, do not export	*/	if (!inet_address_valid (ip_dgram_fd_ptr->src_addr))		FOUT;		/* Get the IP address string	*/	inet_address_print (src_addr_str, ip_dgram_fd_ptr->src_addr);			/* Get the name of the node	*/	inet_address_to_hname (ip_dgram_fd_ptr->src_addr, src_node_name);		/* Append the two	*/	sprintf (src_str, "%s (%s)", src_addr_str, src_node_name);		/* Get the IP address string	*/	inet_address_print (dest_addr_str, ip_dgram_fd_ptr->dest_addr);			/* Get the name of the node	*/	inet_address_to_hname (ip_dgram_fd_ptr->dest_addr, dest_node_name);		/* Append the two	*/	sprintf (dest_str, "%s (%s)", dest_addr_str, dest_node_name);	

⌨️ 快捷键说明

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