45#include "contiki-net.h"
53#if ROUTING_CONF_RPL_LITE
54#include "net/routing/rpl-lite/rpl.h"
56#if ROUTING_CONF_RPL_CLASSIC
57#include "net/routing/rpl-classic/rpl.h"
61#define DEBUG DEBUG_NONE
68#define SMRF_FWD_DELAY() (CLOCK_SECOND / 8)
70#define SMRF_INTERVAL_COUNT ((CLOCK_SECOND >> 2) / fwd_delay)
74static struct ctimer mcast_periodic;
75static uint8_t mcast_len;
77static uint8_t fwd_delay;
78static uint8_t fwd_spread;
83 memcpy(
uip_buf, &mcast_buf, mcast_len);
94 uip_ipaddr_t *parent_ipaddr;
95 const uip_lladdr_t *parent_lladdr;
105 d = rpl_get_any_dag();
107 PRINTF(
"SMRF: No DODAG\n");
108 UIP_MCAST6_STATS_ADD(mcast_dropped);
109 return UIP_MCAST6_DROP;
113 parent_ipaddr = rpl_parent_get_ipaddr(d->preferred_parent);
116 if(parent_lladdr == NULL) {
117 PRINTF(
"SMRF: No Parent found\n");
118 UIP_MCAST6_STATS_ADD(mcast_dropped);
119 return UIP_MCAST6_DROP;
126 if(memcmp(parent_lladdr, packetbuf_addr(PACKETBUF_ADDR_SENDER),
128 PRINTF(
"SMRF: Routable in but SMRF ignored it\n");
129 UIP_MCAST6_STATS_ADD(mcast_dropped);
130 return UIP_MCAST6_DROP;
134 UIP_MCAST6_STATS_ADD(mcast_dropped);
135 PRINTF(
"SMRF: TTL too low\n");
136 return UIP_MCAST6_DROP;
139 UIP_MCAST6_STATS_ADD(mcast_in_all);
140 UIP_MCAST6_STATS_ADD(mcast_in_unique);
146 UIP_MCAST6_STATS_ADD(mcast_fwd);
153 fwd_delay = SMRF_FWD_DELAY();
156#if SMRF_MIN_FWD_DELAY
157 if(fwd_delay < SMRF_MIN_FWD_DELAY) {
158 fwd_delay = SMRF_MIN_FWD_DELAY;
169 fwd_spread = SMRF_INTERVAL_COUNT;
170 if(fwd_spread > SMRF_MAX_SPREAD) {
171 fwd_spread = SMRF_MAX_SPREAD;
174 fwd_delay = fwd_delay * (1 + ((
random_rand() >> 11) % fwd_spread));
179 ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL);
181 PRINTF(
"SMRF: %u bytes: fwd in %u [%u]\n",
182 uip_len, fwd_delay, fwd_spread);
184 PRINTF(
"SMRF: Group unknown, dropping\n");
188 if(!uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr)) {
189 PRINTF(
"SMRF: Not a group member. No further processing\n");
190 return UIP_MCAST6_DROP;
192 PRINTF(
"SMRF: Ours. Deliver to upper layers\n");
193 UIP_MCAST6_STATS_ADD(mcast_in_ours);
194 return UIP_MCAST6_ACCEPT;
201 UIP_MCAST6_STATS_INIT(NULL);
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
static void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
const struct uip_mcast6_driver smrf_driver
The SMRF engine driver.
uint8_t tcpip_output(const uip_lladdr_t *a)
Output packet to layer 2 The eventual parameter is the MAC address of the destination.
uip_mcast6_route_t * uip_mcast6_route_lookup(uip_ipaddr_t *group)
Lookup a multicast route.
void uip_mcast6_route_init()
Multicast routing table init routine.
#define UIP_LLADDR_LEN
802.15.4 address
const uip_lladdr_t * uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr)
Get the link-layer address associated with a specified IPv6 address.
#define UIP_IP_BUF
Direct access to IPv6 header.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Packet buffer (packetbuf) management.
Routing driver header file.
Header file for the SMRF forwarding engine.
The data structure used to represent a multicast engine.
void(* out)(void)
Process an outgoing datagram with a multicast IPv6 destination address.
uint8_t(* in)(void)
Process an incoming multicast datagram and determine whether it should be delivered up the stack or n...
void(* init)(void)
Initialize the multicast engine.
A set of debugging macros for the IP stack.
Header file for multicast routing table manipulation.
Header file for IPv6 multicast forwarding stats maintenance.
This header file contains configuration directives for uIPv6 multicast support.