[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/ctp
LruCtpMsgCacheC.nc, NONE, 1.1.2.1 LruCtpMsgCacheP.nc, NONE,
1.1.2.1 CtpForwardingEngineP.nc, 1.1.2.4, 1.1.2.5 CtpP.nc,
1.1.2.1, 1.1.2.2 CtpPacket.nc, 1.1.2.2, 1.1.2.3
Phil Levis
scipio at users.sourceforge.net
Wed Sep 6 13:14:32 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/ctp
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26942/ctp
Modified Files:
Tag: tinyos-2_0_devel-BRANCH
CtpForwardingEngineP.nc CtpP.nc CtpPacket.nc
Added Files:
Tag: tinyos-2_0_devel-BRANCH
LruCtpMsgCacheC.nc LruCtpMsgCacheP.nc
Log Message:
Changed cache to consider origin, seqno, type, and thl. Updated CtpPacket
interface accordingly.
--- NEW FILE: LruCtpMsgCacheC.nc ---
/*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* An LRU cache CTP packet instances, where insertion represents use.
*
* @author Philip Levis
*/
generic configuration LruCtpMsgCacheC(uint8_t CACHE_SIZE) {
provides interface Cache<message_t*>;
}
implementation {
components MainC, new LruCtpMsgCacheP(CACHE_SIZE) as CacheP;
components CtpP;
Cache = CacheP;
CacheP.CtpPacket -> CtpP;
MainC.SoftwareInit -> CacheP;
}
--- NEW FILE: LruCtpMsgCacheP.nc ---
/*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* An LRU cache that stores the signature of a CTP packet instance.
* An insert operation indicates "use". Inserting an element not in
* the cache will replace the oldest, and inserting an element already
* in the cache will refresh its age.
*
* @author Philip Levis
*/
#include <message.h>
generic module LruCtpMsgCacheP(uint8_t size) {
provides {
interface Init;
interface Cache<message_t*>;
}
uses {
interface CtpPacket;
}
}
implementation {
typedef struct {
am_addr_t origin;
uint8_t seqno;
collection_id_t type;
uint8_t thl;
} ctp_packet_sig_t;
ctp_packet_sig_t cache[size];
uint8_t first;
uint8_t count;
command error_t Init.init() {
first = 0;
count = 0;
return SUCCESS;
}
void printCache() {
#ifdef TOSSIM
int i;
dbg("Cache","Cache:");
for (i = 0; i < count; i++) {
dbg_clear("Cache", " %04x %02x %02x %02x", cache[i].origin, cache[i].seqno, cache[i].type, cache[i].thl);
if (i == first)
dbg_clear("Cache","*");
}
dbg_clear("Cache","\n");
#endif
}
/* if key is in cache returns the index (offset by first), otherwise returns count */
uint8_t lookup(message_t* m) {
uint8_t i;
uint8_t index;
for (i = 0; i < count; i++) {
index = (i + first) % size;
if (call CtpPacket.getOrigin(m) == cache[index].origin &&
call CtpPacket.getSequenceNumber(m) == cache[index].seqno &&
call CtpPacket.getThl(m) == cache[index].thl &&
call CtpPacket.getType(m) == cache[index].type) {
break;
}
}
return i;
}
/* remove the entry with index i (relative to first) */
void remove(uint8_t i) {
uint8_t j;
if (i >= count)
return;
if (i == 0) {
//shift all by moving first
first = (first + 1) % size;
} else {
//shift everyone down
for (j = i; j < count; j++) {
memcpy(&cache[(j + first) % size], &cache[(j + first + 1) % size], sizeof(ctp_packet_sig_t));
}
}
count--;
}
command void Cache.insert(message_t* m) {
uint8_t i;
if (count == size ) {
//remove someone. If item not in
//cache, remove the first item.
//otherwise remove the item temporarily for
//reinsertion. This moves the item up in the
//LRU stack.
i = lookup(m);
remove(i % count);
}
//now count < size
cache[(first + count) % size].origin = call CtpPacket.getOrigin(m);
cache[(first + count) % size].seqno = call CtpPacket.getSequenceNumber(m);
cache[(first + count) % size].thl = call CtpPacket.getThl(m);
cache[(first + count) % size].type = call CtpPacket.getType(m);
count++;
}
command bool Cache.lookup(message_t* m) {
return (lookup(m) < count);
}
command void Cache.flush() {
call Init.init();
}
}
Index: CtpForwardingEngineP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/ctp/Attic/CtpForwardingEngineP.nc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** CtpForwardingEngineP.nc 29 Aug 2006 16:43:10 -0000 1.1.2.4
--- CtpForwardingEngineP.nc 6 Sep 2006 20:14:30 -0000 1.1.2.5
***************
*** 150,154 ****
interface Pool<message_t> as MessagePool;
interface Timer<TMilli> as RetxmitTimer;
! interface Cache<uint32_t> as SentCache;
interface CtpInfo;
interface PacketAcknowledgements;
--- 150,154 ----
interface Pool<message_t> as MessagePool;
interface Timer<TMilli> as RetxmitTimer;
! interface Cache<message_t*> as SentCache;
interface CtpInfo;
interface PacketAcknowledgements;
***************
*** 388,395 ****
uint8_t payloadLen = call SubPacket.payloadLength(qe->msg);
am_addr_t dest = call UnicastNameFreeRouting.nextHop();
- uint32_t msg_uid = call CtpPacket.getPacketId(qe->msg);
uint16_t gradient;
! if (call SentCache.lookup(msg_uid)) {
call CollectionDebug.logEvent(NET_C_FE_DUPLICATE_CACHE_AT_SEND);
call SendQueue.dequeue();
--- 388,394 ----
uint8_t payloadLen = call SubPacket.payloadLength(qe->msg);
am_addr_t dest = call UnicastNameFreeRouting.nextHop();
uint16_t gradient;
! if (call SentCache.lookup(qe->msg)) {
call CollectionDebug.logEvent(NET_C_FE_DUPLICATE_CACHE_AT_SEND);
call SendQueue.dequeue();
***************
*** 559,563 ****
call CollectionPacket.getOrigin(msg),
call AMPacket.destination(msg));
! call SentCache.insert(call CtpPacket.getPacketId(qe->msg));
call SendQueue.dequeue();
if (call MessagePool.put(qe->msg) != SUCCESS)
--- 558,562 ----
call CollectionPacket.getOrigin(msg),
call AMPacket.destination(msg));
! call SentCache.insert(qe->msg);
call SendQueue.dequeue();
if (call MessagePool.put(qe->msg) != SUCCESS)
***************
*** 675,680 ****
uint8_t netlen;
collection_id_t collectid;
-
- uint32_t msg_uid;
bool duplicate = FALSE;
fe_queue_entry_t* qe;
--- 674,677 ----
***************
*** 682,686 ****
- msg_uid = call CtpPacket.getPacketId(msg);
collectid = call CtpPacket.getType(msg);
--- 679,682 ----
***************
*** 701,705 ****
//See if we remember having seen this packet
//We look in the sent cache ...
! if (call SentCache.lookup(msg_uid)) {
call CollectionDebug.logEvent(NET_C_FE_DUPLICATE_CACHE);
return msg;
--- 697,701 ----
//See if we remember having seen this packet
//We look in the sent cache ...
! if (call SentCache.lookup(msg)) {
call CollectionDebug.logEvent(NET_C_FE_DUPLICATE_CACHE);
return msg;
***************
*** 709,713 ****
for (i = call SendQueue.size(); --i;) {
qe = call SendQueue.element(i);
! if (call CtpPacket.getPacketId(qe->msg) == msg_uid) {
duplicate = TRUE;
break;
--- 705,709 ----
for (i = call SendQueue.size(); --i;) {
qe = call SendQueue.element(i);
! if (call CtpPacket.matchInstance(qe->msg, msg)) {
duplicate = TRUE;
break;
***************
*** 816,828 ****
// implement duplicate suppression as described in TEP 123.
! command uint32_t CtpPacket.getPacketId(message_t* msg) {
! uint32_t id = call CtpPacket.getOrigin(msg);
! id = id << 8;
! id |= call CtpPacket.getType(msg);
! id = id << 8;
! id |= call CtpPacket.getThl(msg);
! return id;
}
!
default event void
Send.sendDone[uint8_t client](message_t *msg, error_t error) {
--- 812,828 ----
// implement duplicate suppression as described in TEP 123.
! command bool CtpPacket.matchInstance(message_t* m1, message_t* m2) {
! return (call CtpPacket.getOrigin(m1) == call CtpPacket.getOrigin(m2) &&
! call CtpPacket.getSequenceNumber(m1) == call CtpPacket.getSequenceNumber(m2) &&
! call CtpPacket.getThl(m1) == call CtpPacket.getThl(m2) &&
! call CtpPacket.getType(m1) == call CtpPacket.getType(m2));
}
!
! command bool CtpPacket.matchPacket(message_t* m1, message_t* m2) {
! return (call CtpPacket.getOrigin(m1) == call CtpPacket.getOrigin(m2) &&
! call CtpPacket.getSequenceNumber(m1) == call CtpPacket.getSequenceNumber(m2) &&
! call CtpPacket.getType(m1) == call CtpPacket.getType(m2));
! }
!
default event void
Send.sendDone[uint8_t client](message_t *msg, error_t error) {
Index: CtpP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/ctp/Attic/CtpP.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** CtpP.nc 6 Sep 2006 17:39:27 -0000 1.1.2.1
--- CtpP.nc 6 Sep 2006 20:14:30 -0000 1.1.2.2
***************
*** 117,121 ****
Forwarder.SendQueue -> SendQueueP;
! components new LruIntCacheC(uint32_t, CACHE_SIZE) as SentCacheP;
Forwarder.SentCache -> SentCacheP;
--- 117,121 ----
Forwarder.SendQueue -> SendQueueP;
! components new LruCtpMsgCacheC(CACHE_SIZE) as SentCacheP;
Forwarder.SentCache -> SentCacheP;
Index: CtpPacket.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/ctp/Attic/CtpPacket.nc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** CtpPacket.nc 25 Aug 2006 00:41:28 -0000 1.1.2.2
--- CtpPacket.nc 6 Sep 2006 20:14:30 -0000 1.1.2.3
***************
*** 61,65 ****
command void setType(message_t* msg, uint8_t id);
! command uint32_t getPacketId(message_t* msg);
!
}
--- 61,65 ----
command void setType(message_t* msg, uint8_t id);
! command bool matchInstance(message_t* m1, message_t* m2);
! command bool matchPacket(message_t* m1, message_t* m2);
}
More information about the Tinyos-2-commits
mailing list