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

📄 obs_rte.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
📖 第 1 页 / 共 4 页
字号:
/* Process model C form file: OBS_rte.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 OBS_rte_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 428E9E89 428E9E89 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 	"route.h"
#include    <stdio.h>
#include    <stdlib.h>

#define		BEG_SIM (op_intrpt_type () == OPC_INTRPT_BEGSIM)
#define 	END_SIM	(op_intrpt_type () == OPC_INTRPT_ENDSIM)

#define 	MAX_HOPS 		15
#define 	PK_ARRIVAL (op_intrpt_type () == OPC_INTRPT_STRM)


#define 	PK_IN_STRM_BCP	4	
#define 	PK_IN_STRM_BURST	17	
#define 	PK_OUT_STRM 	4
#define 	PK_OUT_STRM_BCP	17

double		gap[NODE_NUM][NODE_NUM][WAVE_NUM];
Packet*		pkptr;
FILE 		*fp;

typedef struct {
double 		start;
double 		dtime;
} wave_info;

typedef struct {
double 		start;
double 		dtime;
} wavelength_info;

int			first_time = 0;
//double		pk_size_total_reiv=0;
//int			pk_count_total_reiv=0;


typedef struct {
	double start_time;
	double duration_time;
	int source;
	int id;
	int outstrm_num;
} CHANNEL_INFOR;

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

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

typedef struct 
{
	PORT * port;
} NODE;

double pk_size_total_reiv = 0;
int pk_count_total_reiv = 0;
double pk_avg_total_size_rev = 0;

int burst_count_total_lost = 0;
double total_pk_size[6][6];
double total_dropped_burst_length_related_hop = 0;
int    total_dropped_burst_count = 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 */
	Route*	                 		current_rptr;
	Objid	                  		subnet_id;
	Objid	                  		next_node_id;
	int	                    		rev_pk_count;
	Stathandle	             		rev_pk_cnt_stathandle;
	Objid	                  		node_objid;
	Objid	                  		self_objid;
	Objid	                  		subnet_objid;
	int	                    		node_pk_count;
	Objid	                  		dst_node_id;
	int	                    		send_ok;
	Stathandle	             		pk_size_reiv_stathandle;
	Stathandle	             		pk_cnt_reiv_stathandle;
	Stathandle	             		pk_size_total_reiv_stathandle;
	Stathandle	             		pk_cnt_total_reiv_stathandle;
	double	                 		pk_size_reiv;
	int	                    		pk_count_reiv;
	Stathandle	             		pk_rev_cnt_no1_stathandle;
	Stathandle	             		pk_rev_cnt_no2_stathandle;
	Stathandle	             		pk_rev_cnt_no3_stathandle;
	Stathandle	             		pk_rev_cnt_no4_stathandle;
	Stathandle	             		pk_rev_cnt_no5_stathandle;
	Stathandle	             		pk_rev_cnt_no6_stathandle;
	int	                    		pk_cnt_no1;
	int	                    		pk_cnt_no2;
	int	                    		pk_cnt_no3;
	int	                    		pk_cnt_no4;
	int	                    		pk_cnt_no5;
	int	                    		pk_cnt_no6;
	int	                    		jj;
	double	                 		pk_avg_size_rev;
	int	                    		pk_count_rev_channel0;
	int	                    		pk_count_rev_channel1;
	double	                 		pk_size_rev_channel0;
	double	                 		pk_size_rev_channel1;
	Stathandle	             		pk_avg_size_rev_stathandle;
	Stathandle	             		pk_count_rev_channel0_stathandle;
	Stathandle	             		pk_size_rev_channel0_stathandle;
	Stathandle	             		pk_count_rev_channel1_stathandle;
	Stathandle	             		pk_size_rev_channel1_stathandle;
	NODE	                   		node_for_schedule;
	int	                    		link_num;
	int	                    		channel_count1;
	int	                    		link_count;
	int	                    		packet_type;
	int	                    		burst_count_lost;
	Stathandle	             		burst_count_lost_stathandle;
	int	                    		bcp_count_lost;
	Stathandle	             		bcp_count_lost_stathandle;
	Stathandle	             		pk_avg_total_size_rev_stathandle;
	Stathandle	             		burst_count_total_lost_stathandle;
	int	                    		test_state;
	} OBS_rte_state;

#define pr_state_ptr            		((OBS_rte_state*) SimI_Mod_State_Ptr)
#define current_rptr            		pr_state_ptr->current_rptr
#define subnet_id               		pr_state_ptr->subnet_id
#define next_node_id            		pr_state_ptr->next_node_id
#define rev_pk_count            		pr_state_ptr->rev_pk_count
#define rev_pk_cnt_stathandle   		pr_state_ptr->rev_pk_cnt_stathandle
#define node_objid              		pr_state_ptr->node_objid
#define self_objid              		pr_state_ptr->self_objid
#define subnet_objid            		pr_state_ptr->subnet_objid
#define node_pk_count           		pr_state_ptr->node_pk_count
#define dst_node_id             		pr_state_ptr->dst_node_id
#define send_ok                 		pr_state_ptr->send_ok
#define pk_size_reiv_stathandle 		pr_state_ptr->pk_size_reiv_stathandle
#define pk_cnt_reiv_stathandle  		pr_state_ptr->pk_cnt_reiv_stathandle
#define pk_size_total_reiv_stathandle		pr_state_ptr->pk_size_total_reiv_stathandle
#define pk_cnt_total_reiv_stathandle		pr_state_ptr->pk_cnt_total_reiv_stathandle
#define pk_size_reiv            		pr_state_ptr->pk_size_reiv
#define pk_count_reiv           		pr_state_ptr->pk_count_reiv
#define pk_rev_cnt_no1_stathandle		pr_state_ptr->pk_rev_cnt_no1_stathandle
#define pk_rev_cnt_no2_stathandle		pr_state_ptr->pk_rev_cnt_no2_stathandle
#define pk_rev_cnt_no3_stathandle		pr_state_ptr->pk_rev_cnt_no3_stathandle
#define pk_rev_cnt_no4_stathandle		pr_state_ptr->pk_rev_cnt_no4_stathandle
#define pk_rev_cnt_no5_stathandle		pr_state_ptr->pk_rev_cnt_no5_stathandle
#define pk_rev_cnt_no6_stathandle		pr_state_ptr->pk_rev_cnt_no6_stathandle
#define pk_cnt_no1              		pr_state_ptr->pk_cnt_no1
#define pk_cnt_no2              		pr_state_ptr->pk_cnt_no2
#define pk_cnt_no3              		pr_state_ptr->pk_cnt_no3
#define pk_cnt_no4              		pr_state_ptr->pk_cnt_no4
#define pk_cnt_no5              		pr_state_ptr->pk_cnt_no5
#define pk_cnt_no6              		pr_state_ptr->pk_cnt_no6
#define jj                      		pr_state_ptr->jj
#define pk_avg_size_rev         		pr_state_ptr->pk_avg_size_rev
#define pk_count_rev_channel0   		pr_state_ptr->pk_count_rev_channel0
#define pk_count_rev_channel1   		pr_state_ptr->pk_count_rev_channel1
#define pk_size_rev_channel0    		pr_state_ptr->pk_size_rev_channel0
#define pk_size_rev_channel1    		pr_state_ptr->pk_size_rev_channel1
#define pk_avg_size_rev_stathandle		pr_state_ptr->pk_avg_size_rev_stathandle
#define pk_count_rev_channel0_stathandle		pr_state_ptr->pk_count_rev_channel0_stathandle
#define pk_size_rev_channel0_stathandle		pr_state_ptr->pk_size_rev_channel0_stathandle
#define pk_count_rev_channel1_stathandle		pr_state_ptr->pk_count_rev_channel1_stathandle
#define pk_size_rev_channel1_stathandle		pr_state_ptr->pk_size_rev_channel1_stathandle
#define node_for_schedule       		pr_state_ptr->node_for_schedule
#define link_num                		pr_state_ptr->link_num
#define channel_count1          		pr_state_ptr->channel_count1
#define link_count              		pr_state_ptr->link_count
#define packet_type             		pr_state_ptr->packet_type
#define burst_count_lost        		pr_state_ptr->burst_count_lost
#define burst_count_lost_stathandle		pr_state_ptr->burst_count_lost_stathandle
#define bcp_count_lost          		pr_state_ptr->bcp_count_lost
#define bcp_count_lost_stathandle		pr_state_ptr->bcp_count_lost_stathandle
#define pk_avg_total_size_rev_stathandle		pr_state_ptr->pk_avg_total_size_rev_stathandle
#define burst_count_total_lost_stathandle		pr_state_ptr->burst_count_total_lost_stathandle
#define test_state              		pr_state_ptr->test_state

/* 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	OBS_rte_state *op_sv_ptr = pr_state_ptr;


/* Function Block */

enum { _block_origin = __LINE__ };
int list_compare (CHANNEL_INFOR * a,CHANNEL_INFOR * b)
{
	if (a->start_time < b->start_time) return 1;
	else if (a->start_time >= b->start_time) return -1;
	else return 0;
};

void difference_fuction(int * difference_time,int *	temp_difference_time,int * selected_channel,int * current_channel)
{
	//printf("difference_fuction1\n");
	if( (*temp_difference_time)*(*difference_time) < 0 )
	{
		if( *temp_difference_time >= *difference_time)
		{
			*difference_time = *temp_difference_time;
			*selected_channel = *current_channel;
		}
		else
		{
		}
	}
	else if( *temp_difference_time > 0 && *difference_time > 0 )
	{
		if( *temp_difference_time <= *difference_time)
		{
			*difference_time = *temp_difference_time;
			*selected_channel = *current_channel;
		}
		else
		{
		}
	}
	else if( *temp_difference_time < 0 && *difference_time < 0 )
	{
		if( *temp_difference_time <= *difference_time)
		{
			*difference_time = *temp_difference_time;
			*selected_channel = *current_channel;
		}
		else
		{
		}

	}
//	printf("difference_fuction2\n");
//	printf("fuc selec_chan = %d\n",*selected_channel);
};
/*
int find_outstrm_number(Packet* pkptr)
{
	op_rte_pk_current_node(pkptr, &subnet_objid, &current_node_objid);
	op_ima_obj_attr_get (current_node_objid, "user id", &userid_c);	
	op_rte_pk_next_node (pkptr, &subnet_objid, &next_node_objid);
	op_ima_obj_attr_get (next_node_objid, "user id", &userid_n);
	// determine the objid of the next and the link joining it 
	//link_objid = op_topo_connect (node_objid, next_node_objid,OPC_OBJTYPE_LKDUP, 0);
	link_objid = op_topo_connect (current_node_objid, next_node_objid,OPC_OBJTYPE_LKDUP, 0);
	// determine the objid of the stream/tx attached to the link 
	tx_objid = op_topo_assoc ( link_objid, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_PTTX, 0);
	// for a duplex link, there will be two tx's attached to this link, make sure that the tx that we picked is in the same node 
	if (op_topo_parent (tx_objid) != node_objid)
	{
		tx_objid = op_topo_assoc (link_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_PTTX, 1);
	}
	// get the stream id connecting to the transmitter 
	strm_objid = op_topo_assoc (tx_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_STRM, 0);
	// get the stream number 
	op_ima_obj_attr_get (strm_objid, "src stream", &strm_num);
	
}	
*/
void List_Print(List * list)
{
	int num; int i;CHANNEL_INFOR * channel_infor5;
	num = op_prg_list_size(list);
	printf("list_cont=%d\n",num);
	for(i=0;i<num;i++)
	{
		channel_infor5 = (CHANNEL_INFOR *)op_prg_list_access(list,i);
		printf("start=%f,dtime=%f,source=%d,id=%d,outstrm=%d,list_num=%d,\n",channel_infor5->start_time,channel_infor5->duration_time,
																		   channel_infor5->source,    channel_infor5->id, 
																		   channel_infor5->outstrm_num,i);
	
	}
	//getchar();
}
void Cur_Port_List_Print()
{
	int k;int i;

	for(k=0;k<link_count;k++)
	{
		for(i=1;i<channel_count1;i++)
		{
			List_Print(node_for_schedule.port[k].channel[i].occupy_list);
		}
	}
	getchar();
}
/*
void All_List_Print()
{
	int i;int j
	for(i=1;i<7;i++)
	{
		for(j=1;j<7;j++)
		{
			if( i != j )
			{
				Cur_Port_List_Print()
			}
		}	
	}	
}
*/

void function_link_utilization(int userid,int userid_next,double pk_size)
{
	total_pk_size[userid-1][userid_next-1] = total_pk_size[userid-1][userid_next-1] + pk_size;
}
void function_link_utilization_print()
{
	int i,j;
	printf("sim_time=%f\n",op_sim_time());
	for(i=0;i<6;i++)
	{
		for(j=0;j<6;j++)
		{
			printf("total_pk_size[%d][%d]=%f\n",i+1,j+1,total_pk_size[i][j]);
		}	
	}	
}	

/* End of Function Block */

/* 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 OBS_rte (void);
	Compcode OBS_rte_init (void **);
	void OBS_rte_diag (void);
	void OBS_rte_terminate (void);
	void OBS_rte_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
OBS_rte (void)
	{
	int _block_origin = 0;
	FIN (OBS_rte ());
	if (1)
		{
		Objid		dest_objid;
		Objid		src_objid;
		Objid		FIS_dest_objid;
		Objid		FIS_src_objid;
		Objid		src_node_objid;
		Objid		dst_node_objid;
		Objid		current_node_objid;
		Objid		next_node_objid;
		Objid		link_objid;
		Objid		tx_objid;
		Objid		strm_objid;
		int			destination_address;
		int			source_address;
		
		int			fail_name;
		int			strm_num;
		int			strm_num_from_source;
		int			dst_address;
		int			wave_count;
		int			userid;//init
		char		name_id[10];
		
		int			fis_gen_userid;//fis_gen
		char		fis_gen_name_id[10];
		
		int			next_userid;//send
		int			current_userid;
		
		int			same_userid;//same
		char		same_name_id[10];
		
		int			rte_userid;//all
		char		rte_name_id[10];
		
		int			flag;
		int			PK_type;
		
		Packet*		FIS_pkptr;
		Packet*		r_FIS_pkptr;
		Packet*		ack_pkptr;
		Packet*		re_pkptr;
		Route*		FIS_min_rptr_copy;
		Route*		FIS_current_rptr;
		Route*		FIS_rptr;
		double		link_cost;
		Route*		pk_rptr;
		Route*		pk_r;
		Route*		route_ptr;
		Route_Link*	link_ptr;
		Route*		min_rptr_copy;
		Route*		route_test;
		Route_Set*	FIS_rset_ptr_t;
		Route*		FIS_min_rptr_t;
		char		node_name[255];
		char		id[20];
		Objid*		node_objid_ptr;
		int			i, num_nodes;
		int			subnet_ids[10], node_ids[10];
		double		cur_time;
		Packet*		cp_pkptr;
		int			next_address;
		double		start_time, dtime_time;
		double		n_start_time;
		double		o_start_time;
		double		start_time_1, dtime_time_1;
		double		start_time_2, dtime_time_2;
		
		int			s_f, num;
		
		int 		j,k;
		
		int 		check_num, num1, num2,num3,num4;
		double		list_table[100][2];
		double		dtime;
		double		stime;
		

⌨️ 快捷键说明

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