📄 noc_bursty_source.pr.c
字号:
/* Process model C form file: NOC_bursty_source.pr.c */
/* Portions of this file copyright 1992-2004 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char NOC_bursty_source_pr_c [] = "MIL_3_Tfile_Hdr_ 105A 30A modeler 7 43817CBF 43817CBF 1 ccslab-yy 严晔 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 */
/* Include files. */
#include "oms_dist_support.h"
#include <math.h>
/* Define constants used in the process model. */
#define OFF_TO_ON 10
#define ON_TO_ON 20
#define ON_TO_OFF 30
/* State transition macro definitions. */
#define INACTIVE_TO_ACTIVE (intrpt_type == OPC_INTRPT_SELF && intrpt_code == OFF_TO_ON)
#define REMAIN_ACTIVE (intrpt_type == OPC_INTRPT_SELF && intrpt_code == ON_TO_ON)
#define ACTIVE_TO_INACTIVE (intrpt_type == OPC_INTRPT_SELF && intrpt_code == ON_TO_OFF)
/* Function Declarations. */
static void bursty_source_sv_init ();
/*
OmsT_Dist_Handle on_state_dist_handle;
OmsT_Dist_Handle off_state_dist_handle;
OmsT_Dist_Handle intarrvl_time_dist_handle;
OmsT_Dist_Handle packet_size_dist_handle; */
/* 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 */
char pid_string [64] ; /* Process ID display string */
Boolean debug_mode ; /* Determines whether the simulation is in debug mode */
double stop_time ; /* Stop time for traffic generation */
double off_state_start_time ; /* Time at which the process will enter the OFF state */
Stathandle pksize_stathandle ; /* Statistic handle to the "Packet Generation Status" statistic */
OmsT_Dist_Handle on_state_dist_handle ; /* On state distribution handle */
OmsT_Dist_Handle off_state_dist_handle ; /* Off state distribution handle */
OmsT_Dist_Handle intarrvl_time_dist_handle ; /* Interarrival time distribution handle */
OmsT_Dist_Handle packet_size_dist_handle ; /* Packet size distribution handle */
double start_time ; /* Start time for traffic generation */
Stathandle bits_sent_stathandle ;
Stathandle bitssec_sent_stathandle ;
Stathandle pkts_sent_stathandle ;
Stathandle pktssec_sent_stathandle ;
Stathandle bits_sent_gstathandle ;
Stathandle bitssec_sent_gstathandle ;
Stathandle pkts_sent_gstathandle ;
Stathandle pktssec_sent_gstathandle ;
int segmentation_size ; /* Size using which segmentation will occur. */
Sbhandle segmentation_buf_handle ;
} NOC_bursty_source_state;
#define pr_state_ptr ((NOC_bursty_source_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define pid_string pr_state_ptr->pid_string
#define debug_mode pr_state_ptr->debug_mode
#define stop_time pr_state_ptr->stop_time
#define off_state_start_time pr_state_ptr->off_state_start_time
#define pksize_stathandle pr_state_ptr->pksize_stathandle
#define on_state_dist_handle pr_state_ptr->on_state_dist_handle
#define off_state_dist_handle pr_state_ptr->off_state_dist_handle
#define intarrvl_time_dist_handle pr_state_ptr->intarrvl_time_dist_handle
#define packet_size_dist_handle pr_state_ptr->packet_size_dist_handle
#define start_time pr_state_ptr->start_time
#define bits_sent_stathandle pr_state_ptr->bits_sent_stathandle
#define bitssec_sent_stathandle pr_state_ptr->bitssec_sent_stathandle
#define pkts_sent_stathandle pr_state_ptr->pkts_sent_stathandle
#define pktssec_sent_stathandle pr_state_ptr->pktssec_sent_stathandle
#define bits_sent_gstathandle pr_state_ptr->bits_sent_gstathandle
#define bitssec_sent_gstathandle pr_state_ptr->bitssec_sent_gstathandle
#define pkts_sent_gstathandle pr_state_ptr->pkts_sent_gstathandle
#define pktssec_sent_gstathandle pr_state_ptr->pktssec_sent_gstathandle
#define segmentation_size pr_state_ptr->segmentation_size
#define segmentation_buf_handle pr_state_ptr->segmentation_buf_handle
/* 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 NOC_bursty_source_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 = ((NOC_bursty_source_state *)(tcontext_ptr->mod_state_ptr));
#else
# define FIN_PREAMBLE_DEC NOC_bursty_source_state *op_sv_ptr;
# define FIN_PREAMBLE_CODE op_sv_ptr = pr_state_ptr;
#endif
/* Function Block */
#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ };
#endif
static void
bursty_source_sv_init ()
{
Prohandle my_prohandle;
int my_pro_id;
Objid my_id;
Objid traf_gen_comp_attr_objid, traf_conf_objid;
Objid pkt_gen_comp_attr_objid, pkt_gen_args_objid;
char on_state_string [128], off_state_string [128];
char intarrvl_rate_string [128], packet_size_string [128];
char start_time_string [128];
OmsT_Dist_Handle start_time_dist_handle;
/** Initializes state variables associated with **/
/** this process model. **/
FIN (bursty_source_sv_init ());
/* Determine the prohandle of this process as well as */
/* the object IDs of the containing module and node.*/
my_prohandle = op_pro_self ();
my_pro_id = op_pro_id (my_prohandle);
my_id = op_id_self ();
/* Determine the process ID display string. */
sprintf (pid_string, "NOC_bursty_source PID (%d)", my_pro_id);
/* Determine whether or not the simulation is in debug */
/* mode. Trace statement are only enabled when the */
/* simulation is in debug mode. */
debug_mode = op_sim_debug ();
/* Read the traffic generation parameters. */
op_ima_obj_attr_get (my_id, "Traffic Generation Parameters", &traf_gen_comp_attr_objid);
traf_conf_objid = op_topo_child (traf_gen_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);
/* Determine the start time for traffic generation. */
op_ima_obj_attr_get (traf_conf_objid, "Start Time", start_time_string);
if (strcmp (start_time_string, "Never") != 0)
{
start_time_dist_handle = oms_dist_load_from_string (start_time_string);
start_time = oms_dist_outcome (start_time_dist_handle);
}
else
{
start_time = -1.0;
}
/* Determine the stop time for traffic generation. */
op_ima_obj_attr_get (traf_conf_objid, "Stop Time", &stop_time);
if (stop_time == -1.0)
stop_time = OPC_DBL_INFINITY;
/* If the start time is set to "Infinity", then there */
/* is no need to schedule an interrupt as this node has */
/* been set will not generate any traffic. */
if ((start_time >= 0.0) && (stop_time > start_time))
{
/* Load the distribution used to determine the time */
/* for which the process stays in the "ON" state. */
op_ima_obj_attr_get (traf_conf_objid, "ON State Time", on_state_string);
on_state_dist_handle = oms_dist_load_from_string (on_state_string);
/* Load the distribution used to determine the time */
/* for which the process stays in the "OFF" state. */
op_ima_obj_attr_get (traf_conf_objid, "OFF State Time", off_state_string);
off_state_dist_handle = oms_dist_load_from_string (off_state_string);
/* Load the distribution used to determine the packet */
/* interarrivals. */
op_ima_obj_attr_get (traf_conf_objid, "Packet Generation Arguments", &pkt_gen_comp_attr_objid);
pkt_gen_args_objid = op_topo_child (pkt_gen_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);
op_ima_obj_attr_get (pkt_gen_args_objid, "Interarrival Time", intarrvl_rate_string);
intarrvl_time_dist_handle = oms_dist_load_from_string (intarrvl_rate_string);
/* Load the distribution used to determine the size of */
/* the packets being generated. */
op_ima_obj_attr_get (pkt_gen_args_objid, "Packet Size", packet_size_string);
packet_size_dist_handle = oms_dist_load_from_string (packet_size_string);
/* Initilaize the packet generation status statistic */
/* to indicate that currently there are no packets */
/* being generated. */
pksize_stathandle = op_stat_reg ("Traffic Source.Packet Generation Status", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
op_stat_write (pksize_stathandle, (double) OPC_FALSE);
/* Initilaize the statistic handles to keep */
/* track of traffic Sourceed by this process. */
bits_sent_stathandle = op_stat_reg ("Traffic Source.Traffic Sent (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
bitssec_sent_stathandle = op_stat_reg ("Traffic Source.Traffic Sent (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pkts_sent_stathandle = op_stat_reg ("Traffic Source.Traffic Sent (packets)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pktssec_sent_stathandle = op_stat_reg ("Traffic Source.Traffic Sent (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
bits_sent_gstathandle = op_stat_reg ("Traffic Source.Traffic Sent (bits)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
bitssec_sent_gstathandle = op_stat_reg ("Traffic Source.Traffic Sent (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
pkts_sent_gstathandle = op_stat_reg ("Traffic Source.Traffic Sent (packets)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
pktssec_sent_gstathandle = op_stat_reg ("Traffic Source.Traffic Sent (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
/* Check if packet segmentation is modeled. */
op_ima_obj_attr_get (pkt_gen_args_objid, "Segmentation Size", &segmentation_size);
if (segmentation_size != -1)
{
segmentation_size *= 8;
segmentation_buf_handle = op_sar_buf_create (OPC_SAR_BUF_TYPE_SEGMENT, OPC_SAR_BUF_OPT_PK_BNDRY);
}
}
FOUT;
}
/* End of Function Block */
/* 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 NOC_bursty_source (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype NOC_bursty_source_init (int * init_block_ptr);
VosT_Address NOC_bursty_source_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
void NOC_bursty_source_diag (OP_SIM_CONTEXT_ARG_OPT);
void NOC_bursty_source_terminate (OP_SIM_CONTEXT_ARG_OPT);
void NOC_bursty_source_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
NOC_bursty_source (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (NOC_bursty_source ());
{
/* Temporary Variables */
int intrpt_type;
int intrpt_code;
Packet* pkptr;
double pksize;
double dval0 = 0.0;
double dval1 = 0.0;
char pdf_name [256];
char pdf_args [256];
double on_period;
double off_period;
double next_packet_arrival_time;
/* End of Temporary Variables */
FSM_ENTER ("NOC_bursty_source")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "NOC_bursty_source [init enter execs]")
FSM_PROFILE_SECTION_IN ("NOC_bursty_source [init enter execs]", state0_enter_exec)
{
/* Initialize the traffic generation parameters. */
bursty_source_sv_init ();
/* Schedule the first OFF-period scheduling by setting */
/* a self-interrupt for the start time. If the start */
/* time is set to "Infinity", then there is no need to */
/* to schedule an interrupt as this node has been set */
/* will not generate any traffic. */
if (start_time >= 0.0)
{
op_intrpt_schedule_self (op_sim_time () + start_time, 0);
}
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (1,"NOC_bursty_source")
/** state (init) exit executives **/
FSM_STATE_EXIT_UNFORCED (0, "init", "NOC_bursty_source [init exit execs]")
/** state (init) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "off")
/*---------------------------------------------------------*/
/** state (off) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, "off", state1_enter_exec, "NOC_bursty_source [off enter execs]")
FSM_PROFILE_SECTION_IN ("NOC_bursty_source [off enter execs]", state1_enter_exec)
{
/* Determine the time for which the process remains in */
/* the "OFF" (inactive) state. This is determined by */
/* the distribution loaded to characterize the "OFF" */
/* state duration (i.e., time for which the source */
/* does not generate any packets. */
off_period = oms_dist_outcome (off_state_dist_handle);
/* Schedule a self-interrupt to transit to the "ON" */
/* when the "OFF" state duration expires. */
if (op_sim_time () + off_period < stop_time)
op_intrpt_schedule_self (op_sim_time () + off_period, OFF_TO_ON);
}
FSM_PROFILE_SECTION_OUT (state1_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"NOC_bursty_source")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -