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

📄 dsr_interface.pr.c

📁 afit的ad hoc路由协议源码
💻 C
📖 第 1 页 / 共 2 页
字号:
				///////////////////////////////////////////////////////////////
				
				// extract the packet from the DSR Routing strm
				pk_ptr=op_pk_get(FROM_ROUTING_LAYER_STRM);
				
				// update the packet received and efficiency statistics
				++packet_received;
				op_stat_write(stat_packet_received,packet_received);
				op_stat_write(stat_efficiency,(double)packet_received/(double)packet_transmited);
				
				// calcul the delay of the packet and update the corresponding statistic
				packet_delay=(op_sim_time()-op_pk_creation_time_get(pk_ptr));
				op_stat_write(stat_ete_delay,packet_delay); 
				
				// calcul the total delay and update the average delay statistic
				total_delay+=packet_delay;
				op_stat_write(stat_average_delay,total_delay/(double)packet_received); 
				
				// update the packet throughput statistic
				op_stat_write(stat_packet_throughput,(double)packet_received/((double)number_of_nodes*op_sim_time()));
				
				// and send the data packet to the sink
				op_pk_send(pk_ptr,TO_SINK_STRM);
				}


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


			/** state (rx) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "rx", "idle")
				/*---------------------------------------------------------*/



			/** state (tx) enter executives **/
			FSM_STATE_ENTER_FORCED (3, state3_enter_exec, "tx", "dsr_interface () [tx enter execs]")
				{
				///////////////////////////////////////////////////////////////
				// TX STATE
				//
				// Processed when a packet to transmit is received from the source 
				///////////////////////////////////////////////////////////////
				
				// extract the packet from the source stream
				if (SRC_ARRIVAL)
					{
					pk_ptr=op_pk_get(FROM_SRC_STRM);
					// creatre and install an ici to communicate the dsr address of the packet destination to the dsr process model
					iciptr = op_ici_create("Dsr_Dest_Ici");
					op_ici_attr_set(iciptr,"Packet_Destination",destination_dsr_address);
					op_ici_install(iciptr);
					// send the packet to the DSR layer
					printf("A packet to send to %d\n",destination_dsr_address);
					}
				
				// if the node is allowed to transmit new data packets in the network
				if (TRANSMIT)
					{
					// send the packet to the DSR layer
					op_pk_send (pk_ptr,TO_ROUTING_LAYER_STRM);
					// and update statistics
					++packet_transmited;
					op_stat_write(stat_packet_transmited,packet_transmited);
					op_stat_write(stat_efficiency,(double)packet_received/(double)packet_transmited);
					}
				// if the node should not send any new packet
				else
					{
					// the packet is destroyed
					op_pk_destroy(pk_ptr);
					}
				}


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


			/** state (tx) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "tx", "idle")
				/*---------------------------------------------------------*/



			/** state (pre-init) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (4, "pre-init", "dsr_interface () [pre-init enter execs]")
				{
				///////////////////////////////////////////////////////////////
				// DSR INTERFACE PRE-INIT STATE
				//
				// do nothing... just waiting for the dsr model pre-initialisation 
				// completion
				///////////////////////////////////////////////////////////////
				
				// ensure that each node has finised its pre-initialization before going in the init sate
				op_intrpt_schedule_self(op_sim_time(),0);
				}


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


			/** state (pre-init) exit executives **/
			FSM_STATE_EXIT_UNFORCED (4, "pre-init", "dsr_interface () [pre-init exit execs]")
				{
				}


			/** state (pre-init) transition processing **/
			FSM_TRANSIT_FORCE (0, state0_enter_exec, ;, "default", "", "pre-init", "init")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (4,dsr_interface)
		}
	}

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

	FIN (dsr_interface_init (gen_state_pptr))

	if (obtype == OPC_NIL)
		{
		/* Initialize memory management */
		if (Vos_Catmem_Register ("proc state vars (dsr_interface)",
			sizeof (dsr_interface_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 */
		((dsr_interface_state *)(*gen_state_pptr))->current_block = 8;

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



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




void
dsr_interface_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (dsr_interface_terminate (void))

	if (1)
		{
		///////////////////////////////////////////////////////////////
		// DSR INTERFACE TEMPORARY VARIABLES BLOCK
		//
		// Declaration of the temporary variables
		///////////////////////////////////////////////////////////////
		
		Packet* pk_ptr;
		//int destination_dsr_address;
		Ici* iciptr;
		double packet_delay;

		/* No 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 dsr_interface_svar function. */
#undef address_dist
#undef my_dsr_address
#undef my_objid
#undef my_node_objid
#undef my_network_objid
#undef TRANSMIT
#undef destination_dsr_address



void
dsr_interface_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
	{
	dsr_interface_state		*prs_ptr;

	FIN (dsr_interface_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (char *)OPC_NIL;
		FOUT;
		}
	prs_ptr = (dsr_interface_state *)gen_ptr;

	if (strcmp ("address_dist" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->address_dist);
		FOUT;
		}
	if (strcmp ("my_dsr_address" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->my_dsr_address);
		FOUT;
		}
	if (strcmp ("my_objid" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->my_objid);
		FOUT;
		}
	if (strcmp ("my_node_objid" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->my_node_objid);
		FOUT;
		}
	if (strcmp ("my_network_objid" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->my_network_objid);
		FOUT;
		}
	if (strcmp ("TRANSMIT" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->TRANSMIT);
		FOUT;
		}
	if (strcmp ("destination_dsr_address" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->destination_dsr_address);
		FOUT;
		}
	*var_p_ptr = (char *)OPC_NIL;

	FOUT;
	}

⌨️ 快捷键说明

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