/* Process model C form file: csma_tx.pr.c */
/* Portions of this file copyright 1986-2008 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char csma_tx_pr_c [] = "MIL_3_Tfile_Hdr_ 145A 30A modeler 7 539A5EDE 539A5EDE 1 WIN-LK7IGEHQEHD Administrator 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 1bcc 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
/* Input stream from generator module */
#define IN_STRM 0
/* Output stream to bus transmitter module */
#define OUT_STRM 0
/* Conditional macros */
#define PKT_ARVL (op_intrpt_type() == OPC_INTRPT_STRM)
/* Global Variable */
extern int subm_pkts;
#define CH_BUSY_STAT 0
/* Conditional macros */
#define FREE (op_stat_local_read (CH_BUSY_STAT) == 0.0)
#define PKTS_QUEUED (!op_strm_empty (IN_STRM))
#define CH_GOES_FREE (op_intrpt_type () == OPC_INTRPT_STAT )
/* 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 max_packet_count ; /* Number of packets to process */
} csma_tx_state;
#define max_packet_count op_sv_ptr->max_packet_count
/* 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
#define FIN_PREAMBLE_DEC csma_tx_state *op_sv_ptr;
#define FIN_PREAMBLE_CODE \
op_sv_ptr = ((csma_tx_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr));
/* 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 csma_tx (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype _op_csma_tx_init (int * init_block_ptr);
void _op_csma_tx_diag (OP_SIM_CONTEXT_ARG_OPT);
void _op_csma_tx_terminate (OP_SIM_CONTEXT_ARG_OPT);
VosT_Address _op_csma_tx_alloc (VosT_Obtype, int);
void _op_csma_tx_svar (void *, const char *, void **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
csma_tx (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (csma_tx ());
{
FSM_ENTER ("csma_tx")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "csma_tx [init enter execs]")
FSM_PROFILE_SECTION_IN ("csma_tx [init enter execs]", state0_enter_exec)
{
op_ima_sim_attr_get_int32 ("max packet count",
&max_packet_count);
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "csma_tx [init exit execs]")
/** state (init) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "idle", "tr_0", "csma_tx [init -> idle : default / ]")
/*---------------------------------------------------------*/
/** state (idle) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, "idle", state1_enter_exec, "csma_tx [idle enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"csma_tx")
/** state (idle) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "idle", "csma_tx [idle exit execs]")
/** state (idle) transition processing **/
FSM_PROFILE_SECTION_IN ("csma_tx [idle trans conditions]", state1_trans_conds)
FSM_INIT_COND (PKT_ARVL && FREE)
FSM_TEST_COND (PKT_ARVL && !FREE)
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, ;, "PKT_ARVL && FREE", "", "idle", "tx_pkt", "tr_1", "csma_tx [idle -> tx_pkt : PKT_ARVL && FREE / ]")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "PKT_ARVL && !FREE", "", "idle", "wt_free", "tr_4", "csma_tx [idle -> wt_free : PKT_ARVL && !FREE / ]")
FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "default", "", "idle", "idle", "tr_6", "csma_tx [idle -> idle : default / ]")
}
/*---------------------------------------------------------*/
/** state (tx_pkt) enter executives **/
FSM_STATE_ENTER_FORCED (2, "tx_pkt", state2_enter_exec, "csma_tx [tx_pkt enter execs]")
FSM_PROFILE_SECTION_IN ("csma_tx [tx_pkt enter execs]", state2_enter_exec)
{
Packet *out_pkt;
out_pkt = op_pk_get (IN_STRM);
op_pk_send (out_pkt, OUT_STRM);
++subm_pkts;
if (subm_pkts == max_packet_count)
op_sim_end ("max packet count reached.", "", "", "");
}
FSM_PROFILE_SECTION_OUT (state2_enter_exec)
/** state (tx_pkt) exit executives **/
FSM_STATE_EXIT_FORCED (2, "tx_pkt", "csma_tx [tx_pkt exit execs]")
/** state (tx_pkt) transition processing **/
FSM_PROFILE_SECTION_IN ("csma_tx [tx_pkt trans conditions]", state2_trans_conds)
FSM_INIT_COND (PKTS_QUEUED && FREE)
FSM_TEST_COND (PKTS_QUEUED && !FREE)
FSM_DFLT_COND
FSM_TEST_LOGIC ("tx_pkt")
FSM_PROFILE_SECTION_OUT (state2_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "PKTS_QUEUED && FREE", "", "tx_pkt", "tx_pkt", "tr_7", "csma_tx [tx_pkt -> tx_pkt : PKTS_QUEUED && FREE / ]")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "PKTS_QUEUED && !FREE", "", "tx_pkt", "wt_free", "tr_9", "csma_tx [tx_pkt -> wt_free : PKTS_QUEUED && !FREE / ]")
FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "default", "", "tx_pkt", "idle", "tr_2", "csma_tx [tx_pkt -> idle : default / ]")
}
/*---------------------------------------------------------*/
/** state (wt_free) enter executives **/
FSM_STATE_ENTER_UNFORCED (3, "wt_free", state3_enter_exec, "csma_tx [wt_free enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (7,"csma_tx")
/** state (wt_free) exit executives **/
FSM_STATE_EXIT_UNFORCED (3, "wt_free", "csma_tx [wt_free exit execs]")
/** state (wt_free) transition processing **/
FSM_PROFILE_SECTION_IN ("csma_tx [wt_free trans conditions]", state3_trans_conds)
FSM_INIT_COND (CH_GOES_FREE)
FSM_DFLT_COND
FSM_TEST_LOGIC ("wt_free")
FSM_PROFILE_SECTION_OUT (state3_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "CH_GOES_FREE", "", "wt_free", "tx_pkt", "tr_5", "csma_tx [wt_free -> tx_pkt : CH_GOES_FREE / ]")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "default", "", "wt_free", "wt_free", "tr_3", "csma_tx [wt_free -> wt_free : default / ]")
}
/*---------------------------------------------------------*/