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

📄 dsr_interface.pr.c

📁 afit的ad hoc路由协议源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: dsr_interface.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 dsr_interface_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A op_runsim 7 3C8784B0 3C8784B0 1 jballah Jason@Ballah 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 */

///////////////////////////////////////////////////////////////
// DSR INTERFACE HEADER BLOCK
//
// Declaration of every constant, type, lybrary, glabal 
// variables... used by the dsr interface process
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
//////////////////////// INCLUDE ////////////////////////////// 
///////////////////////////////////////////////////////////////

#include "dsr_support.h"

///////////////////////////////////////////////////////////////
///////////////// CONSTANTS DEFINITION ////////////////////////
///////////////////////////////////////////////////////////////

// stream number definition
#define FROM_ROUTING_LAYER_STRM		1
#define FROM_SRC_STRM				0
#define TO_ROUTING_LAYER_STRM		0
#define TO_SINK_STRM				1

///////////////////////////////////////////////////////////////
///////////// TRANSITION MACROS DEFINITION ////////////////////
///////////////////////////////////////////////////////////////

#define SRC_ARRIVAL (op_intrpt_type()==OPC_INTRPT_STRM && op_intrpt_strm()==FROM_SRC_STRM)
#define RCV_ARRIVAL (op_intrpt_type()==OPC_INTRPT_STRM && op_intrpt_strm()==FROM_ROUTING_LAYER_STRM)

///////////////////////////////////////////////////////////////
////////////// GLOBAL VARIABLES DECLARATION ///////////////////
///////////////////////////////////////////////////////////////

// Number of nodes in the network
int number_of_nodes;

// variable for statistics

Stathandle stat_packet_transmited;
int packet_transmited;
Stathandle stat_packet_received;
int packet_received;
Stathandle stat_efficiency;
Stathandle stat_ete_delay;
Stathandle stat_average_delay;
int total_delay;
Stathandle stat_packet_throughput;
int packet_delivery_ratio;
Stathandle stat_packet_delivery_ratio;

/* 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 */
	Distribution *	         		address_dist;
	int	                    		my_dsr_address;
	Objid	                  		my_objid;
	Objid	                  		my_node_objid;
	Objid	                  		my_network_objid;
	int	                    		TRANSMIT;
	int	                    		destination_dsr_address;
	} dsr_interface_state;

#define pr_state_ptr            		((dsr_interface_state*) SimI_Mod_State_Ptr)
#define address_dist            		pr_state_ptr->address_dist
#define my_dsr_address          		pr_state_ptr->my_dsr_address
#define my_objid                		pr_state_ptr->my_objid
#define my_node_objid           		pr_state_ptr->my_node_objid
#define my_network_objid        		pr_state_ptr->my_network_objid
#define TRANSMIT                		pr_state_ptr->TRANSMIT
#define destination_dsr_address 		pr_state_ptr->destination_dsr_address

/* 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	dsr_interface_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 dsr_interface (void);
	Compcode dsr_interface_init (void **);
	void dsr_interface_diag (void);
	void dsr_interface_terminate (void);
	void dsr_interface_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


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


		FSM_ENTER (dsr_interface)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED (0, state0_enter_exec, "init", "dsr_interface () [init enter execs]")
				{
				///////////////////////////////////////////////////////////////
				// DSR INTERFACE INIT STATE
				//
				// Initialize the dsr interface (upper layer) process model 
				///////////////////////////////////////////////////////////////
				
				// get the different objid relative to the current process
				my_objid=op_id_self();
				my_node_objid=op_topo_parent(my_objid);
				my_network_objid=op_topo_parent(my_node_objid);
				
				// find the dsr address used by the current node by calling the dsr support package
				my_dsr_address=dsr_support_get_dsr_address(my_node_objid);
				
				// use also the dsr_support in order to know how many nodes are using the dsr model
				number_of_nodes=dsr_support_number_of_nodes();  
				
				// read the user parameter which says if the current node is going to transmit some data packet
				op_ima_obj_attr_get(my_objid,"Transmit",&TRANSMIT);
				
				// statistics initialization
				stat_packet_transmited=op_stat_reg("Upper Layer Packet Transmited",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL); 
				op_stat_write(stat_packet_transmited,packet_transmited=0);
				stat_packet_received=op_stat_reg("Upper Layer Packet Received",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL); 
				op_stat_write(stat_packet_received,packet_received=0);
				stat_efficiency=op_stat_reg("Upper Layer Packet Delivery Ratio",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL); 
				op_stat_write(stat_efficiency,1);
				stat_ete_delay=op_stat_reg("Upper Layer ETE Delay",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
				op_stat_write(stat_ete_delay,0);
				stat_average_delay=op_stat_reg("Upper Layer Average Delay",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
				op_stat_write(stat_average_delay,total_delay=0);
				stat_packet_throughput=op_stat_reg ("Upper Layer Packet Throughput",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
				op_stat_write(stat_packet_throughput,0);
				
				// init the distribution which will chose a random destination address
				address_dist=op_dist_load("uniform_int",0,(number_of_nodes-1));
				// compute randomly a destination dsr address
				destination_dsr_address=(int)op_dist_outcome(address_dist);
				// check that this destination is not "myself"
				while (destination_dsr_address==my_dsr_address)
					{
					destination_dsr_address=(int)op_dist_outcome(address_dist);
					}
				}


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


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



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


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


			/** state (idle) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "idle", "dsr_interface () [idle exit execs]")
				{
				}


			/** state (idle) transition processing **/
			FSM_INIT_COND (RCV_ARRIVAL)
			FSM_TEST_COND (SRC_ARRIVAL)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("idle")

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "RCV_ARRIVAL", "", "idle", "rx")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "SRC_ARRIVAL", "", "idle", "tx")
				FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "default", "", "idle", "idle")
				}
				/*---------------------------------------------------------*/



			/** state (rx) enter executives **/
			FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "rx", "dsr_interface () [rx enter execs]")
				{
				///////////////////////////////////////////////////////////////
				// RX STATE
				//
				// Processed when a packet is received from the DSR Routing layer

⌨️ 快捷键说明

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