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

📄 dr_cntrl_nchild.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
字号:
/* Process model C form file: dr_cntrl_nchild.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 dr_cntrl_nchild_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A op_runsim 7 3CF1ECAE 3CF1ECAE 1 notebook lhj 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" {
#endif
FSM_EXT_DECS
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif


/* Header Block */

#define FAIL_NODE		0
#define RECOVER_NODE	1

#define FAIL			(op_intrpt_code () == FAIL_NODE)
#define UP				(op_intrpt_code () == RECOVER_NODE)

extern Topology* 		topo_ptr;
extern Anvid			vid;
extern int				debug_sw;

/* 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*	                 		node_objid_ptr;
	Objid	                  		subnet_objid;
	Evhandle	               		recover_evh;
	Prohandle	              		my_proh;
	Distribution*	          		node_mtbf_dist;
	Distribution*	          		node_mttr_dist;
	char	                   		node_name[128];
	int	                    		reentry;
	} dr_cntrl_nchild_state;

#define pr_state_ptr            		((dr_cntrl_nchild_state*) SimI_Mod_State_Ptr)
#define node_objid_ptr          		pr_state_ptr->node_objid_ptr
#define subnet_objid            		pr_state_ptr->subnet_objid
#define recover_evh             		pr_state_ptr->recover_evh
#define my_proh                 		pr_state_ptr->my_proh
#define node_mtbf_dist          		pr_state_ptr->node_mtbf_dist
#define node_mttr_dist          		pr_state_ptr->node_mttr_dist
#define node_name               		pr_state_ptr->node_name
#define reentry                 		pr_state_ptr->reentry

/* 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	dr_cntrl_nchild_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 dr_cntrl_nchild (void);
	Compcode dr_cntrl_nchild_init (void **);
	void dr_cntrl_nchild_diag (void);
	void dr_cntrl_nchild_terminate (void);
	void dr_cntrl_nchild_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
dr_cntrl_nchild (void)
	{
	int _block_origin = 0;
	FIN (dr_cntrl_nchild ());
	if (1)
		{
		int 	condition;
		double	node_mtbf;
		double	node_mttr;
		Objid	self_objid;


		FSM_ENTER (dr_cntrl_nchild)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "dr_cntrl_nchild () [init enter execs]")
				{
				/* get condition of the current object */
				node_objid_ptr = (Objid*) op_pro_argmem_access ();
				subnet_objid = op25_topo_parent (*node_objid_ptr);
				
				/* get the condition and the name of the node */
				op_ima_obj_attr_get (*node_objid_ptr, "condition", &condition);
				op_ima_obj_attr_get (*node_objid_ptr, "name", node_name);
				
				/* set up failure/recovery mean period */
				self_objid = op_id_self ();
				op_ima_obj_attr_get (self_objid, "NODE MTBF", &node_mtbf);
				op_ima_obj_attr_get (self_objid, "NODE MTTR", &node_mttr);
				
				/* initialize the distributions */
				node_mtbf_dist = op_dist_load ("exponential", node_mtbf, 0.0);
				node_mttr_dist = op_dist_load ("exponential", node_mttr, 0.0);
				
				/* get process handle */
				my_proh = op_pro_self ();
				
				/* if the node is enabled now, schedule the next fail action  */
				if (condition)
					{
					/* schedule the next fail action */
					op_intrpt_schedule_process (my_proh, op_sim_time () + op_dist_outcome (node_mtbf_dist), FAIL_NODE);
					}
				
				reentry = 1;
				}


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


			/** state (init) transition processing **/
			FSM_INIT_COND (condition == OPC_FALSE)
			FSM_TEST_COND (condition = OPC_TRUE)
			FSM_TEST_LOGIC ("init")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "condition == OPC_FALSE", "", "init", "fail")
				FSM_CASE_TRANSIT (1, 2, state2_enter_exec, ;, "condition = OPC_TRUE", "", "init", "up")
				}
				/*---------------------------------------------------------*/



			/** state (fail) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "fail", "dr_cntrl_nchild () [fail enter execs]")
				{
				/* cancel the recover event for the previous fail action */
				if (op_ev_valid (recover_evh))
					{
					op_ev_cancel (recover_evh);
					}
				
				if (!reentry)
					{
					/* disable the node */
					op_ima_obj_attr_set (*node_objid_ptr, "condition", OPC_FALSE);          
					op_rte_topo_node_disable (topo_ptr, subnet_objid, *node_objid_ptr);
				
					/* update the node in the animation window */
					op_anim_ime_nobj_update (vid, OPC_ANIM_OBJTYPE_NODE, node_name,
						OPC_ANIM_OBJ_ATTR_ICON, "dr_mnode_fail", OPC_EOL);
					
					/* if debug switch is on */
					if (debug_sw)
						{
						printf ("\t\t\tFailed node name = %s at time %lf\n", node_name,
							op_sim_time ());
						}
						
				    }
				
				/* schedule a recover action */
				recover_evh = op_intrpt_schedule_process (my_proh, op_sim_time () + op_dist_outcome (node_mttr_dist), RECOVER_NODE);
				
				/* schedule the next fail action */
				op_intrpt_schedule_process (my_proh, op_sim_time () + op_dist_outcome (node_mtbf_dist), FAIL_NODE);
				
				}


			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (3,dr_cntrl_nchild)


			/** state (fail) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "fail", "dr_cntrl_nchild () [fail exit execs]")
				{
				}


			/** state (fail) transition processing **/
			FSM_INIT_COND (UP)
			FSM_TEST_COND (FAIL)
			FSM_TEST_LOGIC ("fail")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, reentry = 0;;, "UP", "reentry = 0;", "fail", "up")
				FSM_CASE_TRANSIT (1, 1, state1_enter_exec, reentry = 1;;, "FAIL", "reentry = 1;", "fail", "fail")
				}
				/*---------------------------------------------------------*/



			/** state (up) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, state2_enter_exec, "up", "dr_cntrl_nchild () [up enter execs]")
				{
				/* ignor recover event is the node is already up */
				if (!reentry) 
					{
					/* enable the node */
					op_ima_obj_attr_set (*node_objid_ptr, "condition", OPC_TRUE);    
					op_rte_topo_node_enable (topo_ptr, subnet_objid, *node_objid_ptr);
					
					/* update the node in the animation window */
					op_anim_ime_nobj_update (vid, OPC_ANIM_OBJTYPE_NODE, node_name,
						OPC_ANIM_OBJ_ATTR_ICON, "dr_mnode_ok", OPC_EOL);
				
					/* if the debug switch is on */
					if (debug_sw)
						{
						printf ("\t\t\tEnabled node name = %s at time %lf\n", node_name,
							op_sim_time ());
				        }
					}
				}


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


			/** state (up) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "up", "dr_cntrl_nchild () [up exit execs]")
				{
				}


			/** state (up) transition processing **/
			FSM_TRANSIT_ONLY ((FAIL), 1, state1_enter_exec, reentry = 0;;, "up", "FAIL", "reentry = 0;", "up", "fail")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,dr_cntrl_nchild)
		}
	}

#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)
	}
#endif


Compcode
dr_cntrl_nchild_init (void ** gen_state_pptr)
	{
	int _block_origin = 0;
	static VosT_Address	obtype = OPC_NIL;

	FIN (dr_cntrl_nchild_init (gen_state_pptr))

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

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



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




void
dr_cntrl_nchild_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (dr_cntrl_nchild_terminate (void))

	if (1)
		{
		int 	condition;
		double	node_mtbf;
		double	node_mttr;
		Objid	self_objid;

		/* 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 dr_cntrl_nchild_svar function. */
#undef node_objid_ptr
#undef subnet_objid
#undef recover_evh
#undef my_proh
#undef node_mtbf_dist
#undef node_mttr_dist
#undef node_name
#undef reentry



void
dr_cntrl_nchild_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
	{
	dr_cntrl_nchild_state		*prs_ptr;

	FIN (dr_cntrl_nchild_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (char *)OPC_NIL;
		FOUT;
		}
	prs_ptr = (dr_cntrl_nchild_state *)gen_ptr;

	if (strcmp ("node_objid_ptr" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->node_objid_ptr);
		FOUT;
		}
	if (strcmp ("subnet_objid" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->subnet_objid);
		FOUT;
		}
	if (strcmp ("recover_evh" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->recover_evh);
		FOUT;
		}
	if (strcmp ("my_proh" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->my_proh);
		FOUT;
		}
	if (strcmp ("node_mtbf_dist" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->node_mtbf_dist);
		FOUT;
		}
	if (strcmp ("node_mttr_dist" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->node_mttr_dist);
		FOUT;
		}
	if (strcmp ("node_name" , var_name) == 0)
		{
		*var_p_ptr = (char *) (prs_ptr->node_name);
		FOUT;
		}
	if (strcmp ("reentry" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->reentry);
		FOUT;
		}
	*var_p_ptr = (char *)OPC_NIL;

	FOUT;
	}

⌨️ 快捷键说明

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