📄 dr_cntrl_lchild.pr.c
字号:
/* Process model C form file: dr_cntrl_lchild.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 dr_cntrl_lchild_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A op_runsim 7 3CF1ECAE 3CF1ECAE 1 notebook lhj 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 */
#define FAIL_LINK 0
#define RECOVER_LINK 1
#define FAIL (op_intrpt_code () == FAIL_LINK)
#define UP (op_intrpt_code () == RECOVER_LINK)
extern Topology* topo_ptr;
extern Anvid vid;
extern int debug_sw;
/* 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 */
Objid* link_objid_ptr;
Objid subnet_objid;
Evhandle recover_evh;
Prohandle my_proh;
Distribution* link_mtbf_dist;
Distribution* link_mttr_dist;
char link_name[128];
Route_Link* link0_ptr;
Route_Link* link1_ptr;
int reentry;
} dr_cntrl_lchild_state;
#define pr_state_ptr ((dr_cntrl_lchild_state*) SimI_Mod_State_Ptr)
#define link_objid_ptr pr_state_ptr->link_objid_ptr
#define subnet_objid pr_state_ptr->subnet_objid
#define recover_evh pr_state_ptr->recover_evh
#define my_proh pr_state_ptr->my_proh
#define link_mtbf_dist pr_state_ptr->link_mtbf_dist
#define link_mttr_dist pr_state_ptr->link_mttr_dist
#define link_name pr_state_ptr->link_name
#define link0_ptr pr_state_ptr->link0_ptr
#define link1_ptr pr_state_ptr->link1_ptr
#define reentry pr_state_ptr->reentry
/* 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 dr_cntrl_lchild_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 dr_cntrl_lchild (void);
Compcode dr_cntrl_lchild_init (void **);
void dr_cntrl_lchild_diag (void);
void dr_cntrl_lchild_terminate (void);
void dr_cntrl_lchild_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
dr_cntrl_lchild (void)
{
int _block_origin = 0;
FIN (dr_cntrl_lchild ());
if (1)
{
int condition;
double link_mtbf;
double link_mttr;
Objid self_objid;
Objid node0_objid;
Objid node1_objid;
FSM_ENTER (dr_cntrl_lchild)
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "dr_cntrl_lchild () [init enter execs]")
{
/* get condition of the current object */
link_objid_ptr = (Objid*) op_pro_argmem_access ();
subnet_objid = op25_topo_parent (*link_objid_ptr);
/* find the link in the topology */
node0_objid = op_topo_assoc (*link_objid_ptr, OPC_TOPO_ASSOC_IN,
OPC_OBJTYPE_NDFIX, 0);
node1_objid = op_topo_assoc (*link_objid_ptr, OPC_TOPO_ASSOC_IN,
OPC_OBJTYPE_NDFIX, 1);
link1_ptr = op_rte_topo_link_find (topo_ptr, subnet_objid, node1_objid,
subnet_objid, node0_objid, 0);
link0_ptr = op_rte_topo_link_find (topo_ptr, subnet_objid, node0_objid,
subnet_objid, node1_objid, 0);
/* get condition of the link */
op_ima_obj_attr_get (*link_objid_ptr, "condition", &condition);
op_ima_obj_attr_get (*link_objid_ptr, "name", link_name);
/* set up failure/recovery mean period */
self_objid = op_id_self ();
op_ima_obj_attr_get (self_objid, "LINK MTBF", &link_mtbf);
op_ima_obj_attr_get (self_objid, "LINK MTTR", &link_mttr);
/* initialize the distributions */
link_mtbf_dist = op_dist_load ("exponential", link_mtbf, 0.0);
link_mttr_dist = op_dist_load ("exponential", link_mttr, 0.0);
/* get process handle */
my_proh = op_pro_self ();
/* if the link is enabled now */
if (condition)
{
/* schedule the next fail action */
op_intrpt_schedule_process (my_proh, op_sim_time () + op_dist_outcome (link_mtbf_dist), FAIL_LINK);
}
reentry = 1;
}
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "dr_cntrl_lchild () [init exit execs]")
{
}
/** state (init) transition processing **/
FSM_INIT_COND (condition == OPC_FALSE)
FSM_TEST_COND (condition = OPC_TRUE)
FSM_TEST_LOGIC ("init")
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "condition == OPC_FALSE", "", "init", "fail")
FSM_CASE_TRANSIT (1, 2, state2_enter_exec, ;, "condition = OPC_TRUE", "", "init", "up")
}
/*---------------------------------------------------------*/
/** state (fail) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "fail", "dr_cntrl_lchild () [fail enter execs]")
{
/* cancel the recover event for the previous fail action */
if (op_ev_valid (recover_evh))
{
op_ev_cancel (recover_evh);
}
if (!reentry)
{
/* disable the link */
op_ima_obj_attr_set (*link_objid_ptr, "condition", OPC_FALSE);
op_rte_topo_link_disable (link0_ptr);
op_rte_topo_link_disable (link1_ptr);
/* update the link in the animation window */
op_anim_ime_nobj_update (vid, OPC_ANIM_OBJTYPE_DUPLINK, link_name,
OPC_ANIM_OBJ_ATTR_COLOR, OPC_ANIM_COLOR_RED, OPC_EOL);
/* if debug switch is on */
if (debug_sw)
{
printf ("\t\t\tFailed link name = %s at time %lf\n", link_name,
op_sim_time ());
}
}
/* schedule a recover action */
recover_evh = op_intrpt_schedule_process (my_proh, op_sim_time () + op_dist_outcome (link_mttr_dist), RECOVER_LINK);
/* schedule the next fail action */
op_intrpt_schedule_process (my_proh, op_sim_time () + op_dist_outcome (link_mtbf_dist), FAIL_LINK);
}
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,dr_cntrl_lchild)
/** state (fail) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "fail", "dr_cntrl_lchild () [fail exit execs]")
{
}
/** state (fail) transition processing **/
FSM_INIT_COND (UP)
FSM_TEST_COND (FAIL)
FSM_TEST_LOGIC ("fail")
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, reentry = 0;;, "UP", "reentry = 0;", "fail", "up")
FSM_CASE_TRANSIT (1, 1, state1_enter_exec, reentry = 1;;, "FAIL", "reentry = 1;", "fail", "fail")
}
/*---------------------------------------------------------*/
/** state (up) enter executives **/
FSM_STATE_ENTER_UNFORCED (2, state2_enter_exec, "up", "dr_cntrl_lchild () [up enter execs]")
{
if (!reentry)
{
/* enable the link */
op_ima_obj_attr_set (*link_objid_ptr, "condition", OPC_TRUE);
op_rte_topo_link_enable (link0_ptr);
op_rte_topo_link_enable (link1_ptr);
/* update the link in the animation window */
op_anim_ime_nobj_update (vid, OPC_ANIM_OBJTYPE_DUPLINK, link_name,
OPC_ANIM_OBJ_ATTR_COLOR, OPC_ANIM_COLOR_WHITE, OPC_EOL);
/* if debug switch is on */
if (debug_sw)
{
printf ("\t\t\tEnabled link name = %s at time %lf\n", link_name,
op_sim_time ());
}
}
}
/** blocking after enter executives of unforced state. **/
FSM_EXIT (5,dr_cntrl_lchild)
/** state (up) exit executives **/
FSM_STATE_EXIT_UNFORCED (2, "up", "dr_cntrl_lchild () [up exit execs]")
{
}
/** state (up) transition processing **/
FSM_TRANSIT_ONLY ((FAIL), 1, state1_enter_exec, reentry = 0;;, "up", "FAIL", "reentry = 0;", "up", "fail")
/*---------------------------------------------------------*/
}
FSM_EXIT (0,dr_cntrl_lchild)
}
}
#if defined (__cplusplus)
extern "C" {
#endif
extern VosT_Fun_Status Vos_Catmem_Register (const char * , int , VosT_Void_Null_Proc, VosT_Address *);
extern VosT_Address Vos_Catmem_Alloc (VosT_Address, size_t);
extern VosT_Fun_Status Vos_Catmem_Dealloc (VosT_Address);
#if defined (__cplusplus)
}
#endif
Compcode
dr_cntrl_lchild_init (void ** gen_state_pptr)
{
int _block_origin = 0;
static VosT_Address obtype = OPC_NIL;
FIN (dr_cntrl_lchild_init (gen_state_pptr))
if (obtype == OPC_NIL)
{
/* Initialize memory management */
if (Vos_Catmem_Register ("proc state vars (dr_cntrl_lchild)",
sizeof (dr_cntrl_lchild_state), Vos_Vnop, &obtype) == VOSC_FAILURE)
{
FRET (OPC_COMPCODE_FAILURE)
}
}
*gen_state_pptr = Vos_Catmem_Alloc (obtype, 1);
if (*gen_state_pptr == OPC_NIL)
{
FRET (OPC_COMPCODE_FAILURE)
}
else
{
/* Initialize FSM handling */
((dr_cntrl_lchild_state *)(*gen_state_pptr))->current_block = 0;
FRET (OPC_COMPCODE_SUCCESS)
}
}
void
dr_cntrl_lchild_diag (void)
{
/* No Diagnostic Block */
}
void
dr_cntrl_lchild_terminate (void)
{
int _block_origin = __LINE__;
FIN (dr_cntrl_lchild_terminate (void))
if (1)
{
int condition;
double link_mtbf;
double link_mttr;
Objid self_objid;
Objid node0_objid;
Objid node1_objid;
/* No Termination Block */
}
Vos_Catmem_Dealloc (pr_state_ptr);
FOUT;
}
/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in dr_cntrl_lchild_svar function. */
#undef link_objid_ptr
#undef subnet_objid
#undef recover_evh
#undef my_proh
#undef link_mtbf_dist
#undef link_mttr_dist
#undef link_name
#undef link0_ptr
#undef link1_ptr
#undef reentry
void
dr_cntrl_lchild_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
{
dr_cntrl_lchild_state *prs_ptr;
FIN (dr_cntrl_lchild_svar (gen_ptr, var_name, var_p_ptr))
if (var_name == OPC_NIL)
{
*var_p_ptr = (char *)OPC_NIL;
FOUT;
}
prs_ptr = (dr_cntrl_lchild_state *)gen_ptr;
if (strcmp ("link_objid_ptr" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->link_objid_ptr);
FOUT;
}
if (strcmp ("subnet_objid" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->subnet_objid);
FOUT;
}
if (strcmp ("recover_evh" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->recover_evh);
FOUT;
}
if (strcmp ("my_proh" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->my_proh);
FOUT;
}
if (strcmp ("link_mtbf_dist" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->link_mtbf_dist);
FOUT;
}
if (strcmp ("link_mttr_dist" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->link_mttr_dist);
FOUT;
}
if (strcmp ("link_name" , var_name) == 0)
{
*var_p_ptr = (char *) (prs_ptr->link_name);
FOUT;
}
if (strcmp ("link0_ptr" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->link0_ptr);
FOUT;
}
if (strcmp ("link1_ptr" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->link1_ptr);
FOUT;
}
if (strcmp ("reentry" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->reentry);
FOUT;
}
*var_p_ptr = (char *)OPC_NIL;
FOUT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -