📄 ramimo_proc_multichannel.pr.c
字号:
r_table[i][0] = -1; //initialise routing table, next node
r_table[i][1] = max_distance; //initialise routing table, next node
r_table[i][2] = min_distance; //initialise routing table, next node
dest_node_id = op_id_from_userid(subnet_id, OPC_OBJTYPE_NDMOB, i);
op_ima_obj_attr_get(dest_node_id, "x position", &dest_xpos);
op_ima_obj_attr_get(dest_node_id, "y position", &dest_ypos);
for(j=0;j<numnodes;j++)
{
//get Objids of other nodes in the system
other_node_id = op_id_from_userid(subnet_id, OPC_OBJTYPE_NDMOB, j);
op_ima_obj_attr_get(other_node_id, "x position", &other_xpos);
op_ima_obj_attr_get(other_node_id, "y position", &other_ypos);
//get distance of other node from source and eventual destination
d_source = sqrt ((other_xpos - xpos)*(other_xpos - xpos) + (other_ypos - ypos)*(other_ypos - ypos));
d_destination = sqrt ((other_xpos - dest_xpos)*(other_xpos - dest_xpos) + (other_ypos - dest_ypos)*(other_ypos - dest_ypos));
//printf("Sour UID %d Int UID %d Dest UID %d d_source = %.2f d_destination %.2f\n", user_id, int_uid, dest_uid, d_source,d_destination);
//determine whether new node should be an intermediate node in the routing table
if ((d_source <= tx_range) && (d_destination <= min_distance))
{
//printf("New Next Node Sour UID %d Int UID %d Dest UID %d d_source = %.2f d_destination %.2f\n", user_id, int_uid, dest_uid, d_source,d_destination);
max_distance = d_source;
min_distance = d_destination;
r_table[i][0] = j;
r_table[i][1] = max_distance;
r_table[i][2] = min_distance;
//printf("Source Node %d\n", user_id);
//printf( "Dest NN SD DD\n");
//printf("%d %d %d %d\n", i,r_table[dest_uid][0],r_table[dest_uid][1],r_table[dest_uid][2]);
}
}
}
#ifdef PRINT_INIT
printf("INIT STATE - EXIT EXECS\n");
printf("Number of Mobile Nodes = %d\n", numnodes);
printf("Obtaining Information On The Receiver Group\n");
op_radio_txch_rxgroup_get(txch_id, &numreceivers, &receivers);
printf("Number of Receivers = %d\n", numreceivers);
for(i=0;i<numreceivers;i++)
{
op_ima_obj_attr_get(op_topo_parent(op_topo_assoc(op_topo_parent(op_topo_parent(receivers[i])), OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_QUEUE, 0)), "user id", &tempint);
printf("Receiver User ID = %d\n", tempint);
}
for(i=0;i<numnodes;i++)
{
printf("Routing Table Information\n");
printf("Source Node %d\n", userid);
printf( "Dest NN SD DD\n");
printf("%d %d %d %d\n", i,r_table[i][0],r_table[i][1],r_table[i][2]);
}
#endif
if(userid == 0)
op_prg_odb_bkpt("TEST");
}
FSM_PROFILE_SECTION_OUT (state0_exit_exec)
/** state (INIT) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "INIT", "WAIT")
/*---------------------------------------------------------*/
/** state (WAIT) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, "WAIT", state1_enter_exec, "ramimo_proc_multichannel [WAIT enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [WAIT enter execs]", state1_enter_exec)
{
}
FSM_PROFILE_SECTION_OUT (state1_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"ramimo_proc_multichannel")
/** state (WAIT) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "WAIT", "ramimo_proc_multichannel [WAIT exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [WAIT exit execs]", state1_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state1_exit_exec)
/** state (WAIT) transition processing **/
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [WAIT trans conditions]", state1_trans_conds)
FSM_INIT_COND (END)
FSM_TEST_COND (SRC_ARVL)
FSM_TEST_COND (CTS)
FSM_TEST_COND (RTS)
FSM_TEST_COND (DATA)
FSM_TEST_COND (ACK)
FSM_TEST_COND (PCS)
FSM_TEST_COND (RX_ARVL)
FSM_TEST_COND (VCS_busy)
FSM_TEST_COND (VCS_free)
FSM_TEST_COND (ROB)
FSM_TEST_COND (TX_TIMEOUT)
FSM_TEST_COND (RX_TIMEOUT)
FSM_TEST_LOGIC ("WAIT")
FSM_PROFILE_SECTION_OUT (state1_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "END", "", "WAIT", "END")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "SRC_ARVL", "", "WAIT", "SRCARVL")
FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "CTS", "", "WAIT", "TX")
FSM_CASE_TRANSIT (3, 4, state4_enter_exec, ;, "RTS", "", "WAIT", "TX")
FSM_CASE_TRANSIT (4, 4, state4_enter_exec, ;, "DATA", "", "WAIT", "TX")
FSM_CASE_TRANSIT (5, 4, state4_enter_exec, ;, "ACK", "", "WAIT", "TX")
FSM_CASE_TRANSIT (6, 5, state5_enter_exec, ;, "PCS", "", "WAIT", "SENSE")
FSM_CASE_TRANSIT (7, 6, state6_enter_exec, ;, "RX_ARVL", "", "WAIT", "RXARVL")
FSM_CASE_TRANSIT (8, 5, state5_enter_exec, ;, "VCS_busy", "", "WAIT", "SENSE")
FSM_CASE_TRANSIT (9, 5, state5_enter_exec, ;, "VCS_free", "", "WAIT", "SENSE")
FSM_CASE_TRANSIT (10, 7, state7_enter_exec, ;, "ROB", "", "WAIT", "ROB")
FSM_CASE_TRANSIT (11, 8, state8_enter_exec, ;, "TX_TIMEOUT", "", "WAIT", "TIMEOUT")
FSM_CASE_TRANSIT (12, 8, state8_enter_exec, ;, "RX_TIMEOUT", "", "WAIT", "TIMEOUT")
}
/*---------------------------------------------------------*/
/** state (END) enter executives **/
FSM_STATE_ENTER_UNFORCED (2, "END", state2_enter_exec, "ramimo_proc_multichannel [END enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [END enter execs]", state2_enter_exec)
{
/*Only want one node to write out these statistics*/
if(userid == 0)
{
/*Write out the scalar statistics*/
op_stat_scalar_write("USER_LOAD", userload);
op_stat_scalar_write("NUMGENPKTS", numgenpkts);
op_stat_scalar_write("NUMDISCPKTS", numdiscpkts);
op_stat_scalar_write("NUMRXPKTS", numrxpkts);
//for(i=0;i<numnodes;i++)
//{
// for(j=0;j<numnodes;j++)
//{
// printf("Number of Packets Generated at Node %d for Node %d = %d\n", i, j, pktar[i][j]);
//printf("Number of Packets Discarded at Node %d for Node %d = %d\n", i, j, pktdi[i][j]);
//printf("Number of Packets Queued at Node %d for Node %d = %d\n", i, j, pktqu[i][j]);
//printf("Number of Packets Received at Node %d from Node %d = %d\n\n", j, i, pktrx[i][j]);
// }
op_prg_odb_bkpt("END");
//}
}
}
FSM_PROFILE_SECTION_OUT (state2_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (5,"ramimo_proc_multichannel")
/** state (END) exit executives **/
FSM_STATE_EXIT_UNFORCED (2, "END", "ramimo_proc_multichannel [END exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [END exit execs]", state2_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state2_exit_exec)
/** state (END) transition processing **/
FSM_TRANSIT_MISSING ("END")
/*---------------------------------------------------------*/
/** state (SRCARVL) enter executives **/
FSM_STATE_ENTER_FORCED (3, "SRCARVL", state3_enter_exec, "ramimo_proc_multichannel [SRCARVL enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [SRCARVL enter execs]", state3_enter_exec)
{
/**********************************************************************************/
/*Queue the packet from the traffic generator ready for transmission */
/*Schedule an RTS transmission interrupt to start the transmission process if the */
/*channel is free and the node is not currently processing anything */
/**********************************************************************************/
/*Get the packet from the incoming stream*/
pktptr = op_pk_get(op_intrpt_strm());
/*Calculate and store the next and previous (current) hop for this packet*/
op_pk_nfd_get(pktptr, "SRC", &srcid);
op_pk_nfd_get(pktptr, "DEST", &destid);
op_pk_nfd_set(pktptr, "nexthop", r_table[destid][0]);
op_pk_nfd_set(pktptr, "prevhop", userid);
op_pk_nfd_get(pktptr, "number", &seqnum);
/*Increment the number of generated packets*/
numgenpkts++;
/*Increment a variable to count the number of packet arrivals destined for specific nodes*/
pktar[srcid][destid]++;
pktqu[srcid][destid]++;
#ifdef PRINT_SRC_ARVL
printf("SRCARVL STATE\n");
printf("Node %d\n", userid);
printf("Packet Source = %d\n", srcid);
printf("Packet Destination = %d\n", destid);
printf("Packet Next Hop = %d\n", r_table[destid][0]);
printf("Packet Prev Hop = %d\n", srcid);
printf("Packet Sequence Number = %lf\n", seqnum);
printf("Packet Inserted Into SRC Queue\n");
#endif
/*Schedule an RTS transmission if the channel is free and the node is not busy*/
if( (pcs_state == 0) && (vcs_state == 0) && (busy == 0) )
{
/*Set the destination node ID to be associated with the tx interrupt*/
op_pk_nfd_get(pktptr, "nexthop", &commnodeid);
op_pk_nfd_get(pktptr, "number", &sequencenum);
/*Schedule RTS Interrupt in DIFS seconds time*/
nexttxevent = op_intrpt_schedule_self(op_sim_time() + difs, RTS_INT);
txreq = 1;
txstate = RTS_INT;
busy = 1;
/*Reset the random backoff interval if this is a new transmission*/
rob = -1.0;
#ifdef PRINT_SRC_ARVL
printf("Scheduled an RTS transmission interrupt in DIFS seconds!\n");
printf("Will be communicating with node %d\n", commnodeid);
printf("Packet Sequence Number = %lf\n", sequencenum);
#endif
}
/*Place it in the queue ready for transmission*/
op_subq_pk_insert(SRC_QUEUE, pktptr, OPC_QPOS_TAIL);
op_prg_odb_bkpt("SRCARVL");
//op_prg_odb_bkpt("TEST");
}
FSM_PROFILE_SECTION_OUT (state3_enter_exec)
/** state (SRCARVL) exit executives **/
FSM_STATE_EXIT_FORCED (3, "SRCARVL", "ramimo_proc_multichannel [SRCARVL exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [SRCARVL exit execs]", state3_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state3_exit_exec)
/** state (SRCARVL) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "SRCARVL", "WAIT")
/*---------------------------------------------------------*/
/** state (TX) enter executives **/
FSM_STATE_ENTER_FORCED (4, "TX", state4_enter_exec, "ramimo_proc_multichannel [TX enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [TX enter execs]", state4_enter_exec)
{
#ifdef PRINT_TX
printf("TX STATE\n");
printf("Node %d\n", userid);
#endif
/*If transmission of an RTS packet*/
if(RTS)
{
/*Create an RTS packet*/
pktptr = op_pk_create_fmt("RTS_pkt");
/*set the appropriate size of the packet - An RTS packet is 20 bytes*/
op_pk_total_size_set(pktptr, rtspktsize);
/*Determine the location of the destination node*/
other_node_id = op_id_from_userid(subnet_id, OPC_OBJTYPE_NDMOB, commnodeid);
op_ima_obj_attr_get(other_node_id, "x position", &other_xpos);
op_ima_obj_attr_get(other_node_id, "y position", &other_ypos);
/*Work out the distance between nodes*/
distance = sqrt((other_xpos - xpos)*(other_xpos - xpos) + (other_ypos - ypos)*(other_ypos - ypos));
/*Work out the propagation delay between the source to destination node*/
propdelay = distance/300000000.0;
/*Schedule an interrupt for timeout if a CTS packet is not received*/
tempdouble = 1.1 * ((rtspktsize/datarate) + (2.0*propdelay) + (ctspktsize/datarate) + sifs);
timeout = op_intrpt_schedule_self(op_sim_time() + tempdouble, TX_TIMEOUT_INT);
/*Determine the expected duration of the subsequent exchange of data*/
/*This is the sum of the packet durations, three SIFS and 4 propdelays*/
tempdouble = ((rtspktsize+ctspktsize+datapktsize+ackpktsize)/datarate) + (3.0*sifs) + (4.0*propdelay);
/*Set the fields of the RTS packet*/
op_pk_nfd_set(pktptr, "SRC", userid);
op_pk_nfd_set(pktptr, "DEST", commnodeid);
op_pk_nfd_set(pktptr, "DURATION", tempdouble);
op_pk_nfd_set(pktptr, "number", sequencenum);
//printf("NODE ID = %d\n", userid);
//printf("Transmitting an RTS Packet at %lf time\n", op_sim_time());
//op_prg_odb_bkpt("WIN");
#ifdef PRINT_TX
printf("Transmitting an RTS Packet\n");
printf("Packet Size = %d\n", op_pk_total_size_get(pktptr));
op_pk_nfd_get(pktptr, "SRC", &srcid);
printf("Packet Source = %d\n", srcid);
op_pk_nfd_get(pktptr, "DEST", &destid);
printf("Packet Destination = %d\n", destid);
printf("Distance Between Nodes = %lf\n", distance);
printf("Propagation Delay Between Nodes = %1.10lf\n", propdelay);
op_pk_nfd_get(pktptr, "DURATION", &tempdouble);
printf("Packet Duration Field = %lf\n", tempdouble);
op_pk_nfd_get(pktptr, "number", &tempdouble);
printf("Packet Sequence Number = %lf\n", tempdouble);
printf("Scheduled an RTS Timeout Interrupt for %lfs\n", op_ev_time(timeout));
printf("A transfer is commencing!\n");
#endif
}
/*If transmission of a CTS packet*/
else if(CTS)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -