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

📄 blocking_estimate.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: blocking_estimate.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 blocking_estimate_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 43FADD9A 43FADD9A 1 aurora aurora_plm 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    CTR_TYPE        1
#define    e               0.1
#define    w               4
#define    PROC_time       0.000000512

#define    BCP_ARRIVE      (op_intrpt_type() == OPC_INTRPT_STRM)&&(strm_type == CTR_TYPE)
#define    END_SIM         (op_intrpt_type() == OPC_INTRPT_ENDSIM)


List *     CIT[4]; 

typedef struct
	{
	double Tarrv;
	double Tdest;
	
	double Tsend;
	double Tdepart;
	
	int BUR_DEST_FLAG;// When burst arrives at intermediate node and BCP can not access control channel, so destroy it
	int src;
	
	}burst_pass;


int compare(burst_pass* a, burst_pass* b)
	{
	if(a->Tsend < b->Tsend) return 1;
	else if(a->Tsend >= b->Tsend) return -1;
	else return 0;
	}

int    special_rece = 0;
int    special_send = 0;
int    special_lost = 0;

int    ordinary_rece = 0;
int    ordinary_send = 0;
int    ordinary_lost = 0;

double ordinary__total_size = 0;


FILE *   in;
char     filename[50]; 

/* 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;
	double	                 		denominator;
	double	                 		numerator;
	Packet *	               		pkptr;
	double	                 		offset_time;
	int	                    		PK_SEND_FLAG;
	int	                    		userid;
	int	                    		strm_num;
	int	                    		strm_type;
	int	                    		CONVERT_FLAG;
	int	                    		convert_wave_save;
	int	                    		wave_id;
	int	                    		CONVERT_FAIL;
	int	                    		SPECIAL_RECE;
	double	                 		burst_length;
	} blocking_estimate_state;

#define pr_state_ptr            		((blocking_estimate_state*) SimI_Mod_State_Ptr)
#define self_objid              		pr_state_ptr->self_objid
#define node_objid              		pr_state_ptr->node_objid
#define denominator             		pr_state_ptr->denominator
#define numerator               		pr_state_ptr->numerator
#define pkptr                   		pr_state_ptr->pkptr
#define offset_time             		pr_state_ptr->offset_time
#define PK_SEND_FLAG            		pr_state_ptr->PK_SEND_FLAG
#define userid                  		pr_state_ptr->userid
#define strm_num                		pr_state_ptr->strm_num
#define strm_type               		pr_state_ptr->strm_type
#define CONVERT_FLAG            		pr_state_ptr->CONVERT_FLAG
#define convert_wave_save       		pr_state_ptr->convert_wave_save
#define wave_id                 		pr_state_ptr->wave_id
#define CONVERT_FAIL            		pr_state_ptr->CONVERT_FAIL
#define SPECIAL_RECE            		pr_state_ptr->SPECIAL_RECE
#define burst_length            		pr_state_ptr->burst_length

/* 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	blocking_estimate_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 blocking_estimate (void);
	Compcode blocking_estimate_init (void **);
	void blocking_estimate_diag (void);
	void blocking_estimate_terminate (void);
	void blocking_estimate_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
blocking_estimate (void)
	{
	int _block_origin = 0;
	FIN (blocking_estimate ());
	if (1)
		{
		//int           strm_type;
		int           offset_type;
		//int           wave_id;
		int           list[5];
		
		int           i;
		int           wave_update;
		int           wave_convert;
		int           wave_insert;
		int           debug_list;
		
		double        arrive_time;
		double        depart_time;
		double        check_in;
		double        check_out;
		
		double        convert_in;
		double        convert_out;
		
		double        insert_in;
		double        insert_out;
		
		double        debug_in;
		double        debug_out;
		
		double        cur_in;
		double        cur_out;
		
		double        rest_offset;
		
		double        cur_send;
		double        cur_depart;
		
		double        burst_size;
		
		burst_pass*   burst_into_table;
		burst_pass*   burst_check_table;
		burst_pass*   list_update;
		burst_pass*   wave_convert_table;
		burst_pass*   wave_insert_table;
		burst_pass*   debug_check_table;
		
		char          temp_file_name[50];


		FSM_ENTER (blocking_estimate)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "blocking_estimate () [init enter execs]")
				{
				
				self_objid = op_id_self();
				node_objid = op_topo_parent(self_objid);
				op_ima_obj_attr_get(node_objid, "user id", &userid);
				
				for(i=0; i< 4; i++)
					{
					CIT[i] = (List*)op_prg_mem_alloc(sizeof(List)); 
					op_prg_list_init(CIT[i]);
					}
				
				//printf("\nBlocking_estinmate-->init---->userid: %d\n",userid);
				}


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


			/** state (init) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "wait")
				/*---------------------------------------------------------*/



			/** state (wait) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "wait", "blocking_estimate () [wait enter execs]")
				{
				}


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


			/** state (wait) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "wait", "blocking_estimate () [wait exit execs]")
				{
				if(op_intrpt_type() == OPC_INTRPT_STRM)
					{
					strm_num = op_intrpt_strm();
					
					//if((op_intrpt_strm()>=0)&&(op_intrpt_strm()<=4))
						//{
						strm_type = CTR_TYPE;
						//}
					}
				
				if(strm_num == 5)
					{
				//printf("Blocking_estinmate-->WAIT---->check!\n");
				//printf("strm_type:%d\n", strm_type);
				printf("\nSTRM_num: %d\n", strm_num);
				//getchar();
				}
				}


			/** state (wait) transition processing **/
			FSM_INIT_COND (BCP_ARRIVE)
			FSM_TEST_COND (END_SIM)
			FSM_TEST_LOGIC ("wait")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "BCP_ARRIVE", "", "wait", "blocking_calculate")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "END_SIM", "", "wait", "END")
				}
				/*---------------------------------------------------------*/



			/** state (blocking_calculate) enter executives **/
			FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "blocking_calculate", "blocking_estimate () [blocking_calculate enter execs]")
				{
				//Get the BCPs and get the contents in their fields
				
				
				/****************** Define the initialation *******************/
				PK_SEND_FLAG = 0;
				CONVERT_FLAG = 0;
				CONVERT_FAIL = 0;
				SPECIAL_RECE = 0;
				
				burst_into_table = (burst_pass*)op_prg_mem_alloc(sizeof(burst_pass));
				burst_check_table = (burst_pass*)op_prg_mem_alloc(sizeof(burst_pass));
				list_update = (burst_pass*)op_prg_mem_alloc(sizeof(burst_pass));
				wave_convert_table = (burst_pass*)op_prg_mem_alloc(sizeof(burst_pass));
				debug_check_table = (burst_pass*)op_prg_mem_alloc(sizeof(burst_pass));
				
				/******************** Decide from which wavelength the packets are sent ***********************/
				wave_id = op_intrpt_strm();
				pkptr = op_pk_get(wave_id);
				
				/******************** Get the contents from the received packets ***********************/
				op_pk_nfd_get(pkptr, "send_time", &arrive_time);
				op_pk_nfd_get(pkptr, "offset_type", &offset_type);
				op_pk_nfd_get(pkptr, "burst_length", &burst_size);
				op_pk_nfd_get(pkptr, "offset", &offset_time);
				
				
				if(wave_id != 4)
					{
					//printf("Burst_size: %e\n", (burst_size*1000000000));
					//getchar();
					
					ordinary__total_size = ordinary__total_size + (burst_size*1000000000);
					ordinary_rece++;
					}
				/******************** Count the received number for special bursts ***********************/
				
				if(wave_id == 4)
					{
					 special_rece++;	
					}
				
				
				//rest_offset = offset_time - PROC_time;
				
				burst_into_table->Tsend = arrive_time;
				burst_into_table->Tdepart = arrive_time + burst_size;
				
				cur_in = burst_into_table->Tsend;
				cur_out = burst_into_table->Tdepart;
				
				//printf("wave_id:%d ---->cur_time: %e\n", wave_id, op_sim_time());
				//printf("\nSTART-->current_in: %e, current_out:%e\n", cur_in, cur_out);
				
				
				/******************** Update the list recording the reservation information ***********************/
				
				for(wave_update = 0; wave_update < 4; wave_update++)
					{
					
					list[wave_update] = op_prg_list_size(CIT[wave_update]);
					
					if(list[wave_update] !=0)
						{
							
						for(i = 0; i < list[wave_update]; i++)
							{
							list_update = op_prg_list_access(CIT[wave_update],i);
							
							if(list_update->Tdepart <= op_sim_time())
								{
								
								list_update = op_prg_list_remove(CIT[wave_update],i);
								op_prg_mem_free(list_update);
								
								list[wave_update] = op_prg_list_size(CIT[wave_update]);
				
								i--;
								}
							}
						}
					}
					
				
				// SCHEDULING
				/*************************** Decide whethter the wavelength is available or not ***************************/
				/******************** If the current wavelength is not available, wavelength convert***********************/
				/***************************** If all can't be available, discard the burst *******************************/
				
				if(wave_id != 4)
					{
				
					//printf("List--->check555-->wave_id:%d\n", wave_id);
					
					list[wave_id] = op_prg_list_size(CIT[wave_id]);
					
					//printf("On burst arriving, check its income stream------------------>wave_id: %d\n",wave_id);	
					//printf("# of bursts on its corresponding outstream->list[wave_id]: %d\n",list[wave_id]);
				
					if(list[wave_id] != 0)
						{
					
						for(i=0; i<list[wave_id]; i++)
							{
							
							burst_check_table = op_prg_list_access(CIT[wave_id],i);
						
							check_in = burst_check_table->Tsend;
							check_out = burst_check_table->Tdepart;
							
							//printf("As there exist bursts on the current wavelength, check their time in order\n");
							//printf("check_in: %e, check_out: %e\n", check_in, check_out);
							//getchar();
					   
							//if(((cur_in >= check_in)&&(cur_in <= check_out))||((cur_out >= check_in)&&(cur_out <= check_out)))
							
							if((cur_in >= check_in)&&(cur_in < check_out))
								{
								//printf("Overlap in current wave--->need wavelength convertor!!!\n");
								
								CONVERT_FLAG = 1;
								break;
								}
							}
						}
						
						if(CONVERT_FLAG == 0)
							{
							convert_wave_save = wave_id;
						    //printf("Current_wave is available, WC is not needed!!\n");
							}
						
				   
				
				   /*********************************************************************************************************/
				   /************************************* wavelength converter **********************************************/
				   /*********************************************************************************************************/
					if(CONVERT_FLAG == 1)
						{	
						//printf("Is wave_convertor going to be done??\n");
							
						for(wave_convert = 0; wave_convert < 4; wave_convert++)
							{
								
							if(wave_convert != wave_id)
								{
								
								list[wave_convert] = op_prg_list_size(CIT[wave_convert]);
								//printf("list[wave_convert:%d]:%d\n", wave_convert, list[wave_convert]);
									
								if(list[wave_convert]!= 0)
									{
									
									//printf("list[wave_convert:%d = %d--->check more!!\n",wave_convert,list[wave_convert]);
									
									for(i=0; i<list[wave_convert]; i++)
										{
										wave_convert_table = op_prg_list_access(CIT[wave_convert],i);
										
										convert_in = wave_convert_table->Tsend;
										convert_out = wave_convert_table->Tdepart;
									
									/************ If all fails, discard the packet ************/
									
										//if(((cur_in>=convert_in)&&(cur_in<=convert_out))||((cur_out>=convert_in)&&(cur_out<=convert_out)))
										
										if((cur_in >= convert_in)&&(cur_in < convert_out))
											{	
											
											//printf("convert FAILED on: %d!!!!\n",wave_convert);
											//printf("FAILED w: %d", wave_convert);
										    //getchar();
											
											break;
											}
											
										else
											{
											CONVERT_FAIL = 1;//FOR Jumping out the 2nd 'FOR' loop
											
											//printf("convert SUCCEED-->Jump out 1ST 'FOR' loop!!!!\n");
											//printf("SUCCEED converting wave: %d", wave_convert);

⌨️ 快捷键说明

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