亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? multihopewma.nc

?? MultiHopEngineM多跳路由鄰居表3
?? NC
?? 第 1 頁 / 共 2 頁
字號:
// $Id: MultiHopEWMA.nc,v 1.1 2003/11/21 19:47:24 jlhill Exp $

/*									tab:4
 * "Copyright (c) 2000-2003 The Regents of the University  of California.  
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 * Copyright (c) 2002-2003 Intel Corporation
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached INTEL-LICENSE     
 * file. If you do not find these files, copies can be found by writing to
 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
 * 94704.  Attention:  Intel License Inquiry.
 */


includes AM;
includes MultiHop;


#define MULTI_HOP_DEBUG 1

module MultiHopEWMA {

  provides {
    interface StdControl;
    interface RouteSelect;
    interface RouteControl;
  }

  uses {
    interface Timer;
    interface ReceiveMsg;
    interface Intercept as Snoop[uint8_t id];
    interface SendMsg;
    interface Send as DebugSendMsg;
  }
}

implementation {

  enum {
    NBRFLAG_VALID    = 0x01,
    NBRFLAG_NEW      = 0x02,
    NBRFLAG_EST_INIT = 0x04
  };

  enum {
    BASE_STATION_ADDRESS        = 0,
    ROUTE_TABLE_SIZE            = 16,
    ESTIMATE_TO_ROUTE_RATIO     = 5,
    ACCEPTABLE_MISSED           = -20,
    DATA_TO_ROUTE_RATIO         = 2,
    DATA_FREQ                   = 10000,
    SWITCH_THRESHOLD     	= 192,
    MAX_ALLOWABLE_LINK_COST     = 256*6,
    LIVELINESS              	= 2,
    MAX_DESCENDANT		= 5

  };

  enum {
    ROUTE_INVALID    = 0xff
  };

  struct SortEntry {
    uint16_t id;
    uint8_t  receiveEst;
  };

  struct SortDbgEntry {
    uint16_t id;
    uint8_t  sendEst;
    uint8_t  hopcount; 
  };

  typedef struct RPEstEntry {
    uint16_t id;
    uint8_t receiveEst;
  } __attribute__ ((packed)) RPEstEntry;

  typedef struct RoutePacket {
    uint16_t parent;
    uint16_t cost;
    uint8_t estEntries;
    RPEstEntry estList[1];
  } __attribute__ ((packed)) RoutePacket;

  typedef struct TableEntry {
    uint16_t id;  // Node Address
    uint16_t parent;
    uint16_t cost;
    uint8_t childLiveliness;
    uint16_t missed;
    uint16_t received;
    int16_t lastSeqno;
    uint8_t flags;
    uint8_t liveliness;
    uint8_t hop;
    uint8_t receiveEst;
    uint8_t sendEst;
  } TableEntry;

  TOS_Msg debugMsg; 
  TOS_Msg routeMsg; 
  bool gfSendRouteBusy;

  TableEntry BaseStation;
  TableEntry NeighborTbl[ROUTE_TABLE_SIZE];
  TableEntry *gpCurrentParent;
  uint8_t gbCurrentHopCount;
  uint16_t gbCurrentCost;
  int16_t gCurrentSeqNo;
  uint16_t gwEstTicks;
  uint32_t gUpdateInterval;


  /*////////////////////////////////////////////////////////*/
  /**
   * Return index into neighbor table of the given node addr
   * @author terence
   * @param id
   * @return index, if not found return ROUTE_INVALID
   */

  uint8_t findEntry(uint8_t id) {
    uint8_t i = 0;
    for (i = 0; i < ROUTE_TABLE_SIZE; i++) {
      if ((NeighborTbl[i].flags & NBRFLAG_VALID) && NeighborTbl[i].id == id) {
        return i;
      }
    }
    return ROUTE_INVALID;
  }
  /*////////////////////////////////////////////////////////*/
  /**
   * This function determines which entry should be replace
   * in this case, we find the one with the lease send estimate
   * @author terence
   * @param void
   * @return index of the table
   */

  uint8_t findEntryToBeReplaced() {
    uint8_t i = 0;
    uint8_t minSendEst = -1;
    uint8_t minSendEstIndex = ROUTE_INVALID;
    for (i = 0; i < ROUTE_TABLE_SIZE; i++) {
      if ((NeighborTbl[i].flags & NBRFLAG_VALID) == 0) {
        return i;
      }
      if (minSendEst >= NeighborTbl[i].sendEst) {
        minSendEst = NeighborTbl[i].sendEst;
        minSendEstIndex = i;
      }
    }
    return minSendEstIndex;
  }
  /*////////////////////////////////////////////////////////*/
  /**
   * This is going to make a new entry give an index and a id
   * @author terence
   * @param index, the index of the table
   * @param id, the node id 
   * @return void
   */

  void newEntry(uint8_t indes, uint16_t id) {
    NeighborTbl[indes].id = id;
    NeighborTbl[indes].flags = (NBRFLAG_VALID | NBRFLAG_NEW);
    NeighborTbl[indes].liveliness = 0;
    NeighborTbl[indes].parent = ROUTE_INVALID;
    NeighborTbl[indes].cost = ROUTE_INVALID;
    NeighborTbl[indes].childLiveliness = 0;
    NeighborTbl[indes].hop = ROUTE_INVALID;
    NeighborTbl[indes].missed = 0;
    NeighborTbl[indes].received = 0;
    NeighborTbl[indes].receiveEst = 0;
    NeighborTbl[indes].sendEst = 0;
    //call Estimator.clearTrackInfo(NeighborTbl[indes].trackInfo);
  }


  /*////////////////////////////////////////////////////////*/
  /**
   * Get neighbor table entry corresponding to the given address.
   * If current entry doesn't exist, then create one, possibly
   * evicting a previous entry. 
   * XXX - what if it evicts the parent???
   *
   * @author terence
   * @param id, node id
   * @return index
   */

  uint8_t findPreparedIndex(uint16_t id) {
    uint8_t indes = findEntry(id);
    if (indes == (uint8_t) ROUTE_INVALID) {
      indes = findEntryToBeReplaced();
      newEntry(indes, id);
    }
    return indes;
  }


  int sortByReceiveEstFcn(const void *x, const void *y) {
    struct SortEntry *nx = (struct SortEntry *) x;
    struct SortEntry *ny = (struct SortEntry *) y;
    uint8_t xReceiveEst = nx->receiveEst, yReceiveEst = ny->receiveEst;
    if (xReceiveEst > yReceiveEst) return -1;
    if (xReceiveEst == yReceiveEst) return 0;
    if (xReceiveEst < yReceiveEst) return 1;
    return 0; // shouldn't reach here becasue it covers all the cases
  }

  int sortDebugEstFcn(const void *x, const void *y) {
    struct SortDbgEntry *nx = (struct SortDbgEntry *) x;
    struct SortDbgEntry *ny = (struct SortDbgEntry *) y;
    uint8_t xReceiveEst = nx->sendEst, yReceiveEst = ny->sendEst;
    if (xReceiveEst > yReceiveEst) return -1;
    if (xReceiveEst == yReceiveEst) return 0;
    if (xReceiveEst < yReceiveEst) return 1;
    return 0; // shouldn't reach here becasue it covers all the cases
  }

  uint32_t evaluateCost(uint16_t cost, uint8_t sendEst, uint8_t receiveEst) {
    uint32_t transEst = (uint32_t) sendEst * (uint32_t) receiveEst;
    uint32_t immed = ((uint32_t) 1 << 24);

    if (transEst == 0) return ((uint32_t) 1 << (uint32_t) 16);
    // DO NOT change this LINE! mica compiler is WEIRD!
    immed = immed / transEst;
    immed += ((uint32_t) cost << 6);
    return immed;
  }


  void updateEst(TableEntry *Nbr) {
    uint16_t usExpTotal, usActTotal, newAve;

    if (Nbr->flags & NBRFLAG_NEW)
      return;
    
    usExpTotal = ESTIMATE_TO_ROUTE_RATIO;
    //if (pNbr->hop != 0) {
    //  usExpTotal *= (1 + DATA_TO_ROUTE_RATIO);
    //}
    dbg(DBG_ROUTE,"MultiHopEWMA: Updating Nbr %d. ExpTotl = %d, rcvd= %d, missed = %d\n",
        Nbr->id, usExpTotal, Nbr->received, Nbr->missed);

    atomic {
      usActTotal = Nbr->received + Nbr->missed;
      
      if (usActTotal < usExpTotal) {
        usActTotal = usExpTotal;
      }
      
      newAve = ((uint16_t) 255 * (uint16_t)Nbr->received) / (uint16_t)usActTotal;
      Nbr->missed = 0;
      Nbr->received = 0;

      // If we haven't seen a recieveEst for us from our neighbor, decay our sendEst
      // exponentially
      if (Nbr->liveliness  == 0) {
        Nbr->sendEst >>= 1;
      }else{
      	Nbr->liveliness --;
      }
    
    }
 

    if (Nbr->flags & NBRFLAG_EST_INIT) {
      uint16_t tmp;
      tmp = ((2 * ((uint16_t)Nbr->receiveEst) + (uint16_t)newAve * 6) / 8);
      Nbr->receiveEst = (uint8_t)tmp;
    }
    else {
      Nbr->receiveEst = (uint8_t) newAve;
      Nbr->flags ^= NBRFLAG_EST_INIT;
    }

     if(Nbr->childLiveliness > 0) Nbr->childLiveliness --;
  }

  void updateTable() {
    TableEntry *pNbr;
    uint8_t i = 0;

    gwEstTicks++;
    gwEstTicks %= ESTIMATE_TO_ROUTE_RATIO;

    for(i = 0; i < ROUTE_TABLE_SIZE; i++) {
      pNbr = &NeighborTbl[i];
      if (pNbr->flags & NBRFLAG_VALID) {
        if (gwEstTicks == 0) 
          updateEst(pNbr);
      }
    }
  }

  bool updateNbrCounters(uint16_t saddr, int16_t seqno, uint8_t *NbrIndex) {
    TableEntry *pNbr;
    int16_t sDelta;
    uint8_t iNbr;
    bool Result = FALSE;  // Result is TRUE if message is a duplicate

    iNbr = findPreparedIndex(saddr);
    pNbr = &NeighborTbl[iNbr];

    sDelta = (seqno - NeighborTbl[iNbr].lastSeqno - 1);

    if (pNbr->flags & NBRFLAG_NEW) {
      pNbr->received++;
      pNbr->lastSeqno = seqno;
      pNbr->flags ^= NBRFLAG_NEW;
    }
    else if (sDelta >= 0) {
      pNbr->missed += sDelta;
      pNbr->received++;
      pNbr->lastSeqno = seqno;
    }
    else if (sDelta < ACCEPTABLE_MISSED) {
      // Something happend to this node.  Reinitialize it's state
      newEntry(iNbr,saddr);
      pNbr->received++;
      pNbr->lastSeqno = seqno;
      pNbr->flags ^= NBRFLAG_NEW;
    }
    else {
      Result = TRUE;
    }

    *NbrIndex = iNbr;
    return Result;

  }

  void chooseParent() {
    TableEntry *pNbr;
    uint32_t ulNbrLinkCost = (uint32_t) -1;
    uint32_t ulNbrTotalCost = (uint32_t) -1;
    uint32_t oldParentCost = (uint32_t) -1;
    uint32_t oldParentLinkCost = (uint32_t) -1;
    uint32_t ulMinTotalCost = (uint32_t) -1;
    TableEntry* pNewParent = NULL;
    TableEntry* pOldParent = NULL;
    uint8_t i;

    if (TOS_LOCAL_ADDRESS == BASE_STATION_ADDRESS) return;

    // Choose the parent based on minimal hopcount and cost.  
    // There is a special case for choosing a base-station as it's 
    // receiveEst may be zero (it's not sending any packets)

    for (i = 0;i < ROUTE_TABLE_SIZE;i++) {
      pNbr = &NeighborTbl[i];


      if (!(pNbr->flags & NBRFLAG_VALID)) continue;
      if (pNbr->parent == TOS_LOCAL_ADDRESS) continue;
      if (pNbr->parent == ROUTE_INVALID) continue;
      if (pNbr->hop == ROUTE_INVALID) continue;
      if (pNbr->cost == (uint16_t) ROUTE_INVALID) continue;
      if (pNbr->sendEst < 25 || pNbr->receiveEst < 25) continue;
      if (pNbr->childLiveliness > 0) continue;

      ulNbrLinkCost = evaluateCost(0, pNbr->sendEst,pNbr->receiveEst);
      ulNbrTotalCost = evaluateCost(pNbr->cost, pNbr->sendEst,pNbr->receiveEst);


      if (ulNbrLinkCost > MAX_ALLOWABLE_LINK_COST) continue;
      dbg(DBG_ROUTE,"MultiHopEWMA node: %d, Cost %d, link Cost, %d\n", pNbr->id, ulNbrTotalCost, ulNbrLinkCost);
      if (pNbr == gpCurrentParent) {
	pOldParent = pNbr;
  	oldParentCost = ulNbrTotalCost;
  	oldParentLinkCost = ulNbrLinkCost;
  	continue;
      }
      
      if (ulMinTotalCost > ulNbrTotalCost) {
        ulMinTotalCost = ulNbrTotalCost;
        pNewParent = pNbr;
      }

    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩av网站在线观看| 日本少妇一区二区| 国产精品二区一区二区aⅴ污介绍| 色婷婷精品久久二区二区蜜臀av| 久久精品99久久久| 亚洲综合色自拍一区| 国产精品久久久久久久久免费樱桃 | 亚洲已满18点击进入久久| 欧美色视频一区| 93久久精品日日躁夜夜躁欧美| 狠狠色丁香婷婷综合| 日韩成人伦理电影在线观看| 国产精品电影一区二区三区| 久久精品一区二区三区四区| 91精品免费在线观看| 欧美吻胸吃奶大尺度电影| 99精品久久久久久| 国产精品一区久久久久| 久久成人18免费观看| 日韩在线观看一区二区| 一区二区三区91| 国产欧美一区视频| 91精品国产91久久久久久一区二区| 91国在线观看| 欧美男人的天堂一二区| 91精品国产一区二区| 欧美一级免费大片| 精品少妇一区二区三区视频免付费 | 日韩极品在线观看| 日韩精品每日更新| 秋霞电影一区二区| 五月天激情综合| 青草av.久久免费一区| 亚洲免费在线播放| 亚洲午夜日本在线观看| 美女视频黄免费的久久 | 91美女福利视频| 成人动漫一区二区在线| 成人爱爱电影网址| 91精品国产综合久久久久久| 精品国产一区久久| 国产精品乱码一区二区三区软件| 综合av第一页| 日韩有码一区二区三区| 免费一区二区视频| 成人一区二区三区中文字幕| 99久久精品国产导航| 在线观看国产日韩| 日韩一区二区三区电影在线观看| 久久天天做天天爱综合色| 亚洲女人****多毛耸耸8| 国产日韩欧美激情| 视频在线观看一区| 国产成人精品一区二| 91理论电影在线观看| 欧美日韩精品一区二区天天拍小说 | av电影一区二区| 日韩午夜av一区| 国产日本亚洲高清| 国产成人免费视| 久久亚洲一级片| 青青草精品视频| 欧美日本一区二区| 国产精品人成在线观看免费 | 色狠狠一区二区三区香蕉| 欧美一区二区三区四区高清| 国产日本一区二区| 蜜臀av一区二区在线免费观看| 91蝌蚪porny九色| 欧美日本在线观看| 欧美r级电影在线观看| 精品午夜久久福利影院| 欧美成人官网二区| 免费人成在线不卡| 久久精品视频免费| 91在线porny国产在线看| 久久男人中文字幕资源站| 亚洲成人你懂的| 在线观看视频一区| 欧美经典一区二区三区| 亚洲国产中文字幕在线视频综合| 麻豆精品在线观看| 欧美一区日本一区韩国一区| 亚洲柠檬福利资源导航| 欧美日韩中文字幕精品| 亚洲一二三四在线观看| 99久久综合狠狠综合久久| 久久先锋资源网| 9i在线看片成人免费| 亚洲蜜臀av乱码久久精品| 欧美日韩性生活| 日韩中文字幕区一区有砖一区| 欧洲色大大久久| 日韩一区日韩二区| 欧美影视一区二区三区| 日韩福利电影在线观看| 欧美丝袜自拍制服另类| 午夜精品久久久久久久久| 一本到不卡免费一区二区| 久久精品视频一区二区| 欧美中文字幕亚洲一区二区va在线 | 亚洲国产经典视频| 99riav久久精品riav| 国产尤物一区二区在线| 青青青伊人色综合久久| 亚洲美女精品一区| 欧美大白屁股肥臀xxxxxx| 成人一级片在线观看| 欧美极品美女视频| 9191久久久久久久久久久| 成人aa视频在线观看| 国产一区二区在线观看视频| 天天操天天干天天综合网| 国产精品久久久久永久免费观看 | 国产米奇在线777精品观看| 亚洲国产综合色| 亚洲国产成人自拍| 2014亚洲片线观看视频免费| 日韩视频在线一区二区| 91麻豆国产福利在线观看| 亚洲综合网站在线观看| 国产农村妇女毛片精品久久麻豆| 欧美日精品一区视频| 国产自产高清不卡| 久久精品国产色蜜蜜麻豆| 日韩成人一级片| 一区二区久久久久| 一区二区中文字幕在线| 自拍偷拍国产亚洲| 亚洲欧美日韩一区二区| 国产精品色哟哟| 国产精品理伦片| 樱桃视频在线观看一区| 一区二区三区高清| 亚洲一区在线视频观看| 日本不卡视频在线观看| 老司机精品视频导航| 首页国产欧美日韩丝袜| 亚洲电影在线免费观看| 国产精品久久久久久久久果冻传媒| 欧美一级久久久久久久大片| 久久久久久一级片| 亚洲欧洲日韩在线| 一区二区三区四区乱视频| 一区二区三区欧美久久| 亚洲人成伊人成综合网小说| 中文字幕在线不卡视频| 亚洲高清视频在线| 亚洲免费视频中文字幕| 日韩电影在线看| 夜夜爽夜夜爽精品视频| 亚洲欧美区自拍先锋| 亚洲人成伊人成综合网小说| 亚洲午夜羞羞片| 国产一区二区免费视频| www.亚洲人| 欧美久久一二三四区| 欧美电影在哪看比较好| 欧美色视频在线观看| 欧美zozo另类异族| 亚洲精品国产第一综合99久久| 亚洲一二三区在线观看| 懂色中文一区二区在线播放| 在线视频国内自拍亚洲视频| 日韩欧美一级片| 亚洲一区二区高清| 国产不卡视频在线观看| 欧美性色综合网| 久久午夜色播影院免费高清| 亚洲一区在线观看网站| 国产不卡免费视频| 欧美大黄免费观看| 精品一区二区免费视频| 91免费版在线| 国产三级久久久| 老汉av免费一区二区三区 | 免费观看30秒视频久久| 欧美日免费三级在线| 亚洲免费观看高清完整版在线观看熊| 亚洲成人1区2区| 欧美性受xxxx黑人xyx| 亚洲欧美偷拍三级| 91麻豆国产福利在线观看| 久久婷婷成人综合色| 国产另类ts人妖一区二区| 欧美tickle裸体挠脚心vk| 精品综合免费视频观看| 精品三级av在线| 久久精品国产亚洲高清剧情介绍 | 欧美日本在线播放| 亚洲天堂成人在线观看| 91视频一区二区三区| 日本视频中文字幕一区二区三区| 日韩一区二区精品| 99精品桃花视频在线观看| 青娱乐精品视频在线| 亚洲男人的天堂在线观看| 欧美私人免费视频| 粉嫩高潮美女一区二区三区| 亚洲另类中文字|