Skip to content

Commit

Permalink
integration of new uip6 code from Mathilde and Julien - adds routing …
Browse files Browse the repository at this point in the history
…and improved interface handling
  • Loading branch information
joxe committed Mar 15, 2010
1 parent 7d5e3fb commit fd3d6c4
Show file tree
Hide file tree
Showing 15 changed files with 1,488 additions and 2,378 deletions.
6 changes: 3 additions & 3 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ
TARGET_UPPERCASE := ${shell echo $(TARGET) | sed 'y!$(LOWERCASE)!$(UPPERCASE)!'}
CFLAGS += -DCONTIKI_TARGET_$(TARGET_UPPERCASE)

include $(CONTIKI)/core/net/routing/Makefile.routing
#include $(CONTIKI)/core/net/routing/Makefile.routing
include $(CONTIKI)/core/net/rime/Makefile.rime
include $(CONTIKI)/core/net/mac/Makefile.mac
SYSTEM = process.c procinit.c autostart.c elfloader.c profile.c \
Expand All @@ -60,8 +60,8 @@ ifdef UIP_CONF_IPV6
CFLAGS += -DUIP_CONF_IPV6
UIP = uip6.c tcpip.c psock.c uip-udp-packet.c uip-split.c \
resolv.c tcpdump.c uiplib.c
NET += $(UIP) uip-icmp6.c uip-nd6.c uip-nd6-io.c uip-netif.c \
sicslowpan.c neighbor-attr.c neighbor-info.c
NET += $(UIP) uip-icmp6.c uip-nd6.c \
sicslowpan.c neighbor-attr.c neighbor-info.c uip-ds6.c
else # UIP_CONF_IPV6
UIP = uip.c uiplib.c resolv.c tcpip.c psock.c hc.c uip-split.c uip-fw.c \
uip-fw-drv.c uip_arp.c tcpdump.c uip-neighbor.c uip-udp-packet.c \
Expand Down
28 changes: 14 additions & 14 deletions core/net/sicslowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: sicslowpan.c,v 1.27 2010/03/12 13:40:13 nvt-se Exp $
* $Id: sicslowpan.c,v 1.28 2010/03/15 16:41:24 joxe Exp $
*/
/**
* \file
Expand Down Expand Up @@ -62,7 +62,7 @@
#include "dev/watchdog.h"
#include "net/tcpip.h"
#include "net/uip.h"
#include "net/uip-netif.h"
#include "net/uip-ds6.h"
#include "net/rime.h"
#include "net/sicslowpan.h"
#include "net/neighbor-info.h"
Expand Down Expand Up @@ -753,8 +753,8 @@ uncompress_hdr_hc06(u16_t ip_len) {
/* copy prefix from context */
memcpy(&SICSLOWPAN_IP_BUF->srcipaddr, context->prefix, 8);
/* infer IID from L2 address */
uip_netif_addr_autoconf_set(&SICSLOWPAN_IP_BUF->srcipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
uip_ds6_set_addr_iid(&SICSLOWPAN_IP_BUF->srcipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
break;
}
/* end context based compression */
Expand Down Expand Up @@ -790,8 +790,8 @@ uncompress_hdr_hc06(u16_t ip_len) {
/* copy 12 NULL bytes then 8 last bytes from L2 */
memset(&SICSLOWPAN_IP_BUF->srcipaddr.u8[2], 0, 6);
/* infer IID from L2 address */
uip_netif_addr_autoconf_set(&SICSLOWPAN_IP_BUF->srcipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
uip_ds6_set_addr_iid(&SICSLOWPAN_IP_BUF->srcipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
break;
}
}
Expand Down Expand Up @@ -866,8 +866,8 @@ uncompress_hdr_hc06(u16_t ip_len) {
case SICSLOWPAN_IPHC_DAM_11: /* 0 bits */
/* unicast address */
memcpy(&SICSLOWPAN_IP_BUF->destipaddr, context->prefix, 8);
uip_netif_addr_autoconf_set(&SICSLOWPAN_IP_BUF->destipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
uip_ds6_set_addr_iid(&SICSLOWPAN_IP_BUF->destipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
break;
}
} else {
Expand Down Expand Up @@ -895,8 +895,8 @@ uncompress_hdr_hc06(u16_t ip_len) {
SICSLOWPAN_IP_BUF->destipaddr.u8[0] = 0xfe;
SICSLOWPAN_IP_BUF->destipaddr.u8[1] = 0x80;
memset(&SICSLOWPAN_IP_BUF->destipaddr.u8[2], 0, 6);
uip_netif_addr_autoconf_set(&SICSLOWPAN_IP_BUF->destipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
uip_ds6_set_addr_iid(&SICSLOWPAN_IP_BUF->destipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
break;
}
}
Expand Down Expand Up @@ -1145,11 +1145,11 @@ uncompress_hdr_hc1(u16_t ip_len) {

/* src and dest ip addresses */
uip_ip6addr(&SICSLOWPAN_IP_BUF->srcipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
uip_netif_addr_autoconf_set(&SICSLOWPAN_IP_BUF->srcipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
uip_sd6_set_addr_iid(&SICSLOWPAN_IP_BUF->srcipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
uip_ip6addr(&SICSLOWPAN_IP_BUF->destipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
uip_netif_addr_autoconf_set(&SICSLOWPAN_IP_BUF->destipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
uip_sd6_set_addr_iid(&SICSLOWPAN_IP_BUF->destipaddr,
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));

uncomp_hdr_len += UIP_IPH_LEN;

Expand Down
144 changes: 59 additions & 85 deletions core/net/tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* This file is part of the Contiki operating system.
*
*
* $Id: tcpip.c,v 1.24 2010/02/09 12:58:53 adamdunkels Exp $
* $Id: tcpip.c,v 1.25 2010/03/15 16:41:24 joxe Exp $
*/
/**
* \file
Expand All @@ -47,7 +47,7 @@

#if UIP_CONF_IPV6
#include "net/uip-nd6.h"
#include "net/uip-netif.h"
#include "net/uip-ds6.h"
#endif

#define DEBUG 0
Expand Down Expand Up @@ -469,28 +469,23 @@ eventhandler(process_event_t ev, process_data_t data)
* check the different timers for neighbor discovery and
* stateless autoconfiguration
*/
if(data == &uip_nd6_timer_periodic &&
/*if(data == &uip_nd6_timer_periodic &&
etimer_expired(&uip_nd6_timer_periodic)) {
uip_nd6_periodic();
tcpip_ipv6_output();
}

if(data == &uip_netif_timer_dad &&
etimer_expired(&uip_netif_timer_dad)){
uip_netif_dad();
}*/
#if !UIP_CONF_ROUTER
if(data == &uip_ds6_timer_rs &&
etimer_expired(&uip_ds6_timer_rs)){
uip_ds6_send_rs();
tcpip_ipv6_output();
}
if(data == &uip_netif_timer_rs &&
etimer_expired(&uip_netif_timer_rs)){
uip_netif_send_rs();
#endif /* !UIP_CONF_ROUTER */
if(data == &uip_ds6_timer_periodic &&
etimer_expired(&uip_ds6_timer_periodic)){
uip_ds6_periodic();
tcpip_ipv6_output();
}

if(data == &uip_netif_timer_periodic &&
etimer_expired(&uip_netif_timer_periodic)){
uip_netif_periodic();
}
#endif /* UIP_CONF_IPV6 */
}
break;
Expand Down Expand Up @@ -547,8 +542,8 @@ tcpip_input(void)
void
tcpip_ipv6_output(void)
{
struct uip_nd6_neighbor *nbc = NULL;
struct uip_nd6_defrouter *dr = NULL;
uip_ds6_nbr_t *nbr = NULL;
uip_ipaddr_t* nexthop;

if(uip_len == 0)
return;
Expand All @@ -564,97 +559,76 @@ tcpip_ipv6_output(void)
return;
}
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
/*If destination is on link */
nbc = NULL;
if(uip_nd6_is_addr_onlink(&UIP_IP_BUF->destipaddr)){
nbc = uip_nd6_nbrcache_lookup(&UIP_IP_BUF->destipaddr);
/* Next hop determination */
nbr = NULL;
if(uip_ds6_is_addr_onlink(&UIP_IP_BUF->destipaddr)){
nexthop = &UIP_IP_BUF->destipaddr;
} else {
#if UIP_CONF_ROUTER
/*destination is not on link*/
uip_ipaddr_t ipaddr;
uip_ipaddr_t *next_hop;

/* Try to find the next hop address in the local routing table. */
next_hop = uip_router != NULL ?
uip_router->lookup(&UIP_IP_BUF->destipaddr, &ipaddr) : NULL;
if(next_hop != NULL) {
/* Look for the next hop of the route in the neighbor cache.
Add a cache entry if we can't find it. */
nbc = uip_nd6_nbrcache_lookup(next_hop);
if(nbc == NULL) {
nbc = uip_nd6_nbrcache_add(next_hop, NULL, 1, NO_STATE);
}
} else {
#endif /* UIP_CONF_ROUTER */
/* No route found, check if a default router exists and use it then. */
dr = uip_nd6_choose_defrouter();
if(dr != NULL){
nbc = dr->nb;
} else {
/* shall we send a icmp error message destination unreachable ?*/
UIP_LOG("tcpip_ipv6_output: Destination off-link but no router");
uip_ds6_route_t* locrt;
locrt = uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr);
if(locrt == NULL) {
if((nexthop = uip_ds6_defrt_choose()) == NULL) {
PRINTF("tcpip_ipv6_output: Destination off-link but no route\n");
uip_len = 0;
return;
}
#if UIP_CONF_ROUTER
} else {
nexthop = &locrt->nexthop;
}
#endif /* UIP_CONF_ROUTER */
}
/* there are two cases where the entry logically does not exist:
* 1 it really does not exist. 2 it is in the NO_STATE state */
if (nbc == NULL || nbc->state == NO_STATE) {
if (nbc == NULL) {
/* create neighbor cache entry, original packet is replaced by NS*/
nbc = uip_nd6_nbrcache_add(&UIP_IP_BUF->destipaddr, NULL, 0, INCOMPLETE);
/* end of next hop determination */
if((nbr = uip_ds6_nbr_lookup(nexthop)) == NULL) {
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE)) == NULL) {
uip_len = 0;
return;
} else {
nbc->state = INCOMPLETE;
}
#if UIP_CONF_IPV6_QUEUE_PKT
/* copy outgoing pkt in the queuing buffer for later transmmit */
memcpy(nbc->queue_buf, UIP_IP_BUF, uip_len);
nbc->queue_buf_len = uip_len;
/* copy outgoing pkt in the queuing buffer for later transmmit */
memcpy(nbr->queue_buf, UIP_IP_BUF, uip_len);
nbr->queue_buf_len = uip_len;
#endif
/* RFC4861, 7.2.2:
* "If the source address of the packet prompting the solicitation is the
* same as one of the addresses assigned to the outgoing interface, that
* address SHOULD be placed in the IP Source Address of the outgoing
* solicitation. Otherwise, any one of the addresses assigned to the
* interface should be used."*/
if(uip_netif_is_addr_my_unicast(&UIP_IP_BUF->srcipaddr)){
uip_nd6_io_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbc->ipaddr);
} else {
uip_nd6_io_ns_output(NULL, NULL, &nbc->ipaddr);
}
if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)){
uip_nd6_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbr->ipaddr);
} else {
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
}

stimer_set(&(nbc->last_send),
uip_netif_physical_if.retrans_timer / 1000);
nbc->count_send = 1;
stimer_set(&(nbr->sendns), uip_ds6_if.retrans_timer / 1000);
nbr->nscount = 1;
}
} else {
if (nbc->state == INCOMPLETE){
PRINTF("tcpip_ipv6_output: neighbor cache entry incomplete\n");
if (nbr->state == NBR_INCOMPLETE){
PRINTF("tcpip_ipv6_output: nbr cache entry incomplete\n");
#if UIP_CONF_IPV6_QUEUE_PKT
/* copy outgoing pkt in the queuing buffer for later transmmit and set
the destination neighbor to nbc */
memcpy(nbc->queue_buf, UIP_IP_BUF, uip_len);
nbc->queue_buf_len = uip_len;
the destination nbr to nbr */
memcpy(nbr->queue_buf, UIP_IP_BUF, uip_len);
nbr->queue_buf_len = uip_len;
uip_len = 0;
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
return;
}
/* if running NUD (nbc->state == STALE, DELAY, or PROBE ) keep
sending in parallel see rfc 4861 Node behavior in section 7.7.3*/

if (nbc->state == STALE){
nbc->state = DELAY;
stimer_set(&(nbc->reachable),
if (nbr->state == NBR_STALE){
nbr->state = NBR_DELAY;
stimer_set(&(nbr->reachable),
UIP_ND6_DELAY_FIRST_PROBE_TIME);
PRINTF("tcpip_ipv6_output: neighbor cache entry stale moving to delay\n");
nbr->nscount = 0;
PRINTF("tcpip_ipv6_output: nbr cache entry stale moving to delay\n");
}

stimer_set(&(nbc->last_send),
uip_netif_physical_if.retrans_timer / 1000);
stimer_set(&(nbr->sendns),
uip_ds6_if.retrans_timer / 1000);

tcpip_output(&(nbc->lladdr));
tcpip_output(&(nbr->lladdr));


#if UIP_CONF_IPV6_QUEUE_PKT
Expand All @@ -663,11 +637,11 @@ tcpip_ipv6_output(void)
* NA after sendiong a NS, you receive a NS with SLLAO: the entry moves
*to STALE, and you must both send a NA and the queued packet
*/
if(nbc->queue_buf_len != 0) {
uip_len = nbc->queue_buf_len;
memcpy(UIP_IP_BUF, nbc->queue_buf, uip_len);
nbc->queue_buf_len = 0;
tcpip_output(&(nbc->lladdr));
if(nbr->queue_buf_len != 0) {
uip_len = nbr->queue_buf_len;
memcpy(UIP_IP_BUF, nbr->queue_buf, uip_len);
nbr->queue_buf_len = 0;
tcpip_output(&(nbr->lladdr));
}
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/

Expand Down
Loading

0 comments on commit fd3d6c4

Please sign in to comment.