]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
changes for 4b estimator
authorgnawali <gnawali>
Fri, 21 Sep 2007 23:50:28 +0000 (23:50 +0000)
committergnawali <gnawali>
Fri, 21 Sep 2007 23:50:28 +0000 (23:50 +0000)
tos/lib/net/ctp/CtpP.nc
tos/lib/net/ctp/CtpRoutingEngineP.nc

index 00e20e0ec8217453abcb0a6b93016108925aa79c..b2aa76a779dea4345b20d439fdb075706c468d3c 100644 (file)
@@ -130,8 +130,8 @@ implementation {
   components new AMSenderC(AM_CTP_DATA);
   components new AMReceiverC(AM_CTP_DATA);
   components new AMSnooperC(AM_CTP_DATA);
-  
-  components new CtpRoutingEngineP(TREE_ROUTING_TABLE_SIZE, 1, 1024) as Router;
+
+  components new CtpRoutingEngineP(TREE_ROUTING_TABLE_SIZE, 10, 1024) as Router;
   StdControl = Router;
   StdControl = Estimator;
   RootControl = Router;
@@ -139,6 +139,9 @@ implementation {
   Router.BeaconSend -> Estimator.Send;
   Router.BeaconReceive -> Estimator.Receive;
   Router.LinkEstimator -> Estimator.LinkEstimator;
+
+  Router.CompareBit -> Estimator.CompareBit;
+
   Router.AMPacket -> ActiveMessageC;
   Router.RadioControl -> ActiveMessageC;
   Router.BeaconTimer -> RoutingBeaconTimer;
@@ -149,6 +152,10 @@ implementation {
   Router.CtpCongestion -> Forwarder;
   CtpInfo = Router;
 
+  components CC2420ActiveMessageC;
+  components CC2420PacketC as CC2420;
+  Router.CC2420Packet -> CC2420;
+  
   components new TimerMilliC() as RetxmitTimer;
   Forwarder.RetxmitTimer -> RetxmitTimer;
 
@@ -176,9 +183,13 @@ implementation {
 
   LinkEstimator = Estimator;
   
+  Estimator.Random -> RandomC;
+
   Estimator.AMSend -> SendControl;
   Estimator.SubReceive -> ReceiveControl;
   Estimator.SubPacket -> SendControl;
   Estimator.SubAMPacket -> SendControl;
+  Estimator.LinkPacketMetadata -> CC2420ActiveMessageC;
+  //  Estimator.LinkPacketMetadata -> ActiveMessageC;
   MainC.SoftwareInit -> Estimator;
 }
index 7c8810302b35322bda842609ddf59ae6532f7414..8bfc0eefeff2ca1c35da76bbcff460bc7a568b87 100644 (file)
@@ -113,6 +113,10 @@ generic module CtpRoutingEngineP(uint8_t routingTableSize, uint16_t minInterval,
         interface Random;
         interface CollectionDebug;
         interface CtpCongestion;
+
+       interface CompareBit;
+       interface CC2420Packet;
+
     }
 }
 
@@ -434,7 +438,7 @@ implementation {
 
     event void RouteTimer.fired() {
       if (radioOn && running) {
-       post updateRouteTask();
+         post updateRouteTask();
       }
     }
       
@@ -464,6 +468,7 @@ implementation {
         am_addr_t from;
         ctp_routing_header_t* rcvBeacon;
         bool congested;
+        uint8_t lqi = call CC2420Packet.getLqi(msg);
 
         // Received a beacon, but it's not from us.
         if (len != sizeof(ctp_routing_header_t)) {
@@ -484,7 +489,7 @@ implementation {
         dbg("TreeRouting","%s from: %d  [ parent: %d etx: %d]\n",
             __FUNCTION__, from, 
             rcvBeacon->parent, rcvBeacon->etx);
-        //call CollectionDebug.logEventRoute(NET_C_TREE_RCV_BEACON, rcvBeacon->parent, 0, rcvBeacon->etx);
+        call CollectionDebug.logEventRoute(NET_C_TREE_RCV_BEACON, from, lqi, rcvBeacon->etx);
 
         //update neighbor table
         if (rcvBeacon->parent != INVALID_ADDR) {
@@ -509,6 +514,12 @@ implementation {
         return msg;
     }
 
+
+  //event void LinkEstimator.newNeighbor(am_addr_t neighbor, uint8_t lqi) {
+  //  call CollectionDebug.logEventRoute(NET_C_TREE_RCV_BEACON, neighbor, lqi, 0);
+  //}
+
+
     /* Signals that a neighbor is no longer reachable. need special care if
      * that neighbor is our parent */
     event void LinkEstimator.evicted(am_addr_t neighbor) {
@@ -640,6 +651,61 @@ implementation {
     }
 
 
+  /* This should see if the node should be inserted in the table.
+   * If the white_bit is set, this means the LL believes this is a good
+   * first hop link. 
+   * The link will be recommended for insertion if it is better* than some
+   * link in the routing table that is not our parent.
+   * We are comparing the path quality up to the node, and ignoring the link
+   * quality from us to the node. This is because of a couple of things:
+   *   1. because of the white bit, we assume that the 1-hop to the candidate
+   *      link is good (say, etx=1)
+   *   2. we are being optimistic to the nodes in the table, by ignoring the
+   *      1-hop quality to them (which means we are assuming it's 1 as well)
+   *      This actually sets the bar a little higher for replacement
+   *   3. this is faster
+   *   4. it doesn't require the link estimator to have stabilized on a link
+   */
+    event bool CompareBit.shouldInsert(message_t *msg, void* payload, uint8_t len, bool white_bit) {
+        
+        bool found = FALSE;
+        uint16_t pathEtx;
+        //uint16_t linkEtx = evaluateEtx(0);
+        uint16_t neighEtx;
+        int i;
+        routing_table_entry* entry;
+        ctp_routing_header_t* rcvBeacon;
+
+        if ((call AMPacket.type(msg) != AM_CTP_ROUTING) ||
+            (len != sizeof(ctp_routing_header_t))) 
+            return FALSE;
+
+        /* 1.determine this packet's path quality */
+        rcvBeacon = (ctp_routing_header_t*)payload;
+
+        if (rcvBeacon->parent == INVALID_ADDR)
+            return FALSE;
+        /* the node is a root, recommend insertion! */
+        if (rcvBeacon->etx == 0) {
+            return TRUE;
+        }
+    
+        pathEtx = rcvBeacon->etx; // + linkEtx;
+
+        /* 2. see if we find some neighbor that is worse */
+        for (i = 0; i < routingTableActive && !found; i++) {
+            entry = &routingTable[i];
+            //ignore parent, since we can't replace it
+            if (entry->neighbor == routeInfo.parent)
+                continue;
+            neighEtx = entry->info.etx;
+            //neighEtx = evaluateEtx(call LinkEstimator.getLinkQuality(entry->neighbor));
+            found |= (pathEtx < neighEtx); 
+        }
+        return found;
+    }
+
+
     /************************************************************/
     /* Routing Table Functions                                  */