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

📄 ier.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Process model C form file: IER.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 IER_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 4292844B 4292844B 1 wani wani123 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 PK_IN_STRM 			0
#define PK_OUT_STRM_CONT	0

#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

extern int h_node_count;

#define END_SIM	(op_intrpt_type () == OPC_INTRPT_ENDSIM)
#define BEG_SIM (op_intrpt_type () == OPC_INTRPT_BEGSIM)
#define R_T_INIT (op_intrpt_type() == OPC_INTRPT_SELF && op_intrpt_code()== 111)
#define R_T_UPDATE (op_intrpt_type() == OPC_INTRPT_SELF && op_intrpt_code()== 222)
#define SCHUDING_INIT (op_intrpt_type() == OPC_INTRPT_SELF && op_intrpt_code()== 333)

#define BURST_ARRIVAL (op_intrpt_type () == OPC_INTRPT_STRM )
#define CONTROL_ACCESS (op_intrpt_type() == OPC_INTRPT_SELF && op_intrpt_code()== 444)
#define DATA_ACCESS (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() <= 15))


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





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;
	Objid link_objid;
	double data_rate;
} PORT;

typedef struct 
{
	PORT * port;
} NODE;


double PDTime_EC = 0.0001;
//int node_num = 0;
//int node_count = 0;   

int burst_count_for_sim = 0;
int op_test_count = 0;
int total_burst_send_cound = 0;
int	total_burst_not_send_count = 0;
int	total_bcp_send_count = 0;
int total_bcp_notdelayed_sned_count = 0;
int total_bcp_delaysend_count = 0;
int total_gen_burst_count = 0;
double 		total_s_time = 0;



/* 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_objid1;
	Objid	                  		subnet_objid;
	int	                    		userid;
	ROUTING_TABLE *	        		routing_table;
	NODE	                   		node_for_schedule;
	int	                    		link_num;
	int	                    		channel_count;
	int	                    		node_num;
	int	                    		node_count;
	Topology*	              		topo_objid;
	double	                 		PROC_TIME;
	double	                 		RATE;
	int	                    		sub_queue_index;
	} IER_state;

#define pr_state_ptr            		((IER_state*) SimI_Mod_State_Ptr)
#define self_objid              		pr_state_ptr->self_objid
#define node_objid1             		pr_state_ptr->node_objid1
#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 node_num                		pr_state_ptr->node_num
#define node_count              		pr_state_ptr->node_count
#define topo_objid              		pr_state_ptr->topo_objid
#define PROC_TIME               		pr_state_ptr->PROC_TIME
#define RATE                    		pr_state_ptr->RATE
#define sub_queue_index         		pr_state_ptr->sub_queue_index

/* 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	IER_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 IER (void);
	Compcode IER_init (void **);
	void IER_diag (void);
	void IER_terminate (void);
	void IER_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
IER (void)
	{
	int _block_origin = 0;
	FIN (IER ());
	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, reservation_flag, cur_channel;
		double d_time,difference_time,temp_difference_time ;
		CHANNEL_INFOR * temp_channel_infor;
		int temp_outstrm_num,cur_por,temp_occupy_count;
		int output_strm;
		Objid temp_src_objid, temp_dest_objid;
		Route_Set* temp_routeset;
		Route* temp_min_route;
		int temp_flag_tx, temp_userid,temp_flag_loop;
		double next_stime, next_dtime,temp_delay_time;
		char temp_char[20];
		char temp_char1[20];
		char temp_char2[20];
		char temp_char3[20];
		char temp_char4[20];
		
		
		
		Packet*		pkptr_burst;
		Packet*		pkptr;
		
		int			sequence_number_ack;
		int			sequence_number_rcv;
		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;
		double		offset_time;
		Objid		strm_objid;
		int 		channel_num;
		int			temp_code,temp_sub_queue_index;
		int			num_pks = 0;
		Objid		node_objid;
		double      temp_data_rate;
		
		
		FILE * in;
		char filename[20];
		char temp_file_name[20];
		
		
		


		FSM_ENTER (IER)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "IER () [init 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);
				 
				PROC_TIME = (double)(0.000001);
				RATE = 3000000000;
				
				node_num = op_topo_object_count (OPC_OBJTYPE_NDFIX)-1;
				
				
				//printf("ier;userid=%d,node_objid=%d,pt_objid=%d\n",userid,node_objid, op_id_from_name(node_objid,OPC_OBJTYPE_PTTX,"pt_0"));
				//getchar();	
				
				op_intrpt_schedule_self(op_sim_time(), 111);
				op_intrpt_schedule_self(op_sim_time(), 333);
				
				//printf("IER:userid=%d\n",userid);
				}


			/** state (init) exit executives **/
			FSM_STATE_EXIT_FORCED (0, "init", "IER () [init exit execs]")
				{
				//printf("IER-->inin;out\n");
				}


			/** 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", "IER () [wait enter execs]")
				{
				//printf("IER->wait, userid=%d,op_code=%d\n",userid,op_intrpt_code());
				//getchar();
				}


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


			/** state (wait) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "wait", "IER () [wait exit execs]")
				{
				//printf("IER-->wait;out\n");
				}


			/** state (wait) transition processing **/
			FSM_INIT_COND (BURST_ARRIVAL)
			FSM_TEST_COND (CONTROL_ACCESS)
			FSM_TEST_COND (END_SIM)
			FSM_TEST_COND (DATA_ACCESS)
			FSM_TEST_COND (R_T_INIT)
			FSM_TEST_COND (R_T_UPDATE)
			FSM_TEST_COND (SCHUDING_INIT)
			FSM_TEST_LOGIC ("wait")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 4, state4_enter_exec, ;, "BURST_ARRIVAL", "", "wait", "Data_Buffering")
				FSM_CASE_TRANSIT (1, 2, state2_enter_exec, ;, "CONTROL_ACCESS", "", "wait", "Ctrl_Forwarding&Schduing")
				FSM_CASE_TRANSIT (2, 5, state5_enter_exec, ;, "END_SIM", "", "wait", "end")
				FSM_CASE_TRANSIT (3, 3, state3_enter_exec, ;, "DATA_ACCESS", "", "wait", "Data_Forwarding")
				FSM_CASE_TRANSIT (4, 6, state6_enter_exec, ;, "R_T_INIT", "", "wait", "R_T_init")
				FSM_CASE_TRANSIT (5, 7, state7_enter_exec, ;, "R_T_UPDATE", "", "wait", "R_T_Update")
				FSM_CASE_TRANSIT (6, 8, state8_enter_exec, ;, "SCHUDING_INIT", "", "wait", "Schuding_init")
				}
				/*---------------------------------------------------------*/



			/** state (Ctrl_Forwarding&Schduing) enter executives **/
			FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "Ctrl_Forwarding&Schduing", "IER () [Ctrl_Forwarding&Schduing 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("IER->control_access 1; userid=%d\n",userid);
				
				temp_sub_queue_index = userid-6;
				
				if(op_subq_empty(temp_sub_queue_index) == OPC_FALSE)
				{	
				
					pkptr_burst = op_subq_pk_access (temp_sub_queue_index, OPC_QPOS_HEAD);
					op_pk_nfd_get (pkptr_burst, "source address", &source_address);
					op_pk_nfd_get (pkptr_burst, "destination address", &destination_address);
					pk_size = op_pk_total_size_get (pkptr_burst);
				
					pkptr =op_pk_create_fmt ("BCP_v1");
				
					offset_time = (double)( PROC_TIME* ((double)routing_table[destination_address].hop_count-1) );
					
					//printf("userid=%d,s_add=%d,d_add=%d,sub_queue=%d\n",userid,source_address,destination_address,temp_sub_queue_index);
					//getchar();
				
					//start of resource reservation 
					temp_tx_objid = routing_table[destination_address].output_tx;
					//printf("IER->control_access 1; userid=%d,link_num=%d\n",userid,link_num);
					
					for(i=0; i<link_num; i++)
					{
						//printf("userid=%d,sc_tx=%d,r_tx=%d\n",userid,node_for_schedule.port[i].tx_objid,routing_table[destination_address].output_tx);
						//printf("userid=%d,des_id=%d\n",userid,destination_address);
						//if(node_for_schedule.port[i].tx_objid == temp_tx_objid)
						if(node_for_schedule.port[i].link_objid == routing_table[destination_address].output_link)
						{
							cur_port = i;
						//	printf("find port,u_id=%d,link_num=%d\n",userid,link_num);
						}
						else
						{	
							printf("not find port,u_id=%d,link_num=%d\n",userid,link_num);
						//	getchar();
						}
					}
					
					start_time = offset_time + op_sim_time();
					dtime_time = (double)( (double)pk_size/(double)node_for_schedule.port[cur_port].data_rate );
					
					difference_time = 9999;
					reservation_flag = 0;
					//printf("IER->control_access 2; userid=%d,cur_port=%d\n",userid,cur_port);	
					for(i=1; i<channel_count; i++)
					{
						if(node_for_schedule.port[cur_port].channel[i].horizon > start_time)
						{
							
						}
						else
						{
							
							temp_difference_time = start_time - node_for_schedule.port[cur_port].channel[i].horizon ;
							if(difference_time > temp_difference_time)
							{
								difference_time = temp_difference_time;
								cur_channel = i;
								reservation_flag = 1;
							//	printf("IER->control_access re_1; userid=%d,i=%d,h_time=%e,s_time=%e\n",userid,i,node_for_schedule.port[cur_port].channel[i].horizon,start_time);
							}			
						
						}	
				
					}
					
					if(reservation_flag == 0)
					{
						for(i=1; i<channel_count; i++)
						{
							temp_difference_time = node_for_schedule.port[cur_port].channel[i].horizon - start_time;
							if(difference_time > temp_difference_time)

⌨️ 快捷键说明

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