📄 restoration_fail.pr.c
字号:
/* Process model C form file: Restoration_fail.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_fail_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 40E38A27 40E38A27 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 "route.h"
#define INTRPT_FIS 5
#define MAX_HOPS 15
#define SEND_TO_RTE 0
#define BEG_SIM (op_intrpt_type () == OPC_INTRPT_BEGSIM)
#define F_R ((op_intrpt_type() == OPC_INTRPT_REMOTE) && (op_intrpt_code() == INTRPT_FIS))
/* 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 self_objid;
Objid node_objid;
Objid subnet_objid;
Route* current_rptr;
Objid subnet_id;
Objid next_node_id;
int rev_pk_count;
Stathandle rev_pk_cnt_stathandle;
} Restoration_fail_state;
#define pr_state_ptr ((Restoration_fail_state*) SimI_Mod_State_Ptr)
#define self_objid pr_state_ptr->self_objid
#define node_objid pr_state_ptr->node_objid
#define subnet_objid pr_state_ptr->subnet_objid
#define current_rptr pr_state_ptr->current_rptr
#define subnet_id pr_state_ptr->subnet_id
#define next_node_id pr_state_ptr->next_node_id
#define rev_pk_count pr_state_ptr->rev_pk_count
#define rev_pk_cnt_stathandle pr_state_ptr->rev_pk_cnt_stathandle
/* 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_fail_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_fail (void);
Compcode Restoration_fail_init (void **);
void Restoration_fail_diag (void);
void Restoration_fail_terminate (void);
void Restoration_fail_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
Restoration_fail (void)
{
int _block_origin = 0;
FIN (Restoration_fail ());
if (1)
{
Objid dest_objid;
Objid src_objid;
Objid FIS_dest_objid;
Objid FIS_src_objid;
Objid src_node_objid;
Objid dst_node_objid;
Objid current_node_objid;
Objid next_node_objid;
Objid link_objid;
Objid tx_objid;
Objid strm_objid;
int destination_address;
int source_address;
int fail_name;
int strm_num;
int userid;
int flag,ppp;
int PK_type;
Packet* FIS_pkptr;
Packet* r_FIS_pkptr;
Packet* ack_pkptr;
Route* FIS_min_rptr_copy;
Route* FIS_current_rptr;
Route* FIS_rptr;
double link_cost;
Route* pk_rptr;
Route* pk_r;
Route* route_ptr;
Route_Link* link_ptr;
Route* min_rptr_copy;
Route* route_test;
Route_Set* FIS_rset_ptr_t;
Route* FIS_min_rptr_t;
char node_name[255];
char id[20];
Objid* node_objid_ptr;
int i, num_nodes;
int subnet_ids[10], node_ids[10];
double cur_time;
Packet* cp_pkptr;
int next_address;
double start_time, dtime_time;
double start_time_1, dtime_time_1;
double start_time_2, dtime_time_2;
int s_f, s_f_flag, num,FIS_s_f_flag;
int j,k;
int check_num, num1, num2,num3,num4;
double list_table[100][2];
int delete_num;
int FIS_change_type;
int FIS_node_link;
int FIS_destination;
int FIS_source[17][17];
int x,y;
int PK_source[17][17];
int upstream_check;
int status_flag;
int l;
int num_routes[17][17];
int exit_flag;
int comp_flag;
int diff1, diff2;
int change_flag;
double back_average_delay;
double back_average_hop;
double back_throughput;
double back_loss;
double back_utilization;
FSM_ENTER (Restoration_fail)
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "Restoration_fail () [init enter execs]")
{
}
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "Restoration_fail () [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", "Restoration_fail () [wait enter execs]")
{
}
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,Restoration_fail)
/** state (wait) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "wait", "Restoration_fail () [wait exit execs]")
{
}
/** state (wait) transition processing **/
FSM_INIT_COND (F_R)
FSM_DFLT_COND
FSM_TEST_LOGIC ("wait")
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "F_R", "", "wait", "FAIL_DETECT")
FSM_CASE_TRANSIT (1, 1, state1_enter_exec, ;, "default", "", "wait", "wait")
}
/*---------------------------------------------------------*/
/** state (FAIL_DETECT) enter executives **/
FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "FAIL_DETECT", "Restoration_fail () [FAIL_DETECT enter execs]")
{
self_objid = op_id_self ();
node_objid = op_topo_parent (self_objid);
subnet_objid = op_topo_parent (node_objid);
op_ima_obj_attr_get(node_objid, "user id", &userid);
topo_ptr = op_rte_topo_from_objids ();
diff1 = 0;
diff2 = 0;
//printf("%d GET intrupt\nTime = %f\tTYPE = %d\n",userid,op_sim_time(),notification_message->restoration_type);
//getchar();
/*
if(notification_message->fail_link_node1 == userid && notification_message->fail_type == 3)
{
back_average_delay = (double) back_sum_delay/back_succ;
back_average_hop = (double) back_sum_hop/back_succ;
back_throughput = (double) back_succ/gen_backup_bcp;
back_loss = (double) (back_fail+back_fis_fail)/(gen_backup_bcp+back_fis_fail);
back_utilization = (double) back_burst_time/(back_average_hop*8*3);
printf("back_average_delay = %f\n", back_average_delay);
printf("back_average_hop = %f\n", back_average_hop);
printf("back_succ = %d\n", back_succ);
printf("back_fail = %d\n", back_fail);
printf("back_fis_fail = %d\n", back_fis_fail);
printf("gen_backup_bcp = %d\n", gen_backup_bcp);
printf("back_throughput = %f\n", back_throughput);
printf("back_loss = %f\n", back_loss);
printf("back_burst_time = %f\n", back_burst_time);
printf("back_utilization = %f\n", back_utilization);
getchar();
}
*/
//************************************************* path *****************************************************
if(notification_message->restoration_type == PATH)
{
status_flag = 0;
for( x=1; x<15; x++)
{
for(y=1; y<15; y++)
{
status_flag = 0;
if ( x != y ) //PK source and destination is not same.
{
for ( k = 0; k < primary_num_nodes[x][y]-1; k++)
{
if(
(
(Primary_path[x][y][k] == notification_message->fail_link_node1 && Primary_path[x][y][k+1] == notification_message->fail_link_node2) &&
(userid == notification_message->fail_link_node1)
)
||
(
(Primary_path[x][y][k] == notification_message->fail_link_node2 && Primary_path[x][y][k+1] == notification_message->fail_link_node1) &&
(userid == notification_message->fail_link_node2)
)
)
{
//printf("x = %d y = %d k = %d node1 = %d node2 = %d, userid = %d \n", x,y,k,notification_message->fail_link_node1,notification_message->fail_link_node2,userid);
//printf("Primary_path[x][y][k] = %d Primary_path[x][y][k+1] =%d \n",Primary_path[x][y][k],Primary_path[x][y][k+1]);
status_flag = 1; //this condition exit flag
PK_source[x][y] = x; //FIS destination
FIS_source[x][y] = userid; //FIS source
FIS_pkptr = op_pk_create_fmt ("RES_FIS");
if(notification_message->fail_type == 3 || notification_message->fail_type == 4)
{
op_pk_nfd_set (FIS_pkptr, "node_link", 0); //link
}
else
{
op_pk_nfd_set (FIS_pkptr, "node_link", 1); //node
}
op_pk_nfd_set (FIS_pkptr, "FIS_destination", PK_source[x][y]);
op_pk_nfd_set (FIS_pkptr, "FIS_source", FIS_source[x][y]);
op_pk_nfd_set (FIS_pkptr, "fail_node1", notification_message->fail_link_node1);
op_pk_nfd_set (FIS_pkptr, "fail_node2", notification_message->fail_link_node2);
op_pk_nfd_set (FIS_pkptr, "fail_type", notification_message->fail_type);
//op_pk_print(FIS_pkptr);
//getchar();
if(PK_source[x][y] != FIS_source[x][y])
{
FIS_min_rptr_t = op_rte_routeset_mincost (rset_ptr[FIS_source[x][y]][PK_source[x][y]]);
FIS_min_rptr_copy = op_rte_route_copy (FIS_min_rptr_t);
if (FIS_min_rptr_copy == OPC_NIL)
{
op_pk_destroy (FIS_pkptr);
}
else
{
//insert the route into the packet
FIS_rptr = op_rte_route_copy (FIS_min_rptr_copy);
op_rte_pk_route_insert (FIS_pkptr, FIS_rptr);
}
//op_pk_print(FIS_pkptr);
if(notification_message->upstream_check[PK_source[x][y]] == 0)
{
op_pk_send(FIS_pkptr, SEND_TO_RTE);
notification_message->upstream_check[PK_source[x][y]] = 1;
//printf("send\n");
}
else
{
//printf("not send\n");
op_pk_destroy (FIS_pkptr);
}
} //if(PK_source[x][y] != FIS_source[x][y])
else if(PK_source[x][y] == FIS_source[x][y])
{
//op_pk_print(FIS_pkptr);
if(notification_message->upstream_check[PK_source[x][y]] == 0)
{
op_pk_send(FIS_pkptr, SEND_TO_RTE);
notification_message->upstream_check[PK_source[x][y]] = 1;
//printf("send\n");
//printf("Source = %d\tDestination = %d\n",FIS_source[x][y],PK_source[x][y]);
}
else
{
//printf("not send\n");
//printf("Source = %d\tDestination = %d\n",FIS_source[x][y],PK_source[x][y]);
op_pk_destroy (FIS_pkptr);
}
} //else if(PK_source[x][y] == FIS_source[x][y])
}//This node is not upstream node, so don't created FIS, retrun wait state
if (status_flag == 1) break;
} //for ( k = 1; k < primary_num_nodes[x][y]; k++)
}//if ( x != y )
} //for
}// for
if(notification_message->fail_type == 3)
{
num1 = notification_message->fail_link_node1;
num2 = notification_message->fail_link_node2;
if(userid == num1)
{
diff1 = link_send[num1][num2] - link_receive[num2][num1];
fis_fail[num1][num2] = fis_fail[num1][num2] + diff1;
back_fis_fail = back_fis_fail + diff1;
for (i=0;i<WAVE_NUM;i++)
{
fault_link[num1][num2] = fault_link[num1][num2] + op_prg_list_size(wave_lptr[num1][num2][i]);
printf("%d = %d \n", i, op_prg_list_size(wave_lptr[num1][num2][i]));
}
}
else if(userid == num2)
{
diff2 = link_send[num2][num1] - link_receive[num1][num2];
fis_fail[num2][num1] = fis_fail[num2][num1] + diff2;
back_fis_fail = back_fis_fail + diff2;
for (i=0;i<WAVE_NUM;i++)
{
fault_link[num2][num1] = fault_link[num2][num1] + op_prg_list_size(wave_lptr[num2][num1][i]);
printf("%d = %d \n", i, op_prg_list_size(wave_lptr[num2][num1][i]));
}
}
printf("fault_link = %d %d %d\n", fault_link[num1][num2],fault_link[num2][num1],fault_link[num1][num2]+fault_link[num2][num1]);
getchar();
}
}
//************************************************* Sub *****************************************************
if(notification_message->restoration_type == SUB)
{
//this node is upstream node or downstream node
if((userid == notification_message->fail_link_node1) || (userid == notification_message->fail_link_node2))
{
if(notification_message->fail_type == 3) //fail case
{
for(y=1;y<15;y++)
{
if (userid != y)
{
//Get primary_path
num_routes[userid][y] = op_rte_routeset_num_routes (rset_ptr[userid][y]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -