📄 tan_noc_worm_node_source.pr.c
字号:
/* Process model C form file: tan_noc_worm_node_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 tan_noc_worm_node_source_pr_c [] = "MIL_3_Tfile_Hdr_ 105A 30A modeler 7 49E69219 49E69219 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 */
/* Include files. */
#include <oms_dist_support.h>
/* Special attribute values. */
#define SSC_INFINITE_TIME -1.0
/* Interrupt code values. */
#define SSC_START 0
#define SSC_GENERATE 1
#define SSC_STOP 2
/* Node configuration constants. */
#define SSC_STRM_TO_LOW 0
/* Macro definitions for state */
/* transitions. */
#define START (intrpt_code == SSC_START)
#define DISABLED (intrpt_code == SSC_STOP)
#define STOP (intrpt_code == SSC_STOP)
#define PACKET_GENERATE (intrpt_code == SSC_GENERATE)
/* Function prototypes. */
static void ss_packet_generate (void);
/* 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 */
Objid own_id ; /* Object ID of the surrounding module. */
char format_str_header [64] ; /* header Format of the packets generated by this source. */
double start_time ; /* Time when this source will start its packet generation */
/* activities. */
double stop_time ; /* Time when this source will stop its packet generation */
/* activities. */
OmsT_Dist_Handle interarrival_dist_ptr ; /* PDF used to determine the interarrival times of */
/* generated packets. */
OmsT_Dist_Handle pksize_dist_ptr ; /* PDF used to determine the sizes of generated packets. */
Boolean generate_unformatted ; /* Flag that indicates whether the source will generate */
/* unformatted or formatted packets. */
Evhandle next_pk_evh ; /* Event handle for the arrival of next packet. */
double next_intarr_time ; /* Time between the generation of the last packet and the */
/* next packet. */
Stathandle bits_sent_hndl ; /* Statistic handle for "Traffic Sent (bits/sec)" statistic. */
Stathandle packets_sent_hndl ; /* Statistic handle for "Traffic Sent (packets/sec)" statistic. */
Stathandle packet_size_hndl ; /* Statistic handle for "Packet Size (bits)" statistic. */
Stathandle interarrivals_hndl ; /* Statistic handle for "Packet Interaarival Time (secs)" */
/* statistic. */
char format_str_data [64] ; /* data Format of the packets generated by this process */
OmsT_Dist_Handle flit_num ;
} tan_noc_worm_node_source_state;
#define pr_state_ptr ((tan_noc_worm_node_source_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define own_id pr_state_ptr->own_id
#define format_str_header pr_state_ptr->format_str_header
#define start_time pr_state_ptr->start_time
#define stop_time pr_state_ptr->stop_time
#define interarrival_dist_ptr pr_state_ptr->interarrival_dist_ptr
#define pksize_dist_ptr pr_state_ptr->pksize_dist_ptr
#define generate_unformatted pr_state_ptr->generate_unformatted
#define next_pk_evh pr_state_ptr->next_pk_evh
#define next_intarr_time pr_state_ptr->next_intarr_time
#define bits_sent_hndl pr_state_ptr->bits_sent_hndl
#define packets_sent_hndl pr_state_ptr->packets_sent_hndl
#define packet_size_hndl pr_state_ptr->packet_size_hndl
#define interarrivals_hndl pr_state_ptr->interarrivals_hndl
#define format_str_data pr_state_ptr->format_str_data
#define flit_num pr_state_ptr->flit_num
/* 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_node_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 = ((tan_noc_worm_node_source_state *)(tcontext_ptr->mod_state_ptr));
#else
# define FIN_PREAMBLE_DEC tan_noc_worm_node_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
ss_packet_generate (void)
{
Packet* pkptr;
double pksize;
int i, flit_n;
/** This function creates a packet based on the packet generation **/
/** specifications of the source model and sends it to the lower layer. **/
FIN (ss_packet_generate ());
/* Generate a packet size outcome. */
pksize = (double) ceil (oms_dist_outcome (pksize_dist_ptr));
/* Create a packet of specified format and size. */
if (generate_unformatted == OPC_TRUE)
{
/* We produce unformatted packets. Create one. */
pkptr = op_pk_create (pksize);
}
else
{
/* Create a packet with the specified format. */
flit_n = (int)ceil(oms_dist_outcome(flit_num));
if(flit_n == 1) flit_n = flit_n + 1;
for(i = 0; i < flit_n; i++) {
if(i == 0) {
pkptr = op_pk_create_fmt (format_str_header);
op_pk_nfd_set(pkptr, "flag", 1);
}
else if(i == flit_n - 1) {
pkptr = op_pk_create_fmt(format_str_data);
op_pk_nfd_set(pkptr, "flag", 2);
}
else {
pkptr = op_pk_create_fmt(format_str_data);
op_pk_nfd_set(pkptr, "flag", 0);
}
op_pk_total_size_set (pkptr, pksize);
op_pk_send(pkptr, SSC_STRM_TO_LOW);
}
}
/* Update the packet generation statistics. */
op_stat_write (packets_sent_hndl, 1.0);
op_stat_write (packets_sent_hndl, 0.0);
op_stat_write (bits_sent_hndl, (double) pksize);
op_stat_write (bits_sent_hndl, 0.0);
op_stat_write (packet_size_hndl, (double) pksize);
op_stat_write (interarrivals_hndl, next_intarr_time);
/* Send the packet via the stream to the lower layer. */
//op_pk_send (pkptr, SSC_STRM_TO_LOW);
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 tan_noc_worm_node_source (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype tan_noc_worm_node_source_init (int * init_block_ptr);
VosT_Address tan_noc_worm_node_source_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
void tan_noc_worm_node_source_diag (OP_SIM_CONTEXT_ARG_OPT);
void tan_noc_worm_node_source_terminate (OP_SIM_CONTEXT_ARG_OPT);
void tan_noc_worm_node_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
tan_noc_worm_node_source (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (tan_noc_worm_node_source ());
{
/* Temporary Variables */
/* Variables used in the "init" state. */
char interarrival_str [128];
char size_str [128], num_flit[128];
Prg_List* pk_format_names_lptr;
char* found_format_str;
int low, high;
Boolean format_found, format_found_header, format_found_data;
int i;
/* Variables used in state transitions. */
int intrpt_code;
/* End of Temporary Variables */
FSM_ENTER ("tan_noc_worm_node_source")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "tan_noc_worm_node_source [init enter execs]")
FSM_PROFILE_SECTION_IN ("tan_noc_worm_node_source [init enter execs]", state0_enter_exec)
{
/* At this initial state, we read the values of source attributes */
/* and schedule a selt interrupt that will indicate our start time */
/* for packet generation. */
/* Obtain the object id of the surrounding module. */
own_id = op_id_self ();
/* Read the values of the packet generation parameters, i.e. the */
/* attribute values of the surrounding module. */
op_ima_obj_attr_get (own_id, "Packet Interarrival Time", interarrival_str);
op_ima_obj_attr_get (own_id, "Packet Size", size_str);
op_ima_obj_attr_get (own_id, "Packet Format header", format_str_header);
op_ima_obj_attr_get (own_id, "Packet Format data", format_str_data);
op_ima_obj_attr_get (own_id, "Start Time", &start_time);
op_ima_obj_attr_get (own_id, "Stop Time", &stop_time);
op_ima_obj_attr_get(own_id, "Flit Num", num_flit);
/* Load the PDFs that will be used in computing the packet */
/* interarrival times and packet sizes. */
interarrival_dist_ptr = oms_dist_load_from_string (interarrival_str);
pksize_dist_ptr = oms_dist_load_from_string (size_str);
flit_num = oms_dist_load_from_string (num_flit);
/* Verify the existence of the packet format to be used for */
/* generated packets. */
if (strcmp (format_str_header, "NONE") == 0)
{
/* We will generate unformatted packets. Set the flag. */
generate_unformatted = OPC_TRUE;
}
else
{
/* We will generate formatted packets. Turn off the flag. */
generate_unformatted = OPC_FALSE;
/* Get the list of all available packet formats. */
pk_format_names_lptr = prg_tfile_name_list_get (PrgC_Tfile_Type_Packet_Format);
/* Search the list for the requested packet format. */
format_found = OPC_FALSE;
format_found_header = OPC_FALSE;
format_found_data = OPC_FALSE;
for (i = prg_list_size (pk_format_names_lptr); ((format_found == OPC_FALSE) && (i > 0)); i--)
{
/* Access the next format name and compare with requested */
/* format name. */
found_format_str = (char *) prg_list_access (pk_format_names_lptr, i - 1);
if (strcmp (found_format_str, format_str_header) == 0)
format_found_header = OPC_TRUE;
if(strcmp(found_format_str, format_str_data) == 0)
format_found_data = OPC_TRUE;
}
if(format_found_header == OPC_TRUE && format_found_data == OPC_TRUE)
format_found = OPC_TRUE;
if (format_found == OPC_FALSE)
{
/* The requested format does not exist. Generate */
/* unformatted packets. */
generate_unformatted = OPC_TRUE;
/* Display an appropriate warning. */
op_prg_odb_print_major ("Warning from simple packet generator model (simple_source):",
"The specified packet format", format_str_header,
"is not found. Generating unformatted packets instead.", OPC_NIL);
}
/* Destroy the lits and its elements since we don't need it */
/* anymore. */
prg_list_free (pk_format_names_lptr);
prg_mem_free (pk_format_names_lptr);
}
/* Make sure we have valid start and stop times, i.e. stop time is */
/* not earlier than start time. */
if ((stop_time <= start_time) && (stop_time != SSC_INFINITE_TIME))
{
/* Stop time is earlier than start time. Disable the source. */
start_time = SSC_INFINITE_TIME;
/* Display an appropriate warning. */
op_prg_odb_print_major ("Warning from simple packet generator model (simple_source):",
"Although the generator is not disabled (start time is set to a finite value),",
"a stop time that is not later than the start time is specified.",
"Disabling the generator.", OPC_NIL);
}
/* Schedule a self interrupt that will indicate our start time for */
/* packet generation activities. If the source is disabled, */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -