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

📄 manet_support.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 2 页
字号:
	int						outstrm;	short					output_intf_index;	InetT_Address_Range* 	inet_addr_range_ptr;		/** Checks if the incoming packet has	**/	/** reached its destination				**/	FIN (manet_rte_address_belongs_to_node (<args>));		/* Check if the destination address belongs to one	*/	/* of the directly connected networks of this node	*/	if (ip_rte_destination_local_network (module_data_ptr, node_address, &output_intf_index, 							 &iface_info_ptr, &outstrm, &inet_addr_range_ptr) == OPC_COMPCODE_SUCCESS)		{		/* Packet belongs to a directly connected network	*/		/* Check if the packet is destined for this node	*/		if (inet_address_range_address_equal (inet_addr_range_ptr, &node_address))			{			/* The packet is destined for this node	*/			FRET (OPC_TRUE);			}		}		FRET (OPC_FALSE);	}voidmanet_rte_ip_pkt_info_access (Packet* ip_pkptr, IpT_Dgram_Fields** ip_dgram_fd_pptr,							IpT_Rte_Ind_Ici_Fields** intf_ici_fdstruct_pptr)	{	Ici*			pkt_info_ici_ptr = OPC_NIL;		/** Access the information from the IP packet	**/	FIN (manet_rte_ip_pkt_info_access (<args>));		/* Get the ICI associated with the packet	*/	/* Get the pointer to access the contents	*/	pkt_info_ici_ptr = op_pk_ici_get (ip_pkptr);		/* Get the incoming packet information	*/	op_ici_attr_get (pkt_info_ici_ptr, "rte_info_fields", intf_ici_fdstruct_pptr);		/* Set the incoming packet information	*/	op_ici_attr_set (pkt_info_ici_ptr, "rte_info_fields", *intf_ici_fdstruct_pptr);		/* Set the ICI back in the packet	*/	op_pk_ici_set (ip_pkptr, pkt_info_ici_ptr);		/* Access the fields of the IP datagram	*/	op_pk_nfd_access (ip_pkptr, "fields", ip_dgram_fd_pptr);		FOUT;	}	Packet*manet_rte_ip_pkt_copy (Packet* ip_pkptr)	{	Ici*						pkt_info_ici_ptr;	Ici*						copy_pkt_info_ici_ptr;	IpT_Rte_Ind_Ici_Fields* 	intf_ici_fdstruct_ptr; 	IpT_Rte_Ind_Ici_Fields*		copy_intf_ici_fdstruct_ptr;	Packet*						copy_pkptr;		/** Makes a copy of the IP packet	**/	/** This can only be used for calls	**/	/** in the IP module				**/	FIN (manet_rte_ip_pkt_copy (<args>));		/* Make a copy of the packet	*/	copy_pkptr = op_pk_copy (ip_pkptr);		/* Get the ICI associated with the packet	*/	/* Get the pointer to access the contents	*/	pkt_info_ici_ptr = op_pk_ici_get (ip_pkptr);		/* Set the ICI back in the packet	*/	op_pk_ici_set (ip_pkptr, pkt_info_ici_ptr);		if ((pkt_info_ici_ptr != OPC_NIL) && (op_ici_attr_exists (pkt_info_ici_ptr, "rte_info_fields") == OPC_TRUE))		{		/* Get the incoming packet information	*/		op_ici_attr_get (pkt_info_ici_ptr, "rte_info_fields", &intf_ici_fdstruct_ptr);			/* Set the incoming packet information	*/		op_ici_attr_set (pkt_info_ici_ptr, "rte_info_fields", intf_ici_fdstruct_ptr);			/* Make a copy of the routing info fields	*/		copy_intf_ici_fdstruct_ptr = ip_rte_ind_ici_fdstruct_copy (intf_ici_fdstruct_ptr);			/* Create a new ICI and set the information in that ICI	*/		copy_pkt_info_ici_ptr = op_ici_create ("ip_rte_ind_v4");			/* Set the information	*/		op_ici_attr_set (copy_pkt_info_ici_ptr, "rte_info_fields", copy_intf_ici_fdstruct_ptr);			/* Associate the new ICI with the packet	*/		op_pk_ici_set (copy_pkptr, copy_pkt_info_ici_ptr);		}		FRET (copy_pkptr);	}		voidmanet_rte_ip_pkt_destroy (Packet* ip_pkptr)	{	Ici*		pkt_info_ici_ptr = OPC_NIL;		/** Destroys the IP packet and the ICI	**/	/** associated with the packet if any	**/	FIN (manet_rte_ip_pkt_destroy (<args>));		/* Get the ICI associated with the packet	*/	pkt_info_ici_ptr = op_pk_ici_get (ip_pkptr);		if (pkt_info_ici_ptr != OPC_NIL)		{		/* Destroy the ICI	*/		ip_rte_intf_ici_destroy (pkt_info_ici_ptr);		}		/* Destroy the IP datagram	*/	op_pk_destroy (ip_pkptr);		FOUT;	}voidmanet_rte_path_display_dump (List* record_route_lptr)	{	static OmsT_Ext_File_Handle		ext_file_handle = OPC_NIL;	InetT_Address*					src_addr_ptr;	InetT_Address*					dest_addr_ptr;	InetT_Address*					hop_addr_ptr;	char							file_line_entry [8192] = "";	char							temp_str [128] = "";	char							src_node_name [OMSC_HNAME_MAX_LEN] = "";	char							dest_node_name [OMSC_HNAME_MAX_LEN] = "";	char							hop_node_name [OMSC_HNAME_MAX_LEN] = "";	char							conn_name [512] = "";	int								num_hops, count;		/** Dumps the list of hops to a file to display	**/	/** in the route browser. The list should 		**/	/** contain the entire path of nodes from the	**/	/** source to the destination with the source	**/	/** node at the head of the list and the		**/	/** destination node at the tail. The input 	**/	/** list needs to be freed by the user			**/	FIN (manet_rte_path_display_dump (<args>));		/* 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, "manet_routes_dump", OMSC_EXT_FILE_GDF);		}		/* There should be atleast 2 nodes (source and destination)	*/	/* for it to be a valid route								*/	num_hops = op_prg_list_size (record_route_lptr);		/* Set the source name, destiation name, start 	*/	/* time and call reference number in the file	*/	src_addr_ptr = (InetT_Address*) op_prg_list_access (record_route_lptr, OPC_LISTPOS_HEAD);	inet_address_to_hname (*src_addr_ptr, src_node_name);	strcat (file_line_entry, src_node_name);	strcat (file_line_entry, ",");	dest_addr_ptr = (InetT_Address*) op_prg_list_access (record_route_lptr, OPC_LISTPOS_TAIL);	inet_address_to_hname (*dest_addr_ptr, dest_node_name);	strcat (file_line_entry, dest_node_name);	strcat (file_line_entry, ",");	sprintf (temp_str, "%0.2f", op_sim_time ());	strcat (file_line_entry, temp_str);	strcat (file_line_entry, ",");	sprintf (temp_str, "0");	strcat (file_line_entry, temp_str);	strcat (file_line_entry, ",");		/* Set the connection name to be (src_node_name)<->(dest_node_name)	*/	strcat (conn_name, src_node_name);	strcat (conn_name, "<->");	strcat (conn_name, dest_node_name);	strcat (file_line_entry, conn_name);	strcat (file_line_entry, ",");		/* Read the source node and intermediate nodes in the route	*/	for (count = 0; count < (num_hops - 1); count++)		{		strcat (file_line_entry, ",");				hop_addr_ptr = (InetT_Address*) op_prg_list_access (record_route_lptr, count);		inet_address_to_hname (*hop_addr_ptr, hop_node_name);		strcat (file_line_entry, hop_node_name);		strcat (file_line_entry, ",");						/* Append "None" for the link	*/		strcat (file_line_entry, "None");		}		/* Go to the next line	*/	strcat (file_line_entry, "\n");		/* Write this into the file.	*/	Oms_Ext_File_Info_Append (ext_file_handle, file_line_entry);	FOUT;	}	voidmanet_rte_ip_address_register (IpT_Interface_Info* own_iface_info_ptr)	{	static Boolean		global_list_created = OPC_FALSE;		/** This function is called to register the	**/	/** IP address of every node to select a 	**/	/** random destination by the manet RPG		**/	FIN (manet_rte_ip_address_register (<args>));	if (global_list_created == OPC_FALSE)		{		/* Create a list to hold the IP addresses	*/		global_ip_address_lptr = op_prg_list_create ();				global_list_created = OPC_TRUE;		}		op_prg_list_insert (global_ip_address_lptr, own_iface_info_ptr, OPC_LISTPOS_TAIL);		FOUT;	}InetT_Address*manet_rte_dest_ip_address_obtain (IpT_Interface_Info* own_iface_info_ptr)	{	int						num_dest;	int						num_attempts = 0;	int						dest_index;	Boolean					ipv6_enabled = OPC_FALSE;	Boolean					ipv4_enabled = OPC_FALSE;	InetT_Address			ipv4_address;	InetT_Address			ipv6_address;	InetT_Address			dest_address;	InetT_Address*			dest_address_ptr;	IpT_Interface_Info*		dest_iface_info_ptr;		/** This function picks a random destination	**/	/** IP address for the MANET RPG				**/	FIN (manet_rte_dest_ip_address_obtain (void));		/* Check if this node trying to get a destination	*/	/* has valid IPv6 and IPv4 addresses				*/	if (ip_rte_intf_ip_version_active (own_iface_info_ptr, InetC_Addr_Family_v6) == OPC_TRUE)		{		ipv6_enabled = OPC_TRUE;		ipv6_address = inet_rte_intf_addr_get (own_iface_info_ptr, InetC_Addr_Family_v6);		}	if (ip_rte_intf_ip_version_active (own_iface_info_ptr, InetC_Addr_Family_v4) == OPC_TRUE)		{		ipv4_enabled = OPC_TRUE;		ipv4_address = inet_rte_intf_addr_get (own_iface_info_ptr, InetC_Addr_Family_v4);		}		/* Get the number of possible destinations	*/	num_dest = op_prg_list_size (global_ip_address_lptr);		/* The number of destination have to be greater */	/* than only this one node calling the function	*/	if (num_dest <= 1)		FRET (OPC_NIL);		while (num_attempts <= num_dest)		{		/* Pick a destination uniformly	*/		dest_index = (int) op_dist_uniform (num_dest);				/* Get the randomly picked destination address	*/		dest_iface_info_ptr = (IpT_Interface_Info*) op_prg_list_access (global_ip_address_lptr, dest_index);				if (ipv6_enabled)			{			/* Check if the destination also has IPv6 address	*/			if (ip_rte_intf_ip_version_active (dest_iface_info_ptr, InetC_Addr_Family_v6) == OPC_TRUE)				{				/* Get the destination IPv6 address	*/				dest_address = inet_rte_intf_addr_get (dest_iface_info_ptr, InetC_Addr_Family_v6);								/* Make sure the destination is not this node itself	*/				if (inet_address_equal (dest_address, ipv6_address) == OPC_FALSE)					break;				}			}				if (ipv4_enabled)			{			/* Check if the destination also has IPv4 address	*/			if (ip_rte_intf_ip_version_active (dest_iface_info_ptr, InetC_Addr_Family_v4) == OPC_TRUE)				{				/* Get the destination IPv4 address	*/				dest_address = inet_rte_intf_addr_get (dest_iface_info_ptr, InetC_Addr_Family_v4);								/* Make sure the destination is not this node itself	*/				if (inet_address_equal (dest_address, ipv4_address) == OPC_FALSE)					break;				}			}				num_attempts++;		}		/* Return a copy of the address	*/	dest_address_ptr = inet_address_create_dynamic (dest_address);		FRET (dest_address_ptr);	}			static Manet_Rte_Invoke_Data*manet_rte_invoke_data_mem_alloc (void)	{	Manet_Rte_Invoke_Data*		manet_data_ptr = OPC_NIL;		/** Allocates memory for invoking ip_dispatch	**/	/** in the same event that ip_dispatch invoked	**/	/** this process.								**/	FIN (manet_rte_invoke_data_mem_alloc (void));		manet_data_ptr = (Manet_Rte_Invoke_Data*) op_prg_mem_alloc (sizeof (Manet_Rte_Invoke_Data));	manet_data_ptr->ip_module_data_ptr = OPC_NIL;	manet_data_ptr->ip_pkptr = OPC_NIL;		FRET (manet_data_ptr);	}static voidmanet_rte_invoke_data_mem_free (Manet_Rte_Invoke_Data* manet_data_ptr)	{	/** Frees the memory allocated for the manet	**/	/** procedure interrupt							**/	FIN (manet_rte_invoke_data_mem_free (<args>));		op_prg_mem_free (manet_data_ptr);		FOUT;	}static voidmanet_rte_error (const char* str1, const char* str2, const char* str3)	{	/** This function generates an error and	**/	/** terminates the simulation				**/	FIN (dsr_rte_error <args>);		op_sim_end ("MANET Routing Process : ", str1, str2, str3);		FOUT;	}

⌨️ 快捷键说明

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