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

📄 core.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: CORE.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 CORE_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 43EB4931 43EB4931 1 plm Administrator 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 */

#include <string.h>
#include <stdlib.h>
//#include "header.h"


#define CONTORL_ACCESS		0
#define SUBQ_INDEX_0		0
#define SUBQ_INDEX_1		1
#define SUBQ_INDEX_2		2
#define SUBQ_INDEX_3		3
#define SUBQ_INDEX_4		4
#define SUBQ_INDEX_5		5


#define END_SIM	(op_intrpt_type () == OPC_INTRPT_ENDSIM)
#define BEG_SIM (op_intrpt_type () == OPC_INTRPT_BEGSIM)
#define DATA_RECIEVE (op_intrpt_type() == OPC_INTRPT_STRM && op_intrpt_strm() != 0) 
#define S_M_INIT (op_intrpt_type() == OPC_INTRPT_SELF && op_intrpt_code()== 0)
//#define S_M_UPDATE (op_intrpt_type() == OPC_INTRPT_STAT)
#define S_M_UPDATE (op_intrpt_type() == OPC_INTRPT_STRM && op_intrpt_strm() == 0)

//start of sturct for routing table
typedef struct {
int source;
int destination;
int hop_count;
Objid output_link;
int strm_control;
//int strm_data;
} ROUTING_TABLE;
//end of sturct for routing table

typedef struct {
double s_time;
double d_time;
int input_strum;
int output_strum;
} S_METRIX;



typedef struct {
	double start_time;     //offset time
	double duration_time;  // duration time of burst
	int source;
	int destination;
	int outstrm_num;
	int instrm_num;
} CHANNEL_INFOR;

typedef struct 
{
	double horizon;
	List * gab_list;
	List * occupy_list;
} CHANNEL;

typedef struct 
{
	CHANNEL * channel;
	int next_nodeid;
	Objid tx_objid;
} PORT;

typedef struct 
{
	PORT * port;
} NODE;


//int node_num = 0;
//int node_count = 0;   

//double PDTime_CC = 0.001;
int	total_burst_drop_count = 0;
int  not_strm=0;
FILE * in;
char filename[10];

/* 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	                  		self_objid;
	Objid	                  		node_objid;
	Objid	                  		subnet_objid;
	int	                    		userid;
	ROUTING_TABLE *	        		routing_table;
	NODE	                   		node_for_schedule;
	int	                    		link_num;
	int	                    		channel_count;
	int	                    		pk_type;
	Packet *	               		pkptr_state;
	int	                    		node_num;
	int	                    		node_count;
	Topology*	              		topo_objid;
	int	                    		temp_strm_num;
	List *	                 		s_metrix_list;
	} CORE_state;

#define pr_state_ptr            		((CORE_state*) SimI_Mod_State_Ptr)
#define self_objid              		pr_state_ptr->self_objid
#define node_objid              		pr_state_ptr->node_objid
#define subnet_objid            		pr_state_ptr->subnet_objid
#define userid                  		pr_state_ptr->userid
#define routing_table           		pr_state_ptr->routing_table
#define node_for_schedule       		pr_state_ptr->node_for_schedule
#define link_num                		pr_state_ptr->link_num
#define channel_count           		pr_state_ptr->channel_count
#define pk_type                 		pr_state_ptr->pk_type
#define pkptr_state             		pr_state_ptr->pkptr_state
#define node_num                		pr_state_ptr->node_num
#define node_count              		pr_state_ptr->node_count
#define topo_objid              		pr_state_ptr->topo_objid
#define temp_strm_num           		pr_state_ptr->temp_strm_num
#define s_metrix_list           		pr_state_ptr->s_metrix_list

/* 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	CORE_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 CORE (void);
	Compcode CORE_init (void **);
	void CORE_diag (void);
	void CORE_terminate (void);
	void CORE_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
CORE (void)
	{
	int _block_origin = 0;
	FIN (CORE ());
	if (1)
		{
		int total_node_num = 0;
		//int node_num = 0;
		//int link_num = 0;
		char node_name[20];
		int i,j,k;
		Objid node_objid_ptr, link_objid,tx_objid;
		Route* min_route;
		int subnet_id_ptr, node_id_ptr;
		int strm_num, channel_count1, link_count;
		double pk_size;
		Objid temp_tx_objid;
		int cur_port, difference_time, reservation_flag, cur_channel;
		double d_time, temp_difference_time; 
		CHANNEL_INFOR * temp_channel_infor;
		int temp_outstrm_num,cur_por,temp_occupy_count;
		int output_strm;
		int pkptr_type;
		Objid temp_src_objid, temp_dest_objid;
		Route_Set* temp_routeset;
		Route* temp_min_route;
		int temp_userid, temp_flag_tx;
		double next_stime;
		Ici* temp_ici;
		S_METRIX *temp_s_metrix;
		int intrupt_strum,temp_flag_success,temp_flag_loop;
		Packet* s_metrix_pkptr;
		
		
		
		
		
		
		
		Packet*		pkptr_burst;
		Packet*		pkptr;
		
		int			source_address;
		int			destination_address;
		
		
		
		Route*		pk_rptr;
		double		start_time;
		double		dtime_time;
		double		cur_time;
		int			subnet_ids[10];
		int			node_ids[20];
		int			num_nodes;
		
		
		double 		EXTRA_TIME;
		Objid		strm_objid;
		int 		jj;
		int 		channel_num;
		int			temp_code;
		
		FILE * in;
		char filename[20];
		char temp_file_name[20];


		FSM_ENTER (CORE)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "CORE () [init enter execs]")
				{
				 //start of conform the node id
				self_objid = op_id_self ();
				node_objid = op_topo_parent (self_objid);
				//subnet_objid = op_topo_parent (node_objid);
				//topo_objid = op_rte_topo_from_objids();
				
				
				//op_ima_obj_attr_set (node_objid, "user id", h_node_count++);	 
				op_ima_obj_attr_get(node_objid, "user id", &userid);
				//end of of conform the node id
				
				op_intrpt_schedule_self(op_sim_time(), 0);
				
				
				 printf("sw:userid=%d,node_objid=%d\n",userid,op_id_from_userid(subnet_objid,OPC_OBJTYPE_NDFIX,userid));
				/* printf("sw;userid=%d,node_objid=%d\n",userid,node_objid);
				 
				 printf("sw;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_0"));
				 printf("sw;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_0"));
				
				 printf("sw:userid=%d,node_objid=%d\n",userid,op_id_from_userid(subnet_objid,OPC_OBJTYPE_NDFIX,userid));
				 printf("sw;userid=%d,node_objid=%d\n",userid,node_objid);
				 printf("sw;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_1"));
				 printf("sw;userid=%d,node_objid=%d\n",userid,node_objid);
				 printf("sw:userid=%d,node_objid=%d\n",userid,op_id_from_userid(subnet_objid,OPC_OBJTYPE_NDFIX,userid));
				 printf("sw;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_2"));
				 printf("sw;userid=%d,node_objid=%d\n",userid,node_objid);
				 printf("sw;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_3"));
				 printf("sw:userid=%d,node_objid=%d\n",userid,op_id_from_userid(subnet_objid,OPC_OBJTYPE_NDFIX,userid));
				 printf("sw;userid=%d,node_objid=%d\n",userid,node_objid);
				 printf("sw;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_4"));
				 getchar();
				*/
				}


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


			/** state (init) transition processing **/
			FSM_TRANSIT_ONLY ((BEG_SIM), 1, state1_enter_exec, ;, "init", "BEG_SIM", "", "init", "wait")
				/*---------------------------------------------------------*/



			/** state (wait) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "wait", "CORE () [wait enter execs]")
				{
				//printf("Core->wait, userid=%d\n",userid);
				//getchar();
				}


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


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


			/** state (wait) transition processing **/
			FSM_INIT_COND (DATA_RECIEVE)
			FSM_TEST_COND (END_SIM)
			FSM_TEST_COND (S_M_INIT)
			FSM_TEST_COND (S_M_UPDATE)
			FSM_TEST_LOGIC ("wait")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "DATA_RECIEVE", "", "wait", "data_recieve")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "END_SIM", "", "wait", "end")
				FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "S_M_INIT", "", "wait", "S_M_init")
				FSM_CASE_TRANSIT (3, 5, state5_enter_exec, ;, "S_M_UPDATE", "", "wait", "S_M_Update")
				}
				/*---------------------------------------------------------*/



			/** state (data_recieve) enter executives **/
			FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "data_recieve", "CORE () [data_recieve enter execs]")
				{
				self_objid = op_id_self ();
				node_objid = op_topo_parent (self_objid);
				//subnet_objid = op_topo_parent (node_objid);
				//topo_objid = op_rte_topo_from_objids();
				op_ima_obj_attr_get(node_objid, "user id", &userid);	
				//printf("S_M->data_recieve, userid=%d,op_time=%e\n",userid,op_sim_time());
				//
				
				intrupt_strum = op_intrpt_strm();
				//printf("sr_num=%d\n",intrupt_strum);
				//getchar();
				pkptr_burst = op_pk_get(intrupt_strum);
				
				op_pk_nfd_get (pkptr_burst, "destination address", &destination_address);
				
				temp_occupy_count = op_prg_list_size(s_metrix_list);
					
				
				i=0;
				temp_flag_success = 0;		
				while(i< temp_occupy_count && temp_flag_success == 0)
				{
					//printf("temp_occuy=%d,i=%d\n",temp_occupy_count,i);
					temp_s_metrix = op_prg_list_access(s_metrix_list, i);
					//printf("S_M->data_recieve;userid=%d,in_strm=%d,intr_in_strm=%d,out_strm=%d,op_time=%3.20e,m_time=%3.20e\n",userid,temp_s_metrix->input_strum,
					//	intrupt_strum,temp_s_metrix->output_strum,op_sim_time(),temp_s_metrix->s_time);
					if(   ( (op_sim_time() == temp_s_metrix->s_time ) && intrupt_strum == temp_s_metrix->input_strum ) 	||
						  ( (op_sim_time() - temp_s_metrix->s_time  <= 0.000000000000001) && intrupt_strum == temp_s_metrix->input_strum ))
						//( (temp_s_metrix->s_time - op_sim_time() <= 0.000000000000001) && intrupt_strum == temp_s_metrix->input_strum ) )
					{	
						
						temp_flag_success = 1;
					
					}
					else
					{
						//printf("S_M->data_recieve,fail pass,userid=%d,temp_s_metrix->s_time=10%e,op_time=%10e\n",userid,temp_s_metrix->s_time,op_sim_time());
						//getchar();
				
					}
					i++;
				}		
				
				if(	temp_flag_success == 1)
				{
				//	printf("S_M->data_recieve,success pass,userid=%d,d_ad=%d,out_strm=%d,op_time=%e\n",userid,destination_address,temp_s_metrix->output_strum,op_sim_time());
				//	getchar();
				
					op_pk_send(pkptr_burst, temp_s_metrix->output_strum);
						
				}
				else
				{
					//printf("S_M->data_recieve,failed pass,userid=%d,d_ad=%d,out_strm=%d,op_time=%e\n",userid,destination_address,temp_s_metrix->output_strum,op_sim_time());

⌨️ 快捷键说明

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