Wireless networking in Contiki - uni-freiburg.de · Wireless networking in Contiki Contiki: Rime...
Transcript of Wireless networking in Contiki - uni-freiburg.de · Wireless networking in Contiki Contiki: Rime...
Wireless networking in Contiki
Wireless networking in ContikiKristof Van Laerhoven, Embedded Systems, Uni Freiburg [email protected]
Wireless networking in Contiki
Recap: ISO OSI Model
• ISO : International Organization for Standardization
• OSI : Open Systems Interconnection2
Application
Presentation
Session
Transport
Network
Data Link
Physical
Application
Presentation
Session
Transport
Network
Data Link
Physical
Wireless networking in Contiki
Recap: ISO OSI Model
3
Application
Presentation
Session
Transport
Network
Data Link
Physical sending/receiving bits
reliable data transfer between adjacent stations with frames
connection end-system to end-system
connection source application to destination application
ensures dialog control, token management and synchronization
ensures data presentation independent from end system
application services
Wireless networking in Contiki
Recap: ISO OSI Model, TCP Model
4
Application
Presentation
Session
Transport
Network
Data Link
Physical
Application Services
UDP/TCP
IPv4/v6
Network Interface
Network?
Wireless networking in Contiki
Recap: ISO OSI Model, TCP Model, WSNs
5
Application
Presentation
Session
Transport
Network
Data Link
Physical
Application Services
UDP/TCP
IPv4/v6
Network Interface
Application
UDP/TCP
MAC/IPv4/v6
802.15.4
CC2420 CC1000 …
Wireless networking in Contiki
Networking in WSNs vs Wired Sensor Networks
But: • Devices are battery powered • Lots of nodes share the same network medium • Possibly multihop wireless network • Possibly mobile nodes • Sometimes data-centric • Self-configuring (infrastructure-less)
6
Advantages: • Faster setup of the network • Deployable in many more environments • Easy to change node locations • Cheap for long distances • Allows mobile nodes • …
Wireless networking in Contiki
Multi-hop Traffic Patterns
7
End-to-end, multi-hop communication • node to sink and vice versa (unicast)
• e.g. simple event notification • e.g. instructing a single node to do
something
Group, multi-hop communication • one node to set of nodes
(multi-/broadcast) • e.g. data dissemination, network
programming
• all/many nodes to sink (convergecast) • e.g. data collection at one base station
Wireless networking in Contiki
Contiki Networking Stacks
• uIP : IP stack with support for UPD/TCP (IPv4 and IPv6 compliant)
• Rime : set of communication primitives from anonymous broadcast to multi-hop mesh
8
uIP Rime
Ethernet Low-power Radio
Application Application Application
Wireless networking in Contiki
ContikiQuick start example: brdcast.c
#include “contiki-net.h” void recv(struct broadcast_conn *c) {/* do something here */ ;}; struct broadcast_callbacks callbck={recv};
PROCESS(brdcast_process, “brdcast”); AUTOSTART_PROCESSES(&brdcast_process);
PROCESS_THREAD(brdcast_process, ev, data) { PROCESS_BEGIN(); static struct etimer et; static struct broadcast_conn bc; broadcast_open(&bc, 128, &callbck); while(1) { etimer_set(&et, CLOCK_SECOND*5); PROCESS_WAIT_EVENT_UNTIL( etimer_expired(&et) ); packetbuf_copyfrom(“hi!”, 3); broadcast_send(&bc); } PROCESS_END(); }
9
Wireless networking in Contiki
Contiki: Rime
10
multi-hopsingle-hop
collect
mesh
multihop
route_discovery
netflood
runicast
stbroadcast ipolite
politetrickle
stunicast
neighbor_discovery
unic
ast
broa
dcas
t
unicast
broadcast
abc
reliability
Wireless networking in Contiki
Contiki: Rime Mesh Networking: mesh
11
• Based on two simpler modules: multihop and route_discovery
• multihop sends packet to an identified network node, using multi-hop forwarding at each node
• If no route to specified node is found, upper layer is notified (might request route discovery)
• route_discovery disseminates route requests over netflood and route replies over unicast
• uses 3 channels: one for the multi-hop forwarding and two for the route discovery
Wireless networking in Contiki
ContikiExample: example-mesh.c (1/2)#define MESSAGE "Hello"
static struct mesh_conn mesh;
PROCESS(example_mesh_process, "Mesh example");
AUTOSTART_PROCESSES(&example_mesh_process);
static void sent(struct mesh_conn *c) { printf("packet sent\n");}
static void timedout(struct mesh_conn *c) { printf("packet timedout\n");}
static void recv(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops) {
printf("Data received from %d.%d: %.*s (%d)\n”, from->u8[0], from->u8[1],
packetbuf_datalen(), (char*)packetbuf_dataptr(), packetbuf_datalen());
packetbuf_copyfrom(MESSAGE, strlen(MESSAGE));
mesh_send(&mesh, from);}
12
Wireless networking in Contiki
ContikiExample: example-mesh.c (2/2)const static struct mesh_callbacks callbacks = {recv, sent, timedout};
PROCESS_THREAD(example_mesh_process, ev, data){ PROCESS_EXITHANDLER(mesh_close(&mesh);)
PROCESS_BEGIN();
mesh_open(&mesh, 132, &callbacks); SENSORS_ACTIVATE(button_sensor); while(1) {
rimeaddr_t addr;
/* Wait for button click before sending the first message. */ PROCESS_WAIT_EVENT_UNTIL( ev == sensors_event && data == &button_sensor); printf("Button clicked\n");
/* Send a message to node number 1. */ packetbuf_copyfrom(MESSAGE, strlen(MESSAGE)); addr.u8[0] = 1; addr.u8[1] = 0; mesh_send(&mesh, &addr); } PROCESS_END();}
13
Wireless networking in Contiki
Contiki: Rime Data collection: collect
14
• Tree-based hop-by-hop reliable data collection
• based also on simpler modules: runicast and neighbor_discovery
• uses 2 channels; one for neighbor discovery and one for data packets
• route_discovery disseminates route requests over netflood and route replies over unicast
Wireless networking in Contiki
ContikiExample: example-collect.c (2/2)
15
PROCESS_THREAD(example_collect_process, ev, data) { static struct etimer periodic, et; PROCESS_BEGIN(); collect_open(&tc, 130, COLLECT_ROUTER, &callbacks); if(rimeaddr_node_addr.u8[0] == 1 && rimeaddr_node_addr.u8[1] == 0) { printf("I am sink\n”); collect_set_sink(&tc, 1); } etimer_set(&et, 120 * CLOCK_SECOND); /* Wait for network to settle. */ PROCESS_WAIT_UNTIL(etimer_expired(&et)); while(1) { if(etimer_expired(&periodic)) { /* Send a packet every 30 seconds. */ etimer_set(&periodic, CLOCK_SECOND * 30); etimer_set(&et, random_rand() % (CLOCK_SECOND * 30)); } PROCESS_WAIT_EVENT(); if(etimer_expired(&et)) { static rimeaddr_t oldparent; const rimeaddr_t *parent; printf(“Sending\n"); packetbuf_clear(); packetbuf_set_datalen(sprintf(packetbuf_dataptr(), "%s", "Hello") + 1); collect_send(&tc, 15); parent = collect_parent(&tc); if(!rimeaddr_cmp(parent, &oldparent)) { if(!rimeaddr_cmp(&oldparent, &rimeaddr_null)) printf("#L %d 0\n", oldparent.u8[0]); if(!rimeaddr_cmp(parent, &rimeaddr_null)) printf("#L %d 1\n", parent->u8[0]); rimeaddr_copy(&oldparent, parent); } } } PROCESS_END();}