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

📄 manet_support.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/* manet_support_api.ex.c *//* C file for MANET APIs to interface to IP *//****************************************//*		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 <ip_addr_v4.h>#include <ip_rte_support.h>#include <ip_rte_v4.h>#include <ip_dgram_sup.h>#include <manet.h>/*----- (SECTION - GLOBAL VARIABLE DECLARATIONS)------------------*//* Following variables are visible to functions in this file only *//* An external function needs to call xxx_get () functions in this*//* file to obtain reference to following variables.				  *//*----------------------------------------------------------------*/ /* Global IP address list maintained to obtain a random	*//* IP address destination for a flow					*/static List*		global_ip_address_lptr = OPC_NIL;/***** Prototypes *****/static Manet_Rte_Invoke_Data*		manet_rte_invoke_data_mem_alloc (void);static void							manet_rte_invoke_data_mem_free (Manet_Rte_Invoke_Data*);static void							manet_rte_error (const char* str1, const char* str2, const char* str3);/***** APIs *****/voidmanet_rte_to_higher_layer_pkt_send_schedule (IpT_Rte_Module_Data* module_data_ptr, Prohandle manet_mgr_prohandle, 										Packet* ip_dgram_pkptr)	{	Manet_Rte_Invoke_Data* 			manet_data_ptr = OPC_NIL;		/** Schedules an event for the current simulation time	**/	/** to invoke IP to send the reply packet. The event at	**/	/** this functions gets called is a process invocation	**/	/** for this process from IP. The new event will allow	**/	/** invocation of the IP process as it will not be the 	**/	/** same event that IP was invoked						**/	FIN (manet_rte_to_higher_layer_pkt_send_schedule(<args>));		/** Allocate memory to store information to	**/	/** invoke the IP process					**/	manet_data_ptr = manet_rte_invoke_data_mem_alloc ();	manet_data_ptr->ip_module_data_ptr = module_data_ptr;	manet_data_ptr->manet_mgr_phandle = manet_mgr_prohandle;	manet_data_ptr->ip_pkptr = ip_dgram_pkptr;		/* Use procedure interrupt mechanism to call the IP	*/	/* routing process invoker function.				*/	op_intrpt_schedule_call (op_sim_time (), PKT_TO_HIGHER_LAYER, 		manet_rte_ip_process_invoker, manet_data_ptr);		FOUT;	}voidmanet_rte_to_cpu_pkt_send_schedule (IpT_Rte_Module_Data* module_data_ptr, Prohandle manet_mgr_prohandle, 										int manet_mgr_process_id, Packet* ip_dgram_pkptr)	{	Manet_Rte_Invoke_Data* 			manet_data_ptr = OPC_NIL;		/** Schedules an event for the current simulation time	**/	/** to invoke IP to send the reply packet. The event at	**/	/** this functions gets called is a process invocation	**/	/** for this process from IP. The new event will allow	**/	/** invocation of the IP process as it will not be the 	**/	/** same event that IP was invoked						**/	FIN (manet_rte_to_cpu_pkt_send_schedule (<args>));		/** Allocate memory to store information to	**/	/** invoke the IP process					**/	manet_data_ptr = manet_rte_invoke_data_mem_alloc ();	manet_data_ptr->ip_module_data_ptr = module_data_ptr;	manet_data_ptr->manet_mgr_phandle = manet_mgr_prohandle;	manet_data_ptr->manet_mgr_pro_id = manet_mgr_process_id;	manet_data_ptr->ip_pkptr = ip_dgram_pkptr;		/* Use procedure intruupt mechanism to call the IP	*/	/* routing process invoker function.				*/	op_intrpt_schedule_call (op_sim_time (), PKT_TO_CPU, manet_rte_ip_process_invoker, manet_data_ptr);		FOUT;	}voidmanet_rte_to_cpu_pkt_send_schedule_with_jitter (IpT_Rte_Module_Data* module_data_ptr, Prohandle manet_mgr_prohandle, 										int manet_mgr_process_id, Packet* ip_dgram_pkptr)	{	Manet_Rte_Invoke_Data* 			manet_data_ptr = OPC_NIL;	double							jitter;		/** Schedules an event for the current simulation time	**/	/** to invoke IP to send the reply packet. The event at	**/	/** this functions gets called is a process invocation	**/	/** for this process from IP. The new event will allow	**/	/** invocation of the IP process as it will not be the 	**/	/** same event that IP was invoked						**/	FIN (manet_rte_to_cpu_pkt_send_schedule (<args>));		/* Adding jitter between 0 and 0.01 before sending out packets */	jitter = op_dist_uniform (0.01);		/** Allocate memory to store information to	**/	/** invoke the IP process					**/	manet_data_ptr = manet_rte_invoke_data_mem_alloc ();	manet_data_ptr->ip_module_data_ptr = module_data_ptr;	manet_data_ptr->manet_mgr_phandle = manet_mgr_prohandle;	manet_data_ptr->manet_mgr_pro_id = manet_mgr_process_id;	manet_data_ptr->ip_pkptr = ip_dgram_pkptr;		/* Use procedure intruupt mechanism to call the IP	*/	/* routing process invoker function.				*/	op_intrpt_schedule_call (op_sim_time () + jitter, PKT_TO_CPU, manet_rte_ip_process_invoker, manet_data_ptr);		FOUT;	}voidmanet_rte_ip_process_invoker (void* generic_manet_data_ptr, int code)	{	Manet_Rte_Invoke_Data* manet_data_ptr = OPC_NIL; 	/** Cover function to call the IP process invocation	**/	/** function. This function is called as a result of	**/	/** a procedure interrupt.								**/	FIN (manet_rte_ip_process_invoker (<args>));		manet_data_ptr = (Manet_Rte_Invoke_Data*) generic_manet_data_ptr;		if (code == PKT_TO_CPU)		{		/* Pass the IP datagram to IP routing process for	*/		/* further processing.								*/		manet_rte_to_cpu_pkt_send (manet_data_ptr->ip_module_data_ptr, manet_data_ptr->manet_mgr_phandle, 								manet_data_ptr->manet_mgr_pro_id, manet_data_ptr->ip_pkptr);		}	else if (code == PKT_TO_HIGHER_LAYER)		{		manet_rte_to_higher_layer_pkt_send (manet_data_ptr->ip_module_data_ptr, manet_data_ptr->manet_mgr_phandle, 											manet_data_ptr->ip_pkptr);		}	else		{		manet_rte_error ("Invalid code received in procedure interrupt", OPC_NIL, OPC_NIL);		}		/* Free the memory allocated for this procedure interrupt	*/	manet_rte_invoke_data_mem_free (manet_data_ptr);	FOUT;	}voidmanet_rte_to_cpu_pkt_send (IpT_Rte_Module_Data* module_data_ptr, Prohandle manet_mgr_prohandle, 							int manet_mgr_process_id, Packet* ip_dgram_pkptr)	{	/** Send the packet to the IP CPU process	**/	/** as this packet needs to be processed	**/	/** before being sent out to the MAC layer	**/	FIN (manet_rte_to_cpu_pkt_send (<args>));		/* Install the IP packet in the memory being shared with IP	*/	/* (note that IP gets packets from its child processes		*/	/* using this approach.)									*/	module_data_ptr->ip_ptc_mem.child_pkptr = ip_dgram_pkptr;	module_data_ptr->ip_ptc_mem.child_process_id = manet_mgr_process_id;	/* Invoke IP process model, which routes the IP datagram	*/	/* containing the DSR packet to the destination address.	*/	op_pro_invoke (manet_mgr_prohandle, OPC_NIL);	FOUT;	}voidmanet_rte_to_higher_layer_pkt_send (IpT_Rte_Module_Data* module_data_ptr, Prohandle manet_mgr_prohandle, 									Packet* ip_dgram_pkptr)	{	/** Send the IP datagram to the higher layer **/	FIN (manet_rte_to_higher_layer_pkt_send (<args>));		/* Set the packet in the argument memory to be	*/	/* sent to the higher layer from this process	*/	module_data_ptr->ip_ptc_mem.child_pkptr = OPC_NIL;	op_pro_invoke (manet_mgr_prohandle, ip_dgram_pkptr);		FOUT;	}voidmanet_rte_to_mac_pkt_send_options (IpT_Rte_Module_Data* module_data_ptr, Packet* ip_pkptr, InetT_Address next_hop_addr, 			IpT_Dgram_Fields* ip_dgram_fd_ptr, IpT_Rte_Ind_Ici_Fields* intf_ici_fdstruct_ptr, int output_intf_index)	{	IpT_Interface_Info*		iface_info_ptr;	int						outstrm;	InetT_Address_Range* 	inet_addr_range_ptr;	InetT_Addr_Family		addr_family;	int						slot_index;	short					intf_index;		/** Send the packet out directly to the	**/	/** outgoing interface as this packet 	**/	/** has already been processed by the 	**/	/** IP CPU process and no further 		**/	/** processing is needed on this packet	**/	FIN (manet_rte_to_mac_pkt_send_options (<args>));		if (output_intf_index != IPC_INTF_INDEX_INVALID)		{		/* A valid outgoing interface has been provided by 	*/		/* the calling process. Get the interface_info_ptr	*/		/* AODV protocol usually provides the outgoing intf	*/		iface_info_ptr = inet_rte_intf_tbl_access (module_data_ptr, output_intf_index);		}	else		{		/* Determine the outgoing interface index */		if (ip_rte_destination_local_network (module_data_ptr, next_hop_addr, &intf_index,										 &iface_info_ptr, &outstrm, &inet_addr_range_ptr) == OPC_COMPCODE_FAILURE)			{			/* Unable to determine the outgoing interface	*/			/* as there is no matching interface with the 	*/			/* same local network							*/			manet_rte_error ("manet_rte_to_mac_pkt_send. Unable to determine the outgoing interface", OPC_NIL, OPC_NIL);			}		output_intf_index = (int) intf_index;		}		/* Set the interface info in the interface ICI	*/	intf_ici_fdstruct_ptr->output_intf_index = output_intf_index;	intf_ici_fdstruct_ptr->output_subintf_index = ip_rte_minor_port_from_intf_table_index_get													(module_data_ptr, output_intf_index);	intf_ici_fdstruct_ptr->interface_type 	 = ip_rte_intf_type_get (iface_info_ptr);	intf_ici_fdstruct_ptr->outstrm 		  	 = ip_rte_intf_outstrm_get (iface_info_ptr, ip_pkptr, &slot_index);	intf_ici_fdstruct_ptr->outslot 		  	 = ip_rte_intf_slot_index_get (iface_info_ptr);	intf_ici_fdstruct_ptr->iface_speed 	  	 = ip_rte_intf_link_bandwidth_get (iface_info_ptr);	intf_ici_fdstruct_ptr->next_addr 		 = next_hop_addr;	/* Get the family the IP address next hop belongs to	*/	addr_family = inet_address_family_get (&next_hop_addr);		/* Get the interface MTU size	*/	intf_ici_fdstruct_ptr->output_mtu 		 = inet_rte_intf_mtu_get (iface_info_ptr, addr_family);		/* Send the packet to the next hop	*/	ip_rte_datagram_interface_forward_direct (module_data_ptr,  										ip_pkptr, intf_ici_fdstruct_ptr);		FOUT;	}intmanet_rte_interface_mtu_size_get (IpT_Rte_Module_Data* module_data_ptr, InetT_Address next_hop_addr)	{	IpT_Interface_Info*		iface_info_ptr = OPC_NIL;	InetT_Address_Range* 	inet_addr_range_ptr;	int						outstrm;	short					output_intf_index;	int						intf_mtu;	InetT_Addr_Family		addr_family;		/** Returns the MTU size for the interface	**/	/** to which this next hop node is connected**/	FIN (manet_rte_interface_mtu_size_get (<args>));		/* Determine the outgoing interface index	*/	if (ip_rte_destination_local_network (module_data_ptr, next_hop_addr, &output_intf_index,								&iface_info_ptr, &outstrm, &inet_addr_range_ptr) == OPC_COMPCODE_FAILURE)		{		/* Unable to determine the outgoing interface	*/		/* as there is no matching interface with the 	*/		/* same local network							*/		manet_rte_error ("Unable to determine the outgoing interface", OPC_NIL, OPC_NIL);		}		/* Get the family the IP address next hop belongs to	*/	addr_family = inet_address_family_get (&next_hop_addr);		/* Get the interface MTU size	*/	intf_mtu = inet_rte_intf_mtu_get (iface_info_ptr, addr_family);		FRET (intf_mtu);	}voidmanet_rte_datagram_broadcast (IpT_Rte_Module_Data* module_data_ptr, Packet* ip_pkptr)	{	Ici*						pkt_info_ici_ptr;	IpT_Rte_Ind_Ici_Fields* 	intf_ici_fdstruct_ptr;		/** Broadcasts the IP datagram on all	**/	/** interfaces on this node				**/	FIN (manet_rte_datagram_broadcast (<args>));		/* Get the ICI associated with the packet	*/	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_ptr);		/* Set the packet as if it was being generated	*/	/* by this child process of IP to re-broadcast	*/	intf_ici_fdstruct_ptr->instrm = IpC_Pk_Instrm_Child;		/* Set the incoming packet information	*/	op_ici_attr_set (pkt_info_ici_ptr, "rte_info_fields", intf_ici_fdstruct_ptr);		/* Set the ICI in the packet	*/	op_pk_ici_set (ip_pkptr, pkt_info_ici_ptr);		/* Broadcast the datagram on all interfaces	*/	/* on this node								*/	intf_ici_fdstruct_ptr->output_intf_index = IP_BROADCAST_ALL_INTERFACES;	inet_rte_datagram_broadcast (module_data_ptr, 				ip_pkptr,  				intf_ici_fdstruct_ptr);		FOUT;	}InetT_Addressmanet_rte_rcvd_interface_address_get (IpT_Rte_Module_Data* module_data_ptr,	IpT_Rte_Ind_Ici_Fields* intf_ici_fdstruct_ptr, InetT_Addr_Family addr_family)	{	IpT_Interface_Info *	iface_elem_ptr = OPC_NIL;	InetT_Address			rcvd_intf_addr;		/** Determines the address of the interface	**/	/** on which the packet was received		**/	FIN (manet_rte_rcvd_interface_address_get (<args>));		/* Get the interface_info of the interface specified.					*/	iface_elem_ptr = inet_rte_intf_tbl_access (module_data_ptr, intf_ici_fdstruct_ptr->intf_recvd_index);		/* Get the received interface address	*/	rcvd_intf_addr = inet_rte_intf_addr_get (iface_elem_ptr, addr_family);		FRET (rcvd_intf_addr);	}Booleanmanet_rte_address_belongs_to_node (IpT_Rte_Module_Data* module_data_ptr, InetT_Address node_address)	{	IpT_Interface_Info*		iface_info_ptr = OPC_NIL;

⌨️ 快捷键说明

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