?? tdma3.pr.c
字號:
/* Process model C form file: tdma3.pr.c */
/* Portions of this file copyright 1992-2004 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char tdma3_pr_c [] = "MIL_3_Tfile_Hdr_ 105A 30A modeler 7 473DAE0F 473DAE0F 1 alex lq 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 a09 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
#include <math.h>
/* Constant Definitions */
#define RX_IN_STRM (1)
#define SRC_IN_STRM (0)
#define TX_OUT_STRM (1)
#define SINK_OUT_STRM (0)
#define EPSILON (1e-10) /* rounding error factor */
#define TDMA_COMPLETE (-10)
/* Transition Condition Macros */
#define FROM_RX (current_intrpt_type == OPC_INTRPT_STRM) && (op_intrpt_strm () == RX_IN_STRM)
#define FROM_SRC (current_intrpt_type == OPC_INTRPT_STRM) && (op_intrpt_strm () == SRC_IN_STRM)
#define TRANSMITTING (op_stat_local_read (0) == 1.0)
#define SLOT (current_intrpt_type == OPC_INTRPT_SELF)
#define END (current_intrpt_type == OPC_INTRPT_STAT)
#define DATA_ENQ (!(op_subq_empty (0)))
#define SELF_INTRPT_SCHLD (intrpt_flag == 1)
/* Global Variables */
int tdma_pk_sent;
int tdma_pk_rcvd;
int tdma_bits_sent;
int tdma_bits_rcvd;
int tdma_setup;
int tdma_id;
int num_slots;
/* 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 */
int my_offset ;
double slot_length ;
double tx_data_rate ;
int intrpt_flag ;
int num_pk_sent ;
int num_pk_rcvd ;
int num_bits_sent ;
int num_bits_rcvd ;
Stathandle num_pk_sent_stat ;
Stathandle global_pk_sent_stat ;
Stathandle num_pk_rcvd_stat ;
Stathandle global_pk_rcvd_stat ;
Objid my_node_id ;
Objid my_id ;
Stathandle num_bits_sent_stat ;
Stathandle global_bits_sent_stat ;
Stathandle num_bits_rcvd_stat ;
Stathandle global_bits_rcvd_stat ;
Stathandle bits_sec_rcvd_stat ;
Stathandle bits_sec_sent_stat ;
Stathandle pk_sec_rcvd_stat ;
Stathandle pk_sec_sent_stat ;
Stathandle global_bits_sec_rcvd_stat ;
Stathandle global_bits_sec_sent_stat ;
Stathandle global_pk_sec_rcvd_stat ;
Stathandle global_pk_sec_sent_stat ;
} tdma3_state;
#define pr_state_ptr ((tdma3_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define my_offset pr_state_ptr->my_offset
#define slot_length pr_state_ptr->slot_length
#define tx_data_rate pr_state_ptr->tx_data_rate
#define intrpt_flag pr_state_ptr->intrpt_flag
#define num_pk_sent pr_state_ptr->num_pk_sent
#define num_pk_rcvd pr_state_ptr->num_pk_rcvd
#define num_bits_sent pr_state_ptr->num_bits_sent
#define num_bits_rcvd pr_state_ptr->num_bits_rcvd
#define num_pk_sent_stat pr_state_ptr->num_pk_sent_stat
#define global_pk_sent_stat pr_state_ptr->global_pk_sent_stat
#define num_pk_rcvd_stat pr_state_ptr->num_pk_rcvd_stat
#define global_pk_rcvd_stat pr_state_ptr->global_pk_rcvd_stat
#define my_node_id pr_state_ptr->my_node_id
#define my_id pr_state_ptr->my_id
#define num_bits_sent_stat pr_state_ptr->num_bits_sent_stat
#define global_bits_sent_stat pr_state_ptr->global_bits_sent_stat
#define num_bits_rcvd_stat pr_state_ptr->num_bits_rcvd_stat
#define global_bits_rcvd_stat pr_state_ptr->global_bits_rcvd_stat
#define bits_sec_rcvd_stat pr_state_ptr->bits_sec_rcvd_stat
#define bits_sec_sent_stat pr_state_ptr->bits_sec_sent_stat
#define pk_sec_rcvd_stat pr_state_ptr->pk_sec_rcvd_stat
#define pk_sec_sent_stat pr_state_ptr->pk_sec_sent_stat
#define global_bits_sec_rcvd_stat pr_state_ptr->global_bits_sec_rcvd_stat
#define global_bits_sec_sent_stat pr_state_ptr->global_bits_sec_sent_stat
#define global_pk_sec_rcvd_stat pr_state_ptr->global_pk_sec_rcvd_stat
#define global_pk_sec_sent_stat pr_state_ptr->global_pk_sec_sent_stat
/* 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 tdma3_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 = ((tdma3_state *)(tcontext_ptr->mod_state_ptr));
#else
# define FIN_PREAMBLE_DEC tdma3_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 tdma3 (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype tdma3_init (int * init_block_ptr);
VosT_Address tdma3_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
void tdma3_diag (OP_SIM_CONTEXT_ARG_OPT);
void tdma3_terminate (OP_SIM_CONTEXT_ARG_OPT);
void tdma3_svar (void *, const char *, void **);
VosT_Obtype Vos_Define_Object_Prstate (const char * _op_name, unsigned int _op_size);
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
tdma3 (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (tdma3 ());
{
/* Temporary Variables */
Packet* pkptr;
Objid current_node_id,
tx_id, comp_id, tx_ch_id;
double floor();
double fmod();
int used_slots;
int current_offset;
int next_offset;
int i;
double current_time;
double time_left_in_slot;
double pk_len;
double pk_time;
double my_next_slot_time;
int current_intrpt_type;
int num_fixed, num_mobile, num_sat;
/* End of Temporary Variables */
FSM_ENTER ("tdma3")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "tdma3 [init enter execs]")
FSM_PROFILE_SECTION_IN ("tdma3 [init enter execs]", state0_enter_exec)
{
/* Get the slot length for all nodes */
op_ima_sim_attr_get (OPC_IMA_DOUBLE, "Slot Length", &slot_length);
my_id = op_id_self();
my_node_id = op_topo_parent (my_id);
/* Initialize tdma offsets if not done previously */
if (tdma_setup != TDMA_COMPLETE)
{
num_slots = 0;
tdma_setup = TDMA_COMPLETE;
}
/* Calculate the offset for this node */
num_slots++;
my_offset = num_slots-1;
if (op_prg_odb_ltrace_active ("tdma"))
{
printf ("Node Objid = %d\n", my_node_id);
printf ("Node Offset = %d\n", my_offset);
printf ("\n");
}
/*Determine the number of various types of nodes in the network */
/* Determine the data rate for the transmitter */
tx_id = op_topo_assoc (my_id, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_RATX, 0);
comp_id = op_topo_child (tx_id, OPC_OBJTYPE_COMP, 0);
tx_ch_id = op_topo_child (comp_id, OPC_OBJTYPE_RATXCH, 0);
op_ima_obj_attr_get (tx_ch_id, "data rate", &tx_data_rate);
/* Initialize statistic calculation variables */
/*
tdma_pk_sent = 0;
tdma_pk_rcvd = 0;
tdma_bits_sent = 0;
tdma_bits_rcvd = 0;
num_pk_sent = 0;
num_pk_rcvd = 0;
num_bits_sent = 0;
num_bits_rcvd = 0;
*/
/* Register Statistics */
num_pk_sent_stat = op_stat_reg ("TDMA.Load (packets)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
global_pk_sent_stat = op_stat_reg ("TDMA.TDMA Load (packets)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
num_pk_rcvd_stat = op_stat_reg ("TDMA.Traffic Received (packets)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
global_pk_rcvd_stat = op_stat_reg ("TDMA.TDMA Traffic Received (packets)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
num_bits_sent_stat = op_stat_reg ("TDMA.Load (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
global_bits_sent_stat = op_stat_reg ("TDMA.TDMA Load (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
num_bits_rcvd_stat = op_stat_reg ("TDMA.Traffic Received (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
global_bits_rcvd_stat = op_stat_reg ("TDMA.TDMA Traffic Received (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
bits_sec_rcvd_stat = op_stat_reg ("TDMA.Traffic Received (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
bits_sec_sent_stat = op_stat_reg ("TDMA.Load (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pk_sec_rcvd_stat = op_stat_reg ("TDMA.Traffic Received (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pk_sec_sent_stat = op_stat_reg ("TDMA.Load (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
global_bits_sec_rcvd_stat = op_stat_reg ("TDMA.TDMA Traffic Received (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
global_pk_sec_rcvd_stat = op_stat_reg ("TDMA.TDMA Traffic Received (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
global_pk_sec_sent_stat = op_stat_reg ("TDMA.TDMA Load (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
global_bits_sec_sent_stat = op_stat_reg ("TDMA.TDMA Load (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
/* Schedule interupt to complete initialization in the exit execs */
op_intrpt_schedule_self (op_sim_time (), 0);
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (1,"tdma3")
/** state (init) exit executives **/
FSM_STATE_EXIT_UNFORCED (0, "init", "tdma3 [init exit execs]")
FSM_PROFILE_SECTION_IN ("tdma3 [init exit execs]", state0_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (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, "tdma3 [idle enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"tdma3")
/** state (idle) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "idle", "tdma3 [idle exit execs]")
FSM_PROFILE_SECTION_IN ("tdma3 [idle exit execs]", state1_exit_exec)
{
current_intrpt_type = op_intrpt_type ();
}
FSM_PROFILE_SECTION_OUT (state1_exit_exec)
/** state (idle) transition processing **/
FSM_PROFILE_SECTION_IN ("tdma3 [idle trans conditions]", state1_trans_conds)
FSM_INIT_COND (FROM_RX)
FSM_TEST_COND (FROM_SRC)
FSM_TEST_COND ((END || SLOT) && DATA_ENQ)
FSM_DFLT_COND
FSM_TEST_LOGIC ("idle")
FSM_PROFILE_SECTION_OUT (state1_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "FROM_RX", "", "idle", "fr_rx")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "FROM_SRC", "", "idle", "fr_src")
FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "(END || SLOT) && DATA_ENQ", "", "idle", "tx")
FSM_CASE_TRANSIT (3, 1, state1_enter_exec, ;, "default", "", "idle", "idle")
}
/*---------------------------------------------------------*/
/** state (fr_rx) enter executives **/
FSM_STATE_ENTER_FORCED (2, "fr_rx", state2_enter_exec, "tdma3 [fr_rx enter execs]")
FSM_PROFILE_SECTION_IN ("tdma3 [fr_rx enter execs]", state2_enter_exec)
{
pkptr = op_pk_get (RX_IN_STRM);
pk_len = (double) op_pk_total_size_get (pkptr);
/** Record Statistics **/
/** The bits/sec or packets/sec statistics are recorded in **/
/** bits and packets, and then the OPNET statistic "capture **/
/** mode" is used to obtain a bucketized sum over time. **/
/** Record extra 0.0 data-points to enable proper computation **/
/** of the "sum/time" based statistics. **/
op_stat_write (pk_sec_rcvd_stat, 1.0);
op_stat_write (pk_sec_rcvd_stat, 0.0);
op_stat_write (global_pk_rcvd_stat, 1.0);
op_stat_write (global_pk_sec_rcvd_stat, 1.0);
op_stat_write (global_pk_sec_rcvd_stat, 0.0);
op_stat_write (num_bits_rcvd_stat, pk_len);
op_stat_write (bits_sec_rcvd_stat, pk_len);
op_stat_write (bits_sec_rcvd_stat, 0.0);
op_stat_write (global_bits_rcvd_stat, pk_len);
op_stat_write (global_bits_sec_rcvd_stat, pk_len);
op_stat_write (global_bits_sec_rcvd_stat, 0.0);
op_pk_send (pkptr, SINK_OUT_STRM);
}
FSM_PROFILE_SECTION_OUT (state2_enter_exec)
/** state (fr_rx) exit executives **/
FSM_STATE_EXIT_FORCED (2, "fr_rx", "tdma3 [fr_rx exit execs]")
/** state (fr_rx) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "fr_rx", "idle")
/*---------------------------------------------------------*/
/** state (fr_src) enter executives **/
FSM_STATE_ENTER_FORCED (3, "fr_src", state3_enter_exec, "tdma3 [fr_src enter execs]")
FSM_PROFILE_SECTION_IN ("tdma3 [fr_src enter execs]", state3_enter_exec)
{
pkptr = op_pk_get (SRC_IN_STRM);
op_subq_pk_insert (0, pkptr, OPC_QPOS_TAIL);
}
FSM_PROFILE_SECTION_OUT (state3_enter_exec)
/** state (fr_src) exit executives **/
FSM_STATE_EXIT_FORCED (3, "fr_src", "tdma3 [fr_src exit execs]")
/** state (fr_src) transition processing **/
FSM_PROFILE_SECTION_IN ("tdma3 [fr_src trans conditions]", state3_trans_conds)
FSM_INIT_COND (TRANSMITTING)
FSM_TEST_COND (!TRANSMITTING)
FSM_TEST_LOGIC ("fr_src")
FSM_PROFILE_SECTION_OUT (state3_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "TRANSMITTING", "", "fr_src", "idle")
FSM_CASE_TRANSIT (1, 4, state4_enter_exec, ;, "!TRANSMITTING", "", "fr_src", "tx")
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -