[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/collection
LinkEstimatorP.nc, 1.1.2.14, 1.1.2.15
Omprakash Gnawali
gnawali at users.sourceforge.net
Thu Jun 8 19:17:38 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/collection
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv3071
Modified Files:
Tag: tinyos-2_0_devel-BRANCH
LinkEstimatorP.nc
Log Message:
separate AM type for self beacons, take the structure to a header file
Index: LinkEstimatorP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/collection/Attic/LinkEstimatorP.nc,v
retrieving revision 1.1.2.14
retrieving revision 1.1.2.15
diff -C2 -d -r1.1.2.14 -r1.1.2.15
*** LinkEstimatorP.nc 7 Jun 2006 21:21:11 -0000 1.1.2.14
--- LinkEstimatorP.nc 9 Jun 2006 02:17:36 -0000 1.1.2.15
***************
*** 30,35 ****
*/
!
! #include "Timer.h"
module LinkEstimatorP {
--- 30,35 ----
*/
! #include <Timer.h>
! #include "LinkEstimator.h"
module LinkEstimatorP {
***************
*** 49,52 ****
--- 49,54 ----
interface Packet as SubPacket;
interface Receive as SubReceive;
+ interface AMSend as AMSendLinkEst;
+ interface Receive as ReceiveLinkEst;
interface Timer<TMilli>;
}
***************
*** 55,65 ****
implementation {
- // Number of entries in the neighbor table
- #define NEIGHBOR_TABLE_SIZE 8
- // Timer that determines how often beacons should be
- // sent and link estimate updated
- #define LINKEST_TIMER_RATE 4096
-
-
// configure the link estimator and some constants
enum {
--- 57,60 ----
***************
*** 87,150 ****
};
- // Flags for the neighbor table entry
- enum {
- VALID_ENTRY = 0x1,
- // A link becomes mature after
- // TABLEUPDATE_INTERVAL*LINKEST_TIMER_RATE
- MATURE_ENTRY = 0x2,
- // Flag to indicate that this link has received the
- // first sequence number
- INIT_ENTRY = 0x4
- };
-
-
- // neighbor table
- typedef struct neighbor_table_entry {
- am_addr_t ll_addr;
- uint8_t lastseq;
- uint8_t rcvcnt;
- uint8_t failcnt;
- uint8_t flags;
- uint8_t inage;
- uint8_t outage;
- uint8_t inquality;
- uint8_t outquality;
- } neighbor_table_entry_t;
-
- // for outgoing link estimator message
- // so that we can compute bi-directional quality
- typedef nx_struct neighbor_stat_entry {
- nx_am_addr_t ll_addr;
- nx_uint8_t inquality;
- } neighbor_stat_entry_t;
-
- // we put the above neighbor entry in the footer
- typedef nx_struct linkest_footer {
- neighbor_stat_entry_t neighborList[1];
- } linkest_footer_t;
-
- // Masks for the flag field in the link estimation header
- enum {
- // use last three bits to keep track of
- // how many footer entries there are
- NUM_ENTRIES_FLAG = 0x7,
- // set to 1 if linkestimator originated the
- // beacon because upper layer did not send
- // messages frequently enough
- SELF_BEACON_FLAG = 0x8
- };
-
- // link estimator header added to
- // every message passing thru' the link estimator
- typedef nx_struct linkest_header {
- nx_am_addr_t ll_addr;
- nx_uint8_t seq;
- // Bits Purpose
- // 2,1,0 Number of footer entries
- // 3 Was this packet generated by the link estimator?
- // 4..7 Not used yet
- nx_uint8_t flags;
- } linkest_header_t;
-
// keep information about links from the neighbors
neighbor_table_entry_t NeighborTable[NEIGHBOR_TABLE_SIZE];
--- 82,85 ----
***************
*** 192,195 ****
--- 127,136 ----
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);
***************
*** 347,351 ****
minPkt = TABLEUPDATE_INTERVAL / BEACON_INTERVAL;
dbg("LI", "%s\n", __FUNCTION__);
- dbg("LIPrint", "Link table for %i\n", (int)sim_node());
for (i = 0; i < NEIGHBOR_TABLE_SIZE; i++) {
ne = &NeighborTable[i];
--- 288,291 ----
***************
*** 371,375 ****
newEst = (255 * ne->rcvcnt) / totalPkt;
dbg("LI,LITest", " %hu: %hhu -> %hhu", ne->ll_addr, ne->inquality, (ALPHA * ne->inquality + (10-ALPHA) * newEst)/10);
- dbg("LIPrint", " link[%hhu] = %hu, %hhu\n", i, ne->ll_addr, ne->inquality);
ne->inquality = (ALPHA * ne->inquality + (10-ALPHA) * newEst)/10;
}
--- 311,314 ----
***************
*** 449,457 ****
hdr = getHeader(&linkEstPkt);
- hdr->flags |= SELF_BEACON_FLAG;
dbg("LI", "Sending seq because noone sent: %d\n", linkEstSeq);
print_packet(&linkEstPkt, newlen);
! if (call AMSend.send(AM_BROADCAST_ADDR, &linkEstPkt, newlen) == SUCCESS) {
beaconBusy = TRUE;
}
--- 388,395 ----
hdr = getHeader(&linkEstPkt);
dbg("LI", "Sending seq because noone sent: %d\n", linkEstSeq);
print_packet(&linkEstPkt, newlen);
! if (call AMSendLinkEst.send(AM_BROADCAST_ADDR, &linkEstPkt, newlen) == SUCCESS) {
beaconBusy = TRUE;
}
***************
*** 596,607 ****
}
! // done sending the message that originated at the
! // estimator or the user of this component
event void AMSend.sendDone(message_t* msg, error_t error ) {
! if (msg == &linkEstPkt) {
! beaconBusy = FALSE;
! } else {
! return signal Send.sendDone(msg, error);
! }
}
--- 534,547 ----
}
! // done sending the linkestimation beacone originated
! // by the estimator.
! event void AMSendLinkEst.sendDone(message_t *msg, error_t error) {
! beaconBusy = FALSE;
! }
!
! // done sending the message that originated by
! // the user of this component
event void AMSend.sendDone(message_t* msg, error_t error ) {
! return signal Send.sendDone(msg, error);
}
***************
*** 619,629 ****
}
! // new messages are received here
! // update the neighbor table with the header
! // and footer in the message
! // then signal the user of this component
! event message_t* SubReceive.receive(message_t* msg,
! void* payload,
! uint8_t len) {
uint8_t nidx;
uint8_t num_entries;
--- 559,568 ----
}
!
!
! // called when link estimator generator packet or
! // packets from upper layer that are wired to pass through
! // link estimator is received
! void processReceivedMessage(message_t* msg, void* payload, uint8_t len) {
uint8_t nidx;
uint8_t num_entries;
***************
*** 696,711 ****
}
print_neighbor_table();
-
- // if SELF_BEACON_FLAG is on, we do not need to signal the upper
- // layer because the beacon was originated by the link estimator
- if (hdr->flags & SELF_BEACON_FLAG) {
- dbg("LI", "No need to signal the router, SELF_BEACON_FLAG on\n");
- return msg;
- } else {
- dbg("LI", "It was a router beacon SELF_BEACON_FLAG is off\n");
- }
}
return signal Receive.receive(msg,
call Packet.getPayload(msg, NULL),
--- 635,652 ----
}
print_neighbor_table();
}
+ }
+
+ // new messages are received here
+ // update the neighbor table with the header
+ // and footer in the message
+ // then signal the user of this component
+ event message_t* SubReceive.receive(message_t* msg,
+ void* payload,
+ uint8_t len) {
+ dbg("LI", "Received upper packet. Will signal up\n");
+ processReceivedMessage(msg, payload, len);
return signal Receive.receive(msg,
call Packet.getPayload(msg, NULL),
***************
*** 713,716 ****
--- 654,667 ----
}
+ // handler for packets that were generated by the link estimator
+ event message_t* ReceiveLinkEst.receive(message_t* msg,
+ void* payload,
+ uint8_t len) {
+ dbg("LI", "Received self packet. Will not signal up\n");
+ processReceivedMessage(msg, payload, len);
+ return msg;
+ }
+
+
command void* Receive.getPayload(message_t* msg, uint8_t* len) {
return call Packet.getPayload(msg, len);
More information about the Tinyos-2-commits
mailing list