Program for testing the Rime reliable unicast bulk transfer protocol
This commit is contained in:
parent
1abf2c4c16
commit
6c241b9f2b
141
examples/rime/test-rucb.c
Normal file
141
examples/rime/test-rucb.c
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: test-rucb.c,v 1.1 2007/09/27 22:21:27 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Testing the rucb code in Rime
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/rime/rucb.h"
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include "sys/profile.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define FILESIZE 40000
|
||||
|
||||
static unsigned long bytecount;
|
||||
static clock_time_t start_time;
|
||||
|
||||
extern int profile_max_queuelen;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_rucb_process, "Rucb test");
|
||||
AUTOSTART_PROCESSES(&test_rucb_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_chunk(struct rucb_conn *c, int offset, int flag,
|
||||
char *data, int datalen)
|
||||
{
|
||||
#if NETSIM
|
||||
{
|
||||
char buf[100];
|
||||
printf("received %d; %d\n", offset, datalen);
|
||||
sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE);
|
||||
ether_set_text(buf);
|
||||
}
|
||||
#endif /* NETSIM */
|
||||
|
||||
}
|
||||
static int
|
||||
read_chunk(struct rucb_conn *c, int offset, char *to, int maxsize)
|
||||
{
|
||||
int size;
|
||||
size = maxsize;
|
||||
if(bytecount + maxsize >= FILESIZE) {
|
||||
size = FILESIZE - bytecount;
|
||||
}
|
||||
bytecount += size;
|
||||
|
||||
if(bytecount == FILESIZE) {
|
||||
printf("Completion time %u / %u\n", clock_time() - start_time, CLOCK_SECOND);
|
||||
/* profile_aggregates_print(); */
|
||||
/* profile_print_stats(); */
|
||||
print_stats();
|
||||
}
|
||||
|
||||
/* printf("bytecount %lu\n", bytecount);*/
|
||||
return size;
|
||||
}
|
||||
const static struct rucb_callbacks rucb_call = {write_chunk, read_chunk,
|
||||
NULL};
|
||||
static struct rucb_conn rucb;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "node-id.h"
|
||||
|
||||
PROCESS_THREAD(test_rucb_process, ev, data)
|
||||
{
|
||||
static int fd;
|
||||
PROCESS_EXITHANDLER(rucb_close(&rucb);)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
|
||||
rucb_open(&rucb, 128, &rucb_call);
|
||||
button_sensor.activate();
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
if(rimeaddr_node_addr.u8[0] == 10 &&
|
||||
rimeaddr_node_addr.u8[1] == 0) {
|
||||
rimeaddr_t recv;
|
||||
|
||||
recv.u8[0] = 20;
|
||||
recv.u8[1] = 0;
|
||||
start_time = clock_time();
|
||||
rucb_send(&rucb, &recv);
|
||||
#if NETSIM
|
||||
ether_send_done();
|
||||
#endif /* NETSIM */
|
||||
}
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
||||
data == &button_sensor);
|
||||
/*rucb_stop(&rucb);*/
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
Loading…
Reference in a new issue