Added logic for announcing that a network has a gateway to the outside world (with the function uip_over_mesh_make_announced_gateway()). The announced gateway sends a trickle message to the network, containing the address of the gateway. Other nodes will then know that packets destined to the outside world should go through the gateway node.

This commit is contained in:
adamdunkels 2008-11-09 12:20:56 +00:00
parent 8851a6359a
commit 5243d58ac5
2 changed files with 56 additions and 2 deletions

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: uip-over-mesh.c,v 1.9 2008/06/26 11:19:40 adamdunkels Exp $
* $Id: uip-over-mesh.c,v 1.10 2008/11/09 12:20:56 adamdunkels Exp $
*/
/**
@ -42,16 +42,26 @@
#include "net/hc.h"
#include "net/uip-fw.h"
#include "net/uip-over-mesh.h"
#include "net/rime/route-discovery.h"
#include "net/rime/route.h"
#include "net/rime/trickle.h"
#define ROUTE_TIMEOUT CLOCK_SECOND * 4
static struct queuebuf *queued_packet;
static rimeaddr_t queued_receiver;
/* Connection for route discovery: */
static struct route_discovery_conn route_discovery;
/* Connection for sending data packets to the next hop node: */
static struct unicast_conn dataconn;
/* Connection for sending gateway announcement message to the entire
network: */
static struct trickle_conn gateway_announce_conn;
#define DEBUG 0
#if DEBUG
#include <stdio.h>
@ -121,6 +131,45 @@ timedout(struct route_discovery_conn *c)
static const struct unicast_callbacks data_callbacks = { recv_data };
static const struct route_discovery_callbacks rdc = { new_route, timedout };
/*---------------------------------------------------------------------------*/
struct gateway_msg {
rimeaddr_t gateway;
};
static uint8_t is_gateway;
static void
gateway_announce_recv(struct trickle_conn *c)
{
struct gateway_msg *msg;
msg = rimebuf_dataptr();
PRINTF("%d.%d: gateway message: %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
msg->gateway.u8[0], msg->gateway.u8[1]);
if(!is_gateway) {
uip_over_mesh_set_gateway(&msg->gateway);
}
}
/*---------------------------------------------------------------------------*/
void
uip_over_mesh_make_announced_gateway(void)
{
struct gateway_msg msg;
/* Make this node the gateway node, unless it already is the
gateway. */
if(!is_gateway) {
PRINTF("%d.%d: making myself the gateway\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
uip_over_mesh_set_gateway(&rimeaddr_node_addr);
rimeaddr_copy(&(msg.gateway), &rimeaddr_node_addr);
rimebuf_copyfrom(&msg, sizeof(struct gateway_msg));
trickle_send(&gateway_announce_conn);
is_gateway = 1;
}
}
const static struct trickle_callbacks trickle_call = {gateway_announce_recv};
/*---------------------------------------------------------------------------*/
void
uip_over_mesh_init(u16_t channels)
{
@ -133,6 +182,9 @@ uip_over_mesh_init(u16_t channels)
unicast_open(&dataconn, channels, &data_callbacks);
route_discovery_open(&route_discovery, CLOCK_SECOND / 4,
channels + 1, &rdc);
trickle_open(&gateway_announce_conn, CLOCK_SECOND * 4, channels + 3,
&trickle_call);
/* tcpip_set_forwarding(1);*/
}

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: uip-over-mesh.h,v 1.2 2008/02/03 20:56:07 adamdunkels Exp $
* $Id: uip-over-mesh.h,v 1.3 2008/11/09 12:20:56 adamdunkels Exp $
*/
/**
@ -52,4 +52,6 @@ void uip_over_mesh_set_gateway_netif(struct uip_fw_netif *netif);
void uip_over_mesh_set_gateway(rimeaddr_t *gw);
void uip_over_mesh_set_net(uip_ipaddr_t *addr, uip_ipaddr_t *mask);
void uip_over_mesh_make_announced_gateway(void);
#endif /* __UIP-OVER-MESH_H__ */