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

📄 manet_tora_imep.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 3 页
字号:
	int									list_size, index, cache_period;	static List*						node_cache_lptr = OPC_NIL;	ToraT_Ip_Deliver_List_Entry			*cache_entry_ptr = OPC_NIL, *tmp_cache_entry_ptr;	IpT_Dgram_Fields*					pk_fd_ptr;	Boolean								is_unicast;	static double						ip_deliver_cache_refresh_rate =	-1.0;	InetT_Address 						compare_address_A;	InetT_Address 						compare_address_B;			/** PURPOSE: Deliver the packet to the closeby neighbors bypassing lower layers.**/	/** REQUIRES: packet to send and distance info to neighbors.					**/	/** EFFECTS: packets will be copied and delivered. 								**/	FIN (tora_imep_sup_packet_deliver (pk_ptr, node_objid));		if (max_dist == -1)		{		/* Access the max distance information. */		op_ima_sim_attr_get (OPC_IMA_INTEGER, "TORA Max Communication Distance", &max_dist);		}		if (ip_deliver_cache_refresh_rate == -1.0)		{		/* Access the max distance information. */		op_ima_sim_attr_get (OPC_IMA_DOUBLE, "TORA IMEP Packet Delivery Cache Update", 			&ip_deliver_cache_refresh_rate);		}	if (node_cache_lptr == OPC_NIL)		{		node_cache_lptr = op_prg_list_create ();		}		/* Get the destination. */	op_pk_nfd_access (pk_ptr, "fields", &pk_fd_ptr);	compare_address_A = pk_fd_ptr->dest_addr;	compare_address_B = inet_address_copy (InetI_Imep_Mcast_Addr);	if (inet_address_equal (compare_address_A, compare_address_B) == OPC_TRUE)		{		is_unicast = OPC_FALSE;		}	else		{		is_unicast = OPC_TRUE;		}	/* Check the cache for the entry for me. */	cache_period = (int) (op_sim_time () / ip_deliver_cache_refresh_rate);	list_size = op_prg_list_size (node_cache_lptr);	for (index=0; index < list_size; index++)		{		tmp_cache_entry_ptr = (ToraT_Ip_Deliver_List_Entry*) op_prg_list_access (node_cache_lptr, index);				if (tmp_cache_entry_ptr->nd_objid == nd_objid)			{			/* Found the cache entry.*/			cache_entry_ptr = tmp_cache_entry_ptr;						if (cache_period == cache_entry_ptr->last_update_period)				{				/* We can reuse the cached information. */				list_size = op_prg_list_size (cache_entry_ptr->node_lptr);				for (index=0; index < list_size; index++)					{					tmp_topo_struct_ptr = (ToraT_Topo_Struct*) 						op_prg_list_access (cache_entry_ptr->node_lptr, index);										/* This neighbor can hear me. */					if (is_unicast)						{						compare_address_A = pk_fd_ptr->dest_addr;						compare_address_B = inet_address_from_ipv4_address_create (tmp_topo_struct_ptr->ip_addr);						if (inet_address_equal (compare_address_A, compare_address_B) == OPC_TRUE)							{							/* Matching unicast address. */							op_ici_install (OPC_NIL);							op_pk_deliver_delayed (pk_ptr, tmp_topo_struct_ptr->module_objid, tmp_topo_struct_ptr->stream_from_tora_interface, 								ToraC_Del_Delay);														FOUT;							}						}					else						{						op_ici_install (OPC_NIL);						op_pk_deliver_delayed (op_pk_copy (pk_ptr), 							tmp_topo_struct_ptr->module_objid, tmp_topo_struct_ptr->stream_from_tora_interface, ToraC_Del_Delay);						}					}								op_pk_destroy (pk_ptr);								FOUT;				}			else								break;							}		}		if (!cache_entry_ptr)		{		/* First time for the entry. */		cache_entry_ptr = (ToraT_Ip_Deliver_List_Entry*) op_prg_mem_alloc 			(sizeof (ToraT_Ip_Deliver_List_Entry));		cache_entry_ptr->node_lptr = op_prg_list_create ();		}		/* Update the cached node list. */	cache_entry_ptr->last_update_period = cache_period;	cache_entry_ptr->nd_objid = nd_objid;	while (op_prg_list_size (cache_entry_ptr->node_lptr))		{		/* Remove old information. */		op_prg_list_remove (cache_entry_ptr->node_lptr, OPC_LISTPOS_HEAD);		}		/* Access my current position. */	op_ima_obj_pos_get (nd_objid, &tx_lat, &tx_lon, &tx_alt, &tx_x, &tx_y, &tx_z);		/* Calculate the distance between me and the neighbors in the list. */	list_size = op_prg_list_size (global_tora_node_lptr);	for (index=0; index < list_size; index++)		{		tmp_topo_struct_ptr = (ToraT_Topo_Struct*) op_prg_list_access (global_tora_node_lptr, index);				if (tmp_topo_struct_ptr->node_objid == nd_objid)			{			/* It's me. */			continue;			}				/* Find the position of the neighbor. */		op_ima_obj_pos_get (tmp_topo_struct_ptr->node_objid, 			&rx_lat, &rx_lon, &rx_alt, &rx_x, &rx_y, &rx_z);		/* Calculate the distance. */		distance = prg_geo_lat_long_distance_get 			(tx_lat, tx_lon, tx_alt, rx_lat, rx_lon, rx_alt);				if ((double) max_dist >= distance)			{			if (is_unicast)				{				compare_address_A = pk_fd_ptr->dest_addr;				compare_address_B = inet_address_from_ipv4_address_create (tmp_topo_struct_ptr->ip_addr);				if (inet_address_equal (compare_address_A, compare_address_B) == OPC_TRUE)					{					/* Matching unicast address. */					op_pk_deliver_delayed (op_pk_copy (pk_ptr), 						tmp_topo_struct_ptr->module_objid, tmp_topo_struct_ptr->stream_from_tora_interface, ToraC_Del_Delay);					}				}			else				{				op_pk_deliver_delayed (op_pk_copy (pk_ptr), 					tmp_topo_struct_ptr->module_objid, tmp_topo_struct_ptr->stream_from_tora_interface, ToraC_Del_Delay);				}						/* Cache the information. */			op_prg_list_insert (cache_entry_ptr->node_lptr, tmp_topo_struct_ptr, OPC_LISTPOS_TAIL);			}		}		/* Enter the entry to the global list. */	op_prg_list_insert (node_cache_lptr, cache_entry_ptr, OPC_LISTPOS_TAIL);	op_pk_destroy (pk_ptr);		FOUT;	}voidtora_imep_sup_rid_to_ip_addr (int neighbor_rid, IpT_Address* neighbor_address)	{	int							list_size, index;	ToraT_Topo_Struct*			tmp_topo_struct_ptr;		/** PURPOSE: Get the ip address from the Router ID.	**/	/** REQUIRES: Global Neighbor list.					**/	/** EFFECTS: Address is filled and returned. 		**/	FIN (tora_imep_sup_rid_to_ip_addr (neighbor_rid, neighbor_address));	  	/* Find the entry in the global node list. */	list_size = op_prg_list_size (global_tora_node_lptr);	for (index=0; index <  list_size; index++)		{		tmp_topo_struct_ptr = (ToraT_Topo_Struct*) op_prg_list_access 			(global_tora_node_lptr, index);				if (tmp_topo_struct_ptr->rid == neighbor_rid)			{			/* Found it. */			*neighbor_address = tmp_topo_struct_ptr->ip_addr;						FOUT;			}		}		op_sim_end ("error...", OPC_NIL, OPC_NIL, OPC_NIL);	}ToraT_Topo_Struct*tora_imep_sup_ip_addr_to_rid (int* neighbor_rid, IpT_Address neighbor_address)	{	/* Purpose: Function returns the router ID for a given IP Address */	/* Requires: Global neighbor list 								  */	/* Effects: The neighbor router ID is filled and returned.		  */	int list_size, counter;	ToraT_Topo_Struct*	tmp_topo_struct_ptr;		FIN (tora_imep_sup_ip_addr_to_rid (neighbor_rid, neighbor_address))		list_size = op_prg_list_size (global_tora_node_lptr);	for (counter = 0; counter < list_size; counter ++)		{		tmp_topo_struct_ptr = (ToraT_Topo_Struct*) op_prg_list_access (global_tora_node_lptr, counter);				if (ip_address_equal (tmp_topo_struct_ptr->ip_addr, neighbor_address) == OPC_TRUE)			{			*neighbor_rid = tmp_topo_struct_ptr->rid;			FRET (tmp_topo_struct_ptr);			}		}		/* For error handling */		*neighbor_rid = -1;		FRET (OPC_NIL);		}ToraT_Topo_Struct*tora_imep_lan_addr_to_router (IpT_Address dest_address)	{	/* Purpose: Function returns the router ID for a given LAN address */	/* Requires: Global neighbor list 								   */	/* Effects: The neighbor router ID is filled and returned.		   */	int list_size, counter;	ToraT_Topo_Struct*	tmp_topo_struct_ptr;		FIN (tora_imep_sup_lan_addr_to_router (dest_address))		list_size = op_prg_list_size (global_tora_node_lptr);	for (counter = 0; counter < list_size; counter ++)		{		tmp_topo_struct_ptr = (ToraT_Topo_Struct*) op_prg_list_access (global_tora_node_lptr, counter);				if (tmp_topo_struct_ptr->lan_intf_info_ptr)			{			/* Check and see if the dest fall into the range. */			if (ip_address_range_check (dest_address, ip_rte_intf_addr_range_get 				(tmp_topo_struct_ptr->lan_intf_info_ptr)) == OPC_TRUE)				{				FRET (tmp_topo_struct_ptr);				}			}		}			 FRET (OPC_NIL);	}voidtora_imep_sup_debug_comm_reg (void)	{	static Boolean	init = OPC_FALSE;		/* Register debugging command ODB. */	if (!init)		{		op_prg_odb_command_register ("manet_tora",			"manet_tora", "", "", "", tora_imep_sup_status_display,			OPC_NIL, OPC_NIL);				init = OPC_TRUE;		}	}inttora_imep_sup_status_display (const char* PRG_ARG_UNUSED (dummy1), void* PRG_ARG_UNUSED (dummy2))	{	int 							list_size, index;	ToraT_Topo_Struct*				tmp_topo_struct_ptr;	char							ip_addr [32], node_name [256];		/** PURPOSE: Display some info about the tora managers in the net.		**/	/** REQUIRES: Global topo list.											**/	/** EFFECTS: Output to the ODB prompt. 									**/	FIN (tora_imep_sup_status_display (void));		printf ("\n\t*** TORA Node Info Table ***");	printf ("\n\tNode Name\tMgr PID\tIMEP PID\tRouter ID\tIP Address");	printf ("\n\t=======================================================");		if (global_tora_node_lptr)		{		list_size = op_prg_list_size (global_tora_node_lptr);			for (index=0; index <  list_size; index++)			{			tmp_topo_struct_ptr = (ToraT_Topo_Struct*) op_prg_list_access 				(global_tora_node_lptr, index);				ip_address_print (ip_addr, tmp_topo_struct_ptr->ip_addr);			op_ima_obj_attr_get (tmp_topo_struct_ptr->node_objid, "name", node_name);			printf ("\n\t%s\t%d\t%d\t%d\t%s", node_name, tmp_topo_struct_ptr->mgr_pro_id,				tmp_topo_struct_ptr->imep_pro_id, tmp_topo_struct_ptr->rid, ip_addr);			}		}		FRET (0);	}voidtora_imep_support_animation_init ()	{	char 									net_name [128];	char 									subnet_name [128];	static Boolean 							animation_init = OPC_FALSE;	/* Purpose: Initialization function for the animation of Tora and Imep */	/* Requires: Custom animation probe created.						   */	/* Effects: Gets the viewer ID for animation in Tora and Imep.		   */	FIN (tora_imep_support_animation_init ());		if (!animation_init)		{				/* Done with the initializations - just go ahead and reset the bool variable*/		animation_init = OPC_TRUE;		Tora_ImepI_Anvid = op_anim_lprobe_anvid ("MANET");				if ((OPC_ANIM_ANVID_NONE == Tora_ImepI_Anvid) ||			(OPC_ANIM_ID_NIL == Tora_ImepI_Anvid))				{			tora_animation_requested = OPC_FALSE;			FOUT;			}		else			{			op_ima_sim_attr_get (OPC_IMA_STRING, "net_name", &net_name);			Imep_Subnet_Objid = op_topo_child (0, OPC_OBJMTYPE_SITE, 0);			op_ima_obj_attr_get (Imep_Subnet_Objid, "name", &subnet_name);			op_anim_ime_nmod_draw (Tora_ImepI_Anvid, OPC_ANIM_MODTYPE_NETWORK, net_name, subnet_name,				OPC_ANIM_MOD_OPTION_NONE, OPC_ANIM_DEFPROPS);

⌨️ 快捷键说明

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