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

📄 obs_rte.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
📖 第 1 页 / 共 4 页
字号:
												difference_fuction(&difference_time,&temp_difference_time,&selected_channel,&i);
											}
											
										}
									}
									if(list_element_num >= 1)
									{	
										channel_infor = (CHANNEL_INFOR *)op_prg_list_access(node_for_schedule.port[current_port].channel[i].occupy_list,list_element_num-1);
										if(channel_infor->duration_time <= start_time)
										{
											temp_difference_time = -2;
											difference_fuction(&difference_time,&temp_difference_time,&selected_channel,&i);
										}
										channel_infor = (CHANNEL_INFOR *)op_prg_list_access(node_for_schedule.port[current_port].channel[i].occupy_list,0);
										if(channel_infor->start_time > start_time && channel_infor->start_time >= dtime_time)
										{
											temp_difference_time = channel_infor->start_time - dtime_time;
											difference_fuction(&difference_time,&temp_difference_time,&selected_channel,&i);
										}
									}
							
								}	
							
							if(selected_channel == -1)
							{
							//盲澄且寸阑 给罐澜 
								bcp_count_lost++;
								op_stat_write(bcp_count_lost_stathandle,bcp_count_lost);
								op_pk_destroy(pkptr);
								send_ok = 0;
							}
							else if(selected_channel > -1)
							{
								channel_infor3 = (CHANNEL_INFOR *)op_prg_mem_alloc(sizeof(CHANNEL_INFOR));
								channel_infor3->start_time = start_time;
								channel_infor3->duration_time = dtime_time;
								channel_infor3->source = source_address;
								channel_infor3->id = pkptr_id;
								
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								/////////////////////find outstrum_number////////////////////////////////////////////////////////////////////
								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, selected_channel);
								/* get the stream number */
								op_ima_obj_attr_get (strm_objid, "src stream", &strm_num);
								/////////////////////end of "find outstrum_number"//////////////////////////////////////////////////////////////////
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								channel_infor3->outstrm_num = strm_num;
							//	printf("before insert\n");
							//	List_Print(node_for_schedule.port[current_port].channel[0].occupy_list);
							//	List_Print(node_for_schedule.port[current_port].channel[1].occupy_list);
							//	List_Print(node_for_schedule.port[current_port].channel[2].occupy_list);
							//	List_Print(node_for_schedule.port[current_port].channel[3].occupy_list);
							//	printf("sele_ch = %d\n",selected_channel);
							//	printf("channel_infor3 = %f,=%f\n",channel_infor3->start_time,channel_infor3->duration_time);
								op_prg_list_insert(node_for_schedule.port[current_port].channel[selected_channel].occupy_list,channel_infor3,OPC_LISTPOS_TAIL);
								op_prg_list_sort (node_for_schedule.port[current_port].channel[selected_channel].occupy_list, list_compare);
							//	List_Print(node_for_schedule.port[current_port].channel[selected_channel].occupy_list);
							//	getchar();
							//	List_Print(node_for_schedule.port[current_port].channel[0].occupy_list);
							//	List_Print(node_for_schedule.port[current_port].channel[1].occupy_list);
							//	List_Print(node_for_schedule.port[current_port].channel[2].occupy_list);
							//	List_Print(node_for_schedule.port[current_port].channel[3].occupy_list);
							//	getchar();
								send_ok = 1;
								if(strm_num_from_source == PK_IN_STRM_BCP)
								{
									op_intrpt_schedule_remote(op_sim_time(),destination_address,op_id_from_name (node_objid, OPC_OBJTYPE_QUEUE, "proc_q"));
								}
							}	
							//////////////////////////////////////////////////////////////////////////////////////////////////////////////////							
							//end list insert
							//////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
							selected_channel = -1;
							///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
							/////////////////					胶纳临傅颇飘 场(LAUC_VF)									 /////////////////
							/////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
						}
					
					}
					else 
					{
						op_pk_destroy(pkptr);
						send_ok = 0;
					}
				
					}
				}// end of "strm_num == PK_IN_STRM_BURST
				
				
				//printf("rte end  sim=%f\n",op_sim_time());
				
				
				}


			/** state (get_rte) exit executives **/
			FSM_STATE_EXIT_FORCED (2, "get_rte", "OBS_rte () [get_rte exit execs]")
				{
				}


			/** state (get_rte) transition processing **/
			FSM_INIT_COND (END_SIM)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("get_rte")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 4, state4_enter_exec, ;, "END_SIM", "", "get_rte", "end")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "default", "", "get_rte", "send")
				}
				/*---------------------------------------------------------*/



			/** state (send) enter executives **/
			FSM_STATE_ENTER_FORCED (3, state3_enter_exec, "send", "OBS_rte () [send enter execs]")
				{
				if(send_ok == 1)
				{	
					
					if(packet_type == 0)
					{
					//		printf("send_ok :bcp  sim=%f\n",op_sim_time());
							//if bcp
							//fixed channel 0
							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);
					
							/* advance the routing pointer */
							op_rte_pk_advance (pkptr);
							
							/* 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);
							op_pk_nfd_get (pkptr, "start", &start_time);
							new_start_time = start_time - PROC_TIME;
							op_pk_nfd_set (pkptr, "start", new_start_time);
							
							op_pk_nfd_get (pkptr, "dtime",&d_time);
							//printf("c=%d,n=%d,size=%f\n",userid_c,userid_n,d_time * RATE);
							function_link_utilization(userid_c, userid_n,d_time * RATE);
										
							op_pk_send_delayed (pkptr,strm_num, PROC_TIME);
						
					}//end of "packet_type == 0"
					else if(packet_type == 1)
					{	
							//		printf("send_ok :burst sim=%f\n",op_sim_time());
							//printf("burst through  send_part\n");
							//if burst
							//choose channel 1 ~ 4
							op_pk_nfd_get (pkptr, "id", &pk_id);
							op_pk_nfd_get (pkptr, "source address", &pk_address);
							op_pk_nfd_get (pkptr, "destination address", &destination_address);
							loop_flag_i = 1;
							loop_flag_j = 1;
							loop_flag_k = 1;
							channel_infor  = (CHANNEL_INFOR *)op_prg_mem_alloc(sizeof(CHANNEL_INFOR));
				
							for(k=0;k<link_count;k++)
							{
								for(i=1;i<channel_count1;i++)
								{
									j=0;
									list_element_num = op_prg_list_size(node_for_schedule.port[k].channel[i].occupy_list);
									if(list_element_num > 0)
									{	
										while(j < list_element_num && loop_flag_j==1)
										{
											channel_infor = (CHANNEL_INFOR *)op_prg_list_access(node_for_schedule.port[k].channel[i].occupy_list,j);
											if(channel_infor->source == pk_address && channel_infor->id == pk_id) 
											{
							//					printf("rte:send: burst inter node sim=%f\n",op_sim_time());
												loop_flag_j = 0;
												op_pk_send(pkptr,channel_infor->outstrm_num);
											}
											j++;
										}
									}
								}
							}
						//	printf("burst through  send_part 2,flag_j=%d\n",loop_flag_j);
							if(loop_flag_j == 1)
							{
								//if(pk_address == 1)
								//{	
									//temp_time = op_sim_time();
									//if(temp_time > 0.03)	
									//{
									burst_count_lost++;
									op_stat_write(burst_count_lost_stathandle,burst_count_lost);
						//			printf("burst lost,so_addr=%d,des_addr=%d\n",pk_address,destination_address);
									burst_count_total_lost++;
									op_stat_write(burst_count_total_lost_stathandle,burst_count_total_lost);
									//op_pk_nfd_get (pkptr, "destination address", &e_d);
									//op_pk_nfd_get (pkptr, "source address", &e_s);
									//op_pk_nfd_get (pkptr, "id", &e_id);	
									//printf("burst_lost=%d,s=%d,d=%d,id=%d\n",burst_count_total_lost,e_s,e_d,e_id);
									//getchar();
									dropped_burst_size = 0;
									dropped_burst_size = op_pk_total_size_get(pkptr);
				//					printf("pk_address=%d, userid=%d\n",pk_address,userid);
				//					getchar();
									total_dropped_burst_count++;
									total_dropped_burst_length_related_hop = total_dropped_burst_length_related_hop + dropped_burst_size * (op_rte_route_num_nodes (min_rptr[pk_address][userid])-1);//num_routes[pk_address][userid];
									op_pk_destroy(pkptr);
									
									//}
								//}
							}
							loop_flag_j = 1;
							//op_prg_mem_free(channel_infor); //捞巴 锭巩俊 List狼 付瘤阜捞 0栏肺 檬扁拳 登菌促. !!!! 内爹矫 林狼 !!!!!
					}//end of "packet_type == 1"
					
				}//if(send_ok == 0)
				
					
					
					
				
					
				/*
					// get the stream id connecting to the transmitter 
					strm_objid = op_topo_assoc (tx_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_STRM, 0);
					strm_objid1 = op_topo_assoc (tx_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_STRM, 1);
					
					// get the stream number 
					op_ima_obj_attr_get (strm_objid, "src stream", &strm_num);
					op_ima_obj_attr_get (strm_objid1, "src stream", &strm_num1);
					//printf("strm number = %d\n",strm_num);
					//printf("strm number = %d\n",strm_num1);
					
					op_pk_nfd_get (pkptr, "start", &start_time);
					new_start_time = start_time - PROC_TIME;
					op_pk_nfd_set (pkptr, "start", new_start_time);
				
					if(op_dist_uniform(op_topo_assoc_count(tx_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_STRM)))
						op_pk_send_delayed (pkptr, strm_num, PROC_TIME);
					else
						op_pk_send_delayed (pkptr, strm_num1, PROC_TIME);
				
					op_pk_nfd_get(pkptr,"channel",&temp_channel_num);
					op_pk_nfd_get (pkptr, "dtime", &d_time);
					if(temp_channel_num == 0)
					{
						pk_count_rev_channel0++;
						pk_size_rev_channel0 = d_time * RATE;
						op_stat_write(pk_count_rev_channel0_stathandle, pk_count_rev_channel0);
						op_stat_write(pk_size_rev_channel0_stathandle, pk_size_rev_channel0);
						op_pk_send_delayed (pkptr,strm_num, PROC_TIME);	
					}
					else if(temp_channel_num == 1)
					{
						pk_count_rev_channel1++;
						pk_size_rev_channel1 = d_time * RATE;
						op_stat_write(pk_count_rev_channel1_stathandle, pk_count_rev_channel1);
						op_stat_write(pk_size_rev_channel1_stathandle, pk_size_rev_channel1);
						op_pk_send_delayed (pkptr,strm_num1, PROC_TIME);	
					}
				*/
				
				}


			/** state (send) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "send", "OBS_rte () [send exit execs]")
				{
				}


			/** state (send) transition processing **/
			FSM_INIT_COND ((1))
			FSM_TEST_COND (END_SIM)
			FSM_TEST_LOGIC ("send")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "", "", "send", "wait")
				FSM_CASE_TRANSIT (1, 4, state4_enter_exec, ;, "END_SIM", "", "send", "end")
				}
				/*---------------------------------------------------------*/



			/** state (end) enter executives **/
			FSM_STATE_ENTER_UNFORCED (4, state4_enter_exec, "end", "OBS_rte () [end enter execs]")
				{
				link_num = 0;
				
				function_link_utilization_print();
				
				printf("total_dropped_burst_length_related_hop = %f, count=%d\n",total_dropped_burst_length_related_hop,total_dropped_burst_count);
				/*
				for(i = 1; i < NODE_NUM+1; i++)
				{
					if(i != userid)
					{
				    //	printf("userid = %d, i = %d, connect_count = %d\n",userid,i,op_topo_connect_count (userid, i,OPC_OBJMTYPE_LINK));
						if(op_topo_connect_count (userid, i,OPC_OBJMTYPE_LINK))
						{
							link_num++;
							op_ima_obj_attr_get (op_topo_connect (userid, i, OPC_OBJTYPE_LKDUP, 0), "channel count", &channel_count1);
					//		printf("userid = %d, i = %d, channel_count = %d\n",userid,i,channel_count1);
						}
					 }
				}
				for(i = 0; i < link_num; i++)
				{
					for(j = 0; j < channel_count1; j++)
					{
						op_prg_mem_free(node_for_schedule.port[i].channel[j].gab_list);
						op_prg_mem_free(node_for_schedule.port[i].channel[j].occupy_list);
					}
					free(node_for_schedule.port[i].channel);
				}
				free(node_for_schedule.port);
				link_num = 0;
				*/
				//printf("chan_count=%d",channel_cou
				}


			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (9,OBS_rte)


			/** state (end) exit executives **/
			FSM_STATE_EXIT_UNFORCED (4, "end", "OBS_rte () [end exit execs]")
				{
				}


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



			}


		FSM_EXIT (0,OBS_rte)
		}
	}

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

	FIN (OBS_rte_init (gen_state_pptr))

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

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



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




void
OBS_rte_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (OBS_rte_terminate (void))

	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;

⌨️ 快捷键说明

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