A quick and dirty service registry daemon hack. The servreg-hack

allows a program to register an 8-bit service ID that gets
disseminated to the entire network, as long as a servreg-hack daemon
is running on all neighbors. Other nodes can look up the service ID to
figure out what nodes in the network offer this service.

This is officially labeled as a "hack" so that we don't get too comfy
with it; this hack is not the future of service discovery and
advertisement in Contiki.
This commit is contained in:
adamdunkels 2010-06-15 19:00:28 +00:00
parent a84cc7c8a0
commit 5dc55f0a1b
6 changed files with 1013 additions and 0 deletions

View File

@ -0,0 +1,369 @@
/** \addtogroup servreghack
* @{ */
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
* $Id: servreg-hack.c,v 1.1 2010/06/15 19:00:28 adamdunkels Exp $
*/
/**
* \file
* Implementation of the servreg-hack application
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/uip.h"
#include "net/uip-ds6.h"
#include "servreg-hack.h"
#include <stdio.h>
struct servreg_hack_registration {
struct servreg_hack_registration *next;
struct timer timer;
uip_ipaddr_t addr;
servreg_hack_id_t id;
uint8_t seqno;
};
#define MAX_REGISTRATIONS 16
LIST(others_services);
LIST(own_services);
MEMB(registrations, struct servreg_hack_registration, MAX_REGISTRATIONS);
PROCESS(servreg_hack_process, "Service regstry hack");
#define PERIOD_TIME 120 * CLOCK_SECOND
#define NEW_REG_TIME 10 * CLOCK_SECOND
#define MAX_BUFSIZE 2 + 80
#define UDP_PORT 61616
#define LIFETIME 10 * 60 * CLOCK_SECOND
#define SEQNO_LT(a, b) ((signed char)((a) - (b)) < 0)
static struct etimer sendtimer;
/*---------------------------------------------------------------------------*/
/* Go through the list of registrations and remove those that are too
old. */
static void
purge_registrations(void)
{
struct servreg_hack_registration *t;
for(t = list_head(others_services);
t != NULL;
t = list_item_next(t)) {
if(timer_expired(&t->timer)) {
list_remove(others_services, t);
memb_free(&registrations, t);
t = list_head(others_services);
}
}
}
/*---------------------------------------------------------------------------*/
void
servreg_hack_init(void)
{
list_init(others_services);
list_init(own_services);
memb_init(&registrations);
process_start(&servreg_hack_process, NULL);
}
/*---------------------------------------------------------------------------*/
void
servreg_hack_register(servreg_hack_id_t id)
{
servreg_hack_item_t *t;
struct servreg_hack_registration *r;
/* Walk through list, see if we already have a service ID
registered. If not, allocate a new registration and put it on our
list. If we cannot allocate a service registration, we reuse one
from the service registrations made by others. */
for(t = list_head(own_services);
t != NULL;
t = list_item_next(t)) {
if(servreg_hack_item_id(t) == id) {
return;
}
}
r = memb_alloc(&registrations);
if(r == NULL) {
printf("servreg_hack_register: error, could not allocate memory, should reclaim another registration but this has not been implemented yet.\n");
return;
}
r->id = id;
r->seqno = 1;
list_push(own_services, r);
PROCESS_CONTEXT_BEGIN(&servreg_hack_process);
etimer_set(&sendtimer, random_rand() % (NEW_REG_TIME));
PROCESS_CONTEXT_END(&servreg_hack_process);
}
/*---------------------------------------------------------------------------*/
servreg_hack_item_t *
servreg_hack_list_head(void)
{
purge_registrations();
return list_head(others_services);
}
/*---------------------------------------------------------------------------*/
servreg_hack_id_t
servreg_hack_item_id(servreg_hack_item_t *item)
{
return ((struct servreg_hack_registration *)item)->id;
}
/*---------------------------------------------------------------------------*/
uip_ipaddr_t *
servreg_hack_item_address(servreg_hack_item_t *item)
{
return &((struct servreg_hack_registration *)item)->addr;
}
/*---------------------------------------------------------------------------*/
uip_ipaddr_t *
servreg_hack_lookup(servreg_hack_id_t id)
{
servreg_hack_item_t *t;
purge_registrations();
for(t = servreg_hack_list_head(); t != NULL; t = list_item_next(t)) {
if(servreg_hack_item_id(t) == id) {
return servreg_hack_item_address(t);
}
}
return NULL;
}
/*---------------------------------------------------------------------------*/
static void
handle_incoming_reg(const uip_ipaddr_t *owner, servreg_hack_id_t id, uint8_t seqno)
{
servreg_hack_item_t *t;
struct servreg_hack_registration *r;
/* Walk through list, see if we already have a service ID
registered. If so, we do different things depending on the seqno
of the update: if the seqno is older than what we have, we
discard the incoming registration. If the seqno is newer than
what we have, we reset the lifetime timer of the current
registration.
If we did not have the service registered already, we allocate a
new registration and put it on our list. If we cannot allocate a
service registration, we discard the incoming registration (for
now - we might later choose to discard the oldest registration
that we have). */
/* printf("Handle incoming reg id %d seqno %d\n", id, seqno);*/
for(t = servreg_hack_list_head();
t != NULL;
t = list_item_next(t)) {
if(servreg_hack_item_id(t) == id) {
r = t;
if(SEQNO_LT(r->seqno, seqno)) {
r->seqno = seqno;
timer_set(&r->timer, LIFETIME);
/* Put item first on list, so that subsequent lookups will
find this one. */
list_remove(others_services, r);
list_push(others_services, r);
}
return;
}
}
r = memb_alloc(&registrations);
if(r == NULL) {
printf("servreg_hack_register: error, could not allocate memory, should reclaim another registration but this has not been implemented yet.\n");
return;
}
r->id = id;
r->seqno = 1;
uip_ipaddr_copy(&r->addr, owner);
timer_set(&r->timer, LIFETIME);
list_add(others_services, r);
}
/*---------------------------------------------------------------------------*/
/*
* The structure of UDP messages:
*
* +-------------------+-------------------+
* | Numregs (1 byte) | Flags (1 byte) |
* +-------------------+-------------------+-------------------+
* | IP addr (16 bytes)| 3 regs (3 bytes) | Seqno (1 byte) |
* +-------------------+-------------------+-------------------+
* | IP addr (16 bytes)| 3 regs (3 bytes) | Seqno (1 byte) |
* +-------------------+-------------------+-------------------+
* | ... | ... | ... |
* +-------------------+-------------------+-------------------+
*/
#define MSG_NUMREGS_OFFSET 0
#define MSG_FLAGS_OFFSET 1
#define MSG_ADDRS_OFFSET 2
#define MSG_IPADDR_SUBOFFSET 0
#define MSG_REGS_SUBOFFSET 16
#define MSG_SEQNO_SUBOFFSET 19
#define MSG_ADDRS_LEN 20
/*---------------------------------------------------------------------------*/
static void
send_udp_packet(struct uip_udp_conn *conn)
{
int numregs;
uint8_t buf[MAX_BUFSIZE];
int bufptr;
servreg_hack_item_t *t;
uip_ds6_addr_t *addr;
addr = uip_ds6_get_global(-1);
buf[MSG_FLAGS_OFFSET] = 0;
numregs = 0;
bufptr = MSG_ADDRS_OFFSET;
if(addr != NULL) {
for(t = list_head(own_services);
(bufptr + MSG_ADDRS_LEN <= MAX_BUFSIZE) && t != NULL;
t = list_item_next(t)) {
uip_ipaddr_copy((uip_ipaddr_t *)&buf[bufptr + MSG_IPADDR_SUBOFFSET],
&addr->ipaddr);
buf[bufptr + MSG_REGS_SUBOFFSET] =
servreg_hack_item_id(t);
buf[bufptr + MSG_REGS_SUBOFFSET + 1] =
buf[bufptr + MSG_REGS_SUBOFFSET + 2] = 0;
buf[bufptr + MSG_SEQNO_SUBOFFSET] = ((struct servreg_hack_registration *)t)->seqno;
bufptr += MSG_ADDRS_LEN;
++numregs;
}
}
for(t = servreg_hack_list_head();
(bufptr + MSG_ADDRS_LEN <= MAX_BUFSIZE) && t != NULL;
t = list_item_next(t)) {
uip_ipaddr_copy((uip_ipaddr_t *)&buf[bufptr + MSG_IPADDR_SUBOFFSET],
servreg_hack_item_address(t));
buf[bufptr + MSG_REGS_SUBOFFSET] =
servreg_hack_item_id(t);
buf[bufptr + MSG_REGS_SUBOFFSET + 1] =
buf[bufptr + MSG_REGS_SUBOFFSET + 2] = 0;
buf[bufptr + MSG_SEQNO_SUBOFFSET] = ((struct servreg_hack_registration *)t)->seqno;
bufptr += MSG_ADDRS_LEN;
++numregs;
}
/* printf("send_udp_packet numregs %d\n", numregs);*/
buf[MSG_NUMREGS_OFFSET] = numregs;
if(numregs > 0) {
/* printf("Sending buffer len %d\n", bufptr);*/
uip_udp_packet_send(conn, buf, bufptr);
}
}
/*---------------------------------------------------------------------------*/
static void
parse_incoming_packet(const u8_t *buf, int len)
{
int numregs;
int flags;
int i;
int bufptr;
numregs = buf[MSG_NUMREGS_OFFSET];
flags = buf[MSG_FLAGS_OFFSET];
/* printf("Numregs %d flags %d\n", numregs, flags);*/
bufptr = MSG_ADDRS_OFFSET;
for(i = 0; i < numregs; ++i) {
handle_incoming_reg((uip_ipaddr_t *)&buf[bufptr + MSG_IPADDR_SUBOFFSET],
buf[bufptr + MSG_REGS_SUBOFFSET],
buf[bufptr + MSG_SEQNO_SUBOFFSET]);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(servreg_hack_process, ev, data)
{
static struct etimer periodic;
static struct uip_udp_conn *outconn, *inconn;
PROCESS_BEGIN();
/* Create outbound UDP connection. */
outconn = udp_broadcast_new(HTONS(UDP_PORT), NULL);
udp_bind(outconn, HTONS(UDP_PORT));
/* Create inbound UDP connection. */
inconn = udp_new(NULL, HTONS(UDP_PORT), NULL);
udp_bind(inconn, HTONS(UDP_PORT));
etimer_set(&periodic, PERIOD_TIME);
etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
while(1) {
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER && data == &periodic) {
etimer_reset(&periodic);
etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
} else if(ev == PROCESS_EVENT_TIMER && data == &sendtimer) {
send_udp_packet(outconn);
} else if(ev == tcpip_event) {
parse_incoming_packet(uip_appdata, uip_datalen());
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,150 @@
/** \addtogroup apps
* @{ */
/**
* \defgroup servreghack A service registration and diseemination hack
* @{
*
* This application is a quick'n'dirty hack for registering,
* disseminating, and looking up services. A service is identified by
* an 8-bit integer between 1 and 255. Integers below 128 are reserved
* for system services.
*
* A service is registered with the function
* servreg_hack_register(). Registered services will be transmitted to
* all neighbors that run the servreg-hack application. These will in
* turn resend the registration to their neighbors.
*
* Services from neighbors are stored in a local table. Services
* stored in the table can be looked up using a combination of the
* servreg_hack_list() and servreg_hack_item_match() functions.
*
*/
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
* $Id: servreg-hack.h,v 1.1 2010/06/15 19:00:28 adamdunkels Exp $
*/
/**
* \file
* Header file for the servreg-hack application
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef SERVREG_HACK_H
#define SERVREG_HACK_H
#include "contiki-conf.h"
#include "net/uip.h"
typedef uint8_t servreg_hack_id_t;
typedef void servreg_hack_item_t;
/**
* \brief Initialize and start the servreg-hack application
*
* This function initializes and starts the servreg-hack
* application and daemon.
*/
void servreg_hack_init(void);
/**
* \brief Register that this node provides a service
* \param service_id The 8-bit ID for the service
*
* This function is used to register a
* service. Registering a service means that other nodes
* in the network will become aware that this node
* provides this service. The servreg-hack application
* does not specify what this service means, nor does it
* provide any mechanism by which the service can be
* reached: this is up to the application that uses the
* servreg-hack application.
*/
void servreg_hack_register(servreg_hack_id_t service_id);
/**
* \brief Get the IP address of a node offering a service
* \param service_id The service ID of the service
* \return A pointer to the IP address of the node, or NULL if the service was not known
*
* This function returns the address of the node offering
* a specific service. If the service is not known, the
* function returns NULL. If there are more than one nodes
* offering the service, this function returns the address
* of the node that most recently announced its service.
*
* To get a list of all nodes offering a specific service,
* use the servreg_hack_list_head() function to get the
* full list of offered services.
*/
uip_ipaddr_t * servreg_hack_lookup(servreg_hack_id_t service_id);
/**
* \brief Obtain the list of services provided by neighbors
* \return The list of services
*
* This function returns a list of services registered by
* other nodes. To find a specific service, the caller
* needs to iterate through the list and check each list
* item with the servreg_hack_item_match() function.
*/
servreg_hack_item_t *servreg_hack_list_head(void);
/**
* \brief Get the service ID for a list item
* \param item The list item
* \return The service ID for a list item
*
* This function is used when iterating through the list
* of registered services.
*/
servreg_hack_id_t servreg_hack_item_id(servreg_hack_item_t *item);
/**
* \brief Get the IP address for a list item
* \param item The list item
* \return The IP address
*
* This function is used when iterating through the list
* of registered services.
*/
uip_ipaddr_t * servreg_hack_item_address(servreg_hack_item_t *item);
#endif /* SERVREG_HACK_H */
/** @} */
/** @} */

View File

@ -0,0 +1,11 @@
CONTIKI_PROJECT = example-servreg-client
all: $(CONTIKI_PROJECT)
WITH_UIP6=1
UIP_CONF_IPV6=1
APPS=servreg-hack
CONTIKI = ../..
include $(CONTIKI)/Makefile.include
-include /home/user/nes/testbed-scripts/Makefile.include

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
* $Id: example-servreg-client.c,v 1.1 2010/06/15 19:00:28 adamdunkels Exp $
*/
/**
* \file
* A very simple Contiki application showing how Contiki programs look
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "net/uip-debug.h"
#include "net/uip-ds6.h"
#include "servreg-hack.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(example_servreg_client_process, "Example servreg client");
AUTOSTART_PROCESSES(&example_servreg_client_process);
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_servreg_client_process, ev, data)
{
PROCESS_BEGIN();
servreg_hack_init();
set_global_address();
while(1) {
static struct etimer et;
etimer_set(&et, CLOCK_SECOND * 10);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
{
servreg_hack_item_t *item;
for(item = servreg_hack_list_head();
item != NULL;
item = list_item_next(item)) {
printf("Id %d address ", servreg_hack_item_id(item));
uip_debug_ipaddr_print(servreg_hack_item_address(item));
printf("\n");
PROCESS_EXIT();
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
* $Id: example-servreg-server.c,v 1.1 2010/06/15 19:00:28 adamdunkels Exp $
*/
/**
* \file
* A very simple Contiki application showing how Contiki programs look
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "net/uip-ds6.h"
#include "servreg-hack.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(example_servreg_server_process, "Example servreg server");
AUTOSTART_PROCESSES(&example_servreg_server_process);
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_servreg_server_process, ev, data)
{
PROCESS_BEGIN();
set_global_address();
servreg_hack_init();
servreg_hack_register(188);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,316 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/native_gateway</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/mobility</project>
<simulation>
<title>Servreg hack test</title>
<delaytime>0</delaytime>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
se.sics.cooja.radiomediums.UDGM
<transmitting_range>40.0</transmitting_range>
<interference_range>40.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
se.sics.cooja.mspmote.SkyMoteType
<identifier>sky1</identifier>
<description>Servreg server</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/servreg-hack/example-servreg-server.c</source>
<commands EXPORT="discard">make example-servreg-server.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/servreg-hack/example-servreg-server.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspClock</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspMoteID</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyButton</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyFlash</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspSerial</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyLED</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
</motetype>
<motetype>
se.sics.cooja.mspmote.SkyMoteType
<identifier>sky2</identifier>
<description>Servreg hack client</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/servreg-hack/example-servreg-client.c</source>
<commands EXPORT="discard">make example-servreg-client.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/servreg-hack/example-servreg-client.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspClock</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspMoteID</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyButton</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyFlash</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspSerial</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyLED</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>45.693987609497896</x>
<y>26.353051242505675</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>1</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>18.451397050087735</x>
<y>55.93074152489276</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>2</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>45.082598269523864</x>
<y>52.7178388400784</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>3</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>11.116935333105516</x>
<y>49.070534908051414</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>4</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>85.11866272622683</x>
<y>30.030092430999066</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>5</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>30.71302161006234</x>
<y>13.877842534368446</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>6</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>44.43705509785284</x>
<y>69.81167027376168</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>7</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>64.10992023465046</x>
<y>20.589540162635835</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>8</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>32.29787406276132</x>
<y>18.754900913594753</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>9</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>25.28398611019028</x>
<y>69.27186586570369</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>10</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>19.3359466030565</x>
<y>17.321986704081503</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>11</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
</simulation>
<plugin>
se.sics.cooja.plugins.SimControl
<width>318</width>
<z>1</z>
<height>172</height>
<location_x>0</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Visualizer
<plugin_config>
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.AttributeVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.UDGMVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.GridVisualizerSkin</skin>
<viewport>3.56257040103728 0.0 0.0 3.56257040103728 -26.423046586149052 -28.07489060373735</viewport>
</plugin_config>
<width>300</width>
<z>2</z>
<height>300</height>
<location_x>1140</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.LogListener
<plugin_config>
<filter />
</plugin_config>
<width>1440</width>
<z>3</z>
<height>324</height>
<location_x>2</location_x>
<location_y>270</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.TimeLine
<plugin_config>
<mote>0</mote>
<mote>1</mote>
<mote>2</mote>
<mote>3</mote>
<mote>4</mote>
<mote>5</mote>
<mote>6</mote>
<mote>7</mote>
<mote>8</mote>
<mote>9</mote>
<mote>10</mote>
<showRadioRXTX />
<showRadioHW />
<split>125</split>
<zoomfactor>1633.2339825135305</zoomfactor>
</plugin_config>
<width>1440</width>
<z>4</z>
<height>238</height>
<location_x>0</location_x>
<location_y>595</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.ScriptRunner
<plugin_config>
<script>/*
* Example Contiki test script (JavaScript).
* A Contiki test script acts on mote output, such as via printf()'s.
* The script may operate on the following variables:
* Mote mote, int id, String msg
*/
TIMEOUT(120000);
num = 0;
while(true) {
YIELD();
WAIT_UNTIL(msg.startsWith('Id'));
num++;
if(num == 9) {
log.testOK();
}
}</script>
<active>true</active>
</plugin_config>
<width>600</width>
<z>0</z>
<height>700</height>
<location_x>526</location_x>
<location_y>6</location_y>
</plugin>
</simconf>