⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 802_11.pc

📁 simulator for ad hoc
💻 PC
📖 第 1 页 / 共 5 页
字号:
/* * GloMoSim is COPYRIGHTED software.  Release 2.02 of GloMoSim is available  * at no cost to educational users only. * * Commercial use of this software requires a separate license.  No cost, * evaluation licenses are available for such purposes; please contact * info@scalable-networks.com * * By obtaining copies of this and any other files that comprise GloMoSim2.02, * you, the Licensee, agree to abide by the following conditions and * understandings with respect to the copyrighted software: * * 1.Permission to use, copy, and modify this software and its documentation *   for education and non-commercial research purposes only is hereby granted *   to Licensee, provided that the copyright notice, the original author's *   names and unit identification, and this permission notice appear on all *   such copies, and that no charge be made for such copies. Any entity *   desiring permission to use this software for any commercial or *   non-educational research purposes should contact:  * *   Professor Rajive Bagrodia  *   University of California, Los Angeles  *   Department of Computer Science  *   Box 951596  *   3532 Boelter Hall  *   Los Angeles, CA 90095-1596  *   rajive@cs.ucla.edu * * 2.NO REPRESENTATIONS ARE MADE ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY *   PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. * * 3.Neither the software developers, the Parallel Computing Lab, UCLA, or any *   affiliate of the UC system shall be liable for any damages suffered by *   Licensee from the use of this software. */// Use the latest version of Parsec if this line causes a compiler error./* * $Id: 802_11.pc,v 1.68 2001/12/19 22:31:53 jmartin Exp $ */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <math.h>#include "api.h"#include "structmsg.h"#include "fileio.h"#include "message.h"#include "mac.h"#include "802_11.h"#include "radio.h"#include "../main/lookahead.h"/*  * Used to force remote nodes to yield longer for the data exchange. * Also needed since when packets will arrive at the same time a timer * times out.  Add delay to allow packets to be process first before * timers get a chance to expire.  Therefore, this value to be at * least 1. */#define EPSILON_DELAY 1static //inline//clocktype CalcFragmentTransmissionDuration(   int bandwidthBytesPerSec,   int dataSizeBytes) {   return (SYNCHRONIZATION_TIME +       ((dataSizeBytes + sizeof(M802_11FrameHdr)) * SECOND) /        bandwidthBytesPerSec);}/* * When using promiscuous mode, DO NOT use fragmentation!  This mode won't * work with it.  The remote stations' mac layer cannot determine when * fragments should be assembled.  Also, the remote nodes WILL * receive packets even if they are not in sequence!  Again, the remote * stations' mac layer cannot determine if a packet is in sequence. *//* * NAME:        Mac802_11WaitForNAV. * * PURPOSE:     See if this node is holding for NAV. * * PARAMETERS:  node, node that is checking to see if holding for NAV. * * RETURN:      TRUE if holding for NAV, FALSE otherwise. * * ASSUMPTION:  None. */static //inline// BOOL Mac802_11WaitForNAV(GlomoNode *node, GlomoMac802_11 *M802){   return (M802->NAV > simclock());}/* * NAME:        Mac802_11SetState. * * PURPOSE:     Set the state of the node. * * PARAMETERS:  node, node that is setting its state. *              state, the state that is being set to. * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11SetState(GlomoNode *node, GlomoMac802_11 *M802, int state){   M802->prevState = M802->state;   M802->state = state;}/* * NAME:        Mac802_11StartTimer. * * PURPOSE:     Setting the various timers in 802.11. * * PARAMETERS:  timerValue: duration of the timer being set. * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11StartTimer(   GlomoNode *node, GlomoMac802_11 *M802, clocktype timerDelay){   Message *newMsg;   M802->timerSequenceNumber++;   newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, MAC_PROTOCOL_802_11,                           MSG_MAC_TimerExpired);   GLOMO_MsgSetInstanceId(newMsg, M802->myGlomoMac->interfaceIndex);   GLOMO_MsgInfoAlloc(node, newMsg, sizeof(M802->timerSequenceNumber));   *((int*)(newMsg->info)) = M802->timerSequenceNumber;    GLOMO_MsgSend(node, newMsg, timerDelay);      }/* * NAME:        Mac802_11CancelTimer. * * PURPOSE:     Cancelling the current timer set in 802.11. * * PARAMETERS:  node, node that is cancelling the timer. *              timerType, type of timer being cancelled. * * RETURN:      None. * * ASSUMPTION:  None. */static //inline//void Mac802_11CancelTimer(GlomoNode *node, GlomoMac802_11 *M802){   // Has the effect of making the current timer "obsolete".      M802->timerSequenceNumber++;         }static //inline//void StartTransmittingPacket(   GlomoNode* node,    GlomoMac802_11* M802,   Message* packet,    clocktype delay) {   int radioIndex = M802->myGlomoMac->interfaceIndex;   M802_11LongControlFrame* hdr = (M802_11LongControlFrame *)packet->packet;      // printf("%d Sending to %d at %I64d %I64d\n", node->id, hdr->destAddr, simclock(), delay);      GLOMO_RadioStartTransmittingPacket(node, radioIndex, packet, hdr->destAddr,      TRUE, delay);}static //inline//RadioStatusType RadioStatus(GlomoNode *node, GlomoMac802_11 *M802){   return GLOMO_RadioGetStatus(node, M802->myGlomoMac->interfaceIndex);}static //inline//void AttemptToGoIntoWaitForDifsOrEifsState(   GlomoNode *node, GlomoMac802_11 *M802) {   if (RadioStatus(node, M802) == RADIO_IDLE) {      if (Mac802_11WaitForNAV(node, M802)) {          //          // Set timer to wait for NAV (Software Carrier Sense) to finish.         //         Mac802_11SetState(node, M802, M802_11_S_WFNAV);         Mac802_11StartTimer(node, M802, (M802->NAV - simclock()));      } else {          Mac802_11SetState(node, M802, M802_11_S_WF_DIFS_OR_EIFS);               if (M802->IsInExtendedIfsMode) {            Mac802_11StartTimer(node, M802, M802_11_EXTENDED_IFS_DELAY);         } else {            Mac802_11StartTimer(node, M802, M802_11_TX_DIFS);         }//if//      }//if//   } else {      Mac802_11SetState(node, M802, M802_11_S_IDLE);      Mac802_11CancelTimer(node, M802);   }//if//}/* * NAME:        Mac802_11IncreaseCW. * * PURPOSE:     Increase control window since node has to retransmit. * * PARAMETERS:  node, node that is increasing its control window. * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11IncreaseCW(GlomoNode *node, GlomoMac802_11 *M802){   M802->CW = MIN( (((M802->CW+1) * 2) - 1), M802_11_CW_MAX);}/* * NAME:        Mac802_11GetSeqNo. * * PURPOSE:     Returns the entry for given destAddr. * * PARAMETERS:  node, address of neighboring node for given entry. * * RETURN:      SeqNoEntry Pointer to Entry for given destAddr. * * ASSUMPTION:  None. */static SeqNoEntry *Mac802_11GetSeqNo(    GlomoNode *node, GlomoMac802_11 *M802, NODE_ADDR destAddr){   SeqNoEntry *entry = M802->seqNoHead,              *prev = NULL;   if (!entry)   {      entry = pc_malloc(sizeof(SeqNoEntry));      assert (entry);      entry->nodeAddr = destAddr;      entry->fromSeqNo = 0;      entry->toSeqNo = 0;      entry->next = NULL;      M802->seqNoHead = entry;      return entry;   }   while (entry)   {      if (entry->nodeAddr == destAddr)         return entry;      else      {         prev = entry;         entry = entry->next;      }   }   entry = pc_malloc(sizeof(SeqNoEntry));   assert(entry);   entry->nodeAddr = destAddr;   entry->fromSeqNo = 0;   entry->toSeqNo = 0;   entry->next = NULL;   prev->next = entry;   return entry;}/* * NAME:        Mac802_11SetBackoffIfZero. * * PURPOSE:     Setting the backoff counter for this node. * * PARAMETERS:  node, node that is being backed off. * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11SetBackoffIfZero(GlomoNode *node, GlomoMac802_11 *M802){   if (M802->BO == 0) {      M802->BO = (pc_nrand(node->seed) % M802->CW) * M802_11_SLOT_TIME;   }//if//}/* * NAME:        Mac802_11CheckForOutgoingPacket. * * PURPOSE:     See if there's a packet in the queue that needs to be sent out. *              Should only be called right after the medium was busy, *              So assume 802.11 will backoff. * * * PARAMETERS:  node, node that is checking its queue.  * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11CheckForOutgoingPacket(GlomoNode *node, GlomoMac802_11 *M802){   if (!NetworkIpOutputQueueIsEmpty(node, M802->myGlomoMac->interfaceIndex))   {      Mac802_11SetBackoffIfZero(node, M802);      AttemptToGoIntoWaitForDifsOrEifsState(node, M802);   }   else   {      assert(M802->BO == 0);      Mac802_11SetState(node, M802, M802_11_S_IDLE);      Mac802_11CancelTimer(node, M802);   }}/* * NAME:        Mac802_11InformNetworkOfPktDrop. * * PURPOSE:     Tells Network layer that a packet is dropped because of *              unsuccessful delivery. * * PARAMETERS:  node, node that was unable to deliver the network packet. *              msg, network packet that got dropped. * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11InformNetworkOfPktDrop(    GlomoNode *node, GlomoMac802_11 *M802, Message *msg, NODE_ADDR nextHop){   NetworkIpNotifyOfPacketDrop(node, msg, nextHop);}/* * NAME:        Mac802_11DecreaseCW. * * PURPOSE:     Resetting control window since transmission was successful. * * PARAMETERS:  node, node that is resetting its control window. * * RETURN:      None. * * ASSUMPTION:  None. */static void Mac802_11DecreaseCW(GlomoNode *node, GlomoMac802_11 *M802){   M802->CW = M802_11_CW_MIN;}/* * NAME:        Mac802_11RetransmitFrag. * * PURPOSE:     Retransmitting a fragment that is part of a frame. * * PARAMETERS:  node, node that is retransmitting the fragment of a frame. * * RETURN:      None. * * ASSUMPTION:  None. */staticvoid Mac802_11RetransmitFrag(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;   assert(FALSE); abort();  // Fragmentation Needs to be rewritten. (Jay)    //NoFrag    NetworkIpOutputQueueTopPacketForAPriority(//NoFrag       node, M802->myGlomoMac->interfaceIndex, M802->currentPriority,//NoFrag       &topPacket, &nextHopAddress);//NoFrag                    //NoFrag    if  (topPacket == NULL)//NoFrag    {//NoFrag       Mac802_11CheckForOutgoingPacket(node, M802);//NoFrag       return;//NoFrag    }//NoFrag //NoFrag    remainder = topPacket->packetSize -//NoFrag                (M802_11_FRAG_THRESH * M802->currentFrag);//NoFrag //NoFrag    /* Retransmit fragment which is not the last one. *///NoFrag    if (remainder > 0)//NoFrag    {//NoFrag       fragmentSize = M802_11_FRAG_THRESH;//NoFrag    }//NoFrag    /* Retransmitting last fragment. *///NoFrag    else//NoFrag    {//NoFrag       fragmentSize = M802_11_FRAG_THRESH * M802->currentFrag -//NoFrag                      topPacket->packetSize;//NoFrag    }//NoFrag //NoFrag    /*//NoFrag     * Long retry count only applies to data frames greater//NoFrag     * than RTS_THRESH.  RTS uses short retry count.//NoFrag     *///NoFrag //NoFrag    if (fragmentSize > M802_11_RTS_THRESH)//NoFrag    {//NoFrag       curval = &(M802->SLRC);//NoFrag       limit = M802_11_LONG_RETRY_LIMIT;//NoFrag    }//NoFrag    else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -