📄 obs_proc.pr.c
字号:
/* Process model C form file: OBS_proc.pr.c */
/* Portions of this file copyright 1992-2001 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
static const char OBS_proc_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 412EDFF9 412EDFF9 1 babo123 Administrator 0 0 none none 0 0 none 0 0 0 0 0 0 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
#if defined (__cplusplus)
extern "C" {
#endif
FSM_EXT_DECS
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Header Block */
#include <string.h>
#include <stdlib.h>
#include <route.h>
#define PK_IN_STRM 0
#define PK_OUT_STRM 0
#define PK_OUT_STRM_STORE 1
#define MAX_NODES 15
#define END_SIM (op_intrpt_type () == OPC_INTRPT_ENDSIM)
#define BEG_SIM (op_intrpt_type () == OPC_INTRPT_BEGSIM)
#define BURST_ARRIVAL (op_intrpt_type () == OPC_INTRPT_STRM && op_intrpt_strm () == PK_IN_STRM)
int node_count = 0;
double pk_size_total_send = 0;
int pk_count_total_send = 0;
double pk_avg_total_size_send = 0;
/* End of Header Block */
#if !defined (VOSD_NO_FIN)
#undef BIN
#undef BOUT
#define BIN FIN_LOCAL_FIELD(last_line_passed) = __LINE__ - _block_origin;
#define BOUT BIN
#define BINIT FIN_LOCAL_FIELD(last_line_passed) = 0; _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 sequence_number_wait;
int sequence_number_current;
int node_address;
int nodes_total;
int queue_size;
int pk_rcvd[MAX_NODES];
Distribution* address_dist;
Objid sar_mod_objid;
Objid node_id;
Objid subnet_id;
Objid next_node_id;
Stathandle num_pk_gen_gsh;
Stathandle dup_pk_gsh;
Route* current_rptr;
int pk_count;
Stathandle pk_cnt_stathandle;
Distribution * start_dist;
Distribution * dtime_dist;
Objid dest_node_objid;
Objid node_objid;
Objid self_objid;
Distribution* wave_dist;
Stathandle pk_size_temp;
double pk_size;
int pik_count;
Stathandle pk_cnt_no1_stathandle;
Stathandle pk_size_no1_stathandle;
Stathandle pk_size_total_send_stathandle;
Stathandle pk_cnt_total_send_stathandle;
double pk_avg_size_send;
int pk_count_send_channel0;
int pk_count_send_channel1;
double pk_size_send_channel0;
double pk_size_send_channel1;
Stathandle pk_avg_size_send_stathandle;
Stathandle pk_count_send_channel0_stathandle;
Stathandle pk_size_send_channel0_stathandle;
Stathandle pk_count_send_channel1_stathandle;
Stathandle pk_size_send_channel1_stathandle;
Stathandle pk_avg_total_size_send_stathandle;
int id_number;
} OBS_proc_state;
#define pr_state_ptr ((OBS_proc_state*) SimI_Mod_State_Ptr)
#define sequence_number_wait pr_state_ptr->sequence_number_wait
#define sequence_number_current pr_state_ptr->sequence_number_current
#define node_address pr_state_ptr->node_address
#define nodes_total pr_state_ptr->nodes_total
#define queue_size pr_state_ptr->queue_size
#define pk_rcvd pr_state_ptr->pk_rcvd
#define address_dist pr_state_ptr->address_dist
#define sar_mod_objid pr_state_ptr->sar_mod_objid
#define node_id pr_state_ptr->node_id
#define subnet_id pr_state_ptr->subnet_id
#define next_node_id pr_state_ptr->next_node_id
#define num_pk_gen_gsh pr_state_ptr->num_pk_gen_gsh
#define dup_pk_gsh pr_state_ptr->dup_pk_gsh
#define current_rptr pr_state_ptr->current_rptr
#define pk_count pr_state_ptr->pk_count
#define pk_cnt_stathandle pr_state_ptr->pk_cnt_stathandle
#define start_dist pr_state_ptr->start_dist
#define dtime_dist pr_state_ptr->dtime_dist
#define dest_node_objid pr_state_ptr->dest_node_objid
#define node_objid pr_state_ptr->node_objid
#define self_objid pr_state_ptr->self_objid
#define wave_dist pr_state_ptr->wave_dist
#define pk_size_temp pr_state_ptr->pk_size_temp
#define pk_size pr_state_ptr->pk_size
#define pik_count pr_state_ptr->pik_count
#define pk_cnt_no1_stathandle pr_state_ptr->pk_cnt_no1_stathandle
#define pk_size_no1_stathandle pr_state_ptr->pk_size_no1_stathandle
#define pk_size_total_send_stathandle pr_state_ptr->pk_size_total_send_stathandle
#define pk_cnt_total_send_stathandle pr_state_ptr->pk_cnt_total_send_stathandle
#define pk_avg_size_send pr_state_ptr->pk_avg_size_send
#define pk_count_send_channel0 pr_state_ptr->pk_count_send_channel0
#define pk_count_send_channel1 pr_state_ptr->pk_count_send_channel1
#define pk_size_send_channel0 pr_state_ptr->pk_size_send_channel0
#define pk_size_send_channel1 pr_state_ptr->pk_size_send_channel1
#define pk_avg_size_send_stathandle pr_state_ptr->pk_avg_size_send_stathandle
#define pk_count_send_channel0_stathandle pr_state_ptr->pk_count_send_channel0_stathandle
#define pk_size_send_channel0_stathandle pr_state_ptr->pk_size_send_channel0_stathandle
#define pk_count_send_channel1_stathandle pr_state_ptr->pk_count_send_channel1_stathandle
#define pk_size_send_channel1_stathandle pr_state_ptr->pk_size_send_channel1_stathandle
#define pk_avg_total_size_send_stathandle pr_state_ptr->pk_avg_total_size_send_stathandle
#define id_number pr_state_ptr->id_number
/* This macro definition 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
#define FIN_PREAMBLE OBS_proc_state *op_sv_ptr = pr_state_ptr;
/* No Function Block */
enum { _block_origin = __LINE__ };
/* 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 OBS_proc (void);
Compcode OBS_proc_init (void **);
void OBS_proc_diag (void);
void OBS_proc_terminate (void);
void OBS_proc_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
OBS_proc (void)
{
int _block_origin = 0;
FIN (OBS_proc ());
if (1)
{
Packet* pkptr_burst;
Packet* pkptr;
int sequence_number_ack;
int sequence_number_rcv;
int source_address;
int destination_address;
int i,j,k;
Route* pk_rptr;
Route* p_min_rptr_copy;
double start_time;
double dtime_time;
double cur_time;
int subnet_ids[10];
int node_ids[20];
int num_nodes;
int userid;
double EXTRA_TIME;
int ok_flag;
int wavelength_number;
int u_id;
Objid strm_objid;
int jj;
int channel_num;
double temp_time;
FSM_ENTER (OBS_proc)
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "OBS_proc () [init enter execs]")
{
self_objid = op_id_self(); //precess id
node_id = op_topo_parent (self_objid); //node id
subnet_id = op_topo_parent(node_id); //subnet_id 牢单 咯扁辑绰 subnet_id 客 network_id啊 鞍促
node_count++;
node_address = node_count;
op_ima_obj_attr_set (node_id, "user id", node_address);
id_number = 0;
/* determine the total number of end nodes connceted to the network */
nodes_total = op_topo_object_count (OPC_OBJTYPE_NDFIX); //Node Difine IndeX
/* set up the address distribution */
address_dist = op_dist_load ("uniform_int", 1, NODE_NUM);
/* register global stats and write an init point in each */
//num_pk_gen_gsh = op_stat_reg ("Global application packets generated (pks)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
//op_stat_write (num_pk_gen_gsh, num_pk_gen);
pk_size = 0;
pk_size_no1_stathandle = op_stat_reg("PK_SIZE_NODE1",OPC_STAT_INDEX_NONE,OPC_STAT_LOCAL);
pk_count = 0;
pk_cnt_no1_stathandle = op_stat_reg("PK_COUNT_NODE1", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
//pk_size_total_send = 0;
pk_size_total_send_stathandle = op_stat_reg("PK_SIZE_TOTAL_SEND",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
//pk_count_total_send = 0;
pk_cnt_total_send_stathandle = op_stat_reg("PK_COUNT_TOTAL_SEND", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
//pk_avg_total_size_send = 0;
pk_avg_total_size_send_stathandle = op_stat_reg("PK_AVG_TOTAL_SIZE_SEND", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
pk_avg_size_send = 0;
pk_avg_size_send_stathandle = op_stat_reg("PK_AVG_SIZE_SEND", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pk_count_send_channel0 = 0;
pk_count_send_channel0_stathandle = op_stat_reg("PK_COUNT_SEND_CHANNEL0", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pk_size_send_channel0 = 0;
pk_size_send_channel0_stathandle = op_stat_reg("PK_SIZE_SEND_CHANNEL0", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pk_count_send_channel1 = 0;
pk_count_send_channel1_stathandle = op_stat_reg("PK_COUNT_SEND_CHANNEL1", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
pk_size_send_channel1 = 0;
pk_size_send_channel1_stathandle = op_stat_reg("PK_SIZE_SEND_CHANNEL1", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
}
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "OBS_proc () [init exit execs]")
{
}
/** state (init) transition processing **/
FSM_TRANSIT_ONLY ((BEG_SIM), 1, state1_enter_exec, ;, "init", "BEG_SIM", "", "init", "wait")
/*---------------------------------------------------------*/
/** state (wait) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "wait", "OBS_proc () [wait enter execs]")
{
}
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,OBS_proc)
/** state (wait) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "wait", "OBS_proc () [wait exit execs]")
{
}
/** state (wait) transition processing **/
FSM_INIT_COND (BURST_ARRIVAL)
FSM_TEST_COND (END_SIM)
FSM_TEST_LOGIC ("wait")
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "BURST_ARRIVAL", "", "wait", "proc")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "END_SIM", "", "wait", "end")
}
/*---------------------------------------------------------*/
/** state (proc) enter executives **/
FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "proc", "OBS_proc () [proc enter execs]")
{
self_objid = op_id_self ();
node_objid = op_topo_parent(self_objid);
op_ima_obj_attr_get(node_objid, "user id", &userid); //user id甫 掘绢坷绰备唱
/* obtain the app packet*/
pkptr_burst = op_pk_get(op_intrpt_strm());
pk_count++;
pk_size = op_pk_total_size_get (pkptr_burst);
//node 1俊辑 惯积茄 burst捞搁
op_stat_write(pk_size_no1_stathandle, pk_size);
op_stat_write(pk_cnt_no1_stathandle, pk_count);
temp_time = op_sim_time();
//printf("temp_time=%f\n",temp_time);
//if(temp_time > 0.03)
//{
pk_count_total_send++;
pk_size_total_send = pk_size_total_send + op_pk_total_size_get (pkptr_burst);
pk_avg_total_size_send = (double)(pk_size_total_send/(double)pk_count_total_send);
//pk_avg_size_send = (double)(pk_size_total_send/(double)pk_count_total_send);
op_stat_write(pk_size_total_send_stathandle, pk_size_total_send);
op_stat_write(pk_cnt_total_send_stathandle, pk_count_total_send);
op_stat_write(pk_avg_total_size_send_stathandle, pk_avg_total_size_send);
//}
// bcp积己
pkptr =op_pk_create_fmt ("BCP");
op_pk_nfd_set (pkptr, "source address", node_address);
source_address = node_address;
while(1)
{
destination_address = op_dist_uniform(NODE_NUM);
destination_address++;
if(userid != destination_address) break;
}
op_pk_nfd_set (pkptr, "destination address", destination_address);
if (min_rptr[source_address][destination_address] == OPC_NIL) //扼快泼 抛捞喉俊 粮犁窍瘤 臼栏搁
{
p_min_rptr_copy = OPC_NIL;
}
else
{
p_min_rptr_copy = op_rte_route_copy (min_rptr[source_address][destination_address]);
}
current_rptr = p_min_rptr_copy;
if (current_rptr == OPC_NIL)
{
op_pk_destroy (pkptr);
}
else
{
/* insert the route into the packet */
id_number++;
pk_rptr = op_rte_route_copy (current_rptr);
op_rte_pk_route_insert (pkptr, pk_rptr);
num_nodes = op_rte_route_num_nodes (min_rptr[source_address][destination_address]);
dtime_time = (double) pk_size/RATE; //???????????????RATE绰 绢叼俊 急攫等芭具??????????
op_ima_obj_attr_get(self_objid, "EXTRA_TIME", &EXTRA_TIME); //EXTRA_TIME篮 檬扁拳救夌绰单.???????
start_time = (double) PROC_TIME*num_nodes; //傈价瘤楷篮 公矫窍唱??????????????????
op_pk_nfd_set (pkptr, "start", start_time);
op_pk_nfd_set (pkptr, "dtime", dtime_time);
op_pk_nfd_set (pkptr, "type", 0);
op_pk_nfd_set (pkptr, "id", id_number);
wave_dist = op_dist_load ("uniform_int", 0, WAVE_NUM-1);
wavelength_number = op_dist_outcome (wave_dist);
op_pk_nfd_set (pkptr, "wavelength", wavelength_number);
//set attributy of burst
op_pk_nfd_set (pkptr_burst, "source address", node_address);
op_pk_nfd_set (pkptr_burst, "destination address", destination_address);
op_pk_nfd_set (pkptr_burst, "start", start_time);
op_pk_nfd_set (pkptr_burst, "dtime", dtime_time);
//if type == 0 than bcp, if type == 1 than burst
op_pk_nfd_set (pkptr_burst, "type", 1);
op_pk_nfd_set (pkptr_burst, "id", id_number);
op_pk_send (pkptr, PK_OUT_STRM);
op_pk_send(pkptr_burst, PK_OUT_STRM_STORE);
}
//op_pk_destroy (pkptr_burst);
//op_rte_route_print(min_rptr[1][4]);
//getchar();
//if(jj==0)
//{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -