From: scipio Date: Sat, 7 Apr 2007 01:58:04 +0000 (+0000) Subject: Move to be 119 compliant. X-Git-Tag: tinyos/2.0.1~89 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;h=310e2c03397186f878ac789d0edcc51df4af09a7;p=tinyos-2.x.git Move to be 119 compliant. --- diff --git a/tos/lib/net/SendVirtualizerP.nc b/tos/lib/net/SendVirtualizerP.nc new file mode 100644 index 00000000..1e291bb3 --- /dev/null +++ b/tos/lib/net/SendVirtualizerP.nc @@ -0,0 +1,192 @@ +// $Id$ +/* +* "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +* DAMAGE. +* +* STANFORD UNIVERSITY 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 STANFORD UNIVERSITY +* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, +* ENHANCEMENTS, OR MODIFICATIONS." +*/ + +/** + * A Send queue that provides a Service Instance pattern for formatted + * packets and calls an underlying Send in a round-robin fashion. Used + * to share L3 bandwidth between different communication clients. + * + * @author Philip Levis + * @date April 6 2007 + */ + +#include "AM.h" + +generic module SendVirtualizerP(int numClients) { + provides interface Send[uint8_t client]; + uses { + interface Send as SubSend; + interface Packet; + } +} + +implementation { + typedef struct { + message_t* msg; + } queue_entry_t; + + uint8_t current = numClients; // mark as empty + queue_entry_t queue[numClients]; + uint8_t cancelMask[numClients/8 + 1]; + + void tryToSend(); + + void nextPacket() { + uint8_t i; + current = (current + 1) % numClients; + for(i = 0; i < numClients; i++) { + if((queue[current].msg == NULL) || + (cancelMask[current/8] & (1 << current%8))) + { + current = (current + 1) % numClients; + } + else { + break; + } + } + if(i >= numClients) current = numClients; + } + + /** + * Accepts a properly formatted AM packet for later sending. + * Assumes that someone has filled in the AM packet fields + * (destination, AM type). + * + * @param msg - the message to send + * @param len - the length of the payload + * + */ + command error_t Send.send[uint8_t clientId](message_t* msg, + uint8_t len) { + if (clientId >= numClients) { + return FAIL; + } + if (queue[clientId].msg != NULL) { + return EBUSY; + } + dbg("AMQueue", "AMQueue: request to send from %hhu (%p): passed checks\n", clientId, msg); + + queue[clientId].msg = msg; + call Packet.setPayloadLength(msg, len); + + if (current >= numClients) { // queue empty + error_t err; + current = clientId; + + err = call SubSend.send(msg, len); + if (err != SUCCESS) { + dbg("AMQueue", "%s: underlying send failed.\n", __FUNCTION__); + current = numClients; + queue[clientId].msg = NULL; + } + return err; + } + else { + dbg("AMQueue", "AMQueue: request to send from %hhu (%p): queue not empty\n", clientId, msg); + } + return SUCCESS; + } + + task void CancelTask() { + uint8_t i,j,mask,last; + message_t *msg; + for(i = 0; i < numClients/8 + 1; i++) { + if(cancelMask[i]) { + for(mask = 1, j = 0; j < 8; j++) { + if(cancelMask[i] & mask) { + last = i*8 + j; + msg = queue[last].msg; + queue[last].msg = NULL; + cancelMask[i] &= ~mask; + signal Send.sendDone[last](msg, ECANCEL); + } + mask <<= 1; + } + } + } + } + + command error_t Send.cancel[uint8_t clientId](message_t* msg) { + if (clientId >= numClients || // Not a valid client + queue[clientId].msg == NULL || // No packet pending + queue[clientId].msg != msg) { // Not the right packet + return FAIL; + } + if(current == clientId) { + error_t err = call SubSend.cancel(msg); + return err; + } + else { + cancelMask[clientId/8] |= 1 << clientId % 8; + post CancelTask(); + return SUCCESS; + } + } + + void sendDone(uint8_t last, message_t *msg, error_t err) { + queue[last].msg = NULL; + tryToSend(); + signal Send.sendDone[last](msg, err); + } + + task void errorTask() { + sendDone(current, queue[current].msg, FAIL); + } + + // NOTE: Increments current! + void tryToSend() { + nextPacket(); + if (current < numClients) { // queue not empty + error_t nextErr; + message_t* nextMsg = queue[current].msg; + uint8_t len = call Packet.payloadLength(nextMsg); + nextErr = call SubSend.send(nextMsg, len); + if(nextErr != SUCCESS) { + post errorTask(); + } + } + } + + event void SubSend.sendDone(message_t* msg, error_t err) { + if(queue[current].msg == msg) { + sendDone(current, msg, err); + } + else { + dbg("PointerBug", "%s received send done for %p, signaling for %p.\n", + __FUNCTION__, msg, queue[current].msg); + } + } + + command uint8_t Send.maxPayloadLength[uint8_t id]() { + return call SubSend.maxPayloadLength(); + } + + command void* Send.getPayload[uint8_t id](message_t* m) { + return call SubSend.getPayload(m); + } + + default event void Send.sendDone[uint8_t id](message_t* msg, error_t err) { + // Do nothing + } +} diff --git a/tos/lib/net/lqi/CollectionC.nc b/tos/lib/net/lqi/CollectionC.nc index 554af6ab..88667c39 100644 --- a/tos/lib/net/lqi/CollectionC.nc +++ b/tos/lib/net/lqi/CollectionC.nc @@ -1,55 +1,68 @@ -/* tab:4 - * "Copyright (c) 2000-2003 The Regents of the University of California. +/* + * Copyright (c) 2006 Stanford University. * 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. + * 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. * - * IN NO EVENT SHALL THE UNIVERSITY OF 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 - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - * Copyright (c) 2002-2003 Intel Corporation - * All rights reserved. - * - * This file is distributed under the terms in the attached INTEL-LICENSE - * file. If you do not find these files, copies can be found by writing to - * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, - * 94704. Attention: Intel License Inquiry. + * 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. */ + /** - * @author Joe Polastre + * @author Philip Levis */ -#include "MultiHop.h" +#include "MultiHopLqi.h" configuration CollectionC { provides { interface StdControl; - interface Receive; - interface Send; + interface Send[uint8_t client]; + interface Receive[collection_id_t id]; + interface Receive as Snoop[collection_id_t]; + interface Intercept[collection_id_t id]; interface Packet; + interface CollectionPacket; interface RootControl; } } implementation { - components LQIMultiHopRouter as Router; - + components MultiHopLqiP as Router; + components new SendVirtualizerP(NUM_LQI_CLIENTS); + + Send = SendVirtualizerP; + SendVirtualizerP.SubSend -> Router.Send; + SendVirtualizerP.Packet -> Router; + StdControl = Router; - Receive = Router; - Send = Router; + Receive = Router.Receive; RootControl = Router; Packet = Router; + Snoop = Router.Snoop; + Intercept = Router.Intercept; + CollectionPacket = Router; } diff --git a/tos/lib/net/lqi/CollectionSenderC.nc b/tos/lib/net/lqi/CollectionSenderC.nc index c5ed5901..374d2e67 100644 --- a/tos/lib/net/lqi/CollectionSenderC.nc +++ b/tos/lib/net/lqi/CollectionSenderC.nc @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2007 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. + */ /** * The virtualized collection sender abstraction. * @@ -7,7 +37,7 @@ * @see TinyOS Net2-WG */ -#include +#include generic configuration CollectionSenderC(collection_id_t collectid) { provides { @@ -16,7 +46,9 @@ generic configuration CollectionSenderC(collection_id_t collectid) { } } implementation { - components CollectionC as Router; - Send = Router; - Packet = Router; + components new CollectionSenderP(collectid), CollectionC; + Send = CollectionSenderP; + Packet = CollectionC; + CollectionSenderP.SubSend -> CollectionC.Send[unique(UQ_LQI_CLIENT)]; + CollectionSenderP.CollectionPacket -> CollectionC; } diff --git a/tos/lib/net/lqi/CollectionSenderP.nc b/tos/lib/net/lqi/CollectionSenderP.nc new file mode 100644 index 00000000..708085ae --- /dev/null +++ b/tos/lib/net/lqi/CollectionSenderP.nc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2007 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. + */ + +#include "Collection.h" + +generic module CollectionSenderP(collection_id_t collectid) { + provides interface Send; + uses interface Send as SubSend; + uses interface CollectionPacket; +} + +implementation { + command error_t Send.send(message_t* msg, uint8_t len) { + call CollectionPacket.setType(msg, collectid); + return call SubSend.send(msg, len); + } + + command error_t Send.cancel(message_t* msg) { + return call SubSend.cancel(msg); + } + + command void* Send.getPayload(message_t* m) { + return call SubSend.getPayload(m); + } + + command uint8_t Send.maxPayloadLength() { + return call SubSend.maxPayloadLength(); + } + + event void SubSend.sendDone(message_t* m, error_t err) { + signal Send.sendDone(m, err); + } +} diff --git a/tos/lib/net/lqi/LQIMultiHopRouter.nc b/tos/lib/net/lqi/LQIMultiHopRouter.nc deleted file mode 100644 index 28467f7a..00000000 --- a/tos/lib/net/lqi/LQIMultiHopRouter.nc +++ /dev/null @@ -1,100 +0,0 @@ -/* tab:4 - * "Copyright (c) 2000-2003 The Regents of the University of 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 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 - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - * Copyright (c) 2002-2003 Intel Corporation - * All rights reserved. - * - * This file is distributed under the terms in the attached INTEL-LICENSE - * file. If you do not find these files, copies can be found by writing to - * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, - * 94704. Attention: Intel License Inquiry. - */ - -/** - * @author Joe Polastre - */ - -#include "MultiHop.h" - -configuration LQIMultiHopRouter { - - provides { - interface StdControl; - interface Receive; - interface Send; - interface RouteControl; - interface LqiRouteStats; - interface Packet; - interface RootControl; - interface CollectionPacket; - } - -} - -implementation { - - components - MultiHopEngineM, - MultiHopLQI, - new AMSenderC(AM_BEACONMSG) as BeaconSender, - new AMReceiverC(AM_BEACONMSG) as BeaconReceiver, - new AMSenderC(AM_DATAMSG) as DataSender, - new AMReceiverC(AM_DATAMSG) as DataReceiver, - new TimerMilliC(), - NoLedsC, LedsC, - RandomC, - ActiveMessageC, - MainC; - - MainC.SoftwareInit -> MultiHopEngineM; - MainC.SoftwareInit -> MultiHopLQI; - - components CC2420ActiveMessageC as CC2420; - - StdControl = MultiHopLQI.StdControl; - - Receive = MultiHopEngineM; - Send = MultiHopEngineM; - RouteControl = MultiHopEngineM; - LqiRouteStats = MultiHopEngineM; - Packet = MultiHopEngineM; - CollectionPacket = MultiHopEngineM; - RootControl = MultiHopLQI; - - MultiHopEngineM.RouteSelectCntl -> MultiHopLQI.RouteControl; - MultiHopEngineM.RouteSelect -> MultiHopLQI; - MultiHopEngineM.SubSend -> DataSender; - MultiHopEngineM.SubReceive -> DataReceiver; - MultiHopEngineM.Leds -> LedsC; - MultiHopEngineM.AMPacket -> ActiveMessageC; - MultiHopEngineM.SubPacket -> ActiveMessageC; - MultiHopEngineM.PacketAcknowledgements -> ActiveMessageC; - MultiHopEngineM.RootControl -> MultiHopLQI; - - MultiHopLQI.AMSend -> BeaconSender; - MultiHopLQI.Receive -> BeaconReceiver; - MultiHopLQI.Random -> RandomC; - MultiHopLQI.Timer -> TimerMilliC; - MultiHopLQI.LqiRouteStats -> MultiHopEngineM; - MultiHopLQI.CC2420Packet -> CC2420; - MultiHopLQI.AMPacket -> ActiveMessageC; - MultiHopLQI.Packet -> ActiveMessageC; - MultiHopLQI.Leds -> NoLedsC; -} diff --git a/tos/lib/net/lqi/LqiForwardingEngineP.nc b/tos/lib/net/lqi/LqiForwardingEngineP.nc new file mode 100644 index 00000000..e3dc5d00 --- /dev/null +++ b/tos/lib/net/lqi/LqiForwardingEngineP.nc @@ -0,0 +1,395 @@ +// $Id$ + + +/* Copyright (c) 2007 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. + */ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of 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 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 + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ + +/* + * A simple module that handles multihop packet movement. It accepts + * messages from both applications and the network and does the necessary + * interception and forwarding. + * It interfaces to an algorithmic componenet via RouteSelect. It also acts + * as a front end for RouteControl + */ + + +/** + * @author Philip Buonadonna + * @auihor Alec Woo + * @author Crossbow Inc. + * @author Philip Levis (port from TinyOS 1.x) + */ + +#include "AM.h" +#include "MultiHopLqi.h" + +module LqiForwardingEngineP { + provides { + interface Init; + interface Send; + interface Receive[collection_id_t id]; + interface Receive as Snoop[collection_id_t]; + interface Intercept[collection_id_t id]; + interface CollectionPacket; + interface RouteControl; + interface LqiRouteStats; + interface Packet; + } + uses { + interface Receive as SubReceive; + interface AMSend as SubSend; + interface RouteControl as RouteSelectCntl; + interface RouteSelect; + interface Leds; + interface Packet as SubPacket; + interface AMPacket; + interface RootControl; + interface PacketAcknowledgements; + } +} + +implementation { + + enum { + FWD_QUEUE_SIZE = MHOP_QUEUE_SIZE, // Forwarding Queue + EMPTY = 0xff + }; + + /* Internal storage and scheduling state */ + message_t FwdBuffers[FWD_QUEUE_SIZE]; + message_t *FwdBufList[FWD_QUEUE_SIZE]; + uint8_t FwdBufBusy[FWD_QUEUE_SIZE]; + uint8_t iFwdBufHead, iFwdBufTail; + uint16_t sendFailures = 0; + uint8_t fail_count = 0; + + lqi_header_t* getHeader(message_t* msg) { + return (lqi_header_t*) call SubPacket.getPayload(msg, NULL); + } + + /*********************************************************************** + * Initialization + ***********************************************************************/ + + + static void initialize() { + int n; + + for (n=0; n < FWD_QUEUE_SIZE; n++) { + FwdBufList[n] = &FwdBuffers[n]; + FwdBufBusy[n] = 0; + } + iFwdBufHead = iFwdBufTail = 0; + + sendFailures = 0; + } + + command error_t Init.init() { + initialize(); + return SUCCESS; + } + + + /*********************************************************************** + * Commands and events + ***********************************************************************/ + command error_t Send.send(message_t* pMsg, uint8_t len) { + len += sizeof(lqi_header_t); + if (len > call SubPacket.maxPayloadLength()) { + call Leds.led0On(); + return ESIZE; + } + if (call RootControl.isRoot()) { + call Leds.led1On(); + return FAIL; + } + call RouteSelect.initializeFields(pMsg); + + if (call RouteSelect.selectRoute(pMsg, 0) != SUCCESS) { + call Leds.led2On(); + return FAIL; + } + call PacketAcknowledgements.requestAck(pMsg); + if (call SubSend.send(call AMPacket.destination(pMsg), pMsg, len) != SUCCESS) { + sendFailures++; + return FAIL; + } + + return SUCCESS; + } + + int8_t get_buff(){ + uint8_t n; + for (n=0; n < FWD_QUEUE_SIZE; n++) { + uint8_t done = 0; + atomic{ + if(FwdBufBusy[n] == 0){ + FwdBufBusy[n] = 1; + done = 1; + } + } + if(done == 1) return n; + + } + return -1; + } + + int8_t is_ours(message_t* ptr){ + uint8_t n; + for (n=0; n < FWD_QUEUE_SIZE; n++) { + if(FwdBufList[n] == ptr){ + return n; + } + } + return -1; + } + + static message_t* mForward(message_t* msg) { + message_t* newMsg = msg; + int8_t buf = get_buff(); + call Leds.led2Toggle(); + + if (buf == -1) { + dbg("LQI", "Dropped packet due to no space in queue.\n"); + return msg; + } + + if ((call RouteSelect.selectRoute(msg, 0)) != SUCCESS) { + FwdBufBusy[(uint8_t)buf] = 0; + return msg; + } + + // Failures at the send level do not cause the seq. number space to be + // rolled back properly. This is somewhat broken. + call PacketAcknowledgements.requestAck(msg); + if (call SubSend.send(call AMPacket.destination(msg), + msg, + call SubPacket.payloadLength(msg) == SUCCESS)) { + newMsg = FwdBufList[(uint8_t)buf]; + FwdBufList[(uint8_t)buf] = msg; + } + else{ + FwdBufBusy[(uint8_t)buf] = 0; + sendFailures++; + } + return newMsg; + } + + event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) { + collection_id_t id = call CollectionPacket.getType(msg); + payload += sizeof(lqi_header_t); + len -= sizeof(lqi_header_t); + + if (call RootControl.isRoot()) { + return signal Receive.receive[id](msg, payload, len); + } + else if (signal Intercept.forward[id](msg, payload, len)) { + return mForward(msg); + } + else { + return msg; + } + } + + + event void SubSend.sendDone(message_t* msg, error_t success) { + int8_t buf; + if (!call PacketAcknowledgements.wasAcked(msg) && + call AMPacket.destination(msg) != TOS_BCAST_ADDR && + fail_count < 5){ + call RouteSelect.selectRoute(msg, 1); + if (call SubSend.send(call AMPacket.destination(msg), + msg, + call SubPacket.payloadLength(msg)) == SUCCESS) { + fail_count ++; + } else { + sendFailures++; + } + } + + fail_count = 0; + + buf = is_ours(msg); + + if (buf != -1) { // Msg was from forwarding queue + FwdBufBusy[(uint8_t)buf] = 0; + } else { + signal Send.sendDone(msg, success); + } + } + + + command uint16_t RouteControl.getParent() { + return call RouteSelectCntl.getParent(); + } + + command uint8_t RouteControl.getQuality() { + return call RouteSelectCntl.getQuality(); + } + + command uint8_t RouteControl.getDepth() { + return call RouteSelectCntl.getDepth(); + } + + command uint8_t RouteControl.getOccupancy() { + uint16_t uiOutstanding = (uint16_t)iFwdBufTail - (uint16_t)iFwdBufHead; + uiOutstanding %= FWD_QUEUE_SIZE; + return (uint8_t)uiOutstanding; + } + + + command error_t RouteControl.setUpdateInterval(uint16_t Interval) { + return call RouteSelectCntl.setUpdateInterval(Interval); + } + + command error_t RouteControl.manualUpdate() { + return call RouteSelectCntl.manualUpdate(); + } + + command uint16_t LqiRouteStats.getSendFailures() { + return sendFailures; + } + + command void Packet.clear(message_t* msg) { + + } + + command void* Send.getPayload(message_t* m) { + return call Packet.getPayload(m, NULL); + } + + command uint8_t Send.maxPayloadLength() { + return call Packet.maxPayloadLength(); + } + + command error_t Send.cancel(message_t* m) { + return FAIL; + } + + + command void* Receive.getPayload[collection_id_t id](message_t* msg, uint8_t* len) { + return call Packet.getPayload(msg, len); + } + + command uint8_t Receive.payloadLength[collection_id_t id](message_t* m) { + return call Packet.payloadLength(m); + } + + command void* Snoop.getPayload[collection_id_t id](message_t* msg, uint8_t* len) { + return call Packet.getPayload(msg, len); + } + + command uint8_t Snoop.payloadLength[collection_id_t id](message_t* m) { + return call Packet.payloadLength(m); + } + + command uint8_t Packet.payloadLength(message_t* msg) { + return call SubPacket.payloadLength(msg) - sizeof(lqi_header_t); + } + command void Packet.setPayloadLength(message_t* msg, uint8_t len) { + call SubPacket.setPayloadLength(msg, len + sizeof(lqi_header_t)); + } + command uint8_t Packet.maxPayloadLength() { + return (call SubPacket.maxPayloadLength() - sizeof(lqi_header_t)); + } + command void* Packet.getPayload(message_t* msg, uint8_t* len) { + void* rval = call SubPacket.getPayload(msg, len); + *len -= sizeof(lqi_header_t); + rval += sizeof(lqi_header_t); + return rval; + } + + command am_addr_t CollectionPacket.getOrigin(message_t* msg) { + lqi_header_t* hdr = getHeader(msg); + return hdr->originaddr; + } + + command void CollectionPacket.setOrigin(message_t* msg, am_addr_t addr) { + lqi_header_t* hdr = getHeader(msg); + hdr->originaddr = addr; + } + + command collection_id_t CollectionPacket.getType(message_t* msg) { + return getHeader(msg)->collectId; + } + + command void CollectionPacket.setType(message_t* msg, collection_id_t id) { + getHeader(msg)->collectId = id; + } + + command uint8_t CollectionPacket.getSequenceNumber(message_t* msg) { + lqi_header_t* hdr = getHeader(msg); + return hdr->originseqno; + } + + command void CollectionPacket.setSequenceNumber(message_t* msg, uint8_t seqno) { + lqi_header_t* hdr = getHeader(msg); + hdr->originseqno = seqno; + } + + default event void Send.sendDone(message_t* pMsg, error_t success) {} + default event message_t* Snoop.receive[collection_id_t id](message_t* pMsg, void* payload, uint8_t len) {return pMsg;} + default event message_t* Receive.receive[collection_id_t id](message_t* pMsg, void* payload, uint8_t len) { + return pMsg; + } + default event bool Intercept.forward[collection_id_t id](message_t* pMsg, void* payload, uint16_t len) { + return 1; + } +} + diff --git a/tos/lib/net/lqi/LqiRouteStats.nc b/tos/lib/net/lqi/LqiRouteStats.nc index 02cc56a6..c03f7fba 100644 --- a/tos/lib/net/lqi/LqiRouteStats.nc +++ b/tos/lib/net/lqi/LqiRouteStats.nc @@ -1,3 +1,34 @@ + +/* Copyright (c) 2007 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. + */ + /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. @@ -32,6 +63,7 @@ /** * Provides information on how many send failures there have been. * @author Joe Polastre + * @author Philip Levis (port from TinyOS 1.x) */ diff --git a/tos/lib/net/lqi/LqiRoutingEngineP.nc b/tos/lib/net/lqi/LqiRoutingEngineP.nc new file mode 100644 index 00000000..8a099e88 --- /dev/null +++ b/tos/lib/net/lqi/LqiRoutingEngineP.nc @@ -0,0 +1,380 @@ +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of 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 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 + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ + + + +/** + * + * @author Gilman Tolle + * @author Philip Levis (port to TinyOS 2.x) + */ + + +#include "MultiHopLqi.h" + +module LqiRoutingEngineP { + + provides { + interface Init; + interface StdControl; + interface RouteSelect; + interface RouteControl; + interface RootControl; + } + + uses { + interface Timer; + interface AMSend; + interface Receive; + interface Random; + interface Packet; + interface AMPacket; + interface LqiRouteStats; + interface CC2420Packet; + interface Leds; + } +} + +implementation { + + enum { + BASE_STATION_ADDRESS = 0, + BEACON_PERIOD = 32, + BEACON_TIMEOUT = 8, + }; + + enum { + ROUTE_INVALID = 0xff + }; + + bool isRoot = FALSE; + + message_t msgBuf; + bool msgBufBusy; + + uint16_t gbCurrentParent; + uint16_t gbCurrentParentCost; + uint16_t gbCurrentLinkEst; + uint8_t gbCurrentHopCount; + uint16_t gbCurrentCost; + + uint8_t gLastHeard; + + int16_t gCurrentSeqNo; + + uint16_t gUpdateInterval; + + uint8_t gRecentIndex; + uint16_t gRecentPacketSender[MHOP_HISTORY_SIZE]; + int16_t gRecentPacketSeqNo[MHOP_HISTORY_SIZE]; + + uint8_t gRecentOriginIndex; + uint16_t gRecentOriginPacketSender[MHOP_HISTORY_SIZE]; + int16_t gRecentOriginPacketSeqNo[MHOP_HISTORY_SIZE]; + + uint16_t adjustLQI(uint8_t val) { + uint16_t result = (80 - (val - 50)); + result = (((result * result) >> 3) * result) >> 3; + return result; + } + + lqi_header_t* getHeader(message_t* msg) { + return (lqi_header_t*)call Packet.getPayload(msg, NULL); + } + + lqi_beacon_msg_t* getBeacon(message_t* msg) { + return (lqi_beacon_msg_t*)call Packet.getPayload(msg, NULL); + } + + task void SendRouteTask() { + lqi_beacon_msg_t* bMsg = getBeacon(&msgBuf); + uint8_t length = sizeof(lqi_beacon_msg_t); + + dbg("LQI","MultiHopRSSI Sending route update msg.\n"); + + if (gbCurrentParent != TOS_BCAST_ADDR) { + dbg("LQO","MultiHopRSSI: Parent = %d\n", gbCurrentParent); + } + + if (msgBufBusy) { + post SendRouteTask(); + return; + } + + dbg("LQI","MultiHopRSSI: Current cost: %d.\n", + gbCurrentParentCost + gbCurrentLinkEst); + + if (isRoot) { + bMsg->parent = TOS_NODE_ID; + bMsg->cost = 0; + bMsg->originaddr = TOS_NODE_ID; + bMsg->hopcount = 0; + bMsg->originseqno = gCurrentSeqNo; + bMsg->seqno = gCurrentSeqNo++; + } + else { + bMsg->parent = gbCurrentParent; + bMsg->cost = gbCurrentParentCost + gbCurrentLinkEst; + bMsg->originaddr = TOS_NODE_ID; + bMsg->hopcount = gbCurrentHopCount; + bMsg->originseqno = gCurrentSeqNo; + bMsg->seqno = gCurrentSeqNo++; + } + + if (call AMSend.send(TOS_BCAST_ADDR, &msgBuf, length) == SUCCESS) { + msgBufBusy = TRUE; + } + } + + task void TimerTask() { + uint8_t val; + val = ++gLastHeard; + if (!isRoot && (val > BEACON_TIMEOUT)) { + gbCurrentParent = TOS_BCAST_ADDR; + gbCurrentParentCost = 0x7fff; + gbCurrentLinkEst = 0x7fff; + gbCurrentHopCount = ROUTE_INVALID; + gbCurrentCost = 0xfffe; + } + post SendRouteTask(); + } + + command error_t Init.init() { + int n; + + gRecentIndex = 0; + for (n = 0; n < MHOP_HISTORY_SIZE; n++) { + gRecentPacketSender[n] = TOS_BCAST_ADDR; + gRecentPacketSeqNo[n] = 0; + } + + gRecentOriginIndex = 0; + for (n = 0; n < MHOP_HISTORY_SIZE; n++) { + gRecentOriginPacketSender[n] = TOS_BCAST_ADDR; + gRecentOriginPacketSeqNo[n] = 0; + } + + gbCurrentParent = TOS_BCAST_ADDR; + gbCurrentParentCost = 0x7fff; + gbCurrentLinkEst = 0x7fff; + gbCurrentHopCount = ROUTE_INVALID; + gbCurrentCost = 0xfffe; + + gCurrentSeqNo = 0; + gUpdateInterval = BEACON_PERIOD; + msgBufBusy = FALSE; + + return SUCCESS; + } + + command error_t RootControl.setRoot() { + call Leds.led2On(); + isRoot = TRUE; + return SUCCESS; + } + + command error_t RootControl.unsetRoot() { + isRoot = FALSE; + return SUCCESS; + } + + command bool RootControl.isRoot() { + return isRoot; + } + + command error_t StdControl.start() { + gLastHeard = 0; + call Timer.startOneShot(call Random.rand32() % (1024 * gUpdateInterval)); + return SUCCESS; + } + + command error_t StdControl.stop() { + call Timer.stop(); + return SUCCESS; + } + + command bool RouteSelect.isActive() { + return TRUE; + } + + command error_t RouteSelect.selectRoute(message_t* msg, uint8_t resend) { + int i; + lqi_header_t* hdr = getHeader(msg); + if (isRoot) { + return FAIL; + } + + if (hdr->originaddr != TOS_NODE_ID && resend == 0) { + // supress duplicate packets + for (i = 0; i < MHOP_HISTORY_SIZE; i++) { + if ((gRecentPacketSender[i] == call AMPacket.source(msg)) && + (gRecentPacketSeqNo[i] == hdr->seqno)) { + return FAIL; + } + } + + gRecentPacketSender[gRecentIndex] = call AMPacket.source(msg); + gRecentPacketSeqNo[gRecentIndex] = hdr->seqno; + gRecentIndex = (gRecentIndex + 1) % MHOP_HISTORY_SIZE; + + // supress multihop cycles and try to break out of it + for (i = 0; i < MHOP_HISTORY_SIZE; i++) { + if ((gRecentOriginPacketSender[i] == hdr->originaddr) && + (gRecentOriginPacketSeqNo[i] == hdr->originseqno)) { + gbCurrentParentCost = 0x7fff; + gbCurrentLinkEst = 0x7fff; + gbCurrentParent = TOS_BCAST_ADDR; + gbCurrentHopCount = ROUTE_INVALID; + return FAIL; + } + } + gRecentOriginPacketSender[gRecentOriginIndex] = hdr->originaddr; + gRecentOriginPacketSeqNo[gRecentOriginIndex] = hdr->originseqno; + gRecentOriginIndex = (gRecentOriginIndex + 1) % MHOP_HISTORY_SIZE; + } + + if (resend == 0) { + hdr->seqno = gCurrentSeqNo++; + } + + call AMPacket.setDestination(msg, gbCurrentParent); + + return SUCCESS; + } + + command error_t RouteSelect.initializeFields(message_t* msg) { + lqi_header_t* header = (lqi_header_t*)call Packet.getPayload(msg, NULL); + + header->originaddr = TOS_NODE_ID; + header->originseqno = gCurrentSeqNo; + + if (isRoot) { + header->hopcount = 0; + } + else { + header->hopcount = gbCurrentHopCount; + } + + return SUCCESS; + } + + command uint8_t* RouteSelect.getBuffer(message_t* Msg, uint16_t* Len) { + + } + + + command uint16_t RouteControl.getParent() { + return gbCurrentParent; + } + + command uint8_t RouteControl.getQuality() { + return gbCurrentLinkEst; + } + + command uint8_t RouteControl.getDepth() { + return gbCurrentHopCount; + } + + command uint8_t RouteControl.getOccupancy() { + return 0; + } + + command error_t RouteControl.setUpdateInterval(uint16_t Interval) { + + gUpdateInterval = Interval; + return SUCCESS; + } + + command error_t RouteControl.manualUpdate() { + post SendRouteTask(); + return SUCCESS; + } + + + event void Timer.fired() { + post TimerTask(); + call Timer.startOneShot(1024 * gUpdateInterval + 1); + } + + event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) { + if (isRoot) { + return msg; + } + else { + lqi_beacon_msg_t* bMsg = (lqi_beacon_msg_t*)payload; + am_addr_t source = call AMPacket.source(msg); + uint8_t lqi = call CC2420Packet.getLqi(msg); + + if (source == gbCurrentParent) { + // try to prevent cycles + if (bMsg->parent != TOS_NODE_ID) { + gLastHeard = 0; + gbCurrentParentCost = bMsg->cost; + gbCurrentLinkEst = adjustLQI(lqi); + gbCurrentHopCount = bMsg->hopcount + 1; + } + else { + gLastHeard = 0; + gbCurrentParentCost = 0x7fff; + gbCurrentLinkEst = 0x7fff; + gbCurrentParent = TOS_BCAST_ADDR; + gbCurrentHopCount = ROUTE_INVALID; + } + + } else { + + /* if the message is not from my parent, + compare the message's cost + link estimate to my current cost, + switch if necessary */ + + // make sure you don't pick a parent that creates a cycle + if (((uint32_t) bMsg->cost + (uint32_t) adjustLQI(lqi) + < + ((uint32_t) gbCurrentParentCost + (uint32_t) gbCurrentLinkEst) - + (((uint32_t) gbCurrentParentCost + (uint32_t) gbCurrentLinkEst) >> 2) + ) && + (bMsg->parent != TOS_NODE_ID)) { + gLastHeard = 0; + gbCurrentParent = call AMPacket.source(msg); + gbCurrentParentCost = bMsg->cost; + gbCurrentLinkEst = adjustLQI(lqi); + gbCurrentHopCount = bMsg->hopcount + 1; + } + } + } + + return msg; + } + + event void AMSend.sendDone(message_t* msg, error_t success) { + msgBufBusy = FALSE; + } + +} + diff --git a/tos/lib/net/lqi/MultiHop.h b/tos/lib/net/lqi/MultiHop.h deleted file mode 100644 index e1d2c765..00000000 --- a/tos/lib/net/lqi/MultiHop.h +++ /dev/null @@ -1,101 +0,0 @@ -// $Id$ - -/* tab:4 - * "Copyright (c) 2000-2003 The Regents of the University of 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 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 - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - * Copyright (c) 2002-2003 Intel Corporation - * All rights reserved. - * - * This file is distributed under the terms in the attached INTEL-LICENSE - * file. If you do not find these files, copies can be found by writing to - * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, - * 94704. Attention: Intel License Inquiry. - */ - -/* - * - * Authors: Philip Buonadonna, Crossbow, Gilman Tolle - * Date last modified: 2/20/03 - * - */ - -/** - * @author Philip Buonadonna - */ - - -#ifndef _TOS_MULTIHOP_H -#define _TOS_MULTIHOP_H - -#ifndef MHOP_QUEUE_SIZE -#define MHOP_QUEUE_SIZE 2 -#endif - -#ifndef MHOP_HISTORY_SIZE -#define MHOP_HISTORY_SIZE 4 -#endif - -#include "AM.h" -enum { - AM_BEACONMSG = 250, - AM_DATAMSG = 251, - AM_DEBUGPACKET = 3 -}; - -/* Fields of neighbor table */ -typedef struct TOS_MHopNeighbor { - uint16_t addr; // state provided by nbr - uint16_t recv_count; // since last goodness update - uint16_t fail_count; // since last goodness, adjusted by TOs - uint16_t hopcount; - uint8_t goodness; - uint8_t timeouts; // since last recv -} TOS_MHopNeighbor; - -typedef nx_struct lqi_header { - nx_uint16_t originaddr; - nx_int16_t seqno; - nx_int16_t originseqno; - nx_uint16_t hopcount; -} lqi_header_t; - -typedef nx_struct beacon_msg { - nx_uint16_t originaddr; - nx_int16_t seqno; - nx_int16_t originseqno; - nx_uint16_t parent; - nx_uint16_t cost; - nx_uint16_t hopcount; -} beacon_msg_t; - -typedef struct DBGEstEntry { - uint16_t id; - uint8_t hopcount; - uint8_t sendEst; -} DBGEstEntry; - -typedef struct DebugPacket { -// uint16_t seqno; - uint16_t estEntries; - DBGEstEntry estList[0]; -} DebugPacket; - -#endif /* _TOS_MULTIHOP_H */ - diff --git a/tos/lib/net/lqi/MultiHopLQI.nc b/tos/lib/net/lqi/MultiHopLQI.nc deleted file mode 100644 index f1c18dfb..00000000 --- a/tos/lib/net/lqi/MultiHopLQI.nc +++ /dev/null @@ -1,377 +0,0 @@ -/* tab:4 - * "Copyright (c) 2000-2003 The Regents of the University of 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 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 - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." - * - * Copyright (c) 2002-2003 Intel Corporation - * All rights reserved. - * - * This file is distributed under the terms in the attached INTEL-LICENSE - * file. If you do not find these files, copies can be found by writing to - * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, - * 94704. Attention: Intel License Inquiry. - */ - - - -/* - * Authors: Gilman Tolle - */ - - -#include "MultiHop.h" - -module MultiHopLQI { - - provides { - interface Init; - interface StdControl; - interface RouteSelect; - interface RouteControl; - interface RootControl; - } - - uses { - interface Timer; - interface AMSend; - interface Receive; - interface Random; - interface Packet; - interface AMPacket; - interface LqiRouteStats; - interface CC2420Packet; - interface Leds; - } -} - -implementation { - - enum { - BASE_STATION_ADDRESS = 0, - BEACON_PERIOD = 32, - BEACON_TIMEOUT = 8, - }; - - enum { - ROUTE_INVALID = 0xff - }; - - bool isRoot = FALSE; - - message_t msgBuf; - bool msgBufBusy; - - uint16_t gbCurrentParent; - uint16_t gbCurrentParentCost; - uint16_t gbCurrentLinkEst; - uint8_t gbCurrentHopCount; - uint16_t gbCurrentCost; - - uint8_t gLastHeard; - - int16_t gCurrentSeqNo; - - uint16_t gUpdateInterval; - - uint8_t gRecentIndex; - uint16_t gRecentPacketSender[MHOP_HISTORY_SIZE]; - int16_t gRecentPacketSeqNo[MHOP_HISTORY_SIZE]; - - uint8_t gRecentOriginIndex; - uint16_t gRecentOriginPacketSender[MHOP_HISTORY_SIZE]; - int16_t gRecentOriginPacketSeqNo[MHOP_HISTORY_SIZE]; - - uint16_t adjustLQI(uint8_t val) { - uint16_t result = (80 - (val - 50)); - result = (((result * result) >> 3) * result) >> 3; - return result; - } - - lqi_header_t* getHeader(message_t* msg) { - return (lqi_header_t*)call Packet.getPayload(msg, NULL); - } - beacon_msg_t* getBeacon(message_t* msg) { - return (beacon_msg_t*)call Packet.getPayload(msg, NULL); - } - - task void SendRouteTask() { - beacon_msg_t* bMsg = getBeacon(&msgBuf); - uint8_t length = sizeof(beacon_msg_t); - - dbg("LQI","MultiHopRSSI Sending route update msg.\n"); - - if (gbCurrentParent != TOS_BCAST_ADDR) { - dbg("LQO","MultiHopRSSI: Parent = %d\n", gbCurrentParent); - } - - if (msgBufBusy) { - post SendRouteTask(); - return; - } - - dbg("LQI","MultiHopRSSI: Current cost: %d.\n", - gbCurrentParentCost + gbCurrentLinkEst); - - if (isRoot) { - bMsg->parent = TOS_NODE_ID; - bMsg->cost = 0; - bMsg->originaddr = TOS_NODE_ID; - bMsg->hopcount = 0; - bMsg->originseqno = gCurrentSeqNo; - bMsg->seqno = gCurrentSeqNo++; - } - else { - bMsg->parent = gbCurrentParent; - bMsg->cost = gbCurrentParentCost + gbCurrentLinkEst; - bMsg->originaddr = TOS_NODE_ID; - bMsg->hopcount = gbCurrentHopCount; - bMsg->originseqno = gCurrentSeqNo; - bMsg->seqno = gCurrentSeqNo++; - } - - if (call AMSend.send(TOS_BCAST_ADDR, &msgBuf, length) == SUCCESS) { - msgBufBusy = TRUE; - } - } - - task void TimerTask() { - uint8_t val; - val = ++gLastHeard; - if (!isRoot && (val > BEACON_TIMEOUT)) { - gbCurrentParent = TOS_BCAST_ADDR; - gbCurrentParentCost = 0x7fff; - gbCurrentLinkEst = 0x7fff; - gbCurrentHopCount = ROUTE_INVALID; - gbCurrentCost = 0xfffe; - } - post SendRouteTask(); - } - - command error_t Init.init() { - int n; - - gRecentIndex = 0; - for (n = 0; n < MHOP_HISTORY_SIZE; n++) { - gRecentPacketSender[n] = TOS_BCAST_ADDR; - gRecentPacketSeqNo[n] = 0; - } - - gRecentOriginIndex = 0; - for (n = 0; n < MHOP_HISTORY_SIZE; n++) { - gRecentOriginPacketSender[n] = TOS_BCAST_ADDR; - gRecentOriginPacketSeqNo[n] = 0; - } - - gbCurrentParent = TOS_BCAST_ADDR; - gbCurrentParentCost = 0x7fff; - gbCurrentLinkEst = 0x7fff; - gbCurrentHopCount = ROUTE_INVALID; - gbCurrentCost = 0xfffe; - - gCurrentSeqNo = 0; - gUpdateInterval = BEACON_PERIOD; - msgBufBusy = FALSE; - - return SUCCESS; - } - - command error_t RootControl.setRoot() { - call Leds.led2On(); - isRoot = TRUE; - return SUCCESS; - } - - command error_t RootControl.unsetRoot() { - isRoot = FALSE; - return SUCCESS; - } - - command bool RootControl.isRoot() { - return isRoot; - } - - command error_t StdControl.start() { - gLastHeard = 0; - call Timer.startOneShot(call Random.rand32() % (1024 * gUpdateInterval)); - return SUCCESS; - } - - command error_t StdControl.stop() { - call Timer.stop(); - return SUCCESS; - } - - command bool RouteSelect.isActive() { - return TRUE; - } - - command error_t RouteSelect.selectRoute(message_t* msg, uint8_t resend) { - int i; - lqi_header_t* hdr = getHeader(msg); - if (isRoot) { - return FAIL; - } - - if (hdr->originaddr != TOS_NODE_ID && resend == 0) { - // supress duplicate packets - for (i = 0; i < MHOP_HISTORY_SIZE; i++) { - if ((gRecentPacketSender[i] == call AMPacket.source(msg)) && - (gRecentPacketSeqNo[i] == hdr->seqno)) { - return FAIL; - } - } - - gRecentPacketSender[gRecentIndex] = call AMPacket.source(msg); - gRecentPacketSeqNo[gRecentIndex] = hdr->seqno; - gRecentIndex = (gRecentIndex + 1) % MHOP_HISTORY_SIZE; - - // supress multihop cycles and try to break out of it - for (i = 0; i < MHOP_HISTORY_SIZE; i++) { - if ((gRecentOriginPacketSender[i] == hdr->originaddr) && - (gRecentOriginPacketSeqNo[i] == hdr->originseqno)) { - gbCurrentParentCost = 0x7fff; - gbCurrentLinkEst = 0x7fff; - gbCurrentParent = TOS_BCAST_ADDR; - gbCurrentHopCount = ROUTE_INVALID; - return FAIL; - } - } - gRecentOriginPacketSender[gRecentOriginIndex] = hdr->originaddr; - gRecentOriginPacketSeqNo[gRecentOriginIndex] = hdr->originseqno; - gRecentOriginIndex = (gRecentOriginIndex + 1) % MHOP_HISTORY_SIZE; - } - - if (resend == 0) { - hdr->seqno = gCurrentSeqNo++; - } - - call AMPacket.setDestination(msg, gbCurrentParent); - - return SUCCESS; - } - - command error_t RouteSelect.initializeFields(message_t* msg) { - lqi_header_t* header = (lqi_header_t*)call Packet.getPayload(msg, NULL); - - header->originaddr = TOS_NODE_ID; - header->originseqno = gCurrentSeqNo; - - if (isRoot) { - header->hopcount = 0; - } - else { - header->hopcount = gbCurrentHopCount; - } - - return SUCCESS; - } - - command uint8_t* RouteSelect.getBuffer(message_t* Msg, uint16_t* Len) { - - } - - - command uint16_t RouteControl.getParent() { - return gbCurrentParent; - } - - command uint8_t RouteControl.getQuality() { - return gbCurrentLinkEst; - } - - command uint8_t RouteControl.getDepth() { - return gbCurrentHopCount; - } - - command uint8_t RouteControl.getOccupancy() { - return 0; - } - - command error_t RouteControl.setUpdateInterval(uint16_t Interval) { - - gUpdateInterval = Interval; - return SUCCESS; - } - - command error_t RouteControl.manualUpdate() { - post SendRouteTask(); - return SUCCESS; - } - - - event void Timer.fired() { - post TimerTask(); - call Timer.startOneShot(1024 * gUpdateInterval + 1); - } - - event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) { - if (isRoot) { - return msg; - } - else { - beacon_msg_t* bMsg = (beacon_msg_t*)payload; - am_addr_t source = call AMPacket.source(msg); - uint8_t lqi = call CC2420Packet.getLqi(msg); - - if (source == gbCurrentParent) { - // try to prevent cycles - if (bMsg->parent != TOS_NODE_ID) { - gLastHeard = 0; - gbCurrentParentCost = bMsg->cost; - gbCurrentLinkEst = adjustLQI(lqi); - gbCurrentHopCount = bMsg->hopcount + 1; - } - else { - gLastHeard = 0; - gbCurrentParentCost = 0x7fff; - gbCurrentLinkEst = 0x7fff; - gbCurrentParent = TOS_BCAST_ADDR; - gbCurrentHopCount = ROUTE_INVALID; - } - - } else { - - /* if the message is not from my parent, - compare the message's cost + link estimate to my current cost, - switch if necessary */ - - // make sure you don't pick a parent that creates a cycle - if (((uint32_t) bMsg->cost + (uint32_t) adjustLQI(lqi) - < - ((uint32_t) gbCurrentParentCost + (uint32_t) gbCurrentLinkEst) - - (((uint32_t) gbCurrentParentCost + (uint32_t) gbCurrentLinkEst) >> 2) - ) && - (bMsg->parent != TOS_NODE_ID)) { - gLastHeard = 0; - gbCurrentParent = call AMPacket.source(msg); - gbCurrentParentCost = bMsg->cost; - gbCurrentLinkEst = adjustLQI(lqi); - gbCurrentHopCount = bMsg->hopcount + 1; - } - } - } - - return msg; - } - - event void AMSend.sendDone(message_t* msg, error_t success) { - msgBufBusy = FALSE; - } - -} - diff --git a/tos/lib/net/lqi/MultiHopLqi.h b/tos/lib/net/lqi/MultiHopLqi.h new file mode 100644 index 00000000..a7d1e82a --- /dev/null +++ b/tos/lib/net/lqi/MultiHopLqi.h @@ -0,0 +1,139 @@ +// $Id$ + + +/* Copyright (c) 2007 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. + */ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of 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 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 + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ + +/* + * + * Authors: Philip Buonadonna, Crossbow, Gilman Tolle + * Date last modified: 2/20/03 + * + */ + +/** + * @author Philip Buonadonna + * @author Philip Levis (port from TinyOS 1.x) + */ + + +#ifndef _TOS_MULTIHOP_H +#define _TOS_MULTIHOP_H + +#ifndef MHOP_QUEUE_SIZE +#define MHOP_QUEUE_SIZE 2 +#endif + +#ifndef MHOP_HISTORY_SIZE +#define MHOP_HISTORY_SIZE 4 +#endif + +#include "AM.h" +#include "Collection.h" + +#define UQ_LQI_CLIENT "LqiForwardingEngineP.Send" + +enum { + AM_LQI_BEACON_MSG = 250, + AM_LQI_DATA_MSG = 251, + AM_LQI_DEBUG_PACKET = 3, + NUM_LQI_CLIENTS = uniqueCount(UQ_LQI_CLIENT), +}; + +/* Fields of neighbor table */ +typedef struct TOS_MHopNeighbor { + uint16_t addr; // state provided by nbr + uint16_t recv_count; // since last goodness update + uint16_t fail_count; // since last goodness, adjusted by TOs + uint16_t hopcount; + uint8_t goodness; + uint8_t timeouts; // since last recv +} TOS_MHopNeighbor; + +typedef nx_struct lqi_data_msg { + nx_uint16_t originaddr; + nx_int16_t seqno; + nx_int16_t originseqno; + nx_uint16_t hopcount; + nx_collection_id_t collectId; +} lqi_header_t; + +typedef nx_struct lqi_beacon_msg { + nx_uint16_t originaddr; + nx_int16_t seqno; + nx_int16_t originseqno; + nx_uint16_t parent; + nx_uint16_t cost; + nx_uint16_t hopcount; +} lqi_beacon_msg_t; + +typedef struct DBGEstEntry { + uint16_t id; + uint8_t hopcount; + uint8_t sendEst; +} DBGEstEntry; + +typedef struct DebugPacket { +// uint16_t seqno; + uint16_t estEntries; + DBGEstEntry estList[0]; +} DebugPacket; + +#endif /* _TOS_MULTIHOP_H */ + diff --git a/tos/lib/net/lqi/MultiHopLqiP.nc b/tos/lib/net/lqi/MultiHopLqiP.nc new file mode 100644 index 00000000..4b84194a --- /dev/null +++ b/tos/lib/net/lqi/MultiHopLqiP.nc @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2007 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. + */ +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of 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 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 + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF 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 CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ + +/** + * @author Joe Polastre + * @author Philip Levis (port to TinyOS 2.x) + */ + +#include "MultiHopLqi.h" + +configuration MultiHopLqiP { + provides { + interface StdControl; + interface Send; + interface Receive[collection_id_t id]; + interface Receive as Snoop[collection_id_t]; + interface Intercept[collection_id_t id]; + interface RouteControl; + interface LqiRouteStats; + interface Packet; + interface RootControl; + interface CollectionPacket; + } + +} + +implementation { + + components LqiForwardingEngineP as Forwarder, LqiRoutingEngineP as Router; + components + new AMSenderC(AM_LQI_BEACON_MSG) as BeaconSender, + new AMReceiverC(AM_LQI_BEACON_MSG) as BeaconReceiver, + new AMSenderC(AM_LQI_DATA_MSG) as DataSender, + new AMReceiverC(AM_LQI_DATA_MSG) as DataReceiver, + new TimerMilliC(), + NoLedsC, LedsC, + RandomC, + ActiveMessageC, + MainC; + + MainC.SoftwareInit -> Forwarder; + MainC.SoftwareInit -> Router; + + components CC2420ActiveMessageC as CC2420; + + StdControl = Router.StdControl; + + Receive = Forwarder.Receive; + Send = Forwarder; + Intercept = Forwarder.Intercept; + Snoop = Forwarder.Snoop; + RouteControl = Forwarder; + LqiRouteStats = Forwarder; + Packet = Forwarder; + CollectionPacket = Forwarder; + RootControl = Router; + + Forwarder.RouteSelectCntl -> Router.RouteControl; + Forwarder.RouteSelect -> Router; + Forwarder.SubSend -> DataSender; + Forwarder.SubReceive -> DataReceiver; + Forwarder.Leds -> LedsC; + Forwarder.AMPacket -> ActiveMessageC; + Forwarder.SubPacket -> ActiveMessageC; + Forwarder.PacketAcknowledgements -> ActiveMessageC; + Forwarder.RootControl -> Router; + + Router.AMSend -> BeaconSender; + Router.Receive -> BeaconReceiver; + Router.Random -> RandomC; + Router.Timer -> TimerMilliC; + Router.LqiRouteStats -> Forwarder; + Router.CC2420Packet -> CC2420; + Router.AMPacket -> ActiveMessageC; + Router.Packet -> ActiveMessageC; + Router.Leds -> NoLedsC; +} diff --git a/tos/lib/net/lqi/RouteControl.nc b/tos/lib/net/lqi/RouteControl.nc index fecba989..4345af03 100644 --- a/tos/lib/net/lqi/RouteControl.nc +++ b/tos/lib/net/lqi/RouteControl.nc @@ -1,5 +1,35 @@ // $Id$ +/* + * Copyright (c) 2007 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. + */ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. @@ -37,6 +67,7 @@ /** * Control/Monitor interface to a routing component * @author Phil Buonadonna + * @author Philip Levis (port from TinyOS 1.x) */ interface RouteControl { diff --git a/tos/lib/net/lqi/RouteSelect.nc b/tos/lib/net/lqi/RouteSelect.nc index ab63783a..db69a35e 100644 --- a/tos/lib/net/lqi/RouteSelect.nc +++ b/tos/lib/net/lqi/RouteSelect.nc @@ -1,5 +1,34 @@ // $Id$ +/* Copyright (c) 2007 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. + */ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved.