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) 74 static struct ctimer mcast_periodic;
75 static uint8_t mcast_len;
77 static uint8_t fwd_delay;
78 static uint8_t fwd_spread;
82 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 98 uip_ipaddr_t *parent_ipaddr;
99 const uip_lladdr_t *parent_lladdr;
111 PRINTF(
"SMRF: No DODAG\n");
112 UIP_MCAST6_STATS_ADD(mcast_dropped);
113 return UIP_MCAST6_DROP;
117 parent_ipaddr = rpl_parent_get_ipaddr(d->preferred_parent);
118 parent_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(parent_ipaddr);
120 if(parent_lladdr == NULL) {
121 PRINTF(
"SMRF: No Parent found\n");
122 UIP_MCAST6_STATS_ADD(mcast_dropped);
123 return UIP_MCAST6_DROP;
130 if(memcmp(parent_lladdr, packetbuf_addr(PACKETBUF_ADDR_SENDER),
132 PRINTF(
"SMRF: Routable in but SMRF ignored it\n");
133 UIP_MCAST6_STATS_ADD(mcast_dropped);
134 return UIP_MCAST6_DROP;
138 UIP_MCAST6_STATS_ADD(mcast_dropped);
139 PRINTF(
"SMRF: TTL too low\n");
140 return UIP_MCAST6_DROP;
143 UIP_MCAST6_STATS_ADD(mcast_in_all);
144 UIP_MCAST6_STATS_ADD(mcast_in_unique);
150 UIP_MCAST6_STATS_ADD(mcast_fwd);
157 fwd_delay = SMRF_FWD_DELAY();
160 #if SMRF_MIN_FWD_DELAY 161 if(fwd_delay < SMRF_MIN_FWD_DELAY) {
162 fwd_delay = SMRF_MIN_FWD_DELAY;
173 fwd_spread = SMRF_INTERVAL_COUNT;
174 if(fwd_spread > SMRF_MAX_SPREAD) {
175 fwd_spread = SMRF_MAX_SPREAD;
178 fwd_delay = fwd_delay * (1 + ((
random_rand() >> 11) % fwd_spread));
183 ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL);
185 PRINTF(
"SMRF: %u bytes: fwd in %u [%u]\n",
186 uip_len, fwd_delay, fwd_spread);
188 PRINTF(
"SMRF: Group unknown, dropping\n");
192 if(!uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr)) {
193 PRINTF(
"SMRF: Not a group member. No further processing\n");
194 return UIP_MCAST6_DROP;
196 PRINTF(
"SMRF: Ours. Deliver to upper layers\n");
197 UIP_MCAST6_STATS_ADD(mcast_in_ours);
198 return UIP_MCAST6_ACCEPT;
205 UIP_MCAST6_STATS_INIT(NULL);
void uip_mcast6_route_init()
Multicast routing table init routine.
#define UIP_IP_BUF
Pointer to IP header.
uint8_t tcpip_output(const uip_lladdr_t *a)
Output packet to layer 2 The eventual parameter is the MAC address of the destination.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
The data structure used to represent a multicast engine.
A set of debugging macros for the IP stack
#define UIP_LLADDR_LEN
802.15.4 address
This header file contains configuration directives for uIPv6 multicast support.
uint8_t(* in)(void)
Process an incoming multicast datagram and determine whether it should be delivered up the stack or n...
#define UIP_LLH_LEN
The link level header length.
const struct uip_mcast6_driver smrf_driver
The SMRF engine driver.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Routing driver header file
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
rpl_dag_t * rpl_get_any_dag(void)
Returns pointer to any DAG (for compatibility with legagy RPL code)
Header file for multicast routing table manipulation.
void(* out)(void)
Process an outgoing datagram with a multicast IPv6 destination address.
void(* init)(void)
Initialize the multicast engine.
Header file for the SMRF forwarding engine.
Header file for IPv6 multicast forwarding stats maintenance
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
uip_mcast6_route_t * uip_mcast6_route_lookup(uip_ipaddr_t *group)
Lookup a multicast route.