📄 tan_noc_worm_packet_seg_test.pr.c
字号:
/* Process model C form file: tan_noc_worm_packet_seg_test.pr.c */
/* Portions of this file copyright 1992-2004 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char tan_noc_worm_packet_seg_test_pr_c [] = "MIL_3_Tfile_Hdr_ 105A 30A modeler 7 49D9C885 49D9C885 1 05934b0918b5482 Administrator 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 a0a 3 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
#define ARRIVAL op_intrpt_type() == OPC_INTRPT_STRM
#define SELF_INT op_intrpt_type() == OPC_INTRPT_SELF
#define HLP_INSTRM 0
#define LLP_OUTSTRM 0
#define FIFO_request 0
#define REQUEST (op_intrpt_type() == OPC_INTRPT_STAT)&&(op_intrpt_stat() == FIFO_request)
/* 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 service_rate ;
Stathandle fifo_allow ;
int rem_size ;
int seg_size ;
int pk_seq_num ;
Objid own_id ;
int server_busy ;
int isallow ;
Sar_Buffer* seg_sbh ;
} tan_noc_worm_packet_seg_test_state;
#define pr_state_ptr ((tan_noc_worm_packet_seg_test_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define service_rate pr_state_ptr->service_rate
#define fifo_allow pr_state_ptr->fifo_allow
#define rem_size pr_state_ptr->rem_size
#define seg_size pr_state_ptr->seg_size
#define pk_seq_num pr_state_ptr->pk_seq_num
#define own_id pr_state_ptr->own_id
#define server_busy pr_state_ptr->server_busy
#define isallow pr_state_ptr->isallow
#define seg_sbh pr_state_ptr->seg_sbh
/* 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 tan_noc_worm_packet_seg_test_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 = ((tan_noc_worm_packet_seg_test_state *)(tcontext_ptr->mod_state_ptr));
#else
# define FIN_PREAMBLE_DEC tan_noc_worm_packet_seg_test_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 tan_noc_worm_packet_seg_test (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype tan_noc_worm_packet_seg_test_init (int * init_block_ptr);
VosT_Address tan_noc_worm_packet_seg_test_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
void tan_noc_worm_packet_seg_test_diag (OP_SIM_CONTEXT_ARG_OPT);
void tan_noc_worm_packet_seg_test_terminate (OP_SIM_CONTEXT_ARG_OPT);
void tan_noc_worm_packet_seg_test_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
tan_noc_worm_packet_seg_test (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (tan_noc_worm_packet_seg_test ());
{
/* Temporary Variables */
Packet * src_pkptr;
SimT_Packet * seg_pkptr;
//Sar_Buffer * seg_sbh;
double seg_tx_time;
/* End of Temporary Variables */
FSM_ENTER ("tan_noc_worm_packet_seg_test")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "tan_noc_worm_packet_seg_test [init enter execs]")
FSM_PROFILE_SECTION_IN ("tan_noc_worm_packet_seg_test [init enter execs]", state0_enter_exec)
{
// get queue module's own object id
own_id = op_id_self();
// get assigned value of server processing rate
op_ima_obj_attr_get(own_id, "service_rate", &service_rate);
// regdit stathand
fifo_allow = op_stat_reg("FIFO_allow", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
// create the segment buf.
/*
// Allocate a connection data structure.
conn_ptr = (GpT_Connection *)op_prg_mem_alloc(sizeof(GpT_Connection));
// Initialize connection variables.
conn_ptr->seq_num = 0;
conn_ptr->active = 1;
*/
// Create a segmentation buffer for use by the connection.
pk_seq_num = 0;
server_busy = 0;
seg_size = 8;
isallow = 1;
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "tan_noc_worm_packet_seg_test [init exit execs]")
/** state (init) transition processing **/
FSM_PROFILE_SECTION_IN ("tan_noc_worm_packet_seg_test [init trans conditions]", state0_trans_conds)
FSM_INIT_COND (ARRIVAL)
FSM_DFLT_COND
FSM_TEST_LOGIC ("init")
FSM_PROFILE_SECTION_OUT (state0_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "ARRIVAL", "", "init", "arrival")
FSM_CASE_TRANSIT (1, 2, state2_enter_exec, ;, "default", "", "init", "idle")
}
/*---------------------------------------------------------*/
/** state (arrival) enter executives **/
FSM_STATE_ENTER_FORCED (1, "arrival", state1_enter_exec, "tan_noc_worm_packet_seg_test [arrival enter execs]")
FSM_PROFILE_SECTION_IN ("tan_noc_worm_packet_seg_test [arrival enter execs]", state1_enter_exec)
{
// acquire the arriving packets
if(server_busy == 0) {
src_pkptr = op_pk_get(HLP_INSTRM);
rem_size = op_pk_total_size_get(src_pkptr);
seg_sbh = op_sar_buf_create(OPC_SAR_BUF_TYPE_SEGMENT, OPC_SAR_BUF_OPT_PK_BNDRY);
//op_sar_buf_options_set(seg_sbh, OPC_SAR_BUF_OPT_FLUSH_TIMED, 600.0);
op_sar_segbuf_pk_insert(seg_sbh, src_pkptr, pk_seq_num++);
// printf("rem_size : %d %d\n", rem_size, seg_size);
// op_stat_write(fifo_allow, 1.0);
seg_tx_time = (double) seg_size/service_rate;
}
// while(1);
// send
//while(rem_size > 0)
if(server_busy == 1){
seg_pkptr = op_sar_srcbuf_seg_remove(seg_sbh, seg_size);
op_pk_send(seg_pkptr, LLP_OUTSTRM);
rem_size = rem_size - seg_size;
}
if(rem_size > 0) {
op_intrpt_schedule_self(op_sim_time() + seg_tx_time, 0);
server_busy = 1;
}
else {
server_busy = 0;
op_sar_buf_destroy(seg_sbh);
}
}
FSM_PROFILE_SECTION_OUT (state1_enter_exec)
/** state (arrival) exit executives **/
FSM_STATE_EXIT_FORCED (1, "arrival", "tan_noc_worm_packet_seg_test [arrival exit execs]")
/** state (arrival) transition processing **/
FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "arrival", "idle")
/*---------------------------------------------------------*/
/** state (idle) enter executives **/
FSM_STATE_ENTER_UNFORCED (2, "idle", state2_enter_exec, "tan_noc_worm_packet_seg_test [idle enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (5,"tan_noc_worm_packet_seg_test")
/** state (idle) exit executives **/
FSM_STATE_EXIT_UNFORCED (2, "idle", "tan_noc_worm_packet_seg_test [idle exit execs]")
/** state (idle) transition processing **/
FSM_PROFILE_SECTION_IN ("tan_noc_worm_packet_seg_test [idle trans conditions]", state2_trans_conds)
FSM_INIT_COND (ARRIVAL || SELF_INT)
FSM_TEST_COND (REQUEST)
FSM_TEST_COND ((!isallow) && (!server_busy))
FSM_TEST_LOGIC ("idle")
FSM_PROFILE_SECTION_OUT (state2_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "ARRIVAL || SELF_INT", "", "idle", "arrival")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "REQUEST", "", "idle", "REQ")
FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "(!isallow) && (!server_busy)", "", "idle", "ALLOW")
}
/*---------------------------------------------------------*/
/** state (REQ) enter executives **/
FSM_STATE_ENTER_FORCED (3, "REQ", state3_enter_exec, "tan_noc_worm_packet_seg_test [REQ enter execs]")
FSM_PROFILE_SECTION_IN ("tan_noc_worm_packet_seg_test [REQ enter execs]", state3_enter_exec)
{
if(server_busy == 0) {
op_stat_write(fifo_allow, 1.0);
isallow = 1;
}
else
isallow = 0;
}
FSM_PROFILE_SECTION_OUT (state3_enter_exec)
/** state (REQ) exit executives **/
FSM_STATE_EXIT_FORCED (3, "REQ", "tan_noc_worm_packet_seg_test [REQ exit execs]")
/** state (REQ) transition processing **/
FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "REQ", "idle")
/*---------------------------------------------------------*/
/** state (ALLOW) enter executives **/
FSM_STATE_ENTER_FORCED (4, "ALLOW", state4_enter_exec, "tan_noc_worm_packet_seg_test [ALLOW enter execs]")
FSM_PROFILE_SECTION_IN ("tan_noc_worm_packet_seg_test [ALLOW enter execs]", state4_enter_exec)
{
op_stat_write(fifo_allow, 1.0);
isallow = 1;
}
FSM_PROFILE_SECTION_OUT (state4_enter_exec)
/** state (ALLOW) exit executives **/
FSM_STATE_EXIT_FORCED (4, "ALLOW", "tan_noc_worm_packet_seg_test [ALLOW exit execs]")
/** state (ALLOW) transition processing **/
FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "ALLOW", "idle")
/*---------------------------------------------------------*/
}
FSM_EXIT (0,"tan_noc_worm_packet_seg_test")
}
}
void
tan_noc_worm_packet_seg_test_diag (OP_SIM_CONTEXT_ARG_OPT)
{
/* No Diagnostic Block */
}
void
tan_noc_worm_packet_seg_test_terminate (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = __LINE__;
#endif
FIN_MT (tan_noc_worm_packet_seg_test_terminate ())
/* No Termination Block */
Vos_Poolmem_Dealloc_MT (OP_SIM_CONTEXT_THREAD_INDEX_COMMA pr_state_ptr);
FOUT
}
/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in tan_noc_worm_packet_seg_test_svar function. */
#undef service_rate
#undef fifo_allow
#undef rem_size
#undef seg_size
#undef pk_seq_num
#undef own_id
#undef server_busy
#undef isallow
#undef seg_sbh
#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE
#define FIN_PREAMBLE_DEC
#define FIN_PREAMBLE_CODE
VosT_Obtype
tan_noc_worm_packet_seg_test_init (int * init_block_ptr)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
VosT_Obtype obtype = OPC_NIL;
FIN_MT (tan_noc_worm_packet_seg_test_init (init_block_ptr))
obtype = Vos_Define_Object_Prstate ("proc state vars (tan_noc_worm_packet_seg_test)",
sizeof (tan_noc_worm_packet_seg_test_state));
*init_block_ptr = 0;
FRET (obtype)
}
VosT_Address
tan_noc_worm_packet_seg_test_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype obtype, int init_block)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
tan_noc_worm_packet_seg_test_state * ptr;
FIN_MT (tan_noc_worm_packet_seg_test_alloc (obtype))
ptr = (tan_noc_worm_packet_seg_test_state *)Vos_Alloc_Object_MT (VOS_THREAD_INDEX_COMMA obtype);
if (ptr != OPC_NIL)
ptr->_op_current_block = init_block;
FRET ((VosT_Address)ptr)
}
void
tan_noc_worm_packet_seg_test_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr)
{
tan_noc_worm_packet_seg_test_state *prs_ptr;
FIN_MT (tan_noc_worm_packet_seg_test_svar (gen_ptr, var_name, var_p_ptr))
if (var_name == OPC_NIL)
{
*var_p_ptr = (void *)OPC_NIL;
FOUT
}
prs_ptr = (tan_noc_worm_packet_seg_test_state *)gen_ptr;
if (strcmp ("service_rate" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->service_rate);
FOUT
}
if (strcmp ("fifo_allow" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->fifo_allow);
FOUT
}
if (strcmp ("rem_size" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->rem_size);
FOUT
}
if (strcmp ("seg_size" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->seg_size);
FOUT
}
if (strcmp ("pk_seq_num" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->pk_seq_num);
FOUT
}
if (strcmp ("own_id" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->own_id);
FOUT
}
if (strcmp ("server_busy" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->server_busy);
FOUT
}
if (strcmp ("isallow" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->isallow);
FOUT
}
if (strcmp ("seg_sbh" , var_name) == 0)
{
*var_p_ptr = (void *) (&prs_ptr->seg_sbh);
FOUT
}
*var_p_ptr = (void *)OPC_NIL;
FOUT
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -