📄 restoration_control.pr.c
字号:
/* Process model C form file: Restoration_control.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 Restoration_control_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 40E42424 40E42424 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 "stdlib.h"
#include "string.h"
#include "route.h"
#include <stdio.h>
#define MAX_HOPS 15
#define STOP_SIM 2
#define FAIL_NODE 3
#define FAIL_LINK 4
#define RECOVER_NODE 5
#define RECOVER_LINK 6
#define TRPRT_OUT_STREAM 0
#define LINK_ACTION 0
#define NODE_ACTION 1
#define FAIL 0
#define RECOVER 1
#define BEGSIM (op_intrpt_type () == OPC_INTRPT_BEGSIM)
#define ND_FAIL (remote_int_code == FAIL_NODE)
#define LK_FAIL (remote_int_code == FAIL_LINK)
#define ND_RCOVR (remote_int_code == RECOVER_NODE)
#define LK_RCOVR (remote_int_code == RECOVER_LINK)
#define MAX_NUM_LOOPS 200
List* link_enabled_lptr;
List* link_disabled_lptr;
List* link_non_mesh_lptr;
List* call_router_lptr;
List* mesh_nd_enabled_lptr;
List* mesh_nd_disabled_lptr;
typedef struct
{
double time;
int act_obj_type;
char arg1[128];
char arg2[128];
int act;
int restoration;
} Fail_Table;
/*
double Net_top[NODE_NUM][NODE_NUM]={
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14
{0, 1100, 1600, 0, 0, 0, 0, 2800, 0, 0, 0, 0, 0, 0},
{1100, 0, 600, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1600, 600, 0, 0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1000, 0, 0, 600, 0, 0, 0, 0, 0, 2400, 0, 0, 0},
{0, 0, 0, 600, 0, 1100, 800, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 2000, 0, 1100, 0, 0, 0, 1200, 0, 0, 0, 2000, 0},
{0, 0, 0, 0, 800, 0, 0, 700, 0, 0, 0, 0, 0, 0},
{2800, 0, 0, 0, 0, 0, 700, 0, 0, 700, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1200, 0, 0, 0, 900, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 700, 900, 0, 0, 500, 0, 500},
{0, 0, 0, 2400, 0, 0, 0, 0, 0, 0, 0, 800, 0, 800},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 800, 0, 300, 0},
{0, 0, 0, 0, 0, 2000, 0, 0, 0, 0, 0, 300, 0, 300},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 800, 0, 300, 0}
};
double Net_delay[NODE_NUM][NODE_NUM]={
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14
{0, 0.0055, 0.008, 0, 0, 0, 0, 0.014, 0, 0, 0, 0, 0, 0},
{0.0055, 0, 0.003, 0.005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0.008, 0.003, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0.005, 0, 0, 0.003, 0, 0, 0, 0, 0, 0.012, 0, 0, 0},
{0, 0, 0, 0.003, 0, 0.0055, 0.004, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0.01, 0, 0.0055, 0, 0, 0, 0.006, 0, 0, 0, 0.01, 0},
{0, 0, 0, 0, 0.004, 0, 0, 0.0035, 0, 0, 0, 0, 0, 0},
{0.014, 0, 0, 0, 0, 0, 0.0035, 0, 0, 0.0035, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0.006, 0, 0, 0, 0.0045, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0.0035, 0.0045, 0, 0, 0.0025, 0, 0.0025},
{0, 0, 0, 0.012, 0, 0, 0, 0, 0, 0, 0, 0.004, 0, 0.004},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0025, 0.004, 0, 0.0015, 0},
{0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0.0015, 0, 0.0015},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0025, 0.004, 0, 0.0015, 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 num_fixed_nodes;
int num_dup_links;
Objid node_objid;
Objid subnet_objid;
int num_call_routers;
int num_lines;
int schedule_num;
List* fail_file_ptr;
Fail_Table* fail_table_ptr;
Fail_Table* schedule_ptr;
int action_obj_type;
int action_obj_index;
int action;
int remote_int_code;
int fail_index;
Objid mesh_node_objid_1;
Objid mesh_process_objid_1;
Objid mesh_node_objid_2;
Objid mesh_process_objid_2;
} Restoration_control_state;
#define pr_state_ptr ((Restoration_control_state*) SimI_Mod_State_Ptr)
#define num_fixed_nodes pr_state_ptr->num_fixed_nodes
#define num_dup_links pr_state_ptr->num_dup_links
#define node_objid pr_state_ptr->node_objid
#define subnet_objid pr_state_ptr->subnet_objid
#define num_call_routers pr_state_ptr->num_call_routers
#define num_lines pr_state_ptr->num_lines
#define schedule_num pr_state_ptr->schedule_num
#define fail_file_ptr pr_state_ptr->fail_file_ptr
#define fail_table_ptr pr_state_ptr->fail_table_ptr
#define schedule_ptr pr_state_ptr->schedule_ptr
#define action_obj_type pr_state_ptr->action_obj_type
#define action_obj_index pr_state_ptr->action_obj_index
#define action pr_state_ptr->action
#define remote_int_code pr_state_ptr->remote_int_code
#define fail_index pr_state_ptr->fail_index
#define mesh_node_objid_1 pr_state_ptr->mesh_node_objid_1
#define mesh_process_objid_1 pr_state_ptr->mesh_process_objid_1
#define mesh_node_objid_2 pr_state_ptr->mesh_node_objid_2
#define mesh_process_objid_2 pr_state_ptr->mesh_process_objid_2
/* 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 Restoration_control_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 Restoration_control (void);
Compcode Restoration_control_init (void **);
void Restoration_control_diag (void);
void Restoration_control_terminate (void);
void Restoration_control_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
Restoration_control (void)
{
int _block_origin = 0;
FIN (Restoration_control ());
if (1)
{
char icon_name[20];
Objid simple_objid;
Objid rec_node_objid;
Objid dest_objid;
Objid src_objid;
Objid self_objid;
Packet* pkptr;
Packet* f_pkptr;
Boolean condition;
Boolean node_condition;
Boolean link_condition;
Objid* rand_node_objid_ptr;
Packet* rand_node_objid_ptr_1;
Objid* traffic_generate_objid_ptr;
Objid* rand_link_objid_ptr;
char node_name[255];
char node0_name[255];
char node1_name[255];
char link_name[255];
char script_filename[255];
char err_str[255];
char f_type[1],f_data[1];
int rand_num;
int num_nds_enabled;
int num_nds_disabled;
int num_links_enabled;
int num_links_disabled;
int userid;
int i,j,k,l,m,x,y;
int comp_flag,exit_flag;
Objid* node_objid_ptr;
Objid* node0_objid_ptr;
Objid* node1_objid_ptr;
Objid* link_objid_ptr;
int interrupt_code;
Objid node0_objid;
Objid node1_objid;
Objid link_objid;
Route_Link* link_ptr;
Objid call_router_objid;
char* line;
List* field_list_ptr;
double node_mtbf;
double node_mttr;
double link_mtbf;
double link_mttr;
double link_cost;
double link_cost_default;
int subnet_ids[16];
int node_ids[16];
int num_nodes;
FILE *fp;
char f_name[50];
int userid0;
int userid1;
int userid2;
int hop_num[15][15];
double Average_hop_num;
int Hop_num;
int include_flag;
FSM_ENTER (Restoration_control)
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "Restoration_control () [init enter execs]")
{
self_objid = op_id_self();
node_objid = op_topo_parent (self_objid);
op_ima_obj_attr_get(node_objid, "user id", &userid);
subnet_objid = op_topo_parent (node_objid);
topo_ptr = op_rte_topo_from_objids ();
/* create 6 lists for enabled, disabled, links, and nodes */
link_enabled_lptr = op_prg_list_create ();
link_disabled_lptr = op_prg_list_create ();
link_non_mesh_lptr = op_prg_list_create ();
call_router_lptr = op_prg_list_create ();
mesh_nd_enabled_lptr = op_prg_list_create ();
mesh_nd_disabled_lptr = op_prg_list_create ();
/* get total number of fixed nodes */
num_fixed_nodes = op_topo_object_count (OPC_OBJTYPE_NDFIX);
/* insert node objid's to different lists */
for (i = 0; i < num_fixed_nodes; i++)
{
node_objid_ptr = (Objid *) op_prg_mem_alloc (sizeof (Objid));
/* get the node's name and condition */
*node_objid_ptr = op_topo_object (OPC_OBJTYPE_NDFIX, i);
op_ima_obj_attr_get (*node_objid_ptr, "name", node_name);
op_ima_obj_attr_get (*node_objid_ptr, "condition", &node_condition);
op_ima_obj_attr_get (*node_objid_ptr, "user id", &userid);
// printf("name = %s condition = %d user id = %d\n",node_name,node_condition,userid);
/* end nodes */
if (toupper(node_name[0]) == 'N')
{
*node_objid_ptr = op_id_from_name (*node_objid_ptr, OPC_OBJTYPE_PROC, "rte");
/* insert objid of "rte" module to call_router_list */
op_prg_list_insert (call_router_lptr, node_objid_ptr, OPC_LISTPOS_TAIL);
}
/* mesh nodes */
else if ( (toupper(node_name[0]) == 'M') && (node_condition == OPC_TRUE) )
{
op_prg_list_insert (mesh_nd_enabled_lptr, node_objid_ptr,OPC_LISTPOS_TAIL);
}
/* if not controller node, this node is disabled */
else if (toupper(node_name[0]) != 'C')
{
/* disable this node in the topology and insert it to the disabled nodes' list */
op_rte_topo_node_disable (topo_ptr, subnet_objid, *node_objid_ptr);
op_prg_list_insert (mesh_nd_disabled_lptr, node_objid_ptr,OPC_LISTPOS_TAIL);
}
}
//************************ set link cost and delay *********************************
/* get total number of duplex links */
num_dup_links = op_topo_object_count (OPC_OBJTYPE_LKDUP);
/* insert links to different lists */
for (i = 0; i < num_dup_links; i++)
{
/* allocate memory of each link objid */
link_objid_ptr = (Objid *) op_prg_mem_alloc (sizeof (Objid));
*link_objid_ptr = op_topo_object (OPC_OBJTYPE_LKDUP, i);
/* get the link's condition */
op_ima_obj_attr_get (*link_objid_ptr, "condition", &link_condition);
/* get name of the two nodes connected to this link */
node0_objid = op_topo_assoc (*link_objid_ptr, OPC_TOPO_ASSOC_OUT,OPC_OBJTYPE_NDFIX, 0);
node1_objid = op_topo_assoc (*link_objid_ptr, OPC_TOPO_ASSOC_OUT,OPC_OBJTYPE_NDFIX, 1);
op_ima_obj_attr_get (node0_objid, "name", node0_name);
op_ima_obj_attr_get (node1_objid, "name", node1_name);
op_ima_obj_attr_get (node0_objid, "user id", &userid0);
op_ima_obj_attr_get (node1_objid, "user id", &userid1);
userid0 = userid0-1;
userid1 = userid1-1;
link_ptr = op_rte_topo_link_find (topo_ptr, subnet_objid, node0_objid, subnet_objid, node1_objid, 0);
// op_rte_topo_link_cost_set (link_ptr, Net_top[userid0][userid1]);
op_rte_topo_link_cost_set (link_ptr, 1);
// op_ima_obj_attr_set (*link_objid_ptr, "delay", Net_delay[userid0][userid1]);
op_ima_obj_attr_set (*link_objid_ptr, "delay", LINK_DELAY);
link_ptr = op_rte_topo_link_find (topo_ptr, subnet_objid, node1_objid, subnet_objid, node0_objid, 0);
// op_rte_topo_link_cost_set (link_ptr, Net_top[userid1][userid0]);
op_rte_topo_link_cost_set (link_ptr, 1);
// op_ima_obj_attr_set (*link_objid_ptr, "delay", Net_delay[userid1][userid0]);
op_ima_obj_attr_set (*link_objid_ptr, "delay", LINK_DELAY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -