From 1e699aeee49782114b391c2b12f492632aac46bf Mon Sep 17 00:00:00 2001 From: scipio Date: Fri, 14 Sep 2007 00:22:18 +0000 Subject: [PATCH] Moving dissemination to net/drip. --- tos/lib/net/README | 7 +- tos/lib/net/drip/DisseminationC.nc | 52 ++++ tos/lib/net/drip/DisseminationCache.nc | 51 ++++ tos/lib/net/drip/DisseminationEngine.h | 57 ++++ tos/lib/net/drip/DisseminationEngineImplP.nc | 257 +++++++++++++++++++ tos/lib/net/drip/DisseminationEngineP.nc | 78 ++++++ tos/lib/net/drip/DisseminationTimerP.nc | 51 ++++ tos/lib/net/drip/DisseminatorC.nc | 72 ++++++ tos/lib/net/drip/DisseminatorP.nc | 111 ++++++++ 9 files changed, 733 insertions(+), 3 deletions(-) create mode 100644 tos/lib/net/drip/DisseminationC.nc create mode 100644 tos/lib/net/drip/DisseminationCache.nc create mode 100644 tos/lib/net/drip/DisseminationEngine.h create mode 100644 tos/lib/net/drip/DisseminationEngineImplP.nc create mode 100644 tos/lib/net/drip/DisseminationEngineP.nc create mode 100644 tos/lib/net/drip/DisseminationTimerP.nc create mode 100644 tos/lib/net/drip/DisseminatorC.nc create mode 100644 tos/lib/net/drip/DisseminatorP.nc diff --git a/tos/lib/net/README b/tos/lib/net/README index 4906a856..687ced88 100644 --- a/tos/lib/net/README +++ b/tos/lib/net/README @@ -1,7 +1,8 @@ This directory contains network protocols that are part of the TinyOS core distribution. They are: -ctp: Collection Tree Protocol (TEP 123) -dip: DIssemination Protocol (TEP 1xx) -rstp: Root Sequenced Tree Protocol (TEP 124) +ctp: Collection Tree Protocol (TEP 123), a collection (TEP 119) protocol +drip: Drip, a dissemination (TEP 118) protocol +le: Link Estimation Exchange Protocol (TEP 124) +lqi: MultihopLQI, a collection (TEP 119) protocol diff --git a/tos/lib/net/drip/DisseminationC.nc b/tos/lib/net/drip/DisseminationC.nc new file mode 100644 index 00000000..1fb00403 --- /dev/null +++ b/tos/lib/net/drip/DisseminationC.nc @@ -0,0 +1,52 @@ +#include + +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/** + * The DisseminationC component is the top-level interface to the + * dissemination protocol. StdControl controls all of the trickle + * timers used for all of the keys. + * + * See TEP118 - Dissemination for details. + * + * @author Gilman Tolle + * @version $Revision$ + */ + +configuration DisseminationC { + provides interface StdControl; +} +implementation { + components DisseminationEngineP; + StdControl = DisseminationEngineP; +} diff --git a/tos/lib/net/drip/DisseminationCache.nc b/tos/lib/net/drip/DisseminationCache.nc new file mode 100644 index 00000000..290c7d1d --- /dev/null +++ b/tos/lib/net/drip/DisseminationCache.nc @@ -0,0 +1,51 @@ + +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/** + * The DisseminationCache interface connects each DisseminatorC + * component to the DisseminationEngineC component. + * + * See TEP118 - Dissemination for details. + * + * @author Gilman Tolle + * @version $Revision$ $Date$ + */ + +interface DisseminationCache { + event error_t start(); + event error_t stop(); + command void* requestData( uint8_t* size ); + command void storeData( void* data, uint8_t size, uint32_t seqno ); + command uint32_t requestSeqno(); + event void newData(); +} diff --git a/tos/lib/net/drip/DisseminationEngine.h b/tos/lib/net/drip/DisseminationEngine.h new file mode 100644 index 00000000..5092a79f --- /dev/null +++ b/tos/lib/net/drip/DisseminationEngine.h @@ -0,0 +1,57 @@ +#ifndef DISSEMINATION_ENGINE_H +#define DISSEMINATION_ENGINE_H + +/* + * Copyright (c) 2006 Arched Rock Corporation + * 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 Arched Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/* + * TODO: Add a tiebreaker and an application GUID to the header + */ + +enum { + AM_DISSEMINATION_MESSAGE = 13, + AM_DISSEMINATION_PROBE_MESSAGE = 14, + DISSEMINATION_SEQNO_UNKNOWN = 0, +}; + +typedef nx_struct dissemination_message { + nx_uint16_t key; + nx_uint32_t seqno; + nx_uint8_t data[0]; +} dissemination_message_t; + +typedef nx_struct dissemination_probe_message { + nx_uint16_t key; +} dissemination_probe_message_t; + +#endif + diff --git a/tos/lib/net/drip/DisseminationEngineImplP.nc b/tos/lib/net/drip/DisseminationEngineImplP.nc new file mode 100644 index 00000000..16be42f0 --- /dev/null +++ b/tos/lib/net/drip/DisseminationEngineImplP.nc @@ -0,0 +1,257 @@ +#include + +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/** + * The DisseminationEngineImplP component implements the dissemination + * logic. + * + * See TEP118 - Dissemination for details. + * + * @author Gilman Tolle + * @version $Revision$ $Date$ + */ + +module DisseminationEngineImplP { + provides interface StdControl; + + uses { + interface DisseminationCache[uint16_t key]; + interface TrickleTimer[uint16_t key]; + interface StdControl as DisseminatorControl[uint16_t id]; + + interface AMSend; + interface Receive; + + interface AMSend as ProbeAMSend; + interface Receive as ProbeReceive; + + interface Leds; + } +} +implementation { + + enum { NUM_DISSEMINATORS = uniqueCount("DisseminationTimerC.TrickleTimer") }; + + message_t m_buf; + bool m_running; + bool m_bufBusy; + + void sendProbe( uint16_t key ); + void sendObject( uint16_t key ); + + command error_t StdControl.start() { + uint8_t i; + for ( i = 0; i < NUM_DISSEMINATORS; i++ ) { + call DisseminatorControl.start[ i ](); + } + m_running = TRUE; + return SUCCESS; + } + + command error_t StdControl.stop() { + uint8_t i; + for ( i = 0; i < NUM_DISSEMINATORS; i++ ) { + call DisseminatorControl.stop[ i ](); + } + m_running = FALSE; + return SUCCESS; + } + + event error_t DisseminationCache.start[ uint16_t key ]() { + error_t result = call TrickleTimer.start[ key ](); + call TrickleTimer.reset[ key ](); + return result; + } + + event error_t DisseminationCache.stop[ uint16_t key ]() { + call TrickleTimer.stop[ key ](); + return SUCCESS; + } + + event void DisseminationCache.newData[ uint16_t key ]() { + + if ( !m_running || m_bufBusy ) { return; } + + sendObject( key ); + call TrickleTimer.reset[ key ](); + } + + event void TrickleTimer.fired[ uint16_t key ]() { + + if ( !m_running || m_bufBusy ) { return; } + + sendObject( key ); + } + + void sendProbe( uint16_t key ) { + dissemination_probe_message_t* dpMsg = + (dissemination_probe_message_t*) call ProbeAMSend.getPayload( &m_buf, sizeof(dissemination_probe_message_t)); + if (dpMsg != NULL) { + m_bufBusy = TRUE; + + dpMsg->key = key; + + call ProbeAMSend.send( AM_BROADCAST_ADDR, &m_buf, + sizeof( dissemination_probe_message_t ) ); + } + } + + void sendObject( uint16_t key ) { + void* object; + uint8_t objectSize = 0; + + dissemination_message_t* dMsg = + (dissemination_message_t*) call AMSend.getPayload( &m_buf, sizeof(dissemination_message_t) ); + if (dMsg != NULL) { + m_bufBusy = TRUE; + + dMsg->key = key; + dMsg->seqno = call DisseminationCache.requestSeqno[ key ](); + + if ( dMsg->seqno != DISSEMINATION_SEQNO_UNKNOWN ) { + object = call DisseminationCache.requestData[ key ]( &objectSize ); + if ((objectSize + sizeof(dissemination_message_t)) > + call AMSend.maxPayloadLength()) { + objectSize = call AMSend.maxPayloadLength() - sizeof(dissemination_message_t); + } + memcpy( dMsg->data, object, objectSize ); + } + call AMSend.send( AM_BROADCAST_ADDR, + &m_buf, sizeof( dissemination_message_t ) + objectSize ); + } + } + + event void ProbeAMSend.sendDone( message_t* msg, error_t error ) { + m_bufBusy = FALSE; + } + + event void AMSend.sendDone( message_t* msg, error_t error ) { + m_bufBusy = FALSE; + } + + event message_t* Receive.receive( message_t* msg, + void* payload, + uint8_t len ) { + + dissemination_message_t* dMsg = + (dissemination_message_t*) payload; + + uint16_t key = dMsg->key; + uint32_t incomingSeqno = dMsg->seqno; + uint32_t currentSeqno = call DisseminationCache.requestSeqno[ key ](); + + if ( !m_running ) { return msg; } + + if ( currentSeqno == DISSEMINATION_SEQNO_UNKNOWN && + incomingSeqno != DISSEMINATION_SEQNO_UNKNOWN ) { + + call DisseminationCache.storeData[ key ] + ( dMsg->data, + len - sizeof( dissemination_message_t ), + incomingSeqno ); + + call TrickleTimer.reset[ key ](); + return msg; + } + + if ( incomingSeqno == DISSEMINATION_SEQNO_UNKNOWN && + currentSeqno != DISSEMINATION_SEQNO_UNKNOWN ) { + + call TrickleTimer.reset[ key ](); + return msg; + } + + if ( (int32_t)( incomingSeqno - currentSeqno ) > 0 ) { + + call DisseminationCache.storeData[key] + ( dMsg->data, + len - sizeof(dissemination_message_t), + incomingSeqno ); + dbg("Dissemination", "Received dissemination value 0x%08x,0x%08x @ %s\n", (int)key, (int)incomingSeqno, sim_time_string()); + call TrickleTimer.reset[ key ](); + + } else if ( (int32_t)( incomingSeqno - currentSeqno ) == 0 ) { + + call TrickleTimer.incrementCounter[ key ](); + + } else { + + // Still not sure which of these is the best. Immediate send for now. + sendObject( key ); + // call TrickleTimer.reset[ key ](); + + } + + return msg; + } + + event message_t* ProbeReceive.receive( message_t* msg, + void* payload, + uint8_t len) { + + dissemination_probe_message_t* dpMsg = + (dissemination_probe_message_t*) payload; + + if ( !m_running ) { return msg; } + + if ( call DisseminationCache.requestSeqno[ dpMsg->key ]() != + DISSEMINATION_SEQNO_UNKNOWN ) { + sendObject( dpMsg->key ); + } + + return msg; + } + + default command void* + DisseminationCache.requestData[uint16_t key]( uint8_t* size ) { return NULL; } + + default command void + DisseminationCache.storeData[uint16_t key]( void* data, + uint8_t size, + uint32_t seqno ) {} + + default command uint32_t + DisseminationCache.requestSeqno[uint16_t key]() { return DISSEMINATION_SEQNO_UNKNOWN; } + + default command error_t TrickleTimer.start[uint16_t key]() { return FAIL; } + + default command void TrickleTimer.stop[uint16_t key]() { } + + default command void TrickleTimer.reset[uint16_t key]() { } + + default command void TrickleTimer.incrementCounter[uint16_t key]() { } + + default command error_t DisseminatorControl.start[uint16_t id]() { return FAIL; } + default command error_t DisseminatorControl.stop[uint16_t id]() { return FAIL; } +} diff --git a/tos/lib/net/drip/DisseminationEngineP.nc b/tos/lib/net/drip/DisseminationEngineP.nc new file mode 100644 index 00000000..f507a71c --- /dev/null +++ b/tos/lib/net/drip/DisseminationEngineP.nc @@ -0,0 +1,78 @@ +#include + +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/** + * The DisseminationEngineP component retrieves values from the + * DisseminatorP components and disseminates them over the radio. + * + * TODO: Hook DisseminationProbe up to the serial instead of the radio. + * + * See TEP118 - Dissemination for details. + * + * @author Gilman Tolle + * @version $Revision$ $Date$ + */ + +configuration DisseminationEngineP { + provides interface StdControl; + + uses { + interface DisseminationCache[uint16_t key]; + interface TrickleTimer[uint16_t key]; + interface StdControl as DisseminatorControl[uint16_t id]; + } +} +implementation { + components DisseminationEngineImplP; + StdControl = DisseminationEngineImplP; + DisseminationCache = DisseminationEngineImplP; + TrickleTimer = DisseminationEngineImplP; + DisseminatorControl = DisseminationEngineImplP; + + components new AMSenderC(AM_DISSEMINATION_MESSAGE) as DisseminationSendC; + DisseminationEngineImplP.AMSend -> DisseminationSendC.AMSend; + + components new AMReceiverC(AM_DISSEMINATION_MESSAGE) as DisseminationReceiveC; + DisseminationEngineImplP.Receive -> DisseminationReceiveC.Receive; + + components new AMSenderC(AM_DISSEMINATION_PROBE_MESSAGE) as DisseminationProbeSendC; + DisseminationEngineImplP.ProbeAMSend -> DisseminationProbeSendC.AMSend; + + components new AMReceiverC(AM_DISSEMINATION_PROBE_MESSAGE) + as DisseminationProbeReceiveC; + DisseminationEngineImplP.ProbeReceive -> DisseminationProbeReceiveC.Receive; + + components NoLedsC; + DisseminationEngineImplP.Leds -> NoLedsC; +} diff --git a/tos/lib/net/drip/DisseminationTimerP.nc b/tos/lib/net/drip/DisseminationTimerP.nc new file mode 100644 index 00000000..d9e48f9f --- /dev/null +++ b/tos/lib/net/drip/DisseminationTimerP.nc @@ -0,0 +1,51 @@ + +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/* + * The DisseminationTimerP component maintains a set of Trickle timers + * and is wired to DisseminationEngineC once for each DisseminatorC. + * + * See TEP118 - Dissemination for details. + * + * @author Gilman Tolle + * @version $Revision$ $Date$ + */ + +configuration DisseminationTimerP { + provides interface TrickleTimer[uint8_t id]; +} +implementation { + components new TrickleTimerMilliC(1, 1024, 1, + uniqueCount("DisseminationTimerC.TrickleTimer")); + TrickleTimer = TrickleTimerMilliC; +} diff --git a/tos/lib/net/drip/DisseminatorC.nc b/tos/lib/net/drip/DisseminatorC.nc new file mode 100644 index 00000000..3890a96d --- /dev/null +++ b/tos/lib/net/drip/DisseminatorC.nc @@ -0,0 +1,72 @@ +#include + +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/** + * The DisseminatorC component holds and synchronizes a single value + * of a chosen type, and identifies that value by a chosen 16-bit key. + * Different nodes should use the same key for the same value. + * + * See TEP118 - Dissemination for details. + * + * @param t the type of the object that will be disseminated + * @param key the 16-bit identifier of the disseminated object + * + * @author Gilman Tolle + * @version $Revision$ $Date$ + */ + +generic configuration DisseminatorC(typedef t, uint16_t key) { + provides interface DisseminationValue; + provides interface DisseminationUpdate; +} +implementation { + enum { + TIMER_ID = unique("DisseminationTimerC.TrickleTimer") + }; + + components new DisseminatorP(t); + DisseminationValue = DisseminatorP; + DisseminationUpdate = DisseminatorP; + + components DisseminationEngineP; + DisseminationEngineP.DisseminationCache[key] -> DisseminatorP; + DisseminationEngineP.DisseminatorControl[TIMER_ID] -> DisseminatorP; + + components DisseminationTimerP; + DisseminationEngineP.TrickleTimer[key] -> + DisseminationTimerP.TrickleTimer[TIMER_ID]; + + components LedsC; + DisseminatorP.Leds -> LedsC; +} diff --git a/tos/lib/net/drip/DisseminatorP.nc b/tos/lib/net/drip/DisseminatorP.nc new file mode 100644 index 00000000..1a628044 --- /dev/null +++ b/tos/lib/net/drip/DisseminatorP.nc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2006 Arch Rock Corporation + * 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 Arch Rock Corporation 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 THE + * ARCHED ROCK 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 + * + */ + +/** + * The DisseminatorP module holds and synchronizes a single value of a + * chosen type. + * + * See TEP118 - Dissemination for details. + * + * @param t the type of the object that will be disseminated + * + * @author Gilman Tolle + * @version $Revision$ $Date$ + */ + +generic module DisseminatorP(typedef t) { + provides interface StdControl; + + provides interface DisseminationValue; + provides interface DisseminationUpdate; + provides interface DisseminationCache; + + uses interface Leds; +} +implementation { + t valueCache; + bool m_running; + + // A sequence number is 32 bits. The top 16 bits are an incrementing + // counter, while the bottom 16 bits are a unique node identifier. + uint32_t seqno = DISSEMINATION_SEQNO_UNKNOWN; + + command error_t StdControl.start() { + error_t result = signal DisseminationCache.start(); + if ( result == SUCCESS ) { m_running = TRUE; } + return result; + } + + command error_t StdControl.stop() { + if ( !m_running ) { return EOFF; } + m_running = FALSE; + return signal DisseminationCache.stop(); + } + + command const t* DisseminationValue.get() { + return &valueCache; + } + + command void DisseminationValue.set( const t* val ) { + valueCache = *val; + } + + command void DisseminationUpdate.change( t* newVal ) { + if ( !m_running ) { return; } + memcpy( &valueCache, newVal, sizeof(t) ); + /* Increment the counter and append the local node ID. */ + seqno = seqno >> 16; + seqno++; + if ( seqno == DISSEMINATION_SEQNO_UNKNOWN ) { seqno++; } + seqno = seqno << 16; + seqno += TOS_NODE_ID; + signal DisseminationCache.newData(); + } + + command void* DisseminationCache.requestData( uint8_t* size ) { + *size = sizeof(t); + return &valueCache; + } + + command void DisseminationCache.storeData( void* data, uint8_t size, + uint32_t newSeqno ) { + memcpy( &valueCache, data, size < sizeof(t) ? size : sizeof(t) ); + seqno = newSeqno; + signal DisseminationValue.changed(); + } + + command uint32_t DisseminationCache.requestSeqno() { + return seqno; + } + + default event void DisseminationValue.changed() { } +} -- 2.39.2