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

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

?? linkestimatorp.nc

?? tinyos-2.x.rar
?? NC
?? 第 1 頁 / 共 2 頁
字號:
/* $Id: LinkEstimatorP.nc,v 1.16 2009/03/13 05:13:29 gnawali Exp $ */
/*
 * "Copyright (c) 2006 University of Southern 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 SOUTHERN 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 SOUTHERN CALIFORNIA HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE UNIVERSITY OF SOUTHERN 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
 * SOUTHERN CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 */

/*
 @ author Omprakash Gnawali
 @ Created: April 24, 2006
 */

#include "LinkEstimator.h"

module LinkEstimatorP {
  provides {
    interface StdControl;
    interface AMSend as Send;
    interface Receive;
    interface LinkEstimator;
    interface Init;
    interface Packet;
    interface CompareBit;
  }

  uses {
    interface AMSend;
    interface AMPacket as SubAMPacket;
    interface Packet as SubPacket;
    interface Receive as SubReceive;
    interface LinkPacketMetadata;
    interface Random;
  }
}

implementation {

  // configure the link estimator and some constants
  enum {
    // If the eetx estimate is below this threshold
    // do not evict a link
    EVICT_EETX_THRESHOLD = 55,
    // maximum link update rounds before we expire the link
    MAX_AGE = 6,
    // if received sequence number if larger than the last sequence
    // number by this gap, we reinitialize the link
    MAX_PKT_GAP = 10,
    BEST_EETX = 0,
    INVALID_RVAL = 0xff,
    INVALID_NEIGHBOR_ADDR = 0xff,
    // if we don't know the link quality, we need to return a value so
    // large that it will not be used to form paths
    VERY_LARGE_EETX_VALUE = 0xff,
    // decay the link estimate using this alpha
    // we use a denominator of 10, so this corresponds to 0.2
    ALPHA = 9,
    // number of packets to wait before computing a new
    // DLQ (Data-driven Link Quality)
    DLQ_PKT_WINDOW = 5,
    // number of beacons to wait before computing a new
    // BLQ (Beacon-driven Link Quality)
    BLQ_PKT_WINDOW = 3,
    // largest EETX value that we feed into the link quality EWMA
    // a value of 60 corresponds to having to make six transmissions
    // to successfully receive one acknowledgement
    LARGE_EETX_VALUE = 60
  };

  // keep information about links from the neighbors
  neighbor_table_entry_t NeighborTable[NEIGHBOR_TABLE_SIZE];
  // link estimation sequence, increment every time a beacon is sent
  uint8_t linkEstSeq = 0;
  // if there is not enough room in the packet to put all the neighbor table
  // entries, in order to do round robin we need to remember which entry
  // we sent in the last beacon
  uint8_t prevSentIdx = 0;

  // get the link estimation header in the packet
  linkest_header_t* getHeader(message_t* m) {
    return (linkest_header_t*)call SubPacket.getPayload(m, sizeof(linkest_header_t));
  }

  // get the link estimation footer (neighbor entries) in the packet
  linkest_footer_t* getFooter(message_t* ONE m, uint8_t len) {
    // To get a footer at offset "len", the payload must be len + sizeof large.
    return (linkest_footer_t* ONE)(len + (uint8_t *)call Packet.getPayload(m,len + sizeof(linkest_footer_t)));
  }

  // add the link estimation header (seq no) and link estimation
  // footer (neighbor entries) in the packet. Call just before sending
  // the packet.
  uint8_t addLinkEstHeaderAndFooter(message_t * ONE msg, uint8_t len) {
    uint8_t newlen;
    linkest_header_t *hdr;
    linkest_footer_t *footer;
    uint8_t i, j, k;
    uint8_t maxEntries, newPrevSentIdx;
    dbg("LI", "newlen1 = %d\n", len);
    hdr = getHeader(msg);
    footer = getFooter(msg, len);

    maxEntries = ((call SubPacket.maxPayloadLength() - len - sizeof(linkest_header_t))
		  / sizeof(linkest_footer_t));

    // Depending on the number of bits used to store the number
    // of entries, we can encode up to NUM_ENTRIES_FLAG using those bits
    if (maxEntries > NUM_ENTRIES_FLAG) {
      maxEntries = NUM_ENTRIES_FLAG;
    }
    dbg("LI", "Max payload is: %d, maxEntries is: %d\n", call SubPacket.maxPayloadLength(), maxEntries);

    j = 0;
    newPrevSentIdx = 0;
    for (i = 0; i < NEIGHBOR_TABLE_SIZE && j < maxEntries; i++) {
      uint8_t neighborCount;
      neighbor_stat_entry_t * COUNT(neighborCount) neighborLists;
      if(maxEntries <= NEIGHBOR_TABLE_SIZE)
        neighborCount = maxEntries;
      else
        neighborCount = NEIGHBOR_TABLE_SIZE;
      
      neighborLists = TCAST(neighbor_stat_entry_t * COUNT(neighborCount), footer->neighborList);

      k = (prevSentIdx + i + 1) % NEIGHBOR_TABLE_SIZE;
      if ((NeighborTable[k].flags & VALID_ENTRY) &&
	  (NeighborTable[k].flags & MATURE_ENTRY)) {
	neighborLists[j].ll_addr = NeighborTable[k].ll_addr;
	neighborLists[j].inquality = NeighborTable[k].inquality;
	newPrevSentIdx = k;
	dbg("LI", "Loaded on footer: %d %d %d\n", j, neighborLists[j].ll_addr,
	    neighborLists[j].inquality);
	j++;
      }
    }
    prevSentIdx = newPrevSentIdx;

    hdr->seq = linkEstSeq++;
    hdr->flags = 0;
    hdr->flags |= (NUM_ENTRIES_FLAG & j);
    newlen = sizeof(linkest_header_t) + len + j*sizeof(linkest_footer_t);
    dbg("LI", "newlen2 = %d\n", newlen);
    return newlen;
  }


  // initialize the given entry in the table for neighbor ll_addr
  void initNeighborIdx(uint8_t i, am_addr_t ll_addr) {
    neighbor_table_entry_t *ne;
    ne = &NeighborTable[i];
    ne->ll_addr = ll_addr;
    ne->lastseq = 0;
    ne->rcvcnt = 0;
    ne->failcnt = 0;
    ne->flags = (INIT_ENTRY | VALID_ENTRY);
    ne->inage = MAX_AGE;
    ne->outage = MAX_AGE;
    ne->inquality = 0;
    ne->outquality = 0;
    ne->eetx = 0;
  }

  // find the index to the entry for neighbor ll_addr
  uint8_t findIdx(am_addr_t ll_addr) {
    uint8_t i;
    for (i = 0; i < NEIGHBOR_TABLE_SIZE; i++) {
      if (NeighborTable[i].flags & VALID_ENTRY) {
	if (NeighborTable[i].ll_addr == ll_addr) {
	  return i;
	}
      }
    }
    return INVALID_RVAL;
  }

  // find an empty slot in the neighbor table
  uint8_t findEmptyNeighborIdx() {
    uint8_t i;
    for (i = 0; i < NEIGHBOR_TABLE_SIZE; i++) {
      if (NeighborTable[i].flags & VALID_ENTRY) {
      } else {
	return i;
      }
    }
      return INVALID_RVAL;
  }

  // find the index to the worst neighbor if the eetx
  // estimate is greater than the given threshold
  uint8_t findWorstNeighborIdx(uint8_t thresholdEETX) {
    uint8_t i, worstNeighborIdx;
    uint16_t worstEETX, thisEETX;

    worstNeighborIdx = INVALID_RVAL;
    worstEETX = 0;
    for (i = 0; i < NEIGHBOR_TABLE_SIZE; i++) {
      if (!(NeighborTable[i].flags & VALID_ENTRY)) {
	dbg("LI", "Invalid so continuing\n");
	continue;
      }
      if (!(NeighborTable[i].flags & MATURE_ENTRY)) {
	dbg("LI", "Not mature, so continuing\n");
	continue;
      }
      if (NeighborTable[i].flags & PINNED_ENTRY) {
	dbg("LI", "Pinned entry, so continuing\n");
	continue;
      }
      thisEETX = NeighborTable[i].eetx;
      if (thisEETX >= worstEETX) {
	worstNeighborIdx = i;
	worstEETX = thisEETX;
      }
    }
    if (worstEETX >= thresholdEETX) {
      return worstNeighborIdx;
    } else {
      return INVALID_RVAL;
    }
  }

  // update the quality of the link link: self->neighbor
  // this is found in the entries in the footer of incoming message
  void updateReverseQuality(am_addr_t neighbor, uint8_t outquality) {
    uint8_t idx;
    idx = findIdx(neighbor);
    if (idx != INVALID_RVAL) {
      NeighborTable[idx].outquality = outquality;
      NeighborTable[idx].outage = MAX_AGE;
    }
  }

  // update the EETX estimator
  // called when new beacon estimate is done
  // also called when new DEETX estimate is done
  void updateEETX(neighbor_table_entry_t *ne, uint16_t newEst) {
    ne->eetx = (ALPHA * ne->eetx + (10 - ALPHA) * newEst + 5)/10;
  }


  // update data driven EETX
  void updateDEETX(neighbor_table_entry_t *ne) {
    uint16_t estETX;

    if (ne->data_success == 0) {
      // if there were no successful packet transmission in the
      // last window, our current estimate is the number of failed
      // transmissions
      estETX = (ne->data_total - 1)* 10;
    } else {
      estETX = (10 * ne->data_total) / ne->data_success - 10;
      ne->data_success = 0;
      ne->data_total = 0;
    }
    updateEETX(ne, estETX);
  }


  // EETX (Extra Expected number of Transmission)
  // EETX = ETX - 1
  // computeEETX returns EETX*10
  uint8_t computeEETX(uint8_t q1) {
    uint16_t q;
    if (q1 > 0) {
      q =  2550 / q1 - 10;
      if (q > 255) {
	q = VERY_LARGE_EETX_VALUE;
      }
      return (uint8_t)q;
    } else {
      return VERY_LARGE_EETX_VALUE;
    }
  }

  // BidirETX = 1 / (q1*q2)
  // BidirEETX = BidirETX - 1
  // computeBidirEETX return BidirEETX*10
  uint8_t computeBidirEETX(uint8_t q1, uint8_t q2) {
    uint16_t q;
    if ((q1 > 0) && (q2 > 0)) {
      q =  65025u / q1;
      q = (10*q) / q2 - 10;
      if (q > 255) {
	q = LARGE_EETX_VALUE;
      }
      return (uint8_t)q;
    } else {
      return LARGE_EETX_VALUE;
    }
  }

  // update the inbound link quality by
  // munging receive, fail count since last update
  void updateNeighborTableEst(am_addr_t n) {
    uint8_t i, totalPkt;
    neighbor_table_entry_t *ne;
    uint8_t newEst;
    uint8_t minPkt;

    minPkt = BLQ_PKT_WINDOW;
    dbg("LI", "%s\n", __FUNCTION__);
    for (i = 0; i < NEIGHBOR_TABLE_SIZE; i++) {
      ne = &NeighborTable[i];
      if (ne->ll_addr == n) {
	if (ne->flags & VALID_ENTRY) {
	  if (ne->inage > 0)
	    ne->inage--;
	  if (ne->outage > 0)
	    ne->outage--;
	  
	  if ((ne->inage == 0) && (ne->outage == 0)) {
	    ne->flags ^= VALID_ENTRY;
	    ne->inquality = ne->outquality = 0;
	  } else {
	    dbg("LI", "Making link: %d mature\n", i);
	    ne->flags |= MATURE_ENTRY;
	    totalPkt = ne->rcvcnt + ne->failcnt;
	    dbg("LI", "MinPkt: %d, totalPkt: %d\n", minPkt, totalPkt);
	    if (totalPkt < minPkt) {
	      totalPkt = minPkt;
	    }
	    if (totalPkt == 0) {
	      ne->inquality = (ALPHA * ne->inquality) / 10;
	    } else {
	      newEst = (255 * ne->rcvcnt) / totalPkt;
	      dbg("LI,LITest", "  %hu: %hhu -> %hhu", ne->ll_addr, ne->inquality, (ALPHA * ne->inquality + (10-ALPHA) * newEst + 5)/10);
	      ne->inquality = (ALPHA * ne->inquality + (10-ALPHA) * newEst + 5)/10;
	    }
	    ne->rcvcnt = 0;
	    ne->failcnt = 0;
	  }
	  updateEETX(ne, computeBidirEETX(ne->inquality, ne->outquality));
	}
	else {
	  dbg("LI", " - entry %i is invalid.\n", (int)i);
	}
      }
    }
  }


  // we received seq from the neighbor in idx
  // update the last seen seq, receive and fail count
  // refresh the age
  void updateNeighborEntryIdx(uint8_t idx, uint8_t seq) {
    uint8_t packetGap;

    if (NeighborTable[idx].flags & INIT_ENTRY) {
      dbg("LI", "Init entry update\n");
      NeighborTable[idx].lastseq = seq;
      NeighborTable[idx].flags &= ~INIT_ENTRY;
    }
    
    packetGap = seq - NeighborTable[idx].lastseq;
    dbg("LI", "updateNeighborEntryIdx: prevseq %d, curseq %d, gap %d\n",
	NeighborTable[idx].lastseq, seq, packetGap);
    NeighborTable[idx].lastseq = seq;
    NeighborTable[idx].rcvcnt++;
    NeighborTable[idx].inage = MAX_AGE;
    if (packetGap > 0) {
      NeighborTable[idx].failcnt += packetGap - 1;
    }
    if (packetGap > MAX_PKT_GAP) {
      NeighborTable[idx].failcnt = 0;
      NeighborTable[idx].rcvcnt = 1;
      NeighborTable[idx].outage = 0;
      NeighborTable[idx].outquality = 0;
      NeighborTable[idx].inquality = 0;
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲午夜精品网| 美女任你摸久久| 色综合天天综合网天天狠天天| 久久婷婷国产综合精品青草| 日本欧美一区二区| 欧美精品欧美精品系列| 亚洲成人一区二区| 欧美喷潮久久久xxxxx| 午夜av一区二区| 欧美体内she精视频| 亚洲国产精品视频| 欧美视频三区在线播放| 亚洲国产成人精品视频| 欧美日韩中文字幕一区二区| 亚洲一区二区高清| 欧美日韩一级二级三级| 日韩av一级电影| 日韩一区二区电影| 蜜桃视频在线观看一区| 日韩欧美国产不卡| 狠狠久久亚洲欧美| 国产欧美视频在线观看| av在线综合网| 亚洲裸体xxx| 欧美日韩午夜在线| 日韩精品一二区| 日韩精品中文字幕一区| 国产曰批免费观看久久久| 国产亚洲成年网址在线观看| 成人av网址在线| 亚洲免费在线观看视频| 欧美日韩小视频| 精品一区二区三区视频在线观看 | 91久久精品一区二区二区| 亚洲精品国产一区二区精华液| 欧美综合亚洲图片综合区| 亚洲成人av免费| 精品久久久网站| 粉嫩av一区二区三区在线播放| 亚洲视频资源在线| 欧美乱妇15p| 国产最新精品免费| 国产精品视频在线看| 91黄视频在线| 麻豆中文一区二区| 国产精品女主播av| 精品视频999| 激情都市一区二区| 成人欧美一区二区三区白人| 欧美美女激情18p| 国产一区日韩二区欧美三区| 亚洲免费视频中文字幕| 91精品国产日韩91久久久久久| 国产精品一区二区三区乱码| 一区二区三区日韩精品视频| 日韩视频免费观看高清完整版在线观看| 狠狠久久亚洲欧美| 亚洲黄色录像片| 日韩视频在线观看一区二区| 成人免费看的视频| 婷婷中文字幕综合| 日本一区二区三区在线不卡| 欧美色综合网站| 国产一区二区免费视频| 夜色激情一区二区| 久久在线免费观看| 91麻豆自制传媒国产之光| 免费av成人在线| 日韩美女啊v在线免费观看| 91精品国产综合久久精品图片| 国产盗摄精品一区二区三区在线| 亚洲大型综合色站| 国产嫩草影院久久久久| 欧美精品一二三区| 粉嫩在线一区二区三区视频| 视频一区欧美日韩| 国产日产欧美一区二区视频| 欧美电影在哪看比较好| av中文一区二区三区| 韩国精品免费视频| 亚洲成人www| 18涩涩午夜精品.www| 精品久久99ma| 欧美日韩一级黄| 91小视频在线免费看| 国产麻豆精品在线| 日韩精品一级中文字幕精品视频免费观看 | 欧美亚洲免费在线一区| 国产高清成人在线| 日本不卡123| 亚洲综合一二三区| 国产精品日韩精品欧美在线 | 欧美亚洲一区三区| 成人h动漫精品一区二| 国模无码大尺度一区二区三区| 亚洲不卡一区二区三区| 国产精品传媒入口麻豆| 精品久久久久99| 欧美一区二区三区的| 在线亚洲一区二区| 成人性生交大片免费看中文 | 国产一区二区精品久久91| 丝袜美腿亚洲色图| 一区二区高清免费观看影视大全| 国产精品天天看| 久久综合久色欧美综合狠狠| 91精品国产入口| 欧美日韩亚洲综合在线| 91福利精品第一导航| av在线播放一区二区三区| 国产精品99久久久久久有的能看| 麻豆一区二区在线| 裸体健美xxxx欧美裸体表演| 婷婷中文字幕一区三区| 亚洲线精品一区二区三区| 亚洲欧美视频一区| 中文字幕一区二区三区在线播放| 久久精品日韩一区二区三区| 精品免费国产二区三区| 日韩免费观看高清完整版在线观看| 欧美久久一二三四区| 欧美日韩一区不卡| 欧美日韩黄色影视| 欧美日本在线一区| 欧美色倩网站大全免费| 欧洲一区在线观看| 在线观看网站黄不卡| 在线免费一区三区| 欧美最猛性xxxxx直播| 欧美午夜精品电影| 欧美精品自拍偷拍动漫精品| 欧美人与z0zoxxxx视频| 欧美精品 日韩| 欧美一区二区三区播放老司机| 91精品国产色综合久久 | 欧美无砖砖区免费| 欧美日本乱大交xxxxx| 欧美一区二区三区在线观看| 91精品国产乱码久久蜜臀| 91精品免费观看| 日韩欧美第一区| 久久亚洲私人国产精品va媚药| 久久久国产精品午夜一区ai换脸 | 日韩片之四级片| 亚洲精品一区二区三区福利 | 91精品国产欧美一区二区18| 日韩亚洲欧美中文三级| 精品国产免费视频| 国产偷国产偷亚洲高清人白洁| 欧美国产激情一区二区三区蜜月| 国产精品嫩草99a| 亚洲女人小视频在线观看| 亚洲一区在线观看视频| 免费欧美日韩国产三级电影| 国产又黄又大久久| 成人三级在线视频| 在线亚洲精品福利网址导航| 欧美精品一卡二卡| 精品久久久久久久久久久久久久久 | 中文字幕亚洲欧美在线不卡| 亚洲激情图片小说视频| 日韩中文字幕麻豆| 国产一区二区精品久久99| 99久久精品国产一区| 欧美中文字幕一区二区三区| 欧美日韩高清一区二区三区| 精品国产91洋老外米糕| 国产精品久久久久久久久果冻传媒 | 日韩一区二区电影| 中文字幕欧美日本乱码一线二线| 亚洲欧美国产高清| 日本少妇一区二区| 国产一二精品视频| 色丁香久综合在线久综合在线观看| 欧美日韩国产综合一区二区| 欧美精品一区男女天堂| 成人欧美一区二区三区白人| 日韩av中文字幕一区二区三区| 国产伦精品一区二区三区免费迷| 91老师片黄在线观看| 日韩欧美高清一区| 亚洲色图在线播放| 免播放器亚洲一区| 91美女在线看| 亚洲精品在线三区| 一区二区三区精品久久久| 久久国产成人午夜av影院| www.欧美日韩| 91精品国产91久久综合桃花| 国产精品亲子伦对白| 亚洲v日本v欧美v久久精品| 国产精品亚洲人在线观看| 欧美网站大全在线观看| 国产欧美日本一区视频| 午夜精品久久久久影视| 大白屁股一区二区视频| 这里是久久伊人| 亚洲四区在线观看| 久久成人18免费观看| 色婷婷av一区|