📄 gpr_route_interface.pr.c
字号:
/* Process model C form file: gpr_route_interface.pr.c */
/* Portions of this file copyright 1992-2003 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char gpr_route_interface_pr_c [] = "MIL_3_Tfile_Hdr_ 100A 30A modeler 7 457FD402 457FD402 1 ztl lele 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 8f3 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
///////////////////////////////////////////////////////////////
// GPR INTERFACE HEADER BLOCK
//
// Declaration of every constant, type, lybrary, glabal
// variables... used by the dsr interface process
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//////////////////////// INCLUDE //////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////// 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;
/* 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 */
Distribution * address_dist;
int my_route_address;
Objid my_objid;
Objid my_node_objid;
Objid my_network_objid;
int TRANSMIT;
int GPR_dest_addr;
int i_Delay_tolerent;
double f_off_interval;
} gpr_route_interface_state;
#define pr_state_ptr ((gpr_route_interface_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define address_dist pr_state_ptr->address_dist
#define my_route_address pr_state_ptr->my_route_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 GPR_dest_addr pr_state_ptr->GPR_dest_addr
#define i_Delay_tolerent pr_state_ptr->i_Delay_tolerent
#define f_off_interval pr_state_ptr->f_off_interval
/* 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 gpr_route_interface_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 = ((gpr_route_interface_state *)(tcontext_ptr->mod_state_ptr));
#else
# define FIN_PREAMBLE_DEC gpr_route_interface_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 gpr_route_interface (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype gpr_route_interface_init (int * init_block_ptr);
VosT_Address gpr_route_interface_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
void gpr_route_interface_diag (OP_SIM_CONTEXT_ARG_OPT);
void gpr_route_interface_terminate (OP_SIM_CONTEXT_ARG_OPT);
void gpr_route_interface_svar (void *, const char *, void **);
VosT_Fun_Status Vos_Define_Object (VosT_Obtype * obst_ptr, const char * name, unsigned int size, unsigned int init_obs, unsigned int inc_obs);
VosT_Address Vos_Alloc_Object_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype ob_hndl);
VosT_Fun_Status Vos_Poolmem_Dealloc_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Address ob_ptr);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
gpr_route_interface (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (gpr_route_interface ());
if (1)
{
///////////////////////////////////////////////////////////////
// GPR INTERFACE TEMPORARY VARIABLES BLOCK
//
// Declaration of the temporary variables
///////////////////////////////////////////////////////////////
Packet* pk_ptr;
int destination_GPR_address;
Ici* iciptr;
double packet_delay;
FSM_ENTER ("gpr_route_interface")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED (0, "init", state0_enter_exec, "gpr_route_interface [init enter execs]")
FSM_PROFILE_SECTION_IN (gpr_route_interface [init enter execs], state0_enter_exec)
{
///////////////////////////////////////////////////////////////
// GPR INTERFACE INIT STATE
//
// Initialize the GPR 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);
op_ima_obj_attr_get(my_node_objid,"gpr_route.Dest_GPR_addr",&GPR_dest_addr);
op_ima_obj_attr_get(my_node_objid,"gpr_route.GPR_address",&my_route_address);
op_ima_obj_attr_get(my_node_objid,"partial.Power_Interval",&f_off_interval);
number_of_nodes=20;
// 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);
op_ima_obj_attr_get(my_objid,"Delay_Tolerent",&i_Delay_tolerent);
// statistics initialisation
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 Efficiency",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 an random destination address
address_dist=op_dist_load("uniform_int",0,(number_of_nodes-1));
}
FSM_PROFILE_SECTION_OUT (gpr_route_interface [init enter execs], state0_enter_exec)
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "gpr_route_interface [init exit execs]")
FSM_PROFILE_SECTION_IN (gpr_route_interface [init exit execs], state0_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (gpr_route_interface [init exit execs], state0_exit_exec)
/** state (init) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "idle")
/*---------------------------------------------------------*/
/** state (idle) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, "idle", state1_enter_exec, "gpr_route_interface [idle enter execs]")
FSM_PROFILE_SECTION_IN (gpr_route_interface [idle enter execs], state1_enter_exec)
{
}
FSM_PROFILE_SECTION_OUT (gpr_route_interface [idle enter execs], state1_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"gpr_route_interface")
/** state (idle) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "idle", "gpr_route_interface [idle exit execs]")
FSM_PROFILE_SECTION_IN (gpr_route_interface [idle exit execs], state1_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (gpr_route_interface [idle exit execs], state1_exit_exec)
/** state (idle) transition processing **/
FSM_PROFILE_SECTION_IN (gpr_route_interface [idle trans conditions], state1_trans_conds)
FSM_INIT_COND (RCV_ARRIVAL)
FSM_TEST_COND (SRC_ARRIVAL)
FSM_DFLT_COND
FSM_TEST_LOGIC ("idle")
FSM_PROFILE_SECTION_OUT (gpr_route_interface [idle trans conditions], state1_trans_conds)
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, "rx", state2_enter_exec, "gpr_route_interface [rx enter execs]")
FSM_PROFILE_SECTION_IN (gpr_route_interface [rx enter execs], state2_enter_exec)
{
///////////////////////////////////////////////////////////////
// RX STATE
//
// Processed when a packet is received from the GPR Routing layer
// data from low layer(route_intf) ,and rvc it and send to high layer(sink)
///////////////////////////////////////////////////////////////
char msg[100];
double ete_delay,now,create_time;
// extract the packet from the GPR Routing strm
pk_ptr=op_pk_get(FROM_ROUTING_LAYER_STRM);
now = op_sim_time () ;
create_time=op_pk_creation_time_get (pk_ptr);
ete_delay=now-create_time;
//if (ete_delay<i_Delay_tolerent*f_off_interval)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -