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

📄 ws_nsf_random.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
字号:
/* Process model C form file: WS_NSF_RANDOM.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 WS_NSF_RANDOM_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 3E410B48 3E410B48 1 WS QIU 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 SELF (op_intrpt_type () == OPC_INTRPT_SELF)
#define END_SIM (op_intrpt_type () == OPC_INTRPT_ENDSIM)

Topology*	topo_ptr;
Anvid		vid;
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
	} WS_NSF_RANDOM_state;

#define pr_state_ptr            		((WS_NSF_RANDOM_state*) SimI_Mod_State_Ptr)

/* 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	WS_NSF_RANDOM_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 WS_NSF_RANDOM (void);
	Compcode WS_NSF_RANDOM_init (void **);
	void WS_NSF_RANDOM_diag (void);
	void WS_NSF_RANDOM_terminate (void);
	void WS_NSF_RANDOM_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
WS_NSF_RANDOM (void)
	{
	int _block_origin = 0;
	FIN (WS_NSF_RANDOM ());
	if (1)
		{
		Prohandle	child_proh;
		Objid		child_objid;
		Objid		self_objid;
		Objid		node_objid;
		Objid*		node_objid_ptr;
		Objid		subnet_objid;
		Objid*		link_objid_ptr;
		Objid		node0_objid;
		Objid		node1_objid;
		int			num_fixed_nodes;
		int			num_dup_links;
		int			i;
		char		node_name[128];
		char		node0_name[128];
		char		node1_name[128];
		Route_Link*	link_ptr;
		double		link_cost_default;
		double		link_cost;


		FSM_ENTER (WS_NSF_RANDOM)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "WS_NSF_RANDOM () [init enter execs]")
				{
				/* get objid's */
				self_objid = op_id_self ();
				node_objid = op25_topo_parent (self_objid);
				subnet_objid = op25_topo_parent (node_objid);
				
				/* get default link cost */
				op_ima_sim_attr_get (OPC_IMA_DOUBLE, "default link cost", &link_cost_default);
				
				/* get network topology */
				topo_ptr = op_rte_topo_from_objids ();
				
				/* get total number of fixed nodes */
				num_fixed_nodes = op_topo_object_count (OPC_OBJTYPE_NDFIX);
				
				/* create child processes for mesh nodes */
				for (i = 0; i < num_fixed_nodes; i++)
					{
					node_objid_ptr = (Objid *) op_prg_mem_alloc (sizeof (Objid));
					*node_objid_ptr = op_topo_object (OPC_OBJTYPE_NDFIX, i);
					op_ima_obj_attr_get (*node_objid_ptr, "name", node_name);
					
					/* mesh nodes */
					if (toupper(node_name[0]) == 'M')
						{
				
						/* create and invoke a child process to handle this mesh node */
						child_proh = op_pro_create ("dr_cntrl_nchild", node_objid_ptr);
						op_pro_invoke (child_proh, node_objid_ptr);
					    }
					else
						{
						/* this is not  a mesh node, free the memory allocated */
						op_prg_mem_free (node_objid_ptr);
						}
					}
				
				/* get total number of mesh duplex links */
				num_dup_links = op_topo_object_count (OPC_OBJTYPE_LKDUP);
				
				/* create child processes for mesh links */
				for (i = 0; i < num_dup_links; i++)
					{
					link_objid_ptr = (Objid *) op_prg_mem_alloc (sizeof (Objid));
				    *link_objid_ptr = op_topo_object (OPC_OBJTYPE_LKDUP, i);
				
					/* get name of the two nodes connected to this link */
					node0_objid = op_topo_assoc (*link_objid_ptr, OPC_TOPO_ASSOC_OUT,
						OPC_OBJTYPE_NDFIX, 0);
					node1_objid = op_topo_assoc (*link_objid_ptr, OPC_TOPO_ASSOC_OUT,
						OPC_OBJTYPE_NDFIX, 1);
				
					/* set link cost */
					op_ima_obj_attr_get (*link_objid_ptr, "cost", &link_cost);
					
					/* find the link in the topology */
					link_ptr = op_rte_topo_link_find (topo_ptr, subnet_objid, node0_objid,
							subnet_objid, node1_objid, 0); 
						
					/* set the link cost and delay, delay is set to cost*0.01 sec */
					if (link_cost == 0.0) 
						{
				
						/* if cost attribute of the link is zero, set the cost to a default value */
						op_rte_topo_link_cost_set (link_ptr, link_cost_default);
						op_ima_obj_attr_set (*link_objid_ptr, "cost", link_cost_default);
						op_ima_obj_attr_set (*link_objid_ptr, "delay", link_cost_default * 0.01);
						}
					else
						{
				
						/* if the cost attribute of the link is not zero, set the link cost to this value */
						op_rte_topo_link_cost_set (link_ptr, link_cost);
						op_ima_obj_attr_set (*link_objid_ptr, "delay", link_cost * 0.01);
						}
				
					/* get the link ptr of the second link in this duplex link */
					link_ptr = op_rte_topo_link_find (topo_ptr, subnet_objid, node1_objid,
							subnet_objid, node0_objid, 0); 
					
					if (link_cost == 0.0)
						{
				
						/* if cost attribute of the link is zero, set the cost to a default value */
						op_rte_topo_link_cost_set (link_ptr, link_cost_default);
				        }
					else 
						{
						/* if the cost attribute of the link is not zero, set the link cost to this value */
						op_rte_topo_link_cost_set (link_ptr, link_cost);
						}
						
				    /* check if this link connects two mesh nodes */
					op_ima_obj_attr_get (node0_objid, "name", node0_name);
					op_ima_obj_attr_get (node1_objid, "name", node1_name);
					if ((toupper(node0_name[0]) == 'M') && (toupper(node1_name[0]) == 'M'))
						{
				
						/* create and invoke a child process to handle this mesh link */
						child_proh = op_pro_create ("dr_cntrl_lchild", link_objid_ptr);
						op_pro_invoke (child_proh, link_objid_ptr);
				        }
					else 
						{
				
						/* this is not a mesh link */
						op_prg_mem_free (link_objid_ptr);
						}
					}
				
				/* determine if verbose is on */
				op_ima_sim_attr_get (OPC_IMA_INTEGER, "DR_VERBOSE", &debug_sw);
				
				/* Rendesvous with auto anim */
				vid = op_anim_lprobe_anvid ("dr_anim");
				
				}


			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (1,WS_NSF_RANDOM)


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


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



			}


		FSM_EXIT (0,WS_NSF_RANDOM)
		}
	}

#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
WS_NSF_RANDOM_init (void ** gen_state_pptr)
	{
	int _block_origin = 0;
	static VosT_Address	obtype = OPC_NIL;

	FIN (WS_NSF_RANDOM_init (gen_state_pptr))

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

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



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




void
WS_NSF_RANDOM_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (WS_NSF_RANDOM_terminate (void))

	if (1)
		{
		Prohandle	child_proh;
		Objid		child_objid;
		Objid		self_objid;
		Objid		node_objid;
		Objid*		node_objid_ptr;
		Objid		subnet_objid;
		Objid*		link_objid_ptr;
		Objid		node0_objid;
		Objid		node1_objid;
		int			num_fixed_nodes;
		int			num_dup_links;
		int			i;
		char		node_name[128];
		char		node0_name[128];
		char		node1_name[128];
		Route_Link*	link_ptr;
		double		link_cost_default;
		double		link_cost;

		/* No Termination Block */

		}
	Vos_Catmem_Dealloc (pr_state_ptr);

	FOUT;
	}




void
WS_NSF_RANDOM_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
	{

	FIN (WS_NSF_RANDOM_svar (gen_ptr, var_name, var_p_ptr))

	*var_p_ptr = (char *)OPC_NIL;

	FOUT;
	}

⌨️ 快捷键说明

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