Merge pull request #30 from nvt/remove-servreg-hack
Removed servreg-hack.
This commit is contained in:
commit
85e0573ffd
@ -1,379 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Implementation of the servreg-hack application
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/** \addtogroup servreghack
|
||||
* @{ */
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include "net/ip/uip.h"
|
||||
|
||||
#include "net/ipv6/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;
|
||||
|
||||
static uint8_t started = 0;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* 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(own_services);
|
||||
t != NULL;
|
||||
t = list_item_next(t)) {
|
||||
if(timer_expired(&t->timer)) {
|
||||
t->seqno++;
|
||||
timer_set(&t->timer, LIFETIME / 2);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(started == 0) {
|
||||
list_init(others_services);
|
||||
list_init(own_services);
|
||||
memb_init(®istrations);
|
||||
|
||||
process_start(&servreg_hack_process, NULL);
|
||||
started = 1;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
servreg_hack_register(servreg_hack_id_t id, const uip_ipaddr_t *addr)
|
||||
{
|
||||
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. */
|
||||
|
||||
servreg_hack_init();
|
||||
|
||||
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;
|
||||
uip_ipaddr_copy(&r->addr, addr);
|
||||
timer_set(&r->timer, LIFETIME / 2);
|
||||
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;
|
||||
|
||||
servreg_hack_init();
|
||||
|
||||
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). */
|
||||
|
||||
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;
|
||||
|
||||
buf[MSG_FLAGS_OFFSET] = 0;
|
||||
|
||||
numregs = 0;
|
||||
bufptr = MSG_ADDRS_OFFSET;
|
||||
|
||||
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],
|
||||
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;
|
||||
}
|
||||
|
||||
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 uint8_t *buf, int len)
|
||||
{
|
||||
int numregs;
|
||||
int i;
|
||||
int bufptr;
|
||||
|
||||
numregs = buf[MSG_NUMREGS_OFFSET];
|
||||
|
||||
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(UIP_HTONS(UDP_PORT), NULL);
|
||||
udp_bind(outconn, UIP_HTONS(UDP_PORT));
|
||||
|
||||
/* Create inbound UDP connection. */
|
||||
inconn = udp_new(NULL, UIP_HTONS(UDP_PORT), NULL);
|
||||
udp_bind(inconn, UIP_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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @} */
|
@ -1,150 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for the servreg-hack application
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/** \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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SERVREG_HACK_H
|
||||
#define SERVREG_HACK_H
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "net/ip/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
|
||||
* \param addr The address associated with 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, const uip_ipaddr_t *addr);
|
||||
|
||||
|
||||
/**
|
||||
* \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 */
|
||||
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
@ -1,6 +0,0 @@
|
||||
all: broadcast-example unicast-sender unicast-receiver
|
||||
APPS=servreg-hack
|
||||
CONTIKI=../../..
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
include $(CONTIKI)/Makefile.include
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/random.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
|
||||
#include "simple-udp.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UDP_PORT 1234
|
||||
|
||||
#define SEND_INTERVAL (20 * CLOCK_SECOND)
|
||||
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
|
||||
|
||||
static struct simple_udp_connection broadcast_connection;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(broadcast_example_process, "UDP broadcast example process");
|
||||
AUTOSTART_PROCESSES(&broadcast_example_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
receiver(struct simple_udp_connection *c,
|
||||
const uip_ipaddr_t *sender_addr,
|
||||
uint16_t sender_port,
|
||||
const uip_ipaddr_t *receiver_addr,
|
||||
uint16_t receiver_port,
|
||||
const uint8_t *data,
|
||||
uint16_t datalen)
|
||||
{
|
||||
printf("Data received on port %d from port %d with length %d\n",
|
||||
receiver_port, sender_port, datalen);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(broadcast_example_process, ev, data)
|
||||
{
|
||||
static struct etimer periodic_timer;
|
||||
static struct etimer send_timer;
|
||||
uip_ipaddr_t addr;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
simple_udp_register(&broadcast_connection, UDP_PORT,
|
||||
NULL, UDP_PORT,
|
||||
receiver);
|
||||
|
||||
etimer_set(&periodic_timer, SEND_INTERVAL);
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
|
||||
etimer_reset(&periodic_timer);
|
||||
etimer_set(&send_timer, SEND_TIME);
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
|
||||
printf("Sending broadcast\n");
|
||||
uip_create_linklocal_allnodes_mcast(&addr);
|
||||
simple_udp_sendto(&broadcast_connection, "Test", 4, &addr);
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -1,248 +0,0 @@
|
||||
<?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>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
|
||||
<project EXPORT="discard">/home/user/nes/papers/smartip-paper/code/cooja_qr</project>
|
||||
<simulation>
|
||||
<title>Simple UDP broadcast example</title>
|
||||
<delaytime>0</delaytime>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.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>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky1</identifier>
|
||||
<description>Broadcast example</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/simple-udp-rpl/broadcast-example.c</source>
|
||||
<commands EXPORT="discard">make broadcast-example.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/simple-udp-rpl/broadcast-example.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>64.1956818968534</x>
|
||||
<y>28.591062627059372</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>51.81261061627534</x>
|
||||
<y>24.647047255346667</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>9.068527629624546</x>
|
||||
<y>46.26817786392282</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>3</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>87.5626508274206</x>
|
||||
<y>4.896101751816129</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>4</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>55.15853460164762</x>
|
||||
<y>3.4681662067903796</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>5</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>99.33682438963966</x>
|
||||
<y>49.73072195748186</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>6</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>61.26294736288044</x>
|
||||
<y>61.845254356789646</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>7</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>70.4693668755668</x>
|
||||
<y>52.43101713632271</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>8</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>33.5789440978246</x>
|
||||
<y>48.10557568631877</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>9</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>62.6079314243491</x>
|
||||
<y>76.96581640898913</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>10</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>318</width>
|
||||
<z>3</z>
|
||||
<height>192</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
|
||||
<viewport>2.9205864417411154 0.0 0.0 2.9205864417411154 -13.303600659817928 3.5428004585568913</viewport>
|
||||
</plugin_config>
|
||||
<width>300</width>
|
||||
<z>2</z>
|
||||
<height>300</height>
|
||||
<location_x>1122</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>1422</width>
|
||||
<z>0</z>
|
||||
<height>236</height>
|
||||
<location_x>-1</location_x>
|
||||
<location_y>302</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.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>
|
||||
<showRadioRXTX />
|
||||
<showRadioHW />
|
||||
<split>125</split>
|
||||
<zoomfactor>500.0</zoomfactor>
|
||||
</plugin_config>
|
||||
<width>1422</width>
|
||||
<z>1</z>
|
||||
<height>190</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>539</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
@ -1,287 +0,0 @@
|
||||
<?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>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
|
||||
<project EXPORT="discard">/home/user/nes/papers/smartip-paper/code/cooja_qr</project>
|
||||
<simulation>
|
||||
<title>Simple UDP unicast example</title>
|
||||
<delaytime>0</delaytime>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.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>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky1</identifier>
|
||||
<description>UDP receiver</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/simple-udp-rpl/unicast-receiver.c</source>
|
||||
<commands EXPORT="discard">make unicast-receiver.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/simple-udp-rpl/unicast-receiver.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky2</identifier>
|
||||
<description>UDP sender</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/simple-udp-rpl/unicast-sender.c</source>
|
||||
<commands EXPORT="discard">make unicast-sender.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/simple-udp-rpl/unicast-sender.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>82.45117687053667</x>
|
||||
<y>90.0660093026363</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>44.53120632368774</x>
|
||||
<y>89.83566130147413</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>91.76407203945963</x>
|
||||
<y>8.764533976596468</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>3</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>10.771554112657956</x>
|
||||
<y>16.155558894723033</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>4</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>40.99108749529099</x>
|
||||
<y>33.68910640819968</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>5</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>49.762281669516085</x>
|
||||
<y>15.219756237459913</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>6</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>26.209078576184762</x>
|
||||
<y>97.71885344901867</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>7</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>96.30596045236783</x>
|
||||
<y>3.353548431613529</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>8</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>52.22023117695779</x>
|
||||
<y>56.516553603970586</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>9</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>57.92282771739404</x>
|
||||
<y>34.17317501704098</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>10</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>3.8628214275088335</x>
|
||||
<y>52.90298303308778</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>11</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>318</width>
|
||||
<z>3</z>
|
||||
<height>192</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
|
||||
<viewport>2.3409990660057263 0.0 0.0 2.3409990660057263 27.752487588138713 2.6948007992423</viewport>
|
||||
</plugin_config>
|
||||
<width>300</width>
|
||||
<z>2</z>
|
||||
<height>300</height>
|
||||
<location_x>1122</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>1422</width>
|
||||
<z>1</z>
|
||||
<height>239</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>293</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.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>500.0</zoomfactor>
|
||||
</plugin_config>
|
||||
<width>1422</width>
|
||||
<z>0</z>
|
||||
<height>198</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>531</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/random.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#include "net/ip/uip-debug.h"
|
||||
|
||||
#include "simple-udp.h"
|
||||
#include "servreg-hack.h"
|
||||
|
||||
#include "net/rpl/rpl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UDP_PORT 1234
|
||||
#define SERVICE_ID 190
|
||||
|
||||
#define SEND_INTERVAL (10 * CLOCK_SECOND)
|
||||
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
|
||||
|
||||
static struct simple_udp_connection unicast_connection;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(unicast_receiver_process, "Unicast receiver example process");
|
||||
AUTOSTART_PROCESSES(&unicast_receiver_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
receiver(struct simple_udp_connection *c,
|
||||
const uip_ipaddr_t *sender_addr,
|
||||
uint16_t sender_port,
|
||||
const uip_ipaddr_t *receiver_addr,
|
||||
uint16_t receiver_port,
|
||||
const uint8_t *data,
|
||||
uint16_t datalen)
|
||||
{
|
||||
printf("Data received from ");
|
||||
uip_debug_ipaddr_print(sender_addr);
|
||||
printf(" on port %d from port %d with length %d: '%s'\n",
|
||||
receiver_port, sender_port, datalen, data);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uip_ipaddr_t *
|
||||
set_global_address(void)
|
||||
{
|
||||
static uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uint8_t state;
|
||||
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
printf("IPv6 addresses: ");
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused &&
|
||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
||||
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return &ipaddr;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
create_rpl_dag(uip_ipaddr_t *ipaddr)
|
||||
{
|
||||
struct uip_ds6_addr *root_if;
|
||||
|
||||
root_if = uip_ds6_addr_lookup(ipaddr);
|
||||
if(root_if != NULL) {
|
||||
rpl_dag_t *dag;
|
||||
uip_ipaddr_t prefix;
|
||||
|
||||
rpl_set_root(RPL_DEFAULT_INSTANCE, ipaddr);
|
||||
dag = rpl_get_any_dag();
|
||||
uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
rpl_set_prefix(dag, &prefix, 64);
|
||||
PRINTF("created a new RPL dag\n");
|
||||
} else {
|
||||
PRINTF("failed to create a new RPL DAG\n");
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(unicast_receiver_process, ev, data)
|
||||
{
|
||||
uip_ipaddr_t *ipaddr;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
servreg_hack_init();
|
||||
|
||||
ipaddr = set_global_address();
|
||||
|
||||
create_rpl_dag(ipaddr);
|
||||
|
||||
servreg_hack_register(SERVICE_ID, ipaddr);
|
||||
|
||||
simple_udp_register(&unicast_connection, UDP_PORT,
|
||||
NULL, UDP_PORT, receiver);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/random.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#include "net/ip/uip-debug.h"
|
||||
|
||||
#include "sys/node-id.h"
|
||||
|
||||
#include "simple-udp.h"
|
||||
#include "servreg-hack.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UDP_PORT 1234
|
||||
#define SERVICE_ID 190
|
||||
|
||||
#define SEND_INTERVAL (60 * CLOCK_SECOND)
|
||||
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
|
||||
|
||||
static struct simple_udp_connection unicast_connection;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(unicast_sender_process, "Unicast sender example process");
|
||||
AUTOSTART_PROCESSES(&unicast_sender_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
receiver(struct simple_udp_connection *c,
|
||||
const uip_ipaddr_t *sender_addr,
|
||||
uint16_t sender_port,
|
||||
const uip_ipaddr_t *receiver_addr,
|
||||
uint16_t receiver_port,
|
||||
const uint8_t *data,
|
||||
uint16_t datalen)
|
||||
{
|
||||
printf("Data received on port %d from port %d with length %d\n",
|
||||
receiver_port, sender_port, datalen);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_global_address(void)
|
||||
{
|
||||
uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uint8_t state;
|
||||
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
printf("IPv6 addresses: ");
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused &&
|
||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
||||
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(unicast_sender_process, ev, data)
|
||||
{
|
||||
static struct etimer periodic_timer;
|
||||
static struct etimer send_timer;
|
||||
uip_ipaddr_t *addr;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
servreg_hack_init();
|
||||
|
||||
set_global_address();
|
||||
|
||||
simple_udp_register(&unicast_connection, UDP_PORT,
|
||||
NULL, UDP_PORT, receiver);
|
||||
|
||||
etimer_set(&periodic_timer, SEND_INTERVAL);
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
|
||||
etimer_reset(&periodic_timer);
|
||||
etimer_set(&send_timer, SEND_TIME);
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
|
||||
addr = servreg_hack_lookup(SERVICE_ID);
|
||||
if(addr != NULL) {
|
||||
static unsigned int message_number;
|
||||
char buf[20];
|
||||
|
||||
printf("Sending unicast to ");
|
||||
uip_debug_ipaddr_print(addr);
|
||||
printf("\n");
|
||||
sprintf(buf, "Message %d", message_number);
|
||||
message_number++;
|
||||
simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr);
|
||||
} else {
|
||||
printf("Service %d not found\n", SERVICE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -1,5 +1,4 @@
|
||||
all: wait-dag
|
||||
APPS=servreg-hack
|
||||
CONTIKI=../../..
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
|
Loading…
Reference in New Issue
Block a user