diff --git a/examples/ipv6/multicast/Makefile b/examples/ipv6/multicast/Makefile new file mode 100644 index 000000000..4bd9ce515 --- /dev/null +++ b/examples/ipv6/multicast/Makefile @@ -0,0 +1,11 @@ +DEFINES+=PROJECT_CONF_H=\"project-conf.h\" +UIP_CONF_IPV6=1 + +CONTIKI_PROJECT = root intermediate sink +all: $(CONTIKI_PROJECT) + +CONTIKI = ../../.. + +MODULES += core/net/ipv6/multicast + +include $(CONTIKI)/Makefile.include diff --git a/examples/ipv6/multicast/intermediate.c b/examples/ipv6/multicast/intermediate.c new file mode 100644 index 000000000..6d8f27284 --- /dev/null +++ b/examples/ipv6/multicast/intermediate.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, Loughborough University - 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 + * This node is part of the RPL multicast example. It basically + * represents a node that does not join the multicast group + * but still knows how to forward multicast packets + * The example will work with or without any number of these nodes + * + * Also, performs some sanity checks for the contiki configuration + * and generates an error if the conf is bad + * + * \author + * George Oikonomou - + */ + +#include "contiki.h" +#include "contiki-net.h" +#include "net/ipv6/multicast/uip-mcast6.h" + +#if !UIP_CONF_IPV6 || !UIP_CONF_ROUTER || !UIP_CONF_IPV6_MULTICAST || !UIP_CONF_IPV6_RPL +#error "This example can not work with the current contiki configuration" +#error "Check the values of: UIP_CONF_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL" +#endif +/*---------------------------------------------------------------------------*/ +PROCESS(mcast_intermediate_process, "Intermediate Process"); +AUTOSTART_PROCESSES(&mcast_intermediate_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(mcast_intermediate_process, ev, data) +{ + PROCESS_BEGIN(); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/ipv6/multicast/multicast.csc b/examples/ipv6/multicast/multicast.csc new file mode 100644 index 000000000..5339f0351 --- /dev/null +++ b/examples/ipv6/multicast/multicast.csc @@ -0,0 +1,257 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/collect-view + [APPS_DIR]/powertracker + + Example of a uIPv6 network with multicast support + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 50.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.mspmote.SkyMoteType + sky1 + root + [CONTIKI_DIR]/examples/ipv6/multicast/root.c + make root.sky TARGET=sky + [CONTIKI_DIR]/examples/ipv6/multicast/root.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + org.contikios.cooja.mspmote.SkyMoteType + sky2 + intermediate + [CONTIKI_DIR]/examples/ipv6/multicast/intermediate.c + make intermediate.sky TARGET=sky + [CONTIKI_DIR]/examples/ipv6/multicast/intermediate.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + org.contikios.cooja.mspmote.SkyMoteType + sky3 + sink + [CONTIKI_DIR]/examples/ipv6/multicast/sink.c + make sink.sky TARGET=sky + [CONTIKI_DIR]/examples/ipv6/multicast/sink.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + + + org.contikios.cooja.interfaces.Position + 5.995813174969022 + 34.43129455447824 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + org.contikios.cooja.interfaces.Position + 40.70237155931961 + 16.396742420332068 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + + org.contikios.cooja.interfaces.Position + 100.3720728044051 + 70.93197095432518 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 3 + + sky3 + + + + + org.contikios.cooja.interfaces.Position + 81.7376718406712 + 28.854291358797 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 4 + + sky3 + + + + + org.contikios.cooja.interfaces.Position + -26.161520836433183 + 8.116006415286686 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 5 + + sky3 + + + + + org.contikios.cooja.interfaces.Position + -34.57705675553882 + 92.87247531485058 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 6 + + sky3 + + + + + org.contikios.cooja.interfaces.Position + 39.86312587077661 + 59.603125741056246 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 7 + + sky2 + + + + + org.contikios.cooja.interfaces.Position + 1.4345607604759194 + 75.2481773153879 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 8 + + sky2 + + + + org.contikios.cooja.plugins.SimControl + 318 + 0 + 192 + 0 + 0 + + + org.contikios.cooja.plugins.Visualizer + + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.AddressVisualizerSkin + 3.914959956760176 0.0 0.0 3.914959956760176 300.2075734071477 -15.682931033747009 + + 869 + 3 + 441 + 320 + 3 + + + org.contikios.cooja.plugins.LogListener + + + + + + 1281 + 2 + 213 + -1 + 714 + + + org.contikios.cooja.plugins.RadioLogger + + 117 + + false + false + + + 1280 + 1 + 268 + 0 + 445 + + + diff --git a/examples/ipv6/multicast/project-conf.h b/examples/ipv6/multicast/project-conf.h new file mode 100644 index 000000000..84686ce21 --- /dev/null +++ b/examples/ipv6/multicast/project-conf.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, Loughborough University - 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 + * Project specific configuration defines for the RPl multicast + * example. + * + * \author + * George Oikonomou - + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#include "net/ipv6/multicast/uip-mcast6-engines.h" + +/* Change this to switch engines. Engine codes in uip-mcast6-engines.h */ +#define UIP_MCAST6_CONF_ENGINE UIP_MCAST6_ENGINE_ROLL_TM + +/* For Imin: Use 16 over NullRDC, 64 over Contiki MAC */ +#define ROLL_TM_CONF_IMIN_1 64 + +#undef UIP_CONF_IPV6_RPL +#undef UIP_CONF_ND6_SEND_RA +#undef UIP_CONF_ROUTER +#define UIP_CONF_IPV6_RPL 1 +#define UIP_CONF_ND6_SEND_RA 0 +#define UIP_CONF_ROUTER 1 +#define UIP_MCAST6_ROUTE_CONF_ROUTES 1 + +#undef UIP_CONF_TCP +#define UIP_CONF_TCP 0 + +/* Code/RAM footprint savings so that things will fit on our device */ +#undef UIP_CONF_DS6_NBR_NBU +#undef UIP_CONF_DS6_ROUTE_NBU +#define UIP_CONF_DS6_NBR_NBU 10 +#define UIP_CONF_DS6_ROUTE_NBU 10 + +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/ipv6/multicast/root.c b/examples/ipv6/multicast/root.c new file mode 100644 index 000000000..2601d71a8 --- /dev/null +++ b/examples/ipv6/multicast/root.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2010, Loughborough University - 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 + * This node is part of the RPL multicast example. It is an RPL root + * and sends a multicast message periodically. For the example to work, + * we need one of those nodes. + * + * \author + * George Oikonomou - + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" +#include "net/ipv6/multicast/uip-mcast6.h" + +#include + +#define DEBUG DEBUG_PRINT +#include "net/ip/uip-debug.h" +#include "net/rpl/rpl.h" + +#define MAX_PAYLOAD_LEN 120 +#define MCAST_SINK_UDP_PORT 3001 /* Host byte order */ +#define SEND_INTERVAL CLOCK_SECOND /* clock ticks */ +#define ITERATIONS 100 /* messages */ + +/* Start sending messages START_DELAY secs after we start so that routing can + * converge */ +#define START_DELAY 60 + +static struct uip_udp_conn * mcast_conn; +static char buf[MAX_PAYLOAD_LEN]; +static uint32_t seq_id; + +#if !UIP_CONF_IPV6 || !UIP_CONF_ROUTER || !UIP_CONF_IPV6_MULTICAST || !UIP_CONF_IPV6_RPL +#error "This example can not work with the current contiki configuration" +#error "Check the values of: UIP_CONF_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL" +#endif +/*---------------------------------------------------------------------------*/ +PROCESS(rpl_root_process, "RPL ROOT, Multicast Sender"); +AUTOSTART_PROCESSES(&rpl_root_process); +/*---------------------------------------------------------------------------*/ +static void +multicast_send() +{ + uint32_t id; + + id = uip_htonl(seq_id); + memset(buf, 0, MAX_PAYLOAD_LEN); + memcpy(buf, &id, sizeof(seq_id)); + + PRINTF("Send to: "); + PRINT6ADDR(&mcast_conn->ripaddr); + PRINTF(" Remote Port %u,", uip_ntohs(mcast_conn->rport)); + PRINTF(" (msg=0x%08lx)", (unsigned long)uip_ntohl(*((uint32_t *)buf))); + PRINTF(" %lu bytes\n", (unsigned long)sizeof(id)); + + seq_id++; + uip_udp_packet_send(mcast_conn, buf, sizeof(id)); +} +/*---------------------------------------------------------------------------*/ +static void +prepare_mcast() +{ + uip_ipaddr_t ipaddr; + + /* + * IPHC will use stateless multicast compression for this destination + * (M=1, DAC=0), with 32 inline bits (1E 89 AB CD) + */ + uip_ip6addr(&ipaddr,0xFF1E,0,0,0,0,0,0x89,0xABCD); + mcast_conn = udp_new(&ipaddr, UIP_HTONS(MCAST_SINK_UDP_PORT), NULL); +} +/*---------------------------------------------------------------------------*/ +static void +set_own_addresses() +{ + int i; + uint8_t state; + rpl_dag_t *dag; + 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); + + PRINTF("Our IPv6 addresses:\n"); + 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)) { + PRINTF(" "); + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + if (state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } + + /* Become root of a new DODAG with ID our global v6 address */ + dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr); + if(dag != NULL) { + rpl_set_prefix(dag, &ipaddr, 64); + PRINTF("Created a new RPL dag with ID: "); + PRINT6ADDR(&dag->dag_id); + PRINTF("\n"); + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(rpl_root_process, ev, data) +{ + static struct etimer et; + + PROCESS_BEGIN(); + + PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); + + NETSTACK_MAC.off(1); + + set_own_addresses(); + + prepare_mcast(); + + etimer_set(&et, START_DELAY * CLOCK_SECOND); + while(1) { + PROCESS_YIELD(); + if(etimer_expired(&et)) { + if(seq_id == ITERATIONS) { + etimer_stop(&et); + } else { + multicast_send(); + etimer_set(&et, SEND_INTERVAL); + } + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/ipv6/multicast/sink.c b/examples/ipv6/multicast/sink.c new file mode 100644 index 000000000..c062d2f69 --- /dev/null +++ b/examples/ipv6/multicast/sink.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2010, Loughborough University - 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 + * This node is part of the RPL multicast example. It is a node that + * joins a multicast group and listens for messages. It also knows how + * to forward messages down the tree. + * For the example to work, we need one or more of those nodes. + * + * \author + * George Oikonomou - + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" +#include "net/ipv6/multicast/uip-mcast6.h" + +#include + +#define DEBUG DEBUG_PRINT +#include "net/ip/uip-debug.h" + +#define MCAST_SINK_UDP_PORT 3001 /* Host byte order */ + +static struct uip_udp_conn *sink_conn; +static uint16_t count; + +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) + +#if !UIP_CONF_IPV6 || !UIP_CONF_ROUTER || !UIP_CONF_IPV6_MULTICAST || !UIP_CONF_IPV6_RPL +#error "This example can not work with the current contiki configuration" +#error "Check the values of: UIP_CONF_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL" +#endif +/*---------------------------------------------------------------------------*/ +PROCESS(mcast_sink_process, "Multicast Sink"); +AUTOSTART_PROCESSES(&mcast_sink_process); +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + if(uip_newdata()) { + count++; + PRINTF("In: [0x%08lx], TTL %u, total %u\n", + uip_ntohl((unsigned long) *((uint32_t *)(uip_appdata))), + UIP_IP_BUF->ttl, count); + } + return; +} +/*---------------------------------------------------------------------------*/ +static uip_ds6_maddr_t * +join_mcast_group() +{ + uip_ipaddr_t addr; + uip_ds6_maddr_t *rv; + + /* First, set our v6 global */ + uip_ip6addr(&addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&addr, &uip_lladdr); + uip_ds6_addr_add(&addr, 0, ADDR_AUTOCONF); + + /* + * IPHC will use stateless multicast compression for this destination + * (M=1, DAC=0), with 32 inline bits (1E 89 AB CD) + */ + uip_ip6addr(&addr,0xFF1E,0,0,0,0,0,0x89,0xABCD); + rv = uip_ds6_maddr_add(&addr); + + if(rv) { + PRINTF("Joined multicast group "); + PRINT6ADDR(&uip_ds6_maddr_lookup(&addr)->ipaddr); + PRINTF("\n"); + } + return rv; +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(mcast_sink_process, ev, data) +{ + PROCESS_BEGIN(); + + PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); + + if(join_mcast_group() == NULL) { + PRINTF("Failed to join multicast group\n"); + PROCESS_EXIT(); + } + + count = 0; + + sink_conn = udp_new(NULL, UIP_HTONS(0), NULL); + udp_bind(sink_conn, UIP_HTONS(MCAST_SINK_UDP_PORT)); + + PRINTF("Listening: "); + PRINT6ADDR(&sink_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", + UIP_HTONS(sink_conn->lport), UIP_HTONS(sink_conn->rport)); + + while(1) { + PROCESS_YIELD(); + if(ev == tcpip_event) { + tcpip_handler(); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/