mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-10-13 05:24:21 +00:00
Simulation test with more RPL nodes than the network can handle that attempt to access a remote HTTP server. After completing their connection, they go to feather mode, freeing up route table entries in the network, to let more nodes reach the HTTP server
This commit is contained in:
parent
bfb29d2f11
commit
52006aec0f
1006
regression-tests/21-large-rpl/01-cooja-http-socket-50.csc
Normal file
1006
regression-tests/21-large-rpl/01-cooja-http-socket-50.csc
Normal file
File diff suppressed because it is too large
Load Diff
1
regression-tests/21-large-rpl/Makefile
Normal file
1
regression-tests/21-large-rpl/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include ../Makefile.simulation-test
|
7
regression-tests/21-large-rpl/code/node/Makefile
Normal file
7
regression-tests/21-large-rpl/code/node/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
CONTIKI=../../../..
|
||||
|
||||
MODULES += core/net/http-socket
|
||||
|
||||
CFLAGS+=-DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
103
regression-tests/21-large-rpl/code/node/client.c
Normal file
103
regression-tests/21-large-rpl/code/node/client.c
Normal file
@ -0,0 +1,103 @@
|
||||
#include "contiki-net.h"
|
||||
#include "http-socket.h"
|
||||
#include "ip64-addr.h"
|
||||
#include "dev/leds.h"
|
||||
#include "rpl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static struct http_socket s;
|
||||
static int bytes_received = 0;
|
||||
static int restarts;
|
||||
static struct ctimer reconnect_timer;
|
||||
|
||||
static void callback(struct http_socket *s, void *ptr,
|
||||
http_socket_event_t e,
|
||||
const uint8_t *data, uint16_t datalen);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(http_example_process, "HTTP Example");
|
||||
AUTOSTART_PROCESSES(&http_example_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
reconnect(void *dummy)
|
||||
{
|
||||
rpl_set_mode(RPL_MODE_MESH);
|
||||
http_socket_get(&s, "http://www.contiki-os.org/", 0, 0,
|
||||
callback, NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
restart(void)
|
||||
{
|
||||
int scale;
|
||||
restarts++;
|
||||
printf("restart %d\n", restarts);
|
||||
|
||||
scale = restarts;
|
||||
if(scale > 5) {
|
||||
scale = 5;
|
||||
}
|
||||
ctimer_set(&reconnect_timer, random_rand() % ((CLOCK_SECOND * 10) << scale),
|
||||
reconnect, NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
callback(struct http_socket *s, void *ptr,
|
||||
http_socket_event_t e,
|
||||
const uint8_t *data, uint16_t datalen)
|
||||
{
|
||||
if(e == HTTP_SOCKET_ERR) {
|
||||
printf("HTTP socket error\n");
|
||||
} else if(e == HTTP_SOCKET_TIMEDOUT) {
|
||||
printf("HTTP socket error: timed out\n");
|
||||
restart();
|
||||
} else if(e == HTTP_SOCKET_ABORTED) {
|
||||
printf("HTTP socket error: aborted\n");
|
||||
restart();
|
||||
} else if(e == HTTP_SOCKET_HOSTNAME_NOT_FOUND) {
|
||||
printf("HTTP socket error: hostname not found\n");
|
||||
restart();
|
||||
} else if(e == HTTP_SOCKET_CLOSED) {
|
||||
if(bytes_received > 0) {
|
||||
printf("HTTP socket closed, %d bytes received\n", bytes_received);
|
||||
leds_off(LEDS_RED);
|
||||
rpl_set_mode(RPL_MODE_FEATHER);
|
||||
} else {
|
||||
restart();
|
||||
}
|
||||
} else if(e == HTTP_SOCKET_DATA) {
|
||||
bytes_received += datalen;
|
||||
printf("HTTP socket received %d bytes of data\n", datalen);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(http_example_process, ev, data)
|
||||
{
|
||||
static struct etimer et;
|
||||
uip_ip4addr_t ip4addr;
|
||||
uip_ip6addr_t ip6addr;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
uip_ipaddr(&ip4addr, 8,8,8,8);
|
||||
ip64_addr_4to6(&ip4addr, &ip6addr);
|
||||
uip_nameserver_update(&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
|
||||
etimer_set(&et, CLOCK_SECOND * 20);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
|
||||
http_socket_init(&s);
|
||||
http_socket_get(&s, "http://www.contiki-os.org/", 0, 0,
|
||||
callback, NULL);
|
||||
leds_on(LEDS_RED);
|
||||
restarts = 0;
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
etimer_reset(&et);
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
6
regression-tests/21-large-rpl/code/node/project-conf.h
Normal file
6
regression-tests/21-large-rpl/code/node/project-conf.h
Normal file
@ -0,0 +1,6 @@
|
||||
#define QUEUEBUF_CONF_STATS 1
|
||||
#define RESOLV_CONF_SUPPORTS_MDNS 0
|
||||
#define COOJA_MTARCH_STACKSIZE 4096
|
||||
|
||||
#define UIP_CONF_MAX_ROUTES 3
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 3
|
5
regression-tests/21-large-rpl/code/router/Makefile
Normal file
5
regression-tests/21-large-rpl/code/router/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
CONTIKI=../../../..
|
||||
|
||||
CFLAGS+=-DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
9
regression-tests/21-large-rpl/code/router/project-conf.h
Normal file
9
regression-tests/21-large-rpl/code/router/project-conf.h
Normal file
@ -0,0 +1,9 @@
|
||||
#define QUEUEBUF_CONF_STATS 1
|
||||
#define RESOLV_CONF_SUPPORTS_MDNS 0
|
||||
#define COOJA_MTARCH_STACKSIZE 4096
|
||||
|
||||
#define UIP_CONF_MAX_ROUTES 8
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 8
|
||||
|
||||
/*#define RPL_CONF_DEFAULT_LIFETIME_UNIT 10
|
||||
#define RPL_CONF_DEFAULT_LIFETIME 10*/
|
27
regression-tests/21-large-rpl/code/router/router.c
Normal file
27
regression-tests/21-large-rpl/code/router/router.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "ip64.h"
|
||||
#include "net/netstack.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(router_node_process, "Router node");
|
||||
AUTOSTART_PROCESSES(&router_node_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(router_node_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Set us up as a RPL root node. */
|
||||
rpl_dag_root_init_dag();
|
||||
|
||||
/* Initialize the IP64 module so we'll start translating packets */
|
||||
ip64_init();
|
||||
|
||||
/* ... and do nothing more. */
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
78
regression-tests/21-large-rpl/testscript.js
Normal file
78
regression-tests/21-large-rpl/testscript.js
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
TIMEOUT(2400000); /* 40 minutes */
|
||||
|
||||
var NR_FEATHERS = mote.getSimulation().getMotesCount() - 1;
|
||||
|
||||
/* conf */
|
||||
var travis = java.lang.System.getenv().get("TRAVIS");
|
||||
if (travis == null) {
|
||||
/* Instant Contiki */
|
||||
CMD_TUNNEL = "echo '-vj' > ~/.slirprc && make Connect.class && java Connect 'nc localhost 60001' 'script -t -f -c slirp'";
|
||||
CMD_PING = "ping -c 5 8.8.8.8";
|
||||
CMD_DIR = "../../wpcapslip";
|
||||
} else {
|
||||
/* Travis */
|
||||
CMD_TUNNEL = "cd $TRAVIS_BUILD_DIR/tools/wpcapslip && sudo apt-get install slirp && echo '-vj' > ~/.slirprc && make Connect.class && java Connect 'nc localhost 60001' 'script -t -f -c slirp'";
|
||||
CMD_PING = "ping -c 5 8.8.8.8";
|
||||
CMD_DIR = ".";
|
||||
}
|
||||
|
||||
/* delay */
|
||||
GENERATE_MSG(1000, "continue");
|
||||
YIELD_THEN_WAIT_UNTIL(msg.equals("continue"));
|
||||
|
||||
/* realtime speed */
|
||||
sim.setSpeedLimit(2.0);
|
||||
|
||||
/* tunnel interface */
|
||||
log.log("opening tunnel interface: " + CMD_TUNNEL + "\n");
|
||||
launcher = new java.lang.ProcessBuilder["(java.lang.String[])"](['sh','-c',CMD_TUNNEL]);
|
||||
launcher.directory(new java.io.File(CMD_DIR));
|
||||
launcher.redirectErrorStream(true);
|
||||
tunProcess = launcher.start();
|
||||
tunRunnable = new Object();
|
||||
tunRunnable.run = function() {
|
||||
var stdIn = new java.io.BufferedReader(new java.io.InputStreamReader(tunProcess.getInputStream()));
|
||||
while ((line = stdIn.readLine()) != null) {
|
||||
if (line != null && !line.trim().equals("")) {
|
||||
//log.log("TUN> " + line + "\n");
|
||||
}
|
||||
}
|
||||
tunProcess.destroy();
|
||||
}
|
||||
new java.lang.Thread(new java.lang.Runnable(tunRunnable)).start();
|
||||
|
||||
GENERATE_MSG(1000, "continue");
|
||||
YIELD_THEN_WAIT_UNTIL(msg.equals("continue"));
|
||||
|
||||
/* ping */
|
||||
log.log("pinging: " + CMD_PING + "\n");
|
||||
launcher = new java.lang.ProcessBuilder["(java.lang.String[])"](['sh','-c',CMD_PING]);
|
||||
launcher.directory(new java.io.File(CMD_DIR));
|
||||
launcher.redirectErrorStream(true);
|
||||
tunProcess = launcher.start();
|
||||
tunRunnable = new Object();
|
||||
tunRunnable.run = function() {
|
||||
var stdIn = new java.io.BufferedReader(new java.io.InputStreamReader(tunProcess.getInputStream()));
|
||||
while ((line = stdIn.readLine()) != null) {
|
||||
if (line != null && !line.trim().equals("")) {
|
||||
log.log("PING> " + line + "\n");
|
||||
}
|
||||
}
|
||||
tunProcess.destroy();
|
||||
}
|
||||
new java.lang.Thread(new java.lang.Runnable(tunRunnable)).start();
|
||||
|
||||
var completed = {};
|
||||
while(Object.keys(completed).length < NR_FEATHERS) {
|
||||
if (!msg.startsWith("#L") && !msg.startsWith("E")) {
|
||||
//log.log(mote + ": " + msg + "\n");
|
||||
}
|
||||
if (id != 1 && msg.startsWith("HTTP socket closed")) {
|
||||
completed[id] = id;
|
||||
log.log("Data compelete " + id + ", heard " + Object.keys(completed).length + " in total\n");
|
||||
}
|
||||
YIELD();
|
||||
}
|
||||
|
||||
log.testOK();
|
Loading…
Reference in New Issue
Block a user