Skip to content
Permalink
Browse files

Merge pull request #377 from mcerveny/multi-hop-forwarding-with-babel…

…-routing

Multi hop forwarding with babel routing
  • Loading branch information
cire831 committed Mar 11, 2017
2 parents ea12cb4 + 4fdd618 commit 1e42e1891e83168a319673382f6d4f04d11d4872
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2012 Martin Cerveny
* 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 copyright holders 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 COPYRIGHT HOLDER OR 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 application sends periodically unicast hello packet to all known destinations.
* Packet is send/received with multihop (MHSenderC/MHReceiverC).
* Routing to multihop engine is provided by babel routing protocol (BabelRoutingC).
* All destination is enumerated from routing table of babel routing protocol (BabelRoutingC.RoutingTable).
*
* @author Martin Cerveny
**/

configuration MHHelloAppC {
}
implementation {
components MainC, MHHelloC, LedsC;
components new TimerMilliC() as Timer;

MHHelloC->MainC.Boot;

MHHelloC.Timer->Timer;
MHHelloC.Leds->LedsC;

components SerialPrintfC;

components LocalIeeeEui64C;
MHHelloC.LocalIeeeEui64->LocalIeeeEui64C;

components ActiveMessageAddressC;
MHHelloC.ActiveMessageAddress->ActiveMessageAddressC;

// L4
components new MHSenderC(0x80+1);
MHHelloC.Packet->MHSenderC;
MHHelloC.AMPacket->MHSenderC;
MHHelloC.AMSend->MHSenderC;
components new MHReceiverC(0x80+1);
MHHelloC.Receive -> MHReceiverC;

// routing (need L3 packet access)
components BabelRoutingC;
components MultiHopC;
BabelRoutingC.RouteSelect<-MultiHopC.RouteSelect;
BabelRoutingC.Packet->MultiHopC.Packet;
BabelRoutingC.AMPacket->MultiHopC.AMPacket;

// other
MHHelloC.RoutingTable->BabelRoutingC.RoutingTable;
MHHelloC.MHControl->MultiHopC.SplitControl;

components ActiveMessageC;
MHHelloC.SubAMPacket -> ActiveMessageC.AMPacket;
}
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2012 Martin Cerveny
* 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 copyright holders 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 COPYRIGHT HOLDER OR 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.
*/

/**
* Implementation of application.
*
* @author Martin Cerveny
**/

#include "Timer.h"
#define NEW_PRINTF_SEMANTICS 1
#include "printf.h"

#include "IeeeEui64.h"
#include "MH.h"
#include "Babel.h"

module MHHelloC {
uses interface Timer<TMilli> as Timer;
uses interface Leds;
uses interface Boot;

uses interface LocalIeeeEui64;

uses interface ActiveMessageAddress;

// L3/L4
uses interface Packet;
uses interface AMPacket;
uses interface AMSend;
uses interface Receive;
uses interface TableReader as RoutingTable;
uses interface SplitControl as MHControl;

// L2
uses interface AMPacket as SubAMPacket;
}
implementation {

uint16_t mhcnt = 0; // incrementing counter
bool mhbusy = FALSE; // busy send layer flag
message_t mhpkt; // send packet
am_addr_t row = AM_BROADCAST_ADDR; // row pointer in routing table, initialized with invalid unicast address

event void Boot.booted() {
uint16_t nodeid;
ieee_eui64_t eui;

// set unique short address (if not unique babel reassign address)
eui = call LocalIeeeEui64.getId();
nodeid = (eui.data[0] | (eui.data[1] << 8)) ^ (eui.data[2] | (eui.data[3] << 8)) ^ (eui.data[4] | (eui.data[5] << 8)) ^ (eui.data[6] | (eui.data[7] << 8));
if(( ! nodeid) || ( ! (~nodeid)))
nodeid = 1;
call ActiveMessageAddress.setAddress(TOS_AM_GROUP, nodeid);

printf("APPL: EUI %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X NODEID %04X\n", eui.data[7], eui.data[6], eui.data[5], eui.data[4], eui.data[3], eui.data[2], eui
.data[1], eui.data[0], nodeid);
printfflush();

call MHControl.start();
}

event void MHControl.startDone(error_t err) {
if(err == SUCCESS) {
printf("APPL: started\n");
call Timer.startPeriodic(200);
}
else {
printf("APPL start error\n");
}
printfflush();
}

event void MHControl.stopDone(error_t err) {
}

async event void ActiveMessageAddress.changed() {
}

event void AMSend.sendDone(message_t * msg, error_t error) {
if(&mhpkt == msg) {
mhbusy = FALSE;
printf("APPL: txdone %d\n", error);
printfflush();
call Leds.led2Off();
}
}

event message_t * Receive.receive(message_t * msg, void * payload, uint8_t len) {

if(len == sizeof(uint16_t)) {
uint16_t * btrpkt = (uint16_t * ) payload;

call Leds.led1On();
printf("APPL: rxdone: cnt %u L3: %04X L2: %04X\n", *btrpkt, call AMPacket.source(msg), call SubAMPacket.source(msg));
printfflush();
call Leds.led1Off();
}
return msg;
}

event void Timer.fired() {

if( ! mhbusy) {
am_addr_t addr;
uint16_t * btrpkt;

if(call RoutingTable.rowNext(&row, sizeof(row)) != SUCCESS) {
if(call RoutingTable.rowFirst(&row, sizeof(row)) != SUCCESS) {
printf("APPL: empty routing table\n");
return;
}
else
mhcnt++;
}
if(call RoutingTable.colRead(&row, BABEL_RT_NODEID, &addr, sizeof(addr)) != SUCCESS) {
printf("APPL: fail to read nodeid\n");
return;
}
if(addr == call ActiveMessageAddress.amAddress()) {
return;
}

btrpkt = (uint16_t * )(call Packet.getPayload(&mhpkt, sizeof(uint16_t)));
*btrpkt = mhcnt;
call Leds.led2On();
printf("APPL: tx cnt %u node %04X\n", mhcnt, addr);
if(call AMSend.send(addr, &mhpkt, sizeof(uint16_t)) == SUCCESS) {
mhbusy = TRUE;
}
printfflush();
}
}

}
@@ -0,0 +1,16 @@
README for MHHello
Author/Contact: Martin Cerveny

Description:

This is testing application for multihop forwarding with babel routing.
The application sends periodically unicast hello packet to all known destinations.
Packet is send/received with multihop (MHSenderC/MHReceiverC).
Routing to multihop engine is provided by babel routing protocol (BabelRoutingC).
All destination is enumerated from routing table of babel routing protocol (BabelRoutingC.RoutingTable).

Tools:

Known bugs/limitations:

beta stage
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2006 Stanford University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the copyright holder 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 COPYRIGHT HOLDER OR 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 active message send abstraction. Each instantiation
* of MHSenderC has its own queue of depth one. Therefore, it does not
* have to contend with other MHSenderC instantiations for queue space.
* The underlying implementation schedules the packets in these queues
* using some form of fair-share queuing.
*
* This source is derived from DirectAMSenderC.
*
* @author Philip Levis
* @author Martin Cerveny
* @see TEP 116: Packet Protocols
*/

#include "MH_private.h"

generic configuration DirectMHSenderC(am_id_t AMId) {
provides {
interface AMSend;
interface Packet;
interface AMPacket;
interface PacketAcknowledgements as Acks;
}
}

implementation {
components new AMQueueEntryP(AMId) as AMQueueEntryP;
components MHQueueP, MultiHopC;

AMQueueEntryP.Send -> MHQueueP.Send[unique(UQ_MHQUEUE_SEND)];
AMQueueEntryP.AMPacket -> MultiHopC;

AMSend = AMQueueEntryP;
Packet = MultiHopC;
AMPacket = MultiHopC;
Acks = MultiHopC;
}

0 comments on commit 1e42e18

Please sign in to comment.
You can’t perform that action at this time.