📄 ramimo_proc_chi.pr.c
字号:
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, ;, "PKT_ARVL", "", "WAIT", "PKTARVL")
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_chi [END enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [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_chi")
/** state (END) exit executives **/
FSM_STATE_EXIT_UNFORCED (2, "END", "ramimo_proc_chi [END exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [END exit execs]", state2_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state2_exit_exec)
/** state (END) transition processing **/
FSM_TRANSIT_MISSING ("END")
/*---------------------------------------------------------*/
/** state (PKTARVL) enter executives **/
FSM_STATE_ENTER_FORCED (3, "PKTARVL", state3_enter_exec, "ramimo_proc_chi [PKTARVL enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [PKTARVL enter execs]", state3_enter_exec)
{
#ifdef PRINT_SRC_ARVL
printf("CHILD PROC\n");
printf("Attempting to schedule an RTS transmission\n");
printf("Channel busy status = %d\n", busy);
printf("Channel PCS State = %d\n", pcs_state);
printf("Channel VCS State = %d\n", vcs_state);
#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) )
{
/*Initilise a flag variable*/
flag = 0;
/*Search through the packet queue to identify an appropriate one to transmit*/
for(i=0;i<op_subq_stat(SRC_QUEUE, OPC_QSTAT_PKSIZE);i++)
{
/*Access the packet at the appropriate position*/
pktptr = op_subq_pk_access(SRC_QUEUE, i);
/*Determine the ID of the corresponding source node*/
op_pk_nfd_get(pktptr, "SRC", &srcid);
#ifdef PRINT_SRC_ARVL
printf("CHILD PROC\n");
printf("Packet SRC ID = %d\n", srcid);
printf("Parent TX SRC ID = %d\n", sharedptr->partxsrcid);
#endif
/*If a packet is found from a different source than the one being handled by the other channel, schedule an RTS for it*/
if((srcid != sharedptr->partxsrcid) && (flag == 0))
{
flag = 1;
/*Set the variable to indicate the ID of the source*/
sharedptr->chitxsrcid = srcid;
/*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("CHILD PROC\n");
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
}
}
}
op_prg_odb_bkpt("SRCARVL");
}
FSM_PROFILE_SECTION_OUT (state3_enter_exec)
/** state (PKTARVL) exit executives **/
FSM_STATE_EXIT_FORCED (3, "PKTARVL", "ramimo_proc_chi [PKTARVL exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [PKTARVL exit execs]", state3_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state3_exit_exec)
/** state (PKTARVL) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "PKTARVL", "WAIT")
/*---------------------------------------------------------*/
/** state (TX) enter executives **/
FSM_STATE_ENTER_FORCED (4, "TX", state4_enter_exec, "ramimo_proc_chi [TX enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [TX enter execs]", state4_enter_exec)
{
#ifdef PRINT_TX
printf("CHILD PROC\n");
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("CHILD PROC\n");
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)
{
/*Create an CTS packet*/
pktptr = op_pk_create_fmt("CTS_pkt");
/*set the appropriate size of the packet - A CTS packet is 14 bytes*/
op_pk_total_size_set(pktptr, ctspktsize);
/*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;
/*Determine the expected duration of the subsequent exchange of data*/
/*This is the sum of the packet durations less RTS, two SIFS and 3 propdelays*/
tempdouble = ((ctspktsize+datapktsize+ackpktsize)/datarate) + (2.0*sifs) + (3.0*propdelay);
/*Set the fields of the CTS 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);
#ifdef PRINT_TX
printf("CHILD PROC\n");
printf("Transmitting a CTS 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);
#endif
}
/*If transmission of a DATA packet*/
else if(DATA)
{
/*Access the relevant packet in the subqueue*/
i = 0;
do
{
/*Access the packet at the new position*/
origpktptr = op_subq_pk_access(SRC_QUEUE, i);
/*Determine the ID of the corresponding source node*/
op_pk_nfd_get(origpktptr, "SRC", &srcid);
/*Increment the index variable*/
i++;
} while(srcid != sharedptr->chitxsrcid);
/*Create a copy of the packet for transmission*/
pktptr = op_pk_copy(origpktptr);
/*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 * ((datapktsize/datarate) + (2.0*propdelay) + (ackpktsize/datarate) + sifs);
timeout = op_intrpt_schedule_self(op_sim_time() + tempdouble, TX_TIMEOUT_INT);
/*Record statistics if from node 0 to 3*/
/*BOTH THESE STATISTICS ARE CONTRIVED FOR SPECIFIC SCENARIO*/
if( (userid == 0) && (commnodeid == 9) )
op_stat_write_t(txstat, 3, op_sim_time());
op_stat_write_t(linkstat, commnodeid, op_sim_time());
//printf("NODE ID = %d\n", userid);
//printf("Transmitting Data Packet at %lf time\n", op_sim_time());
//op_prg_odb_bkpt("WIN");
#ifdef PRINT_TX
printf("CHILD PROC\n");
printf("Transmitting a copy of a DATA 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);
op_pk_nfd_get(pktptr, "number", &tempdouble);
printf("Packet Sequence Number = %lf\n", tempdouble);
printf("Scheduled a DATA Timeout Interrupt for %lfs\n", op_ev_time(timeout));
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -