Added uip-over-mesh, bugfixes, printing of statistics, renamed init() function to netsim_init()

This commit is contained in:
adamdunkels 2007-03-22 18:59:34 +00:00
parent eea7f463d7
commit 1b762247fa
12 changed files with 128 additions and 148 deletions

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: contiki-main.c,v 1.7 2007/03/15 21:58:13 adamdunkels Exp $
* $Id: contiki-main.c,v 1.8 2007/03/22 18:59:34 adamdunkels Exp $
*/
#include "contiki.h"
@ -44,6 +44,7 @@
#include "net/ethernode-uip.h"
#include "net/ethernode-rime.h"
#include "net/ethernode.h"
#include "net/uip-over-mesh.h"
#include "ether.h"
@ -59,14 +60,13 @@
static struct uip_fw_netif tapif =
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tapdev_send)};
static struct uip_fw_netif meshif =
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
/*static struct uip_fw_netif ethernodeif =
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, ethernode_drv_send)};*/
static const struct uip_eth_addr ethaddr = {{0x00,0x06,0x98,0x01,0x02,0x12}};
/*PROCESS(test_send_process, "Test send stuff");
PROCESS(test_tcp_process, "Test TCP");*/
SENSORS(&button_sensor, &pir_sensor, &vib_sensor, &radio_sensor);
PROCINIT(&sensors_process, &etimer_process, &tcpip_process,
@ -74,79 +74,6 @@ PROCINIT(&sensors_process, &etimer_process, &tcpip_process,
&ethernode_rime_process,
&uip_fw_process);
#if 0
static
PT_THREAD(send_packet(struct pt *pt,
struct uip_udp_conn *c, process_event_t ev,
process_data_t data))
{
PT_BEGIN(pt);
tcpip_poll_udp(c);
PT_YIELD_UNTIL(pt, ev == tcpip_event);
uip_send("hej", 3);
PT_END(pt);
}
PROCESS_THREAD(test_send_process, ev, data)
{
static struct uip_udp_conn *conn;
static struct etimer etimer;
static struct pt send_pt;
PROCESS_BEGIN();
conn = udp_broadcast_new(HTONS(3737), NULL);
etimer_set(&etimer, CLOCK_SECOND * 2);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer) || uip_newdata());
if(uip_newdata()) {
/* printf("Got a packet!\n");*/
}
if(etimer_expired(&etimer)) {
PROCESS_SPAWN(&send_pt, send_packet(&send_pt, conn, ev, data));
etimer_set(&etimer, CLOCK_SECOND * 2);
}
}
PROCESS_END();
}
PROCESS_THREAD(test_tcp_process, ev, data)
{
uip_ipaddr_t server;
PROCESS_BEGIN();
uip_ipaddr(server, 255,255,255,255);
tcp_connect(server, HTONS(1000), NULL);
while(1) {
PROCESS_WAIT_EVENT();
printf("test_tcp_process: event %d\n", ev);
}
PROCESS_END();
}
#endif /* 0 */
/*---------------------------------------------------------------------------*/
/*static void
idle(void)
{
ether_server_poll();
display_tick();
display_redraw();
ether_tick();
ek_run();
}*/
/*---------------------------------------------------------------------------*/
void
contiki_main(int flag)
@ -160,16 +87,20 @@ contiki_main(int flag)
procinit_init();
uip_init();
rime_init();
uip_over_mesh_init(0);
if(flag == 1) {
process_start(&tapdev_drv_process, NULL);
/* uip_fw_register(&ethernodeif);*/
uip_fw_register(&meshif);
uip_fw_default(&tapif);
printf("uip_hostaddr %02x%02x\n", uip_hostaddr.u16[0], uip_hostaddr.u16[1]);
} else {
/* uip_fw_default(&ethernodeif);*/
uip_fw_default(&meshif);
}
leds_green(LEDS_ON);
autostart_start(autostart_processes);

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.c,v 1.5 2007/03/13 13:07:47 adamdunkels Exp $
* $Id: ether.c,v 1.6 2007/03/22 18:59:34 adamdunkels Exp $
*/
/**
* \file
@ -107,13 +107,16 @@ static int strength;
static int collisions = 1;
static int num_collisions = 0;
static int num_packets = 0;
static int num_sent = 0;
static int num_received = 0;
static int drop_probability = 0;
static int num_drops = 0;
#include <sys/time.h>
static struct timeval t1;
/*-----------------------------------------------------------------------------------*/
void
int
ether_print_stats(void)
{
unsigned long time;
@ -122,7 +125,20 @@ ether_print_stats(void)
time = (t2.tv_sec * 1000 + t2.tv_usec / 1000) -
(t1.tv_sec * 1000 + t1.tv_usec / 1000);
printf("%d, %d, %f\n", num_packets, num_collisions, time/1000.0);
/* printf("%d, %d, %f\n", num_packets, num_collisions, time/1000.0);*/
printf("Time: %f\n", time/1000.0);
printf("Total packets sent: %d\n", num_sent);
printf("Total collisions: %d\n", num_collisions);
printf("Total packets receptions: %d\n", num_received);
printf("Total randomly dropped packets: %d\n", num_drops);
return 0;
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_drop_probability(double p)
{
drop_probability = p * 65536;
}
/*-----------------------------------------------------------------------------------*/
void
@ -204,8 +220,8 @@ ether_client_init(int port)
}
}
/*-----------------------------------------------------------------------------------*/
u16_t
ether_client_poll(u8_t *buf, int bufsize)
int
ether_client_poll(void)
{
int ret, len;
fd_set fdset;
@ -216,7 +232,24 @@ ether_client_poll(u8_t *buf, int bufsize)
FD_SET(sc, &fdset);
tv.tv_sec = 0;
tv.tv_usec = 5000;
tv.tv_usec = 10000;
return select(sc + 1, &fdset, NULL, NULL, &tv);
}
/*-----------------------------------------------------------------------------------*/
u16_t
ether_client_read(u8_t *buf, int bufsize)
{
int ret, len;
fd_set fdset;
struct timeval tv;
struct ether_hdr *hdr = (struct ether_hdr *)rxbuffer;
FD_ZERO(&fdset);
FD_SET(sc, &fdset);
tv.tv_sec = 0;
tv.tv_usec = 10000;
ret = select(sc + 1, &fdset, NULL, NULL, &tv);
@ -365,7 +398,7 @@ ether_tick(void)
range of this node. */
for(p = list_head(active_packets); p != NULL; p = p->next) {
num_packets++;
num_sent++;
/* Update the node type. */
hdr = (struct ether_hdr *)p->data;
@ -402,13 +435,18 @@ ether_tick(void)
if(interference) {
num_collisions++;
printf("Collisions %d\n", num_collisions);
/* printf("Collisions %d\n", num_collisions);*/
}
if(!interference) {
/* printf("ether: delivering packet from %d to %d\n",
hdr->srcid, port);*/
send_packet(p->data, p->len, port);
if((unsigned int)((rand() * 17) % 65536) >= drop_probability) {
send_packet(p->data, p->len, port);
num_received++;
} else {
num_drops++;
}
}
}

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.h,v 1.4 2007/03/13 13:07:48 adamdunkels Exp $
* $Id: ether.h,v 1.5 2007/03/22 18:59:34 adamdunkels Exp $
*/
#ifndef __ETHER_H__
#define __ETHER_H__
@ -59,7 +59,7 @@ void ether_client_init(int port);
void ether_tick(void);
u16_t ether_client_poll(u8_t *buf, int len);
u16_t ether_client_read(u8_t *buf, int len);
void ether_server_poll(void);
void ether_put(char *packet, int len, int src_x, int src_y);
@ -75,8 +75,9 @@ clock_time_t ether_time(void);
/*#define ETHER_STRENGTH 24*/
int ether_strength(void);
void ether_set_strength(int s);
void ether_set_collisions(int c);
void ether_set_drop_probability(double p);
int ether_print_stats(void);
#endif /* __ETHER_H__ */

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: main.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $
* $Id: main.c,v 1.5 2007/03/22 18:59:34 adamdunkels Exp $
*/
/**
@ -111,7 +111,6 @@ start_node(int x, int y, int b)
pid_t pid;
static unsigned short port = NODES_PORTBASE;
pid = fork();
if(pid == 0) {
@ -121,18 +120,16 @@ start_node(int x, int y, int b)
srandom(getpid());
usleep(1000 * ((random() & 0x0f) << 6) );
usleep(1000 * (rand() % 1000));
node_init(port - NODES_PORTBASE + 2, x, y, b);
ethernode_init(port);
contiki_main(b);
/* NOTREACHED */
}
/* printf("Adding sensor %d at (%d,%d)\n", pid, x, y);*/
/* printf("Adding sensor %d at (%d,%d)\n", pid, x, y);*/
main_process = 1;
nodes_add(pid, x, y, port, port - NODES_PORTBASE + 2);
@ -163,8 +160,9 @@ main(int argc, char **argv)
nodes_init();
atexit(nodes_kill);
atexit(ether_print_stats);
init();
netsim_init();
ether_server_init();

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode-rime.c,v 1.3 2007/03/15 21:58:37 adamdunkels Exp $
* $Id: ethernode-rime.c,v 1.4 2007/03/22 18:59:34 adamdunkels Exp $
*/
#include "contiki.h"
@ -58,7 +58,7 @@ PROCESS_THREAD(ethernode_rime_process, ev, data)
rimebuf_clear();
len = ethernode_poll(rimebuf_dataptr(), RIMEBUF_SIZE);
len = ethernode_read(rimebuf_dataptr(), RIMEBUF_SIZE);
if(len > 0) {

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode-uip.c,v 1.2 2007/03/15 21:59:10 adamdunkels Exp $
* $Id: ethernode-uip.c,v 1.3 2007/03/22 18:59:34 adamdunkels Exp $
*/
#include "contiki.h"
@ -65,7 +65,7 @@ PROCESS_THREAD(ethernode_uip_process, ev, data)
PROCESS_WAIT_EVENT();
/* Poll Ethernet device to see if there is a frame avaliable. */
uip_len = ethernode_poll(uip_buf, UIP_BUFSIZE);
uip_len = ethernode_read(uip_buf, UIP_BUFSIZE);
if(uip_len > 0) {
/* printf("%d: new packet len %d\n", node_id, uip_len);*/

View file

@ -29,7 +29,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode-uip.h,v 1.1 2007/03/14 00:32:30 adamdunkels Exp $
* $Id: ethernode-uip.h,v 1.2 2007/03/22 18:59:34 adamdunkels Exp $
*/
#ifndef __ETHERNODE_UIP_H__
#define __ETHERNODE_UIP_H__
@ -40,6 +40,4 @@ PROCESS_NAME(ethernode_uip_process);
u8_t ethernode_uip_send(void);
u8_t ethernode_uip_send(void);
#endif /* __ETHERNODE_UIP_H__ */

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode.c,v 1.5 2007/03/14 00:32:30 adamdunkels Exp $
* $Id: ethernode.c,v 1.6 2007/03/22 18:59:34 adamdunkels Exp $
*/
/**
* \file
@ -122,13 +122,13 @@ ethernode_init(int port)
*/
/*-------------------------------------------------------------------------------*/
int
ethernode_poll(u8_t *buf, int bufsize)
ethernode_read(u8_t *buf, int bufsize)
{
int len;
u8_t tmpbuf[UIP_BUFSIZE];
struct hdr *hdr = (struct hdr *)tmpbuf;
len = ether_client_poll(tmpbuf, UIP_BUFSIZE);
len = ether_client_read(tmpbuf, UIP_BUFSIZE);
if(len == 0) {
return 0;
}

View file

@ -31,7 +31,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: tapdev.c,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
* $Id: tapdev.c,v 1.2 2007/03/22 18:59:34 adamdunkels Exp $
*/
@ -125,7 +125,9 @@ tapdev_init(void)
}
#endif /* Linux */
snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.2.1");
snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.1.1");
system(buf);
snprintf(buf, sizeof(buf), "route add -net 172.16.0.0 192.168.1.2");
system(buf);
printf("%s\n", buf);

View file

@ -28,13 +28,13 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: netsim-init.c,v 1.1 2007/03/21 09:07:15 adamdunkels Exp $
* @(#)$Id: netsim-init.c,v 1.2 2007/03/22 18:59:34 adamdunkels Exp $
*/
#include "init.h"
#include "random.h"
void
init(void)
netsim_init(void)
{
int x, y;

View file

@ -30,11 +30,12 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node.c,v 1.4 2007/03/13 13:07:48 adamdunkels Exp $
* $Id: node.c,v 1.5 2007/03/22 18:59:34 adamdunkels Exp $
*/
#include "node.h"
#include "contiki.h"
#include "net/uip.h"
#include "net/rime.h"
#include <string.h>
#include <stdlib.h>
@ -58,12 +59,23 @@ node_init(int id, int posx, int posy, int b)
/* node.type = NODE_TYPE_NORMAL;*/
if(b) {
uip_ipaddr(&addr, 192,168,250,2);
uip_ipaddr(&addr, 192,168,1,2);
} else {
uip_ipaddr(&addr, 10,10,posx,posy);
uip_ipaddr(&addr, 172,16,posx,posy);
}
uip_sethostaddr(&addr);
{
rimeaddr_t nodeaddr;
nodeaddr.u8[0] = posx;
nodeaddr.u8[1] = posy;
rimeaddr_set_node_addr(&nodeaddr);
}
drift = random() % 95726272;
init_node_log();