45 #include "contiki-net.h"
50 #include "net/rpl/rpl.h"
54 #define DEBUG DEBUG_NONE
61 #define SMRF_FWD_DELAY() NETSTACK_RDC.channel_check_interval()
63 #define SMRF_INTERVAL_COUNT ((CLOCK_SECOND >> 2) / fwd_delay)
67 static struct ctimer mcast_periodic;
68 static uint8_t mcast_len;
70 static uint8_t fwd_delay;
71 static uint8_t fwd_spread;
75 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
80 memcpy(
uip_buf, &mcast_buf, mcast_len);
91 uip_ipaddr_t *parent_ipaddr;
102 d = rpl_get_any_dag();
104 UIP_MCAST6_STATS_ADD(mcast_dropped);
105 return UIP_MCAST6_DROP;
109 parent_ipaddr = rpl_get_parent_ipaddr(d->preferred_parent);
110 parent_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(parent_ipaddr);
112 if(parent_lladdr ==
NULL) {
113 UIP_MCAST6_STATS_ADD(mcast_dropped);
114 return UIP_MCAST6_DROP;
121 if(memcmp(parent_lladdr, packetbuf_addr(PACKETBUF_ADDR_SENDER),
123 PRINTF(
"SMRF: Routable in but SMRF ignored it\n");
124 UIP_MCAST6_STATS_ADD(mcast_dropped);
125 return UIP_MCAST6_DROP;
129 UIP_MCAST6_STATS_ADD(mcast_dropped);
130 return UIP_MCAST6_DROP;
133 UIP_MCAST6_STATS_ADD(mcast_in_all);
134 UIP_MCAST6_STATS_ADD(mcast_in_unique);
140 UIP_MCAST6_STATS_ADD(mcast_fwd);
147 fwd_delay = SMRF_FWD_DELAY();
150 #if SMRF_MIN_FWD_DELAY
151 if(fwd_delay < SMRF_MIN_FWD_DELAY) {
152 fwd_delay = SMRF_MIN_FWD_DELAY;
163 fwd_spread = SMRF_INTERVAL_COUNT;
164 if(fwd_spread > SMRF_MAX_SPREAD) {
165 fwd_spread = SMRF_MAX_SPREAD;
168 fwd_delay = fwd_delay * (1 + ((
random_rand() >> 11) % fwd_spread));
175 PRINTF(
"SMRF: %u bytes: fwd in %u [%u]\n",
176 uip_len, fwd_delay, fwd_spread);
180 if(!uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr)) {
181 PRINTF(
"SMRF: Not a group member. No further processing\n");
182 return UIP_MCAST6_DROP;
184 PRINTF(
"SMRF: Ours. Deliver to upper layers\n");
185 UIP_MCAST6_STATS_ADD(mcast_in_ours);
186 return UIP_MCAST6_ACCEPT;
193 UIP_MCAST6_STATS_INIT(
NULL);
uip_len
The length of the packet in the uip_buf buffer.
The data structure used to represent a multicast engine.
uint8_t(* in)(void)
Process an incoming multicast datagram and determine whether it should be delivered up the stack or n...
void(* out)(void)
Process an outgoing datagram with a multicast IPv6 destination address.
#define UIP_LLADDR_LEN
Link layer address length.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
#define UIP_IP_BUF
Pointer to IP header.
void uip_mcast6_route_init()
Multicast routing table init routine.
This header file contains configuration directives for uIPv6 multicast support.
#define NULL
The null pointer.
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
uint8_t tcpip_output(const uip_lladdr_t *a)
Output packet to layer 2 The eventual parameter is the MAC address of the destination.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
A set of debugging macros for the IP stack
Header file for the SMRF forwarding engine.
uip_mcast6_route_t * uip_mcast6_route_lookup(uip_ipaddr_t *group)
Lookup a multicast route.
Header file for IPv6 multicast forwarding stats maintenance
Header file for multicast routing table manipulation.
const struct uip_mcast6_driver smrf_driver
The SMRF engine driver.
Include file for the Contiki low-layer network stack (NETSTACK)
void(* init)(void)
Initialize the multicast engine.