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

📄 aodv_app_manager.pr.c

📁 opnet ad hoc adov routing
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: aodv_app_manager.pr.c *//* Portions of this file copyright 1992-2001 by OPNET Technologies, Inc. *//* This variable carries the header into the object file */static const char aodv_app_manager_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A op_runsim 7 3C064A56 3C064A56 1 manet.antd.nist.gov lmiller 0 0 none none 0 0 none 0 0 0 0 0 0                                                                                                                                                                                                                                                                                                                                                                                                        ";#include <string.h>/* OPNET system definitions */#include <opnet.h>#if defined (__cplusplus)extern "C" {#endifFSM_EXT_DECS#if defined (__cplusplus)} /* end of 'extern "C"' */#endif/* Header Block */#define UPP_INPUT_STRM   0#define LOW_INPUT_STRM   1#define LOW_OUTPUT_STRM  0#define UPP_OUTPUT_STRM  1/* transition codes */#define INIT_CODE        0#define CHANGE_DEST_CODE 1/* transition macro */#define UPP_ARVL ( op_intrpt_type () == OPC_INTRPT_STRM && op_intrpt_strm() == UPP_INPUT_STRM)#define LOW_ARVL ( op_intrpt_type () == OPC_INTRPT_STRM && op_intrpt_strm() == LOW_INPUT_STRM)#define INIT     ( op_intrpt_type () == OPC_INTRPT_SELF && op_intrpt_code() == INIT_CODE)#define CHANGE_DEST    ( op_intrpt_type () == OPC_INTRPT_SELF && op_intrpt_code() == CHANGE_DEST_CODE)/* interlocutor values */#define NONE -2#define RANDOM -1/* Global variable */int num_nodes;int NB_FLOWS_AVAIL = 15;int NB_FLOWS       = 15;/* End of Header Block */#if !defined (VOSD_NO_FIN)#undef	BIN#undef	BOUT#define	BIN		FIN_LOCAL_FIELD(last_line_passed) = __LINE__ - _block_origin;#define	BOUT	BIN#define	BINIT	FIN_LOCAL_FIELD(last_line_passed) = 0; _block_origin = __LINE__;#else#define	BINIT#endif /* #if !defined (VOSD_NO_FIN) *//* State variable definitions */typedef struct	{	/* Internal state tracking for FSM */	FSM_SYS_STATE	/* State Variables */	int	                    		DEBUG;	int	                    		node_addr;	int	                    		node_id;	int	                    		INTERLOCUTOR;	int	                    		GRAT_RATIO;	Distribution *	         		grat_dist;	Distribution *	         		address_dist;	int	                    		dest;	int	                    		SRC_ACTIVE;	} aodv_app_manager_state;#define pr_state_ptr            		((aodv_app_manager_state*) SimI_Mod_State_Ptr)#define DEBUG                   		pr_state_ptr->DEBUG#define node_addr               		pr_state_ptr->node_addr#define node_id                 		pr_state_ptr->node_id#define INTERLOCUTOR            		pr_state_ptr->INTERLOCUTOR#define GRAT_RATIO              		pr_state_ptr->GRAT_RATIO#define grat_dist               		pr_state_ptr->grat_dist#define address_dist            		pr_state_ptr->address_dist#define dest                    		pr_state_ptr->dest#define SRC_ACTIVE              		pr_state_ptr->SRC_ACTIVE/* This macro definition will define a local variable called	*//* "op_sv_ptr" in each function containing a FIN statement.	*//* This variable points to the state variable data structure,	*//* and can be used from a C debugger to display their values.	*/#undef FIN_PREAMBLE#define FIN_PREAMBLE	aodv_app_manager_state *op_sv_ptr = pr_state_ptr;/* No Function Block */enum { _block_origin = __LINE__ };/* Undefine optional tracing in FIN/FOUT/FRET *//* The FSM has its own tracing code and the other *//* functions should not have any tracing.		  */#undef FIN_TRACING#define FIN_TRACING#undef FOUTRET_TRACING#define FOUTRET_TRACING#if defined (__cplusplus)extern "C" {#endif	void aodv_app_manager (void);	Compcode aodv_app_manager_init (void **);	void aodv_app_manager_diag (void);	void aodv_app_manager_terminate (void);	void aodv_app_manager_svar (void *, const char *, char **);#if defined (__cplusplus)} /* end of 'extern "C"' */#endif/* Process model interrupt handling procedure */voidaodv_app_manager (void)	{	int _block_origin = 0;	FIN (aodv_app_manager ());	if (1)		{		Objid	     			 params_comp_attr_objid;		Objid                    params_attr_objid;		/* Packet reception */		int pk_type,dest_ip_addr;		/* Packet Transmission */		Packet *pkptr, *rx_pk_ptr;		int   grat_outcome, g_flag;		/* Service request to routing layer */		Ici * ici_ptr, *rx_ici_ptr;		int   segment_count;		int   i;		int   a_requested;		double wait_time;		FSM_ENTER (aodv_app_manager)		FSM_BLOCK_SWITCH			{			/*---------------------------------------------------------*/			/** state (init) enter executives **/			FSM_STATE_ENTER_FORCED (0, state0_enter_exec, "init", "aodv_app_manager () [init enter execs]")				{				// Trace				if(DEBUG > 0)					{					printf("\n<node %d @ app manager>  INIT ::\n", node_addr);					printf("                         - Current time = %f\n", op_sim_time());					printf("                         - Flows avail  = %d\n", NB_FLOWS_AVAIL);					}				// Proceed only if there is more than one node in the network, and if there is at least				// a flow available				if(num_nodes > 1 && NB_FLOWS_AVAIL > 0)					{					// If Interlocutor is different than random or none, then set the dest					// variable to the specified destinatio address, and reserve a flow					if(INTERLOCUTOR != RANDOM && INTERLOCUTOR != NONE)						{								// Reserve a flow						NB_FLOWS_AVAIL--;						// Set destination						dest = INTERLOCUTOR;						}					// If Interlocutor is set to none, then src is not active					else if(INTERLOCUTOR == NONE)						{						// Set dest to none. Src will be silent						dest = NONE;						}					// If Interlocutor is set to random, then pick up a random destination					// and reserve a flow					else if(INTERLOCUTOR == RANDOM)						{						// Reserve a flow						NB_FLOWS_AVAIL--;								// Load distribution						address_dist = op_dist_load ("uniform_int", 0, (num_nodes-1));						// Pick a random destination						dest = (int) op_dist_outcome (address_dist);						// Repeat until dest is valid						while (node_addr == dest)							{							dest = (int) op_dist_outcome (address_dist);							}						}					}				else 					{					if(NB_FLOWS_AVAIL < 1)						if(DEBUG > 0) printf("                         - No more spot left (%d flows avail)\n", NB_FLOWS_AVAIL);					// No more spots are left. source will be silent					dest = NONE;					}				if(DEBUG > 0) printf("                         - Dest is      = %d (None = -2, Rand = -1)\n",dest);				}			/** state (init) exit executives **/			FSM_STATE_EXIT_FORCED (0, "init", "aodv_app_manager () [init exit execs]")				{				}			/** state (init) transition processing **/			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "idle")				/*---------------------------------------------------------*/			/** state (idle) enter executives **/			FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "idle", "aodv_app_manager () [idle enter execs]")				{								}			/** blocking after enter executives of unforced state. **/			FSM_EXIT (3,aodv_app_manager)			/** state (idle) exit executives **/			FSM_STATE_EXIT_UNFORCED (1, "idle", "aodv_app_manager () [idle exit execs]")				{				}			/** state (idle) transition processing **/			FSM_INIT_COND (LOW_ARVL)			FSM_TEST_COND (UPP_ARVL)			FSM_DFLT_COND			FSM_TEST_LOGIC ("idle")			FSM_TRANSIT_SWITCH				{				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "LOW_ARVL", "", "idle", "rx")				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "UPP_ARVL", "", "idle", "tx")				FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "default", "", "idle", "idle")				}				/*---------------------------------------------------------*/			/** state (rx) enter executives **/			FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "rx", "aodv_app_manager () [rx enter execs]")				{				// Read associated ICI				rx_ici_ptr = op_intrpt_ici();				op_ici_attr_get(rx_ici_ptr,"Source",&dest_ip_addr);				op_ici_destroy(rx_ici_ptr);								// Destroy packet from upcoming stream				rx_pk_ptr = op_pk_get (LOW_INPUT_STRM);				op_pk_nfd_get(rx_pk_ptr, "A", &a_requested);				op_pk_destroy(rx_pk_ptr);												// Send a data packet back to the source, in order to 				// fake a bi-directional comm.				if(a_requested)					{					// Trace					if(DEBUG > 2)						{						printf("\n<node %d @ app manager><Time = %f> Data pk rcvd from %d: Sending pk back.\n", node_addr,op_sim_time(),dest_ip_addr);						}									// Generate packet					rx_pk_ptr = op_pk_create_fmt("AODV_DATA_PAYLOAD");					// Set A to 0					op_pk_nfd_set(rx_pk_ptr, "A", 0);					// Request a service from the routing layer					rx_ici_ptr = op_ici_create("service_req_routing");					op_ici_attr_set(rx_ici_ptr,"Dest", dest_ip_addr);					op_ici_attr_set(rx_ici_ptr,"G", 1);					op_ici_install(rx_ici_ptr);					// Send packet to lower layer					op_pk_send (rx_pk_ptr,LOW_OUTPUT_STRM);					}								}

⌨️ 快捷键说明

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