📄 restoration_rte_bak.pr.c
字号:
}
for(i=0;i<num1;i++)
{
wave = (wave_info *)op_prg_list_access (wave_lptr[userid][next_address][wave_count], i);
list_table[i][0] = wave->start;
list_table[i][1] = wave->dtime;
}
if(num1 == 0) //Original list table is empty
{
op_prg_list_insert (wave_lptr[userid][next_address][wave_count], wave_info_table, OPC_LISTPOS_TAIL);
/*
if ( (op_sim_time() >= s_time) )
{
if(userid == 2 && next_address == 4)
{
printf("\nInsert PK to empty list");
getchar();
}
}
*/
}
else //Original list table is not empty
{
for(i=0;i<num1;i++) //every list table check
{
insert_flag = 1;
if(i==num1-1) //list table tail
{
start_time_1 = list_table[i][0];
dtime_time_1 = list_table[i][1];
if(start_time > dtime_time_1) //insert PK to this list tail
{
op_prg_list_insert (wave_lptr[userid][next_address][wave_count], wave_info_table, OPC_LISTPOS_TAIL);
insert_flag = 0;
/*
if ( (op_sim_time() >= s_time) )
{
if(userid == 2 && next_address == 4)
{
printf("\nInsert PK to TAIL");
getchar();
}
}
*/
}
}
if(i!=num1-1) //list table head and body
{
start_time_1 = list_table[i][0];
dtime_time_1 = list_table[i][1];
start_time_2 = list_table[i+1][0];
dtime_time_2 = list_table[i+1][1];
if( (start_time > dtime_time_1) && (dtime_time < start_time_2) )
{
op_prg_list_insert (wave_lptr[userid][next_address][wave_count], wave_info_table, i+1);
insert_flag = 0;
/*
if ( (op_sim_time() >= s_time) )
{
if(userid == 2 && next_address == 4)
{
printf("\nInsert PK to BODY");
getchar();
}
}
*/
}
}
if(insert_flag == 0) break;
} //for(i=0;i<num2;i++)
} // else
}// if(temp_wave != -1)
else
{
send_check = 1;
}
//******************************** allocate update base on time *********************************************
for(wave_count=0;wave_count<WAVE_NUM;wave_count++)
{
num = op_prg_list_size(wave_lptr[userid][next_address][wave_count]);
for(i=0;i<num;i++)
{
wave = (wave_info *)op_prg_list_access (wave_lptr[userid][next_address][wave_count], i);
list_table[i][0] = wave->start;
list_table[i][1] = wave->dtime;
}
delete_num = 999;
num = op_prg_list_size(wave_lptr[userid][next_address][wave_count]);
for(i=0;i<num;i++)
{
if(cur_time > list_table[i][1])
{
delete_num = i;
}
}
if(delete_num != 999)
{
if(delete_num == 0)
{
wave_free = op_prg_list_remove (wave_lptr[userid][next_address][wave_count], OPC_LISTPOS_HEAD);
op_prg_mem_free(wave_free);
}
else
{
for(i=0;i<=delete_num;i++)
{
wave_free = op_prg_list_remove (wave_lptr[userid][next_address][wave_count], OPC_LISTPOS_HEAD);
op_prg_mem_free(wave_free);
}
}
}
} //for(wave_count=0;wave_count<WAVE_NUM;wave_count++)
//******************************* check 2 ************************************************
/*
if ( (op_sim_time() >= s_time) )
{
if(userid == 2 && next_address == 4)
{
printf("\nnew wave list:\ncurrent = %d\tnext = %d",userid, next_address);
}
}
for(wave_count=0;wave_count<WAVE_NUM;wave_count++)
{
num = op_prg_list_size(wave_lptr[userid][next_address][wave_count]);
if ( (op_sim_time() >= s_time) )
{
if(userid == 2 && next_address == 4)
{
printf("\nwave_index = %d\tlist_size = %d", wave_count, num);
}
}
for(i=0;i<num;i++)
{
wave = (wave_info *)op_prg_list_access (wave_lptr[userid][next_address][wave_count], i);
list_table[i][0] = wave->start;
list_table[i][1] = wave->dtime;
if ( (op_sim_time() >= s_time))
{
if(userid == 2 && next_address == 4)
{
printf("\nlist_index = %d\tnow = %f\tstart = %f\tdtime = %f",
i, cur_time, list_table[i][0], list_table[i][1]);
}
}
}
}//for(wave_count=0;wave_count<WAVE_NUM;wave_count++)
if ( (op_sim_time() >= s_time) )
{
if(userid == 2 && next_address == 4)
{
getchar();
}
}
*/
//***************************** send or destory **************************************
//***************************** send or destory **************************************
if(send_check == 0)
{
if(op_sim_time() >= s_time)
{
op_pk_nfd_get (pkptr, "dtime", &dtime);
op_pk_nfd_get (pkptr, "route_flag", &route_flag);
burst_time[userid][next_address] = burst_time[userid][next_address] + dtime;
if(route_flag==1)
{
back_burst_time = back_burst_time + dtime;
}
}
s_f_flag =0;
}
else
{
if(op_sim_time() >= s_time)
{
fail[source_address][destination_address]++;
op_pk_nfd_get(pkptr, "route_flag", &route_flag);
if(route_flag==1)
{
back_fail++;
}
}
op_pk_destroy(pkptr);
op_prg_mem_free(wave_info_table);
s_f_flag = 1;
}
}
//********************************** need schedule ************************************
}//if(PK_type == 1)
//*************************************** FIS ***********************************************
else if(PK_type == 0)
{
s_f_flag = 1;
topo_ptr = op_rte_topo_from_objids ();
op_pk_nfd_get (pkptr, "FIS_destination", &FIS_destination);
op_pk_nfd_get (pkptr, "FIS_source", &FIS_source);
if(userid == FIS_destination)
{
op_pk_nfd_get (pkptr, "fail_type", &FIS_fail_type);
op_pk_nfd_get (pkptr, "fail_node1", &FIS_NODE1[userid]);
op_pk_nfd_get (pkptr, "fail_node2", &FIS_NODE2[userid]);
//printf("NODE %d GET FIS\tTIME = %f\tTYPE = %d\n",userid,op_sim_time(),FIS_fail_type);
//getchar();
FIS_s_f_flag = 1;
op_pk_destroy(pkptr);
if(FIS_fail_type == 3)
{
FIS_GET[userid] = 1;
FIS_TYPE[userid] = PATH;
for(y=1;y<15;y++)
{
if (userid != y)
{
num_routes[userid][y] = op_rte_routeset_num_routes (rset_ptr[userid][y]);
primary_num_nodes[userid][y] = op_rte_route_num_nodes (min_rptr[userid][y]);
// Get Backup_path
exit_flag = 0;
for(k=0;k<primary_num_nodes[userid][y]-1;k++)
{
if((Primary_path[userid][y][k] == FIS_NODE1[userid] && Primary_path[userid][y][k+1] == FIS_NODE2[userid])
||
(Primary_path[userid][y][k] == FIS_NODE2[userid] && Primary_path[userid][y][k+1] == FIS_NODE1[userid]))
{
change_flag = 1;
}
else
{
change_flag = 0;
}
if(change_flag == 1) break;
}
if(change_flag == 1 )
{
for ( i=1;i<num_routes[userid][y];i++ )
{
comp_flag = 0;
op_rte_route_dump ( op_rte_routeset_route_n (rset_ptr[userid][y], i), subnet_ids, node_ids );
num_nodes = op_rte_route_num_nodes (op_rte_routeset_route_n (rset_ptr[userid][y], i));
for (j=0;j<num_nodes;j++)
{
Backup_path[userid][y][j] = node_ids[j];
}
// compare routine
for(k=1;k<primary_num_nodes[userid][y]-1;k++)
{
for(l=1;l<num_nodes-1;l++)
{
if(Primary_path[userid][y][k] == Backup_path[userid][y][l])
{
comp_flag = 1;
}
if(comp_flag ==1) break;
}
if(comp_flag == 1) break;
}
// Get backup path
if(comp_flag == 0)
{
exit_flag = 1;
//printf("Source = %d\tDetination = %d \n",userid, y);
//op_rte_route_print(min_rptr[userid][y]);
min_rptr[userid][y] = op_rte_route_copy(op_rte_routeset_route_n (rset_ptr[userid][y], i));
//op_rte_route_print(min_rptr[userid][y]);
//getchar();
use_backup_path[userid][y] = 1;
}
if(exit_flag == 1) break;
} // for i
if(comp_flag == 1) min_rptr[userid][y] = OPC_NIL; // no backup path
}//if change_flag
} // if
} // for y
} // if notification
else if(FIS_fail_type == 4) // recover
{
FIS_GET[userid] = 0;
FIS_TYPE[userid] = NORMAL;
for(y=1;y<15;y++)
{
if(userid != y)
{
for(k=0;k<primary_num_nodes[userid][y]-1;k++)
{
if((Primary_path[userid][y][k] == FIS_NODE1[userid] && Primary_path[userid][y][k+1] == FIS_NODE2[userid])
||
(Primary_path[userid][y][k] == FIS_NODE2[userid] && Primary_path[userid][y][k+1] == FIS_NODE1[userid]))
{
change_flag = 1;
}
else
{
change_flag = 0;
}
if(change_flag == 1) break;
}
if(change_flag == 1)
{
min_rptr[userid][y] = op_rte_route_copy(p_min_rptr[userid][y]);
use_backup_path[userid][y] = 0;
}
}
}
}
}
// this node intermediate node therefor FIS Packet continue to send
else if(userid != FIS_destination) // FIS continue to send
{
FIS_s_f_flag = 0;
}
}//if(PK_type == 0)
}
/** state (get_rte) exit executives **/
FSM_STATE_EXIT_FORCED (2, "get_rte", "Restoration_rte_bak () [get_rte exit execs]")
{
}
/** state (get_rte) transition processing **/
FSM_INIT_COND (END_SIM)
FSM_DFLT_COND
FSM_TEST_LOGIC ("get_rte")
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 4, state4_enter_exec, ;, "END_SIM", "", "get_rte", "end")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "default", "", "get_rte", "send")
}
/*---------------------------------------------------------*/
/** state (send) enter executives **/
FSM_STATE_ENTER_FORCED (3, state3_enter_exec, "send", "Restoration_rte_bak () [send enter execs]")
{
if(s_f_flag == 0)
{
op_pk_nfd_get (pkptr, "restoration_flag", &restoration_flag);
if(restoration_flag == SUB)
{
//************************************************* sub ***********************************************************
op_rte_pk_next_node (pkptr, &subnet_objid, &next_node_objid);
op_rte_pk_current_node(pkptr, &subnet_objid, ¤t_node_objid);
op_rte_pk_dst_node (pkptr, &subnet_objid, &dst_node_objid);
op_ima_obj_attr_get (current_node_objid, "user id", &userid_c);
op_ima_obj_attr_get (next_node_objid, "user id", &userid_n);
op_ima_obj_attr_get (dst_node_objid, "user id", &userid_d);
/* advance the routing pointer */
op_rte_pk_advance (pkptr);
/* determine the objid of the next and the link joining it */
link_objid = op_topo_connect (node_objid, next_node_objid,OPC_OBJTYPE_LKDUP, 0);
/* determine the objid of the stream/tx attached to the link */
tx_objid = op_topo_assoc ( link_objid, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_PTTX, 0);
/* for a duplex link, there will be two tx's attached to this link, make sure that the tx that we picked is in the same node */
if (op_topo_parent (tx_objid) != node_objid)
{
tx_objid = op_topo_assoc (link_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_PTTX, 1);
}
/* get the stream id connecting to the transmitter */
strm_objid = op_topo_assoc (tx_objid, OPC_TOPO_ASSOC_IN,OPC_OBJTYPE_STRM, 0);
/* get the stream number */
op_ima_obj_attr_get (strm_objid, "src stream", &strm_num);
op_pk_nfd_get(pkptr, "hop", &hop);
hop++;
op_pk_nfd_set(pkptr, "hop", hop);
op_pk_nfd_set(pkptr, "bef", userid);
op_pk_nfd_get (pkptr, "start", &start_time);
new_start_time = start_time - PROC_TIME - LINK_DELAY;
op_pk_nfd_set (pkptr, "start", new_start_time);
link_send[userid][userid_n]++;
op_pk_send_delayed (pkptr, strm_num, PROC_TIME);
//************************************************* sub ***********************************************************
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -