diff --git a/apps/servreg-hack/servreg-hack.c b/apps/servreg-hack/servreg-hack.c new file mode 100644 index 000000000..ced34781f --- /dev/null +++ b/apps/servreg-hack/servreg-hack.c @@ -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 + */ + +#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 + +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(®istrations, t); + t = list_head(others_services); + } + } +} +/*---------------------------------------------------------------------------*/ +void +servreg_hack_init(void) +{ + list_init(others_services); + list_init(own_services); + memb_init(®istrations); + + 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(®istrations); + 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(®istrations); + 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(); +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/servreg-hack/servreg-hack.h b/apps/servreg-hack/servreg-hack.h new file mode 100644 index 000000000..e2ab306ad --- /dev/null +++ b/apps/servreg-hack/servreg-hack.h @@ -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 + */ + +#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 */ + + +/** @} */ +/** @} */ diff --git a/examples/servreg-hack/Makefile b/examples/servreg-hack/Makefile new file mode 100644 index 000000000..23a7a06d8 --- /dev/null +++ b/examples/servreg-hack/Makefile @@ -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 + diff --git a/examples/servreg-hack/example-servreg-client.c b/examples/servreg-hack/example-servreg-client.c new file mode 100644 index 000000000..5657a0155 --- /dev/null +++ b/examples/servreg-hack/example-servreg-client.c @@ -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 + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "net/uip-debug.h" +#include "net/uip-ds6.h" +#include "servreg-hack.h" + +#include /* 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(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/servreg-hack/example-servreg-server.c b/examples/servreg-hack/example-servreg-server.c new file mode 100644 index 000000000..293263270 --- /dev/null +++ b/examples/servreg-hack/example-servreg-server.c @@ -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 + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "net/uip-ds6.h" +#include "servreg-hack.h" + +#include /* 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(); +} +/*---------------------------------------------------------------------------*/ diff --git a/tools/cooja/contiki_tests/servreg-hack.csc b/tools/cooja/contiki_tests/servreg-hack.csc new file mode 100644 index 000000000..a890e5e57 --- /dev/null +++ b/tools/cooja/contiki_tests/servreg-hack.csc @@ -0,0 +1,316 @@ + + + [CONTIKI_DIR]/tools/cooja/apps/mrm + [CONTIKI_DIR]/tools/cooja/apps/mspsim + [CONTIKI_DIR]/tools/cooja/apps/avrora + [CONTIKI_DIR]/tools/cooja/apps/native_gateway + [CONTIKI_DIR]/tools/cooja/apps/serial_socket + /home/user/contikiprojects/sics.se/mobility + + Servreg hack test + 0 + 123456 + 1000000 + + se.sics.cooja.radiomediums.UDGM + 40.0 + 40.0 + 1.0 + 1.0 + + + 40000 + + + se.sics.cooja.mspmote.SkyMoteType + sky1 + Servreg server + [CONTIKI_DIR]/examples/servreg-hack/example-servreg-server.c + make example-servreg-server.sky TARGET=sky + [CONTIKI_DIR]/examples/servreg-hack/example-servreg-server.sky + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.mspmote.interfaces.MspClock + se.sics.cooja.mspmote.interfaces.MspMoteID + se.sics.cooja.mspmote.interfaces.SkyButton + se.sics.cooja.mspmote.interfaces.SkyFlash + se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem + se.sics.cooja.mspmote.interfaces.SkyByteRadio + se.sics.cooja.mspmote.interfaces.MspSerial + se.sics.cooja.mspmote.interfaces.SkyLED + se.sics.cooja.mspmote.interfaces.MspDebugOutput + se.sics.cooja.mspmote.interfaces.SkyTemperature + + + se.sics.cooja.mspmote.SkyMoteType + sky2 + Servreg hack client + [CONTIKI_DIR]/examples/servreg-hack/example-servreg-client.c + make example-servreg-client.sky TARGET=sky + [CONTIKI_DIR]/examples/servreg-hack/example-servreg-client.sky + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.mspmote.interfaces.MspClock + se.sics.cooja.mspmote.interfaces.MspMoteID + se.sics.cooja.mspmote.interfaces.SkyButton + se.sics.cooja.mspmote.interfaces.SkyFlash + se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem + se.sics.cooja.mspmote.interfaces.SkyByteRadio + se.sics.cooja.mspmote.interfaces.MspSerial + se.sics.cooja.mspmote.interfaces.SkyLED + se.sics.cooja.mspmote.interfaces.MspDebugOutput + se.sics.cooja.mspmote.interfaces.SkyTemperature + + + + + se.sics.cooja.interfaces.Position + 45.693987609497896 + 26.353051242505675 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + se.sics.cooja.interfaces.Position + 18.451397050087735 + 55.93074152489276 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 45.082598269523864 + 52.7178388400784 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 3 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 11.116935333105516 + 49.070534908051414 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 4 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 85.11866272622683 + 30.030092430999066 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 5 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 30.71302161006234 + 13.877842534368446 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 6 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 44.43705509785284 + 69.81167027376168 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 7 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 64.10992023465046 + 20.589540162635835 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 8 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 32.29787406276132 + 18.754900913594753 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 9 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 25.28398611019028 + 69.27186586570369 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 10 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 19.3359466030565 + 17.321986704081503 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 11 + + sky2 + + + + se.sics.cooja.plugins.SimControl + 318 + 1 + 172 + 0 + 0 + + + se.sics.cooja.plugins.Visualizer + + se.sics.cooja.plugins.skins.IDVisualizerSkin + se.sics.cooja.plugins.skins.MoteTypeVisualizerSkin + se.sics.cooja.plugins.skins.AttributeVisualizerSkin + se.sics.cooja.plugins.skins.UDGMVisualizerSkin + se.sics.cooja.plugins.skins.GridVisualizerSkin + 3.56257040103728 0.0 0.0 3.56257040103728 -26.423046586149052 -28.07489060373735 + + 300 + 2 + 300 + 1140 + 0 + + + se.sics.cooja.plugins.LogListener + + + + 1440 + 3 + 324 + 2 + 270 + + + se.sics.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + + + 125 + 1633.2339825135305 + + 1440 + 4 + 238 + 0 + 595 + + + se.sics.cooja.plugins.ScriptRunner + + + true + + 600 + 0 + 700 + 526 + 6 + + +