43 #include "contiki-net.h"
48 #include "net/rpl/rpl.h"
52 #define DEBUG DEBUG_NONE
60 #define SMRF_FWD_DELAY() NETSTACK_RDC.channel_check_interval()
62 #define SMRF_INTERVAL_COUNT ((CLOCK_SECOND >> 2) / fwd_delay)
66 static struct ctimer mcast_periodic;
67 static uint8_t mcast_len;
69 static uint8_t fwd_delay;
70 static uint8_t fwd_spread;
74 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
79 memcpy(uip_buf, &mcast_buf, mcast_len);
90 uip_ipaddr_t *parent_ipaddr;
101 d = rpl_get_any_dag();
103 UIP_MCAST6_STATS_ADD(mcast_dropped);
104 return UIP_MCAST6_DROP;
108 parent_ipaddr = rpl_get_parent_ipaddr(d->preferred_parent);
111 if(parent_lladdr ==
NULL) {
112 UIP_MCAST6_STATS_ADD(mcast_dropped);
113 return UIP_MCAST6_DROP;
120 if(memcmp(parent_lladdr, packetbuf_addr(PACKETBUF_ADDR_SENDER),
122 PRINTF(
"SMRF: Routable in but SMRF ignored it\n");
123 UIP_MCAST6_STATS_ADD(mcast_dropped);
124 return UIP_MCAST6_DROP;
128 UIP_MCAST6_STATS_ADD(mcast_dropped);
129 return UIP_MCAST6_DROP;
132 UIP_MCAST6_STATS_ADD(mcast_in_all);
133 UIP_MCAST6_STATS_ADD(mcast_in_unique);
137 if(uip_mcast6_route_lookup(&
UIP_IP_BUF->destipaddr)) {
139 UIP_MCAST6_STATS_ADD(mcast_fwd);
146 fwd_delay = SMRF_FWD_DELAY();
149 #if SMRF_MIN_FWD_DELAY
150 if(fwd_delay < SMRF_MIN_FWD_DELAY) {
151 fwd_delay = SMRF_MIN_FWD_DELAY;
162 fwd_spread = SMRF_INTERVAL_COUNT;
163 if(fwd_spread > SMRF_MAX_SPREAD) {
164 fwd_spread = SMRF_MAX_SPREAD;
167 fwd_delay = fwd_delay * (1 + ((
random_rand() >> 11) % fwd_spread));
170 memcpy(&mcast_buf, uip_buf,
uip_len);
174 PRINTF(
"SMRF: %u bytes: fwd in %u [%u]\n",
175 uip_len, fwd_delay, fwd_spread);
180 PRINTF(
"SMRF: Not a group member. No further processing\n");
181 return UIP_MCAST6_DROP;
183 PRINTF(
"SMRF: Ours. Deliver to upper layers\n");
184 UIP_MCAST6_STATS_ADD(mcast_in_ours);
185 return UIP_MCAST6_ACCEPT;
192 UIP_MCAST6_STATS_INIT(
NULL);
203 const struct uip_mcast6_driver smrf_driver = {