[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/tymo/mh MHControl.nc, NONE, 1.1 MHEngineM.nc, NONE, 1.1 MHPacketM.nc, NONE, 1.1 MHServiceC.nc, NONE, 1.1 mhpacket.h, NONE, 1.1

Romain Thouvenin strabest at users.sourceforge.net
Mon Feb 18 12:25:12 PST 2008


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/tymo/mh
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24227/tymo/mh

Added Files:
	MHControl.nc MHEngineM.nc MHPacketM.nc MHServiceC.nc 
	mhpacket.h 
Log Message:
Initial tymo commit

--- NEW FILE: MHControl.nc ---
interface MHControl {

  event void msgReceived(message_t * msg);

  event void sendFailed(message_t * msg, uint8_t why);

}

--- NEW FILE: MHEngineM.nc ---
/*
 * Copyright (c) 2007 Romain Thouvenin <romain.thouvenin at gmail.com>
 * Published under the terms of the GNU General Public License (GPLv2).
 */

#include "routing.h"

/**
 * MHEngineM - Implements a simple transport protocol, which is
 * nothing more than AM on top of the existing AM stack.
 *
 * @author Romain Thouvenin
 */
module MHEngineM {
  provides interface RouteSelect;
  uses {
    interface AMPacket as MHPacket;
    interface AMPacket;
    interface RoutingTable;
  }
}

implementation {

  rt_info_t info;

  command fw_action_t RouteSelect.selectRoute(message_t * msg, addr_t * destination, uint8_t * am_type){
    dbg("mhe", "MHE: Somebody wants a route, let's see...\n");
    if( call MHPacket.isForMe(msg) 
	|| (destination && (*destination == call MHPacket.address())) ){
      
      *am_type = call MHPacket.type(msg);
      return FW_RECEIVE;

    } else {
      
      error_t e;
      if(destination)
	e = call RoutingTable.getRoute(*destination, &info);
      else
	e = call RoutingTable.getForwardingRoute(call MHPacket.destination(msg), &info);

      if(e == SUCCESS){

	dbg("mhe", "MHE: I've selected a route to %u through %u.\n", info.address, info.nexthop);
	call AMPacket.setDestination(msg, info.nexthop);

	if(destination){
	  call MHPacket.setType(msg, *am_type);
	  call MHPacket.setDestination(msg, *destination);
	  call MHPacket.setSource(msg, call MHPacket.address());
	} else {
	  *am_type = call MHPacket.type(msg);
	}
	return FW_SEND;

      } else if(e == EBUSY){
	dbg("mhe", "MHE: No route is available for now.\n");
	return FW_WAIT;
      } else {
	dbg("mhe", "MHE: I'm discarding the message.\n");
	return FW_DISCARD;
      }

    }
  }

  event void RoutingTable.evicted(const rt_info_t * rt_info, reason_t r){}

}

--- NEW FILE: MHPacketM.nc ---
/*
 * Copyright (c) 2007 Romain Thouvenin <romain.thouvenin at gmail.com>
 * Published under the terms of the GNU General Public License (GPLv2).
 */

#include "mhpacket.h"

#define HEADER  ((mhpacket_header_t *)(call SubPacket.getPayload(amsg, call SubPacket.maxPayloadLength())))

/**
 * MHPacketM - Implements ActiveMessage on top of ActiveMessage,
 * to transport data in a multihop network.
 *
 * @author Romain Thouvenin
 */

module MHPacketM {
  provides {
    interface Packet;
    interface AMPacket as MHPacket;
  }
  uses {
    interface Packet as SubPacket;
    interface AMPacket;
  }
}

implementation {
  
  /**********
   * Packet *
   **********/

  command void Packet.clear(message_t *msg){
    call SubPacket.clear(msg);
  }

  command void * Packet.getPayload(message_t *msg, uint8_t len){
    nx_uint8_t * p = call SubPacket.getPayload(msg, len);
    return (void *)(p + sizeof(mhpacket_header_t));
  }

  command uint8_t Packet.maxPayloadLength(){
    return call SubPacket.maxPayloadLength() - sizeof(mhpacket_header_t);
  }

  command uint8_t Packet.payloadLength(message_t *amsg){
    return HEADER->len;
  }

  command void Packet.setPayloadLength(message_t *amsg, uint8_t len){
    HEADER->len = len;
    call SubPacket.setPayloadLength(amsg, len + sizeof(mhpacket_header_t));
  }

  
  /**********
   * AMPacket *
   **********/

  command am_addr_t MHPacket.address(){
    return call AMPacket.address();
  }

  command am_addr_t MHPacket.destination(message_t *amsg){
    return HEADER->dest;
  }

  command bool MHPacket.isForMe(message_t *amsg){
    return ((HEADER->dest == call MHPacket.address()) || (HEADER->dest == AM_BROADCAST_ADDR));
  }

  command void MHPacket.setDestination(message_t *amsg, am_addr_t addr){
    HEADER->dest = addr;
  }

  command void MHPacket.setSource(message_t *amsg, am_addr_t addr){
    HEADER->src = addr;
  }

  command void MHPacket.setType(message_t *amsg, am_id_t t){
    HEADER->type = t;
    call AMPacket.setType(amsg, AM_MULTIHOP);
  }

  command am_addr_t MHPacket.source(message_t *amsg){
    return HEADER->src;
  }

  command am_id_t MHPacket.type(message_t *amsg){
    return HEADER->type;
  }

  /* *** UNIMPLEMENTED ! *** */
  //TODO what to do with this?

  command am_group_t MHPacket.group(message_t* amsg) {
    return 0;
  }

  command void MHPacket.setGroup(message_t* amsg, am_group_t grp) { }

  command am_group_t MHPacket.localGroup() {
    return 0;
  }

}

--- NEW FILE: MHServiceC.nc ---
/*
 * Copyright (c) 2007 Romain Thouvenin <romain.thouvenin at gmail.com>
 * Published under the terms of the GNU General Public License (GPLv2).
 */

/**
 * MHServiceC - Implements a simple multihop transport protocol
 *
 * @author Romain Thouvenin
 */

configuration MHServiceC {
  provides { //For upper layer
    interface AMSend as MHSend[uint8_t id];
    interface Receive[uint8_t id];
    interface Intercept[uint8_t id];
    interface AMPacket as MHPacket;
    interface Packet;
    interface LinkMonitor;
  }
  uses {  //From lower layer
    interface AMPacket;
    interface Packet as SubPacket;
    interface AMSend;
    interface Receive as SubReceive;
    interface PacketAcknowledgements as Acks;
  }

  provides interface MHControl;
}

implementation {
  components DymoTableC, MHEngineM, MHPacketM;
  components new ForwardingEngineM(), new TimerMilliC();

  //provides
  MHSend      = ForwardingEngineM.AMSend;
  Receive     = ForwardingEngineM.Receive;
  Intercept   = ForwardingEngineM.Intercept;
  LinkMonitor = ForwardingEngineM.LinkMonitor;
  MHPacket    = MHPacketM.MHPacket;
  Packet      = MHPacketM.Packet;
  Acks        = ForwardingEngineM.Acks;

  //uses
  ForwardingEngineM.AMPacket   = AMPacket;  
  MHEngineM.AMPacket	       = AMPacket;  
  MHPacketM.AMPacket	       = AMPacket;  
  MHPacketM.SubPacket	       = SubPacket; 
  ForwardingEngineM.SubPacket  = SubPacket; 
  ForwardingEngineM.SubSend    = AMSend;    
  ForwardingEngineM.SubReceive = SubReceive;

  //MHEngine
  MHEngineM.MHPacket     -> MHPacketM.MHPacket;
  MHEngineM.RoutingTable -> DymoTableC;

  //ForwardingEngine
  ForwardingEngineM.RouteSelect -> MHEngineM;
  ForwardingEngineM.PPacket     -> MHPacketM.Packet;
  ForwardingEngineM.Timer       -> TimerMilliC;

  MHControl = ForwardingEngineM.MHControl;
}

--- NEW FILE: mhpacket.h ---
#ifndef MHPACKET_H
#define MHPACKET_H

#include "AM.h"
#include "message.h"
#include "routing.h"

typedef nx_struct mhpacket_header {
  nx_uint8_t len;
  nx_uint8_t type;
  nx_am_addr_t src;
  nx_am_addr_t dest;
} mhpacket_header_t;

typedef nx_struct mhpacket {
  mhpacket_header_t header;
  nx_uint8_t data[];
} mhpacket_t;

enum { //for mig
  AM_MHPACKET = AM_MULTIHOP,
};

#endif



More information about the Tinyos-2-commits mailing list