📄 ramimo_proc_par.pr.c
字号:
/************************************/
/*Code for the channel becoming free*/
/************************************/
/*If the channel is now free then a random backoff interrupt may need to be scheduled, either for a retransmission*/
/*attempt or a new transmission*/
if((pcs_state == 0) && (vcs_state == 0))
{
#ifdef PRINT_SENSE
printf("PARENT PROC\n");
printf("Channel has just become FREE!\n");
#endif
/*Reschedule a transmission interrupt if required - based on the random backoff procedure*/
if( (busy == 1) && (txreq != 0) )
{
/*Schedule ROB interrupt in eifs time*/
robevent = op_intrpt_schedule_self(op_sim_time() + difs, ROB_INT);
#ifdef PRINT_SENSE
printf("PARENT PROC\n");
printf("Scheduled a Random Backoff Interrupt for an Expected Transmission at %lfs\n", op_ev_time(robevent));
#endif
}
else if(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);
/*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->chitxsrcid) && (flag == 0))
{
flag = 1;
/*Set the variable to indicate the ID of the source*/
sharedptr->partxsrcid = 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*/
robevent = op_intrpt_schedule_self(op_sim_time() + difs, ROB_INT);
txreq = 1;
txstate = RTS_INT;
busy = 1;
/*Reset the random backoff interval if this is a new transmission*/
rob = -1.0;
#ifdef PRINT_SENSE
printf("PARENT PROC\n");
printf("Scheduled a Random Backoff Interrupt for an New Packet Transmission at %lfs\n", op_ev_time(robevent));
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("Will be communicating with node %d\n", commnodeid);
printf("Packet Sequence Number = %lf\n", sequencenum);
#endif
}
}
}
}
op_prg_odb_bkpt("SENSE");
op_prg_odb_bkpt("TEST");
}
FSM_PROFILE_SECTION_OUT (ramimo_proc_par [SENSE enter execs], state5_enter_exec)
/** state (SENSE) exit executives **/
FSM_STATE_EXIT_FORCED (5, "SENSE", "ramimo_proc_par [SENSE exit execs]")
FSM_PROFILE_SECTION_IN (ramimo_proc_par [SENSE exit execs], state5_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (ramimo_proc_par [SENSE exit execs], state5_exit_exec)
/** state (SENSE) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "SENSE", "WAIT")
/*---------------------------------------------------------*/
/** state (RXARVL) enter executives **/
FSM_STATE_ENTER_FORCED (6, "RXARVL", state6_enter_exec, "ramimo_proc_par [RXARVL enter execs]")
FSM_PROFILE_SECTION_IN (ramimo_proc_par [RXARVL enter execs], state6_enter_exec)
{
#ifdef PRINT_RXARVL
printf("PARENT PROC\n");
printf("RXARVL STATE\n");
printf("Node %d\n", userid);
#endif
/******************************************************************/
/*Determine whether the incoming packet can be correctly received */
/******************************************************************/
/*Get the packet from the incoming stream*/
pktptr = op_pk_get(RX_STRM);
/*Determine the packet type from its name*/
op_pk_format(pktptr, &pktname);
if(strcmp(pktname, "DATA_pkt") == 0)
{
/*Read the user ID of the source node*/
op_pk_nfd_get(pktptr, "prevhop", &srcid);
}
else
{
/*Read the user ID of the source node*/
op_pk_nfd_get(pktptr, "SRC", &srcid);
}
/*Obtain the source nodes object ID from the user ID*/
other_node_id = op_id_from_userid(subnet_id, OPC_OBJTYPE_NDMOB, srcid);
/*Determine the location of the source node*/
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));
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("Packet Heard from Node %d\n", srcid);
printf("Distance Between Tx and Rx Nodes = %lf\n", distance);
printf("Transmitting Range Over Which Packets Can Be Received = %lf\n", tx_range);
#endif
/**********************************************************************/
/*If the packet can be received, carry out the appropriate processing */
/**********************************************************************/
/*Receive the packet if the source node is within transmission range and it is not a self packet*/
if( (distance < tx_range) && (srcid != userid) )
{
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("Packet Can be Received\n");
printf("Packet Type = %s\n", pktname);
#endif
/*If it is an RTS packet*/
if(strcmp(pktname, "RTS_pkt") == 0)
{
/*Read the source node user ID*/
op_pk_nfd_get(pktptr, "SRC", &srcid);
/*Read the primary destination node user ID*/
op_pk_nfd_get(pktptr, "DEST", &destid);
/*Determine the duration that the channel will be busy*/
op_pk_nfd_get(pktptr, "DURATION", &vcs_duration);
/*Read tnhe sequence number field*/
op_pk_nfd_get(pktptr, "number", &seqnum);
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("RTS Packet Information:\n");
printf("Packet SRC ID = %d\n", srcid);
printf("Packet DEST ID = %d\n", destid);
printf("Packet Duration Field = %lf\n", vcs_duration);
printf("Packet Sequence Number = %lf\n", seqnum);
#endif
/*Schedule an interrupt to update the channel status*/
if(destid != userid)
{
/*Schedule an interrupt to update the channel busy status if required*/
op_intrpt_schedule_self(op_sim_time(), VCS_BUSY_INT);
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("This Packet is Not Destined for Me\n");
printf("Scheduled a VCS Busy Interrupt\n");
#endif
}
/*Instigate the next stage in the transmission process if the RTS packet is destined for this node*/
if(destid == userid)
{
if((pcs_state == 0) && (vcs_state == 0))
{
if(busy == 0)
{
/*Store the user ID of the communicating node and the packet sequence number*/
commnodeid = srcid;
sequencenum = seqnum;
busy = -1;
}
if( (busy == -1) && (srcid == commnodeid) && (seqnum == sequencenum) )
{
/*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;
/*Set a timeout to return to the idle state after the data packet at the transmitter will have expired*/
//tempdouble = ((double) retrylimit) * (((rtspktsize+ctspktsize+datapktsize+ackpktsize)/datarate)+(4.0*propdelay)+(3.0*sifs));
if(op_ev_valid(rxtimeout) == OPC_TRUE)
op_ev_cancel(rxtimeout);
tempdouble = (((rtspktsize+ctspktsize+datapktsize+ackpktsize)/datarate)+(4.0*propdelay)+(3.0*sifs));
rxtimeout = op_intrpt_schedule_self(op_sim_time() + tempdouble, RX_TIMEOUT_INT);
//printf("Timeout period = %lf\n", tempdouble);
/*Schedule a CTS interrupt if appropriate and the channel is free*/
/*Schedule CTS Interrupt in SIFS seconds time*/
nexttxevent = op_intrpt_schedule_self(op_sim_time() + sifs, CTS_INT);
txreq = 1;
txstate = CTS_INT;
/*Reset the random backoff interval as this is a new transmission*/
rob = -1.0;
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("The Channel is Free and There Are No Ongoing Transmission\n");
printf("Cancelled Any Pending Transmission Interrupts\n");
printf("Scheduled a CTS Tx Interrupt in SIFS seconds\n");
#endif
}
}
op_prg_odb_bkpt("RX");
}
/*Destroy the packet*/
op_pk_destroy(pktptr);
}
/*If it is a CTS packet*/
else if(strcmp(pktname, "CTS_pkt") == 0)
{
/*Read the source node user ID*/
op_pk_nfd_get(pktptr, "SRC", &srcid);
/*Read the primary destination node user ID*/
op_pk_nfd_get(pktptr, "DEST", &destid);
/*Determine the duration that the channel will be busy*/
op_pk_nfd_get(pktptr, "DURATION", &vcs_duration);
/*Read tnhe sequence number field*/
op_pk_nfd_get(pktptr, "number", &seqnum);
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("CTS Packet Information:\n");
printf("Packet SRC ID = %d\n", srcid);
printf("Packet DEST ID = %d\n", destid);
printf("Packet Duration Field = %lf\n", vcs_duration);
printf("Packet Sequence Number = %lf\n", seqnum);
#endif
/*Schedule an interrupt to update the channel status*/
if(destid != userid)
{
/*Schedule an interrupt to update the channel busy status if required*/
op_intrpt_schedule_self(op_sim_time(), VCS_BUSY_INT);
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("This Packet is Not Destined for Me\n");
printf("Scheduled a VCS Busy Interrupt\n");
#endif
}
/*Instigate the next stage in the transmission process if the CTS packet is destined for this node*/
/*and it is from the appropriate terminal*/
if( (destid == userid) && (srcid == commnodeid) && (seqnum == sequencenum) )
{
/*Reset the number of transmission attempts of the RTS packet*/
numretries = 0;
/*Reset the congestion window to its minimum value*/
cw_current = cw_vals[0];
/*Cancel any associated timeoout or scheduled retransmissions*/
if(op_ev_valid(timeout) == OPC_TRUE)
op_ev_cancel(timeout);
/*Schedule a DATA Interrupt in SIFS seconds time*/
nexttxevent = op_intrpt_schedule_self(op_sim_time() + sifs, DATA_INT);
txreq = 1;
txstate = DATA_INT;
//printf("NODE ID = %d\n", userid);
//printf("Data Interrupt Scheduled at %lf time\n", op_sim_time());
//op_prg_odb_bkpt("WIN");
/*Reset the random backoff interval if this is a new transmission*/
rob = -1.0;
#ifdef PRINT_RX_ARVL
printf("PARENT PROC\n");
printf("This Packet is Destined for Me\n");
printf("Reset Congestion Window and Number of Retransmission Attempts\n");
printf("Cancelled the RTS Timeout Interrupt\n");
printf("Scheduled a DATA transmission interrupt in SIFS seconds\n");
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -