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

📄 obs_proc_q.pr.c

📁 实验室前辈用OPNET做的光突发交换网络的仿真实验
💻 C
📖 第 1 页 / 共 3 页
字号:
			FSM_STATE_EXIT_UNFORCED (1, "wait", "OBS_proc_q () [wait exit execs]")
				{
				}


			/** state (wait) transition processing **/
			FSM_INIT_COND (END_SIM)
			FSM_TEST_COND (INTRPT_REMOTE)
			FSM_TEST_COND (BURST_ARRIVAL)
			FSM_TEST_COND (INTRPT_SELF)
			FSM_TEST_LOGIC ("wait")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 3, state3_enter_exec, ;, "END_SIM", "", "wait", "end")
				FSM_CASE_TRANSIT (1, 4, state4_enter_exec, ;, "INTRPT_REMOTE", "", "wait", "send")
				FSM_CASE_TRANSIT (2, 5, state5_enter_exec, ;, "BURST_ARRIVAL", "", "wait", "classfication")
				FSM_CASE_TRANSIT (3, 2, state2_enter_exec, ;, "INTRPT_SELF", "", "wait", "proc")
				}
				/*---------------------------------------------------------*/



			/** state (proc) enter executives **/
			FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "proc", "OBS_proc_q () [proc enter execs]")
				{
				op_ima_obj_attr_get(node_objid, "user id", &userid);
				if (op_subq_empty (subq_index) == OPC_FALSE)
				{
					pkptr_burst = op_subq_pk_access (subq_index, OPC_QPOS_HEAD);
					// bcp积己 
					pkptr =op_pk_create_fmt ("BCP");
					op_pk_nfd_get (pkptr_burst, "source address", &source_address);
					op_pk_nfd_get (pkptr_burst, "destination address", &destination_address);
					op_pk_nfd_get (pkptr_burst, "id", &id_number_temp);
					if (min_rptr[source_address][destination_address] == OPC_NIL)   //扼快泼 抛捞喉俊 粮犁窍瘤 臼栏搁
					{
						p_min_rptr_copy = OPC_NIL;
					}
					else
					{
						p_min_rptr_copy = op_rte_route_copy (min_rptr[source_address][destination_address]);
					}
					current_rptr = p_min_rptr_copy;
					if (current_rptr == OPC_NIL) 
					{
						pkptr_burst = op_subq_pk_remove (subq_index, OPC_QPOS_HEAD);
						op_pk_destroy (pkptr_burst);
						op_pk_destroy (pkptr);
					}
					else 
					{
						/* insert the route into the packet */
						pk_rptr = op_rte_route_copy (current_rptr);
						op_rte_pk_route_insert (pkptr, pk_rptr);
					//	printf("proc:proc:,s=%d,d=%d,userid=%d,sim=%f\n",source_address,destination_address,userid,op_sim_time());
					//	getchar();
						pk_size = op_pk_total_size_get (pkptr_burst);
						num_nodes = op_rte_route_num_nodes (min_rptr[source_address][destination_address]);
						dtime_time = (double) pk_size/RATE;				
						op_ima_obj_attr_get(self_objid, "EXTRA_TIME", &EXTRA_TIME);   
						start_time = (double) PROC_TIME*num_nodes;
						op_pk_nfd_set (pkptr, "source address", source_address);
						op_pk_nfd_set (pkptr, "destination address", destination_address);
						op_pk_nfd_set (pkptr, "start", start_time);
						op_pk_nfd_set (pkptr, "dtime", dtime_time);
						op_pk_nfd_set (pkptr, "type", 0);
						op_pk_nfd_set (pkptr, "id", id_number_temp);
						
						pk_count_total_send++;
						pk_size_total_send = pk_size_total_send + dtime_time * RATE;
						pk_avg_total_size_send = ( (double)pk_size_total_send / (double)pk_count_total_send);
						op_stat_write(pk_cnt_total_send_stathandle,pk_count_total_send);
						op_stat_write(pk_size_total_send_stathandle,pk_size_total_send);
						op_stat_write(pk_avg_total_size_send_stathandle,pk_avg_total_size_send);
						
						op_pk_send (pkptr, PK_OUT_STRM);
						op_pk_nfd_set (pkptr_burst,"start", start_time);
					//	printf("proc:proc,bcp send after:,userid=%d,sim=%f\n",userid,op_sim_time());
					}
					
				}
				else
				{
					//printf("subq access fail,userid=%d,subq_index=%d\n",userid,subq_index);
					//op_subq_print (subq_index);
				}
				subq_index++;
				if(subq_count <= subq_index)
					subq_index = 0;
				
				op_intrpt_schedule_self(op_sim_time()+0.000031875,0);
				
				}


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


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



			/** state (end) enter executives **/
			FSM_STATE_ENTER_UNFORCED (3, state3_enter_exec, "end", "OBS_proc_q () [end enter execs]")
				{
				
				}


			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (7,OBS_proc_q)


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


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



			/** state (send) enter executives **/
			FSM_STATE_ENTER_FORCED (4, state4_enter_exec, "send", "OBS_proc_q () [send enter execs]")
				{
				//printf("proc:sent:,sim=%f\n",op_sim_time());
				/* obtain the app packet*/
				//pkptr = op_pk_get(op_intrpt_strm());
				
				//op_pk_nfd_get (pkptr, "flag_suc", &temp_flag_suc);
				//if(temp_flag_suc == 1)
				//{
					temp_code = op_intrpt_code();
				//	op_pk_nfd_get (pkptr, "destination address", &destination_address);
				//	pkptr_burst = op_subq_pk_remove (destination_address-1, OPC_QPOS_HEAD);
					pkptr_burst = op_subq_pk_remove (temp_code-1, OPC_QPOS_HEAD);
					
					
					if(temp_code == 1)
					{
						burst_count_to_node1++;
						op_stat_write(burst_count_to_node1_stathandle,burst_count_to_node1);
						burst_size_to_node1 = op_pk_total_size_get(pkptr_burst);
						op_stat_write(burst_size_to_node1_stathandle,burst_size_to_node1);
					}
					else if(temp_code == 2)
					{	
						burst_count_to_node2++;
						op_stat_write(burst_count_to_node2_stathandle,burst_count_to_node2);
						burst_size_to_node2 = op_pk_total_size_get(pkptr_burst);
						op_stat_write(burst_size_to_node2_stathandle,burst_size_to_node2);
					}
					else if(temp_code == 3)
					{	
						burst_count_to_node3++;
						op_stat_write(burst_count_to_node3_stathandle,burst_count_to_node3);
						burst_size_to_node3 = op_pk_total_size_get(pkptr_burst);
						op_stat_write(burst_size_to_node3_stathandle,burst_size_to_node3);
					}
					else if(temp_code == 4)
					{	
						burst_count_to_node4++;
						op_stat_write(burst_count_to_node4_stathandle,burst_count_to_node4);
						burst_size_to_node4 = op_pk_total_size_get(pkptr_burst);
						op_stat_write(burst_size_to_node4_stathandle,burst_size_to_node4);
					}
					else if(temp_code == 5)
					{
						burst_count_to_node5++;
						op_stat_write(burst_count_to_node5_stathandle,burst_count_to_node5);
						burst_size_to_node5 = op_pk_total_size_get(pkptr_burst);
						op_stat_write(burst_size_to_node5_stathandle,burst_size_to_node5);
					}
					else if(temp_code == 6)
					{
						burst_count_to_node6++;
						op_stat_write(burst_count_to_node6_stathandle,burst_count_to_node6);
						burst_size_to_node6 = op_pk_total_size_get(pkptr_burst);
						op_stat_write(burst_size_to_node6_stathandle,burst_size_to_node6);
					}	
				
				
					op_pk_send(pkptr_burst, PK_OUT_STRM_STORE);
				//}
				//else if(temp_flag_suc == 0)
				{
				}
				//op_pk_destroy(pkptr);
				
				}


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


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



			/** state (classfication) enter executives **/
			FSM_STATE_ENTER_FORCED (5, state5_enter_exec, "classfication", "OBS_proc_q () [classfication enter execs]")
				{
				//printf("classfication1  sim=%f\n",op_sim_time());
				//getchar();
				self_objid = op_id_self ();
				node_objid = op_topo_parent(self_objid);
				op_ima_obj_attr_get(node_objid, "user id", &userid);	
				//if(userid ==1)
				//{	
				gen_count_total_send++;
				op_stat_write(gen_count_total_send_stathandle,gen_count_total_send);
				
				pkptr_burst = op_pk_get(op_intrpt_strm());
				
				
				source_address = node_address;
				//printf("classfication2\n");
				//getchar();
				while(1)
				{
					destination_address = op_dist_uniform(NODE_NUM);
					destination_address++;
				//	destination_address=2;
				//	printf("classfication, userid=%d,des_address=%d\n",userid,destination_address);
					
					if(userid != destination_address)	
					{	
						
						id_number++;
						op_pk_nfd_set (pkptr_burst, "source address", node_address);
						op_pk_nfd_set (pkptr_burst, "destination address", destination_address);
						//if type == 0 than bcp, if type == 1 than burst
						op_pk_nfd_set (pkptr_burst, "type", 1);
						op_pk_nfd_set (pkptr_burst, "id", id_number);
						//op_subq_print (destination_address-1);
						op_subq_pk_insert (destination_address-1, pkptr_burst, OPC_QPOS_TAIL);
				//		printf("subq insert success,subq_index=%d,userid=%d\n",subq_index,userid);
						//op_subq_print (destination_address-1);
						break;
					}
					else
					{
				//		printf("subq insert fail,userid=%d\n",userid);
					}	
				}
					
				//printf("classfication  sim=%f\n",op_sim_time());
				//getchar();
				
				
				//}
				
				
				
				
				
				}


			/** state (classfication) exit executives **/
			FSM_STATE_EXIT_FORCED (5, "classfication", "OBS_proc_q () [classfication exit execs]")
				{
				}


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



			}


		FSM_EXIT (0,OBS_proc_q)
		}
	}

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

	FIN (OBS_proc_q_init (gen_state_pptr))

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

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



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




void
OBS_proc_q_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (OBS_proc_q_terminate (void))

	if (1)
		{
		Packet*		pkptr_burst;
		Packet*		pkptr;
		
		int			sequence_number_ack;
		int			sequence_number_rcv;
		int			source_address;
		int			destination_address;
		
		
		int 		i,j,k;
		Route*		pk_rptr;
		Route*		p_min_rptr_copy;
		double		start_time;
		double		dtime_time;
		double		cur_time;
		int			subnet_ids[10];
		int			node_ids[20];
		int			num_nodes;
		int			userid;
		
		double 		EXTRA_TIME;
		int			ok_flag;
		int			wavelength_number;
		int 		u_id;
		Objid		strm_objid;
		int 		jj;
		int 		channel_num;
		double		temp_time;
		double      temp_size;
		int			temp_flag_suc;
		int			id_number_temp;
		int			temp_code;
		
		
		

		/* Termination Block */


		BINIT
		

		/* End of Termination Block */

		}
	Vos_Catmem_Dealloc (pr_state_ptr);

	FOUT;
	}


/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in OBS_proc_q_svar function. */
#undef sequence_number_wait
#undef sequence_number_current
#undef node_address
#undef nodes_total
#undef queue_size
#undef pk_rcvd
#undef address_dist
#undef sar_mod_objid

⌨️ 快捷键说明

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