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

📄 ramimo_pktgen.pr.c

📁 用OPNET实现802.11MAC协议DCF协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: ramimo_pktgen.pr.c */
/* Portions of this file copyright 1992-2003 by OPNET Technologies, Inc. */



/* This variable carries the header into the object file */
const char ramimo_pktgen_pr_c [] = "MIL_3_Tfile_Hdr_ 100A 30A op_runsim 7 40C9B394 40C9B394 1 ibis pdm106 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 90b 2                                                                                                                                                                                                                                                                                                                                                                                                             ";
#include <string.h>



/* OPNET system definitions */
#include <opnet.h>



/* Header Block */

#include <math.h>

//#define PKTGEN_INIT
//#define PKTGEN_OFF
//#define PKTGEN_PKT_GEN

#define OUT_STRM 0

#define PKT 0 
#define PROC_INT 0

#define GEN_PKT ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == PKT) )
#define PKT_INT ( (op_intrpt_type() == OPC_INTRPT_PROCESS) && (op_intrpt_code() == PROC_INT) )

/* End of Header Block */


#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define	BOUT	BIN
#define	BINIT	FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_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 */
	double	                 		userload;
	double	                 		datarate;
	Objid	                  		proc_id;
	Objid	                  		node_id;
	Evhandle	               		genpktevent;
	Objid	                  		random_node;
	double	                 		datapktsize;
	char	                   		packetformat[20];
	int	                    		intnumnodes;
	double	                 		dblnumnodes;
	int	                    		destuserid;
	Objid	                  		mainprocid;
	Objid	                  		tx_id;
	Objid	                  		txcomp_id;
	Objid	                  		txch_id;
	double	                 		timebetweenpkts;
	double	                 		sequencenum;
	int	                    		srcuserid;
	char	                   		scenario[20];
	char	                   		traffictype[20];
	} ramimo_pktgen_state;

#define pr_state_ptr            		((ramimo_pktgen_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define userload                		pr_state_ptr->userload
#define datarate                		pr_state_ptr->datarate
#define proc_id                 		pr_state_ptr->proc_id
#define node_id                 		pr_state_ptr->node_id
#define genpktevent             		pr_state_ptr->genpktevent
#define random_node             		pr_state_ptr->random_node
#define datapktsize             		pr_state_ptr->datapktsize
#define packetformat            		pr_state_ptr->packetformat
#define intnumnodes             		pr_state_ptr->intnumnodes
#define dblnumnodes             		pr_state_ptr->dblnumnodes
#define destuserid              		pr_state_ptr->destuserid
#define mainprocid              		pr_state_ptr->mainprocid
#define tx_id                   		pr_state_ptr->tx_id
#define txcomp_id               		pr_state_ptr->txcomp_id
#define txch_id                 		pr_state_ptr->txch_id
#define timebetweenpkts         		pr_state_ptr->timebetweenpkts
#define sequencenum             		pr_state_ptr->sequencenum
#define srcuserid               		pr_state_ptr->srcuserid
#define scenario                		pr_state_ptr->scenario
#define traffictype             		pr_state_ptr->traffictype

/* These macro definitions 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_DEC
#undef FIN_PREAMBLE_CODE
#if defined (OPD_PARALLEL)
#  define FIN_PREAMBLE_DEC	ramimo_pktgen_state *op_sv_ptr; OpT_Sim_Context * tcontext_ptr;
#  define FIN_PREAMBLE_CODE	\
		if (VosS_Mt_Perform_Lock) \
			VOS_THREAD_SPECIFIC_DATA_GET (VosI_Globals.simi_mt_context_data_key, tcontext_ptr, SimT_Context *); \
		else \
			tcontext_ptr = VosI_Globals.simi_sequential_context_ptr; \
		op_sv_ptr = ((ramimo_pktgen_state *)(tcontext_ptr->mod_state_ptr));
#else
#  define FIN_PREAMBLE_DEC	ramimo_pktgen_state *op_sv_ptr;
#  define FIN_PREAMBLE_CODE	op_sv_ptr = pr_state_ptr;
#endif


/* No Function Block */


#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ };
#endif

/* 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 ramimo_pktgen (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Obtype ramimo_pktgen_init (int * init_block_ptr);
	VosT_Address ramimo_pktgen_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
	void ramimo_pktgen_diag (OP_SIM_CONTEXT_ARG_OPT);
	void ramimo_pktgen_terminate (OP_SIM_CONTEXT_ARG_OPT);
	void ramimo_pktgen_svar (void *, const char *, void **);


	VosT_Fun_Status Vos_Define_Object (VosT_Obtype * _op_obst_ptr, const char * _op_name, unsigned int _op_size, unsigned int _op_init_obs, unsigned int _op_inc_obs);
	VosT_Address Vos_Alloc_Object_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype _op_ob_hndl);
	VosT_Fun_Status Vos_Poolmem_Dealloc_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Address _op_ob_ptr);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
ramimo_pktgen (OP_SIM_CONTEXT_ARG_OPT)
	{

#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	FIN_MT (ramimo_pktgen ());
	if (1)
		{
		Packet *pktptr;
		double number;
		int index;
		int tempint;
		double tempdouble;


		FSM_ENTER_NO_VARS ("ramimo_pktgen")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (INIT) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "INIT", "ramimo_pktgen [INIT enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_pktgen [INIT enter execs]", state0_enter_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (state0_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (1,"ramimo_pktgen")


			/** state (INIT) exit executives **/
			FSM_STATE_EXIT_UNFORCED (0, "INIT", "ramimo_pktgen [INIT exit execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_pktgen [INIT exit execs]", state0_exit_exec)
				{
				/*Read in the simulation attributes*/
				op_ima_sim_attr_get(OPC_IMA_DOUBLE, "USER_LOAD", &userload);
				op_ima_sim_attr_get(OPC_IMA_STRING, "PACKET_FORMAT", &packetformat);
				op_ima_sim_attr_get(OPC_IMA_DOUBLE, "DATA_pktsize", &datapktsize);
				op_ima_sim_attr_get(OPC_IMA_STRING, "scenario", &scenario);
				op_ima_sim_attr_get(OPC_IMA_STRING, "TRAFFIC_TYPE", &traffictype);
				
				/*******************************************************************************************/
				
				/*Obtain the ID number of the process module*/
				proc_id = op_id_self();
				
				/*Obtain the ID number of the node at the network level*/
				node_id = op_topo_parent(proc_id);
				
				/*Obtain the User ID number of the node*/
				op_ima_obj_attr_get(node_id, "user id", &srcuserid);
				
				/*Obtain the channel datarate*/
				mainprocid = op_topo_assoc(proc_id, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_QUEUE, 0);
				tx_id = op_topo_assoc(mainprocid, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_RATX, 0);
				txcomp_id = op_topo_child(tx_id, OPC_OBJTYPE_COMP, 0);
				txch_id = op_topo_child(txcomp_id, OPC_OBJTYPE_RATXCH, 0);
				op_ima_obj_attr_get(txch_id, "data rate", &datarate);
				
				/*Get the number of mobile nodes in the network*/
				intnumnodes = op_topo_object_count(OPC_OBJTYPE_NDMOB);
				dblnumnodes = (double) intnumnodes;
				
				/*Initialise variables*/
				sequencenum = dblnumnodes;
				
				/*Calculate the appropriate packet interarrival time given the user load*/
				timebetweenpkts = (datapktsize/datarate) * (1.0 / userload);
				 
				/*set the time between packets and the destination ID's to suit the scenario*/
				if(strcmp(scenario, "singleline") == 0)
				    op_ima_sim_attr_get(OPC_IMA_INTEGER, "destuserid", &destuserid);
				else if(strcmp(scenario, "dualline") == 0)
				{
				    /*There are two fixed links in this scenario*/
					if(srcuserid == 0)
						destuserid = 10;
					else if(srcuserid == 11)
						destuserid = 20;
				}
				else if((strcmp(scenario, "squaregrid") == 0) || (strcmp(scenario, "hexgrid") == 0))
				{
				    /*Pick a random node that will be the destination of the traffic*/
				    //do
					//{	
					//    index = rand()%(intnumnodes);
				    //    random_node = op_topo_object(OPC_OBJTYPE_NDMOB, index);
					//    op_ima_obj_attr_get(random_node, "user id", &destuserid);
				
					//} while(destuserid == srcuserid);	
				
				    /*Set the destination ID based on the specific flow*/
				   if(srcuserid == 0)
					   destuserid = 24;
				   else if(srcuserid == 21)
					   destuserid = 3;
				}
				
#ifdef PKTGEN_INIT
				    printf("PKTGEN_INIT\n");
				    printf("User Load = %lf\n", userload);
				    printf("Packet Format = %s\n", packetformat);
				    printf("Data Packet Size = %lf\n", datapktsize);
				    printf("Scenario = %s\n", scenario);  
					printf("Dest User ID = %d\n", destuserid);
				    printf("Channel Datarate = %lf\n", datarate);
				    printf("Integer Number of Nodes = %d\n", intnumnodes);
				    printf("Double Number of Nodes = %lf\n", dblnumnodes);
				    printf("Time Between Packets = %lf\n", timebetweenpkts);
					printf("Traffic Type = %s\n", traffictype);
#endif
				
				op_prg_odb_bkpt("TEST");
				}
				FSM_PROFILE_SECTION_OUT (state0_exit_exec)


			/** state (INIT) transition processing **/
			FSM_TRANSIT_ONLY ((PKT_INT), 1, state1_enter_exec, ;, INIT, "PKT_INT", "", "INIT", "OFF")
				/*---------------------------------------------------------*/



			/** state (OFF) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, "OFF", state1_enter_exec, "ramimo_pktgen [OFF enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_pktgen [OFF enter execs]", state1_enter_exec)
				{
				/*Schedule the next packet generation for an appropriate time depending on traffic type*/
				if(strcmp(traffictype, "cbr") == 0)
				{
				    /*Schedule an interrupt for packet generation*/
				    genpktevent = op_intrpt_schedule_self(op_sim_time()+timebetweenpkts, PKT);
				}
				else if(strcmp(traffictype, "poisson") == 0)
				{
				    /*Schedule an interrupt for packet generation*/
				    number = op_dist_exponential(timebetweenpkts);
				    genpktevent = op_intrpt_schedule_self(op_sim_time()+number, PKT);
				}
				

⌨️ 快捷键说明

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