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

📄 aodv_app_sink.pr.c

📁 利用opnet对AODV过程进行编码
💻 C
字号:
/* Process model C form file: aodv_app_sink.pr.c *//* Portions of this file copyright 1992-2000 by OPNET Technologies, Inc. *//* This variable carries the header into the object file */static const char aodv_app_sink_pr_c [] = "MIL_3_Tfile_Hdr_ 70B 30A opnet 7 3B545F51 3B545F51 1 manet.antd.nist.gov guemari 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 */#include <stdio.h>#define IN_STRM		0#define PKT_RCVD	(op_intrpt_type () == OPC_INTRPT_STRM)#define END_SIM		(op_intrpt_type () == OPC_INTRPT_ENDSIM)typedef struct	{	int own_input;	int forward_input;	int own_output;	int forward_output;
	int data_pk_destroyed;
	int data_pk_buffer;
	int ack;	} StatBlock;extern StatBlock stats[50];extern int data_pk_buffer;extern int data_pk_destroyed;extern int output;extern int input;extern int ack;int subm_pkts;int rcv;int hop_number;int rcv_control;double total_power;double control_data_power;int total_hop_received;FILE* out;int pk_in_queue;int Replyfromtarget;int Replyfromrelay;int GratuitousReply;int RouteError;int totaldata;int dataserved;int data_count;int request_created;int non_propa_request;int renew_request;int renew_request_propa;int request_from_error;int error;int error_to_source;int packets_extracted;int packets_to_serve;int num_spare_route;int amazing_error;int canceled_reply;int mac_total_retry;int mac_failed;int mac_failed_data;int mac_failed_reply;int mac_failed_error;int mac_amazing_error;int mac_retry_rts;int mac_retry_data;int mac_retry_reply;int mac_retry_error;extern int getBufferSize(int);/* 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 */	Objid	                  		process_id;	char	                   		outfile_name[256];	int	                    		node_addr;	int	                    		DEBUG;	int	                    		node_id;	int	                    		num_nodes;	} aodv_app_sink_state;#define pr_state_ptr            		((aodv_app_sink_state*) SimI_Mod_State_Ptr)#define process_id              		pr_state_ptr->process_id#define outfile_name            		pr_state_ptr->outfile_name#define node_addr               		pr_state_ptr->node_addr#define DEBUG                   		pr_state_ptr->DEBUG#define node_id                 		pr_state_ptr->node_id#define num_nodes               		pr_state_ptr->num_nodes/* 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_sink_state *op_sv_ptr = pr_state_ptr;/* Function Block */enum { _block_origin = __LINE__ };proc_pkt ()	{	Packet* pkptr;	/*	/* Destroyed the upcoming packet from the lower layer	*/	// Extract packet from the upcoming stream	pkptr = op_pk_get (IN_STRM);	// Detroy it	op_pk_destroy (pkptr);				}record_stats ()	{	int i;		/*	/* write the stats into the outputfile	*/	out = fopen(outfile_name,"w");	fprintf (out,"GLOBAL STATS ::\n");	fprintf (out,"~~~~~~~~~~~~~~~\n");	fprintf (out,"	input : %d\n", input);	fprintf (out,"	output : %d\n", output);	fprintf (out,"	data packet destroyed because of non entry: %d\n", data_pk_destroyed);	fprintf (out,"	data packet still in buffer: %d\n", data_pk_buffer);	fprintf (out,"	Ack : %d\n", ack);	fprintf (out,"\nINDIVIDUAL STATS ::\n");	fprintf (out,"~~~~~~~~~~~~~~~~~~~\n");		for(i=0;i< num_nodes;i++)		{			fprintf (out,"\n-> Node %d ::\n",i);			fprintf (out,"-------------\n");			fprintf (out,"	--------------------\n");					fprintf (out,"	| TOTAL INPUT: %d  \n",stats[i].own_input+stats[i].forward_input );			fprintf (out,"	--------------------\n");					fprintf (out,"	own_input : %d\n",stats[i].own_input);			fprintf (out,"	forward_input : %d\n\n", stats[i].forward_input);			fprintf (out,"	--------------------\n");			fprintf (out,"	| TOTAL OUTPUT: %d  \n",stats[i].own_output+stats[i].forward_output );			fprintf (out,"	--------------------\n");			fprintf (out,"	own_output : %d\n",stats[i].own_output);		   	fprintf (out,"	forward_output : %d\n\n", stats[i].forward_output);			fprintf (out,"	data packet destroyed : %d\n", stats[i].data_pk_destroyed);			fprintf (out,"	data packet still in buffer: %d\n", stats[i].data_pk_buffer);			fprintf (out,"	Ack : %d\n", stats[i].ack);		}	fclose(out);	}/* End of Function Block */#if defined (__cplusplus)extern "C" {#endif	void aodv_app_sink (void);	Compcode aodv_app_sink_init (void **);	void aodv_app_sink_diag (void);	void aodv_app_sink_terminate (void);	void aodv_app_sink_svar (void *, const char *, char **);#if defined (__cplusplus)} /* end of 'extern "C"' */#endif/* Process model interrupt handling procedure */voidaodv_app_sink (void)	{	int _block_origin = 0;	FIN (aodv_app_sink ());	if (1)		{		FSM_ENTER (aodv_app_sink)		FSM_BLOCK_SWITCH			{			/*---------------------------------------------------------*/			/** state (init) enter executives **/			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "aodv_app_sink () [init enter execs]")				{				/* Initialize different state variables */				process_id = (op_id_self());				node_id = op_topo_parent (process_id);				/* Read node's address */				op_ima_obj_attr_get(node_id,"wlan_mac.station_address",&node_addr);				op_ima_obj_attr_get(node_id,"DEBUG",&DEBUG);				/* Copy the name of the out[ut file */ 				sprintf(outfile_name,"output_file");				/* Read the number of nodes in the network */				num_nodes = op_topo_object_count (OPC_OBJTYPE_NDMOB);								}			/** state (init) exit executives **/			FSM_STATE_EXIT_FORCED (0, "init", "aodv_app_sink () [init exit execs]")				{				}			/** state (init) transition processing **/			FSM_INIT_COND (PKT_RCVD)			FSM_TEST_COND (END_SIM)			FSM_TEST_LOGIC ("init")			FSM_TRANSIT_SWITCH				{				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, proc_pkt();, "PKT_RCVD", "proc_pkt()", "init", "idle")				FSM_CASE_TRANSIT (1, 1, state1_enter_exec, record_stats();, "END_SIM", "record_stats()", "init", "idle")				}				/*---------------------------------------------------------*/			/** state (idle) enter executives **/			FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "idle", "aodv_app_sink () [idle enter execs]")				{								}			/** blocking after enter executives of unforced state. **/			FSM_EXIT (3,aodv_app_sink)			/** state (idle) exit executives **/			FSM_STATE_EXIT_UNFORCED (1, "idle", "aodv_app_sink () [idle exit execs]")				{								}			/** state (idle) transition processing **/			FSM_INIT_COND (PKT_RCVD)			FSM_TEST_COND (END_SIM)			FSM_DFLT_COND			FSM_TEST_LOGIC ("idle")			FSM_TRANSIT_SWITCH				{				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, proc_pkt();, "PKT_RCVD", "proc_pkt()", "idle", "idle")				FSM_CASE_TRANSIT (1, 1, state1_enter_exec, record_stats();, "END_SIM", "record_stats()", "idle", "idle")				FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "default", "", "idle", "idle")				}				/*---------------------------------------------------------*/			}		FSM_EXIT (0,aodv_app_sink)		}	}#if defined (__cplusplus)	extern "C" { #endif	extern VosT_Fun_Status Vos_Catmem_Register (const char * , int , VosT_Void_Null_Proc, VosT_Address *);	extern VosT_Address Vos_Catmem_Alloc (VosT_Address, size_t);	extern VosT_Fun_Status Vos_Catmem_Dealloc (VosT_Address);#if defined (__cplusplus)	}#endifCompcodeaodv_app_sink_init (void ** gen_state_pptr)	{	int _block_origin = 0;	static VosT_Address	obtype = OPC_NIL;	FIN (aodv_app_sink_init (gen_state_pptr))	if (obtype == OPC_NIL)		{		/* Initialize memory management */		if (Vos_Catmem_Register ("proc state vars (aodv_app_sink)",			sizeof (aodv_app_sink_state), Vos_Vnop, &obtype) == VOSC_FAILURE)			{			FRET (OPC_COMPCODE_FAILURE)			}		}	*gen_state_pptr = Vos_Catmem_Alloc (obtype, 1);	if (*gen_state_pptr == OPC_NIL)		{		FRET (OPC_COMPCODE_FAILURE)		}	else		{		/* Initialize FSM handling */		((aodv_app_sink_state *)(*gen_state_pptr))->current_block = 0;		FRET (OPC_COMPCODE_SUCCESS)		}	}voidaodv_app_sink_diag (void)	{	/* No Diagnostic Block */	}voidaodv_app_sink_terminate (void)	{	int _block_origin = __LINE__;	FIN (aodv_app_sink_terminate (void))	Vos_Catmem_Dealloc (pr_state_ptr);	FOUT;	}/* Undefine shortcuts to state variables to avoid *//* syntax error in direct access to fields of *//* local variable prs_ptr in aodv_app_sink_svar function. */#undef process_id#undef outfile_name#undef node_addr#undef DEBUG#undef node_id#undef num_nodesvoidaodv_app_sink_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)	{	aodv_app_sink_state		*prs_ptr;	FIN (aodv_app_sink_svar (gen_ptr, var_name, var_p_ptr))	if (var_name == OPC_NIL)		{		*var_p_ptr = (char *)OPC_NIL;		FOUT;		}	prs_ptr = (aodv_app_sink_state *)gen_ptr;	if (strcmp ("process_id" , var_name) == 0)		{		*var_p_ptr = (char *) (&prs_ptr->process_id);		FOUT;		}	if (strcmp ("outfile_name" , var_name) == 0)		{		*var_p_ptr = (char *) (prs_ptr->outfile_name);		FOUT;		}	if (strcmp ("node_addr" , var_name) == 0)		{		*var_p_ptr = (char *) (&prs_ptr->node_addr);		FOUT;		}	if (strcmp ("DEBUG" , var_name) == 0)		{		*var_p_ptr = (char *) (&prs_ptr->DEBUG);		FOUT;		}	if (strcmp ("node_id" , var_name) == 0)		{		*var_p_ptr = (char *) (&prs_ptr->node_id);		FOUT;		}	if (strcmp ("num_nodes" , var_name) == 0)		{		*var_p_ptr = (char *) (&prs_ptr->num_nodes);		FOUT;		}	*var_p_ptr = (char *)OPC_NIL;	FOUT;	}

⌨️ 快捷键说明

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