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

📄 dsr_source.pr.c

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

/* Include files.					*/
#include	<oms_dist_support.h>

/* Special attribute values.		*/
#define		SSC_INFINITE_TIME		-1.0

/* Interrupt code values.			*/
#define		SSC_START				0
#define		SSC_GENERATE			1
#define		SSC_STOP				2

/* Node configuration constants.	*/
#define		SSC_STRM_TO_LOW			0

/* Macro definitions for state		*/
/* transitions.						*/
#define		START				(intrpt_code == SSC_START)
#define		DISABLED			(intrpt_code == SSC_STOP)
#define		STOP				(intrpt_code == SSC_STOP)
#define		PACKET_GENERATE		(intrpt_code == SSC_GENERATE)

/* Function prototypes.				*/
static void			ss_packet_generate (void);

/* 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 */
	Objid	                  		own_id;
	char	                   		format_str [64];
	double	                 		start_time;
	double	                 		stop_time;
	OmsT_Dist_Handle	       		interarrival_dist_ptr;
	OmsT_Dist_Handle	       		pksize_dist_ptr;
	Boolean	                		generate_unformatted;
	Evhandle	               		next_pk_evh;
	double	                 		next_intarr_time;
	Stathandle	             		bits_sent_hndl;
	Stathandle	             		packets_sent_hndl;
	Stathandle	             		packet_size_hndl;
	Stathandle	             		interarrivals_hndl;
	Distribution *	         		start_dist;
	} dsr_source_state;

#define pr_state_ptr            		((dsr_source_state*) SimI_Mod_State_Ptr)
#define own_id                  		pr_state_ptr->own_id
#define format_str              		pr_state_ptr->format_str
#define start_time              		pr_state_ptr->start_time
#define stop_time               		pr_state_ptr->stop_time
#define interarrival_dist_ptr   		pr_state_ptr->interarrival_dist_ptr
#define pksize_dist_ptr         		pr_state_ptr->pksize_dist_ptr
#define generate_unformatted    		pr_state_ptr->generate_unformatted
#define next_pk_evh             		pr_state_ptr->next_pk_evh
#define next_intarr_time        		pr_state_ptr->next_intarr_time
#define bits_sent_hndl          		pr_state_ptr->bits_sent_hndl
#define packets_sent_hndl       		pr_state_ptr->packets_sent_hndl
#define packet_size_hndl        		pr_state_ptr->packet_size_hndl
#define interarrivals_hndl      		pr_state_ptr->interarrivals_hndl
#define start_dist              		pr_state_ptr->start_dist

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


/* Function Block */

enum { _block_origin = __LINE__ };
static void
ss_packet_generate (void)
	{
	Packet*				pkptr;
	SimT_Pk_Size		pksize;

	/** This function creates a packet based on the packet generation		**/
	/** specifications of the source model and sends it to the lower layer.	**/
	FIN (ss_packet_generate ());

	/* Generate a packet size outcome.					*/
	pksize = (SimT_Pk_Size) ceil (oms_dist_outcome (pksize_dist_ptr));
	
	/* Create a packet of specified format and size.	*/
	if (generate_unformatted == OPC_TRUE)
		{
		/* We produce unformatted packets. Create one.	*/
		pkptr = op_pk_create (pksize);
		}
	else
		{
		/* Create a packet with the specified format.	*/
		pkptr = op_pk_create_fmt (format_str);
		op_pk_total_size_set (pkptr, pksize);
		}

	/* Update the packet generation statistics.			*/
	op_stat_write (packets_sent_hndl, 1.0);
	op_stat_write (packets_sent_hndl, 0.0);
	op_stat_write (bits_sent_hndl, (double) pksize);
	op_stat_write (bits_sent_hndl, 0.0);
	op_stat_write (packet_size_hndl, (double) pksize);
	op_stat_write (interarrivals_hndl, next_intarr_time);

	/* Send the packet via the stream to the lower layer.	*/
	op_pk_send (pkptr, SSC_STRM_TO_LOW);

	FOUT;
	}	

/* 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 dsr_source (void);
	Compcode dsr_source_init (void **);
	void dsr_source_diag (void);
	void dsr_source_terminate (void);
	void dsr_source_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
dsr_source (void)
	{
	int _block_origin = 0;
	FIN (dsr_source ());
	if (1)
		{
		/* Variables used in the "init" state.		*/
		char		interarrival_str [128];
		char		size_str [128];
		Prg_List*	pk_format_names_lptr;
		char*		found_format_str;
		int			low, high;
		Boolean		format_found;
		int			i;
		
		/* Variables used in state transitions.		*/
		int			intrpt_code;


		FSM_ENTER (dsr_source)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "dsr_source () [init enter execs]")
				{
				/* At this initial state, we read the values of source attributes	*/
				/* and schedule a selt interrupt that will indicate our start time	*/
				/* for packet generation.											*/
				
				/* Obtain the object id of the surrounding module.					*/
				own_id = op_id_self ();
				
				/* Read the values of the packet generation parameters, i.e. the	*/
				/* attribute values of the surrounding module.						*/
				op_ima_obj_attr_get (own_id, "Packet Interarrival Time", interarrival_str);
				op_ima_obj_attr_get (own_id, "Packet Size",              size_str);
				op_ima_obj_attr_get (own_id, "Packet Format",            format_str);
				op_ima_obj_attr_get (own_id, "Start Time",               &start_time);
				op_ima_obj_attr_get (own_id, "Stop Time",                &stop_time);
				
				/* Load the PDFs that will be used in computing the packet			*/
				/* interarrival times and packet sizes.								*/
				interarrival_dist_ptr = oms_dist_load_from_string (interarrival_str);
				pksize_dist_ptr       = oms_dist_load_from_string (size_str);
				
				/* Verify the existence of the packet format to be used for			*/
				/* generated packets.												*/
				if (strcmp (format_str, "NONE") == 0)
					{
					/* We will generate unformatted packets. Set the flag.			*/
					generate_unformatted = OPC_TRUE;
					}
				else
					{
					/* We will generate formatted packets. Turn off the flag.		*/
					generate_unformatted = OPC_FALSE;
				
					/* Get the list of all available packet formats.				*/
					pk_format_names_lptr = prg_tfile_name_list_get (PrgC_Tfile_Type_Packet_Format);
				
					/* Search the list for the requested packet format.				*/
					format_found = OPC_FALSE;
					for (i = prg_list_size (pk_format_names_lptr); ((format_found == OPC_FALSE) && (i > 0)); i--)
						{
						/* Access the next format name and compare with requested 	*/
						/* format name.												*/
						found_format_str = (char *) prg_list_access (pk_format_names_lptr, i - 1); 
						if (strcmp (found_format_str, format_str) == 0)
							format_found = OPC_TRUE;
						}
				
				    if (format_found == OPC_FALSE)
						{
						/* The requested format does not exist. Generate 			*/
						/* unformatted packets.										*/
						generate_unformatted = OPC_TRUE;
					
						/* Display an appropriate warning.							*/
						op_prg_odb_print_major ("Warning from simple packet generator model (simple_source):", 
												"The specified packet format", format_str,
												"is not found. Generating unformatted packets instead.", OPC_NIL);
						}
				
					/* Destroy the lits and its elements since we don't need it		*/
					/* anymore.														*/
					prg_list_free (pk_format_names_lptr);
					prg_mem_free  (pk_format_names_lptr);
					}	
				 
					 
				/* Make sure we have valid start and stop times, i.e. stop time is	*/
				/* not earlier than start time.										*/
				if ((stop_time <= start_time) && (stop_time != SSC_INFINITE_TIME))
					{
					/* Stop time is earlier than start time. Disable the source.	*/
					start_time = SSC_INFINITE_TIME;
				
					/* Display an appropriate warning.								*/
					op_prg_odb_print_major ("Warning from simple packet generator model (simple_source):", 
											"Although the generator is not disabled (start time is set to a finite value),",
											"a stop time that is not later than the start time is specified.",
											"Disabling the generator.", OPC_NIL);
					}
				
				/* Schedule a self interrupt that will indicate our start time for	*/
				/* packet generation activities. If the source is disabled,			*/
				/* schedule it at current time with the appropriate code value.		*/
				if (start_time == SSC_INFINITE_TIME)
					{
					op_intrpt_schedule_self (op_sim_time (), SSC_STOP);
					}
				else
					{
					/* $$$$ DSR  $$$$ */
					// Set the source node to begin generating packets at a time uniformly
					// distributed between 0 and 180 seconds so all packets don't start at once
					start_dist = op_dist_load ("uniform", start_time, start_time+180);
					start_time = op_dist_outcome(start_dist);
					op_intrpt_schedule_self (start_time, SSC_START);
					/* $$$$ DSR  $$$$ */
					
					/* In this case, also schedule the interrupt when we will stop	*/
					/* generating packets, unless we are configured to run until	*/
					/* the end of the simulation.									*/
					if (stop_time != SSC_INFINITE_TIME)

⌨️ 快捷键说明

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