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

📄 pksw_nd_proc2.pr.c

📁 基于OPNET的网络仿真程序
💻 C
字号:
/* Process model C form file: pksw_nd_proc2.pr.c */
/* Portions of this file copyright 1992, 1996, 1998 by MIL 3, Inc. */



/* This variable carries the header into the object file */
static const char pksw_nd_proc2_pr_c [] = "MIL_3_Tfile_Hdr_ 60L 30A op_runsim 7 3793B3ED 3793B3ED 1 rmaddox dsochuliakova 0 0 none none 0 0 none 0 0 0 0 0 0";


/* OPNET system definitions */
#include <opnet.h>
FSM_EXT_DECS


/* Header Block */

/*	Packet stream definitions	*/
#define	RCV_IN_STRM		0
#define	SRC_IN_STRM		1
#define	XMT_OUT_STRM	0

/*	Transition macro			*/
#define	SRC_ARRVL		(op_intrpt_type () == OPC_INTRPT_STRM && \
								op_intrpt_strm () == SRC_IN_STRM)

#define	RCV_ARRVL		(op_intrpt_type () == OPC_INTRPT_STRM && \
								op_intrpt_strm () == RCV_IN_STRM)
#define END_SIM			op_intrpt_type() == OPC_INTRPT_ENDSIM

/* End of Header Block */


#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		_fstack_local_info.last_line_passed = __LINE__ - _block_origin;
#define	BOUT	BIN
#define	BINIT	_fstack_local_info.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 */
	Distribution *          		address_dist;
	Stathandle              		ete_gsh;
	int	                    		pk_count;
	char	                   		my_name[48];
	} pksw_nd_proc2_state;

#define pr_state_ptr            		((pksw_nd_proc2_state*) SimI_Mod_State_Ptr)
#define address_dist            		pr_state_ptr->address_dist
#define ete_gsh                 		pr_state_ptr->ete_gsh
#define pk_count                		pr_state_ptr->pk_count
#define my_name                 		pr_state_ptr->my_name

/* 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	pksw_nd_proc2_state *op_sv_ptr = pr_state_ptr;


/* No Function Block */

enum { _block_origin = __LINE__ };




/* Process model interrupt handling procedure */


void
pksw_nd_proc2 (void)
	{
	int _block_origin = 0;
	FIN (pksw_nd_proc2 ());
	if (1)
		{
		Packet 		*pkptr;
		double 		ete_delay;
		char		tmpstr[128];


		FSM_ENTER (pksw_nd_proc2)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED (0, state0_enter_exec, "init", "pksw_nd_proc2 () [init enter execs]")
				{
				address_dist = op_dist_load ("uniform_int", 0, 3);
				ete_gsh = op_stat_reg("ETE delay", OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
				
				op_ima_obj_attr_get (op_topo_parent(op_id_self()),"name",my_name);
				
				pk_count = 0;
				}


			/** state (init) exit executives **/
			FSM_STATE_EXIT_FORCED (0, state0_exit_exec, "init", "pksw_nd_proc2 () [init exit execs]")
				{
				}


			/** state (init) transition processing **/
			FSM_TRANSIT_FORCE (2, state2_enter_exec, ;)
				/*---------------------------------------------------------*/



			/** state (xmt) enter executives **/
			FSM_STATE_ENTER_FORCED (1, state1_enter_exec, "xmt", "pksw_nd_proc2 () [xmt enter execs]")
				{
				pkptr = op_pk_get (SRC_IN_STRM);
				op_pk_nfd_set (pkptr, "dest_address", (int) op_dist_outcome (address_dist));
				op_pk_send (pkptr, XMT_OUT_STRM);
				}


			/** state (xmt) exit executives **/
			FSM_STATE_EXIT_FORCED (1, state1_exit_exec, "xmt", "pksw_nd_proc2 () [xmt exit execs]")
				{
				}


			/** state (xmt) transition processing **/
			FSM_TRANSIT_FORCE (2, state2_enter_exec, ;)
				/*---------------------------------------------------------*/



			/** state (idle) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, state2_enter_exec, "idle", "pksw_nd_proc2 () [idle enter execs]")
				{
				}


			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (5,pksw_nd_proc2)


			/** state (idle) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, state2_exit_exec, "idle", "pksw_nd_proc2 () [idle exit execs]")
				{
				}


			/** state (idle) transition processing **/
			FSM_INIT_COND (SRC_ARRVL)
			FSM_TEST_COND (RCV_ARRVL)
			FSM_TEST_COND (END_SIM)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("idle")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;)
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;)
				FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;)
				FSM_CASE_TRANSIT (3, 2, state2_enter_exec, ;)
				}
				/*---------------------------------------------------------*/



			/** state (rcv) enter executives **/
			FSM_STATE_ENTER_FORCED (3, state3_enter_exec, "rcv", "pksw_nd_proc2 () [rcv enter execs]")
				{
				pkptr = op_pk_get (RCV_IN_STRM);
				ete_delay = op_sim_time() - op_pk_creation_time_get (pkptr);
				op_stat_write (ete_gsh, ete_delay);
				pk_count++;
				op_pk_destroy (pkptr);
				}


			/** state (rcv) exit executives **/
			FSM_STATE_EXIT_FORCED (3, state3_exit_exec, "rcv", "pksw_nd_proc2 () [rcv exit execs]")
				{
				}


			/** state (rcv) transition processing **/
			FSM_TRANSIT_FORCE (2, state2_enter_exec, ;)
				/*---------------------------------------------------------*/



			/** state (end) enter executives **/
			FSM_STATE_ENTER_UNFORCED (4, state4_enter_exec, "end", "pksw_nd_proc2 () [end enter execs]")
				{
				sprintf (tmpstr, "Node %s: received %d packets.",my_name,pk_count);
				
				op_sim_message (tmpstr, "");
				}


			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (9,pksw_nd_proc2)


			/** state (end) exit executives **/
			FSM_STATE_EXIT_UNFORCED (4, state4_exit_exec, "end", "pksw_nd_proc2 () [end exit execs]")
				{
				}


			/** state (end) transition processing **/
			FSM_TRANSIT_MISSING ("end")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,pksw_nd_proc2)
		}
	}


Compcode
pksw_nd_proc2_init (void ** gen_state_pptr)
	{
	int _block_origin = 0;
	static VosT_Cm_Obtype	obtype = OPC_NIL;

	extern void				Vos_Vnop (void);

	FIN (pksw_nd_proc2_init (gen_state_pptr))

	if (obtype == OPC_NIL)
		{
		/* Initialize memory management */
		if (Vos_Catmem_Register ("proc state vars (pksw_nd_proc2)",
			sizeof (pksw_nd_proc2_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 */
		((pksw_nd_proc2_state *)(*gen_state_pptr))->current_block = 0;

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



void
pksw_nd_proc2_diag (void)
	{
	/* No Diagnostic Block */
	}




void
pksw_nd_proc2_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (pksw_nd_proc2_terminate (void))

	if (1)
		{
		Packet 		*pkptr;
		double 		ete_delay;
		char		tmpstr[128];

		/* No Termination Block */

		}
	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 pksw_nd_proc2_svar function. */
#undef address_dist
#undef ete_gsh
#undef pk_count
#undef my_name



void
pksw_nd_proc2_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
	{
	pksw_nd_proc2_state		*prs_ptr;

	FIN (pksw_nd_proc2_svar (gen_ptr, var_name, var_p_ptr))

	*var_p_ptr = (char *)VOS_NIL;
	prs_ptr = (pksw_nd_proc2_state *)gen_ptr;

	if (Vos_String_Equal ("address_dist" , var_name))
		{
		*var_p_ptr = (char *) (&prs_ptr->address_dist);
		goto func_return;
		}
	if (Vos_String_Equal ("ete_gsh" , var_name))
		{
		*var_p_ptr = (char *) (&prs_ptr->ete_gsh);
		goto func_return;
		}
	if (Vos_String_Equal ("pk_count" , var_name))
		{
		*var_p_ptr = (char *) (&prs_ptr->pk_count);
		goto func_return;
		}
	if (Vos_String_Equal ("my_name" , var_name))
		{
		*var_p_ptr = (char *) (prs_ptr->my_name);
		goto func_return;
		}

func_return:

	FOUT;
	}

⌨️ 快捷键说明

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