📄 802_11.pc
字号:
//NoFrag {//NoFrag curval = &(M802->SSRC);//NoFrag limit = M802_11_SHORT_RETRY_LIMIT;//NoFrag }//NoFrag //NoFrag /* If not greater than retry limit, retransmit frame. *///NoFrag if (*curval < limit)//NoFrag {//NoFrag *curval = *curval + 1;//NoFrag //NoFrag pktToRadio = GLOMO_MsgAlloc(node, 0, 0, 0);//NoFrag //NoFrag hdr.frameType = M802_11_FRAGMENT;//NoFrag hdr.sourceAddr = node->nodeAddr,//NoFrag hdr.destAddr = nextHopAddress;//NoFrag M802->waitingForAckOrCtsFromAddress = nextHopAddress;//NoFrag payloadSize = topPacket->packetSize;//NoFrag //NoFrag entry = Mac802_11GetSeqNo(node, M802, nextHopAddress);//NoFrag assert(entry);//NoFrag hdr.seqNo = entry->toSeqNo;//NoFrag //NoFrag /* Update duration to include next FRAG/ACK sequence. *///NoFrag if (remainder > 0)//NoFrag {//NoFrag frameSize = M802_11_FRAG_THRESH + sizeof(M802_11FrameHdr);//NoFrag //NoFrag left = topPacket->packetSize -//NoFrag (M802->currentFrag * M802_11_FRAG_THRESH);//NoFrag //NoFrag if (left > M802_11_FRAG_THRESH)//NoFrag {//NoFrag //NoFrag hdr.duration =//NoFrag ((sizeof(M802_11ShortControlFrame) +//NoFrag M802_11_FRAG_THRESH + sizeof(M802_11FrameHdr) +//NoFrag M802_11_SHORT_CTRL_FRAME_SIZE) * SECOND) ///NoFrag (M802->bandwidth) +//NoFrag (3 * SYNCHRONIZATION_TIME) +//NoFrag (3 * M802_11_SIFS) + //NoFrag (3 * M802_11_DELAY_UNTIL_SIGNAL_AIRBORN) + //NoFrag (3 * M802->propDelay);//NoFrag }//NoFrag else//NoFrag {//NoFrag //NoFrag /* End of next FRAG/ACK period is last FRAG/ACK. *///NoFrag hdr.duration =//NoFrag ((M802_11_SHORT_CTRL_FRAME_SIZE +//NoFrag remainder + sizeof(M802_11FrameHdr) +//NoFrag M802_11_SHORT_CTRL_FRAME_SIZE) * SECOND) ///NoFrag (M802->bandwidth) +//NoFrag (3 * SYNCHRONIZATION_TIME) +//NoFrag (3 * M802_11_SIFS) + //NoFrag (3 * M802_11_DELAY_UNTIL_SIGNAL_AIRBORN) + //NoFrag (3 * M802->propDelay);//NoFrag }//NoFrag }//NoFrag /* This is the last fragment. *///NoFrag else//NoFrag {//NoFrag //NoFrag hdr.duration =//NoFrag (M802_11_SHORT_CTRL_FRAME_SIZE * SECOND) ///NoFrag (M802->bandwidth) +//NoFrag SYNCHRONIZATION_TIME +//NoFrag M802_11_SIFS + //NoFrag M802_11_DELAY_UNTIL_SIGNAL_AIRBORN +//NoFrag M802->extraPropDelay;//NoFrag }//NoFrag //NoFrag GLOMO_MsgPacketAlloc(node, pktToRadio, fragmentSize);//NoFrag //NoFrag memcpy(pktToRadio->packet,//NoFrag (topPacket->packet + (M802_11_FRAG_THRESH * M802->currentFrag)),//NoFrag fragmentSize);//NoFrag //NoFrag GLOMO_MsgAddHeader(node, pktToRadio, sizeof(M802_11FrameHdr) );//NoFrag //NoFrag macPktLen = fragmentSize + sizeof(M802_11FrameHdr) ;//NoFrag hdr.fragId = M802->currentFrag;//NoFrag //NoFrag //NoFrag memcpy(pktToRadio->packet, &(hdr), sizeof(M802_11FrameHdr) );//NoFrag //NoFrag StartTransmittingPacket(//NoFrag node, M802, pktToRadio, M802_11_DELAY_UNTIL_SIGNAL_AIRBORN);//NoFrag //NoFrag Mac802_11SetState(node, M802, M802_11_X_FRAGMENT);//NoFrag }//NoFrag /* Exceeded retry limit, so drop frame. *///NoFrag else//NoFrag {//NoFrag NODE_ADDR NotUsed;//NoFrag Message* pktFromNetwork;//NoFrag //NoFrag //NoFrag M802->fragsDropped++;//NoFrag //NoFrag *curval = 0;//NoFrag //NoFrag /* Drop frame from queue. *///NoFrag //NoFrag //NoFrag NetworkIpOutputQueueDequeuePacketForAPriority(//NoFrag node, M802->myGlomoMac->interfaceIndex, M802->currentPriority,//NoFrag &pktFromNetwork, &NotUsed);//NoFrag //NoFrag M802->currentPriority = INVALID_PRIORITY;//NoFrag //NoFrag Mac802_11InformNetworkOfPktDrop(node, M802, pktFromNetwork);//NoFrag //NoFrag Mac802_11DecreaseCW(node, M802);//NoFrag Mac802_11CheckForOutgoingPacket(node, M802);//NoFrag }}/* * NAME: Mac802_11Retransmit. * * PURPOSE: Retransmit frame since CTS or ACK was nevered received. * * PARAMETERS: node, node that is retransmitting. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11Retransmit(GlomoNode *node, GlomoMac802_11 *M802){ NODE_ADDR NotUsed; Message* topPacket; int limit; int *curval; NetworkIpOutputQueueTopPacketForAPriority( node, M802->myGlomoMac->interfaceIndex, M802->currentPriority, &topPacket, &NotUsed); assert(topPacket != NULL); /* Long retry count only applies to data frames greater than RTS_THRESH. RTS uses short retry count. */ if ((topPacket->packetSize > M802_11_RTS_THRESH) && (M802->state != M802_11_S_WFCTS)) { curval = &(M802->SLRC); limit = M802_11_LONG_RETRY_LIMIT; } else { curval = &(M802->SSRC); limit = M802_11_SHORT_RETRY_LIMIT; } /* If not greater than maximum retry count allowed, retransmit frame. */ if (*curval < limit) { *curval = *curval + 1; Mac802_11IncreaseCW(node, M802); Mac802_11SetBackoffIfZero(node, M802); AttemptToGoIntoWaitForDifsOrEifsState(node, M802); } else { /* Exceeded maximum retry count allowed, so drop frame. */ NODE_ADDR NotUsed; Message* pktFromNetwork; M802->pktsDropped++; *curval = 0; /* Drop frame from queue. */ NetworkIpOutputQueueDequeuePacketForAPriority( node, M802->myGlomoMac->interfaceIndex, M802->currentPriority, &pktFromNetwork, &NotUsed); M802->currentPriority = INVALID_PRIORITY; Mac802_11InformNetworkOfPktDrop(node, M802, pktFromNetwork, M802->waitingForAckOrCtsFromAddress); Mac802_11DecreaseCW(node, M802); Mac802_11CheckForOutgoingPacket(node, M802); }}/* * NAME: Mac802_11CTSTransmitted. * * PURPOSE: Hold for reply after sending CTS. * * PARAMETERS: node, node that just sent the CTS. * * RETURN: None. * * ASSUMPTION: None. */ static void Mac802_11CTSTransmitted(GlomoNode *node, GlomoMac802_11 *M802){ Mac802_11SetState(node, M802, M802_11_S_WFDATA); Mac802_11StartTimer(node, M802, M802->noResponseTimeoutDuration);}/* * NAME: Mac802_11UnicastedTransmitted. * * PURPOSE: Hold for ACK after data frame is transmitted. * * PARAMETERS: node, node that just sent the data frame. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11UnicastTransmitted(GlomoNode *node, GlomoMac802_11 *M802){ clocktype holdForAck; Mac802_11SetState(node, M802, M802_11_S_WFACK); // This is the right time according to the starndard. holdForAck = M802->extraPropDelay + M802_11_SIFS + M802->ctsOrAckTransmissionDuration + M802->extraPropDelay + M802_11_SLOT_TIME; // This is the time in ns-2 //holdForAck = // M802_11_SIFS + // M802->ctsOrAckTransmissionDuration + // M802_11_DIFS; Mac802_11StartTimer(node, M802, holdForAck);} /* * NAME: Mac802_11FragTransmitted. * * PURPOSE: Hold for reply after a fragmented data frame is transmitted. * * PARAMETERS: node, node that just sent the fragmented data frame. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11FragTransmitted(GlomoNode *node, GlomoMac802_11 *M802){ clocktype holdForFragAck; assert(FALSE); abort(); // Fragmentation Needs to be rewritten. (Jay)//NoFrag //NoFrag //NoFrag holdForFragAck = //NoFrag M802_11_SIFS + (2 * M802_11_DELAY_UNTIL_SIGNAL_AIRBORN) +//NoFrag (2 * M802->extraPropDelay) + (2 * SYNCHRONIZATION_TIME) +//NoFrag ((M802_11_SHORT_CTRL_FRAME_SIZE) * SECOND) ///NoFrag (M802->bandwidth) + EPSILON_DELAY;//NoFrag //NoFrag //NoFrag Mac802_11SetState(node, M802, M802_11_S_WFFRAGACK);//NoFrag Mac802_11StartTimer(node, M802, holdForFragAck);}/* * NAME: Mac802_11AckTransmitted. * * PURPOSE: Check to see if any more packets that needs to be sent * out. * * PARAMETERS: node, node that just sent the ACK. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11AckTransmitted(GlomoNode *node, GlomoMac802_11 *M802){ Mac802_11CheckForOutgoingPacket(node, M802);}/* * NAME: Mac802_11FragAckTransmitted. * * PURPOSE: Hold for reply after ACK is transmitted for a fragmented frame. * * PARAMETERS: node, node that just sent the ACK for a fragmented frame. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11FragAckTransmitted(GlomoNode *node, GlomoMac802_11 *M802){ clocktype holdForData; assert(FALSE); abort(); // Fragmentation Needs to be rewritten. (Jay) //NoFrag Mac802_11SetState(node, M802, M802_11_S_WFDATA);//NoFrag //NoFrag holdForData = M802->noResponseTimeoutDuration + EPSILON_DELAY;//NoFrag //NoFrag //NoFrag Mac802_11StartTimer(node, M802, holdForData);}/* * NAME: Mac802_11RTSTransmitted. * * PURPOSE: Hold for reply after sending RTS. * * PARAMETERS: node, node that just sent the RTS. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11RTSTransmitted(GlomoNode *node, GlomoMac802_11 *M802){ clocktype holdForCts; Mac802_11SetState(node, M802, M802_11_S_WFCTS); holdForCts = M802->extraPropDelay + M802_11_SIFS + M802->ctsOrAckTransmissionDuration + M802->extraPropDelay + M802_11_SLOT_TIME; Mac802_11StartTimer(node, M802, holdForCts);}/* * NAME: Mac802_11PauseBackoff. * * PURPOSE: Stop the backoff counter once carrier is sensed. * * PARAMETERS: node, node that is stopping its own backoff. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11PauseBackoff(GlomoNode *node, GlomoMac802_11 *M802){ M802->BO = M802->BO - (simclock() - M802->lastBOTimeStamp); //printf("Node- %d BO = %I64d (%I64d)\n", node->id, M802->BO, M802->CW); if (M802->BO < 0) { assert(FALSE); abort(); M802->BO = 0; }}/* * NAME: Mac802_11ProcessNotMyFrame. * * PURPOSE: Handle frames that don't belong to this node. * * PARAMETERS: node, node that is handling this packet. * duration, time needed to yield for other nodes. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11ProcessNotMyFrame( GlomoNode *node, GlomoMac802_11 *M802, clocktype duration, BOOL isARtsPacket){ clocktype currentTime = simclock(); clocktype NewNAV = currentTime + duration + EPSILON_DELAY; if (NewNAV > M802->NAV) { M802->NAV = NewNAV; assert(M802->state != M802_11_S_WF_DIFS_OR_EIFS); assert(M802->state != M802_11_S_BO); assert(M802->state != M802_11_S_WFNAV); assert(M802->state != M802_11_S_NAV_RTS_CHECK_MODE); if ((RadioStatus(node, M802) == RADIO_IDLE) && (!NetworkIpOutputQueueIsEmpty( node, M802->myGlomoMac->interfaceIndex))) { // // This is what we should do. // //if (isARtsPacket) { // If RTS-ing node failed to get a CTS and start sending then // reset the NAV (MAC layer virtual carrier sense) for this // bystander node. // Mac802_11SetState(node, M802, M802_11_S_NAV_RTS_CHECK_MODE); // Mac802_11StartTimer(node, M802, // (M802->extraPropDelay + M802_11_SIFS + M802->ctsOrAckTransmissionDuration + // M802->extraPropDelay + 2 * M802_11_SLOT_TIME)); //} else { // // Mac802_11SetState(node, M802, M802_11_S_WFNAV); // Mac802_11StartTimer(node, M802, (M802->NAV - currentTime)); // }//if// // This is for ns-2 comparison. Mac802_11SetState(node, M802, M802_11_S_WFNAV); Mac802_11StartTimer(node, M802, (M802->NAV - currentTime)); }//if// }//if//}//void Mac802_11ProcessNotMyFrame///* * NAME: Mac802_11TransmitNextFrag. * * PURPOSE: Transmitting the next fragment of a frame. * * PARAMETERS: node, node that is sending the next fragment of a frame. * * RETURN: None. * * ASSUMPTION: None. */static void Mac802_11TransmitNextFrag(GlomoNode *node, GlomoMac802_11 *M802){ NODE_ADDR destAddr; Message *topPacket; NODE_ADDR nextHopAddress; Message *pktToRadio; int macPktLen; int i, remainder; int fragmentSize; int frameSize; int left; int *curval; int limit; M802_11FrameHdr hdr; int payloadSize; SeqNoEntry *entry;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -