Skip to content

Commit 3c05f72

Browse files
committed
tests: Initial import of congure_reno tests
1 parent 0f16743 commit 3c05f72

File tree

8 files changed

+1227
-0
lines changed

8 files changed

+1227
-0
lines changed

tests/congure_reno/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
include ../Makefile.tests_common
2+
3+
USEMODULE += congure_reno
4+
USEMODULE += congure_test
5+
USEMODULE += fmt
6+
USEMODULE += shell
7+
USEMODULE += shell_commands
8+
9+
INCLUDES += -I$(CURDIR)
10+
11+
# Use a terminal that does not introduce extra characters into the stream.
12+
RIOT_TERMINAL ?= socat
13+
14+
CFLAGS += -DSTDIO_UART_RX_BUFSIZE=512 # Adapt to SHELL_BUFSIZE in app
15+
16+
include $(RIOTBASE)/Makefile.include
17+
18+
ifndef CONFIG_SHELL_NO_ECHO
19+
CFLAGS += -DCONFIG_SHELL_NO_ECHO=1
20+
endif
21+
22+
ifndef CONFIG_CONGURE_TEST_LOST_MSG_POOL_SIZE
23+
CFLAGS += -DCONFIG_CONGURE_TEST_LOST_MSG_POOL_SIZE=6
24+
endif

tests/congure_reno/Makefile.ci

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BOARD_INSUFFICIENT_MEMORY := \
2+
arduino-duemilanove \
3+
arduino-leonardo \
4+
arduino-nano \
5+
arduino-uno \
6+
atmega328p \
7+
atmega328p-xplained-mini \
8+
nucleo-l011k4 \
9+
#

tests/congure_reno/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Tests for the CongURE TCP Reno implementation
2+
=============================================
3+
4+
This test tests the `congure_reno` implementation.
5+
6+
Usage
7+
-----
8+
9+
The test requires an up-to-date version of `riotctrl` with `rapidjson` support:
10+
11+
```console
12+
$ pip install --upgrade riotctrl[rapidjson]
13+
```
14+
15+
Then simply run the application using:
16+
17+
```console
18+
$ BOARD="<board>" make flash test
19+
```
20+
21+
It can also executed with pytest:
22+
23+
```console
24+
$ pytest tests/01-run.py
25+
```
26+
27+
Expected result
28+
---------------
29+
30+
The application's test script passes without error code.

tests/congure_reno/app.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_KCONFIG_USEMODULE_CONGURE_TEST=y
2+
CONFIG_KCONFIG_USEMODULE_SHELL=y
3+
CONFIG_CONGURE_TEST_LOST_MSG_POOL_SIZE=6
4+
CONFIG_SHELL_NO_ECHO=y

tests/congure_reno/congure_impl.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (C) 2021 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @{
11+
*
12+
* @file
13+
* @author Martine Lenders <[email protected]>
14+
*/
15+
16+
#include <stdbool.h>
17+
#include "kernel_defines.h"
18+
19+
#include "congure_impl.h"
20+
21+
static unsigned _fr_calls;
22+
static bool _same_wnd_adv_res;
23+
24+
static void _fr(congure_reno_snd_t *c);
25+
static bool _same_wnd_adv(congure_reno_snd_t *c, congure_snd_ack_t *ack);
26+
static void _ss_cwnd_inc(congure_reno_snd_t *c);
27+
static void _ca_cwnd_inc(congure_reno_snd_t *c);
28+
static void _fr_cwnd_dec(congure_reno_snd_t *c);
29+
30+
static const congure_reno_snd_consts_t _consts[] = {
31+
{
32+
.fr = _fr,
33+
.same_wnd_adv = _same_wnd_adv,
34+
.init_mss = 1460,
35+
.cwnd_lower = 1095,
36+
.cwnd_upper = 2190,
37+
.init_ssthresh = CONGURE_WND_SIZE_MAX,
38+
.frthresh = 3,
39+
},
40+
{
41+
.fr = _fr,
42+
.same_wnd_adv = _same_wnd_adv,
43+
.ss_cwnd_inc = _ss_cwnd_inc,
44+
.ca_cwnd_inc = _ca_cwnd_inc,
45+
.fr_cwnd_dec = _fr_cwnd_dec,
46+
.init_mss = 1460,
47+
.cwnd_lower = 1095,
48+
.cwnd_upper = 2190,
49+
.init_ssthresh = CONGURE_WND_SIZE_MAX,
50+
.frthresh = 3,
51+
},
52+
};
53+
54+
int congure_test_snd_setup(congure_test_snd_t *c, unsigned id)
55+
{
56+
if (id >= ARRAY_SIZE(_consts)) {
57+
return -1;
58+
}
59+
_fr_calls = 0;
60+
congure_reno_snd_setup(c, &_consts[id]);
61+
return 0;
62+
}
63+
64+
unsigned congure_reno_test_get_fr_calls(void)
65+
{
66+
return _fr_calls;
67+
}
68+
69+
void congure_reno_test_set_same_wnd_adv_res(bool value)
70+
{
71+
_same_wnd_adv_res = value;
72+
}
73+
74+
static void _fr(congure_reno_snd_t *c)
75+
{
76+
(void)c;
77+
_fr_calls++;
78+
}
79+
80+
static bool _same_wnd_adv(congure_reno_snd_t *c, congure_snd_ack_t *ack)
81+
{
82+
(void)c;
83+
(void)ack;
84+
return _same_wnd_adv_res;
85+
}
86+
87+
static void _ss_cwnd_inc(congure_reno_snd_t *c)
88+
{
89+
c->super.cwnd += 1337;
90+
}
91+
92+
static void _ca_cwnd_inc(congure_reno_snd_t *c)
93+
{
94+
c->super.cwnd += 42;
95+
}
96+
97+
static void _fr_cwnd_dec(congure_reno_snd_t *c)
98+
{
99+
c->super.cwnd /= 8;
100+
}
101+
102+
/** @} */

tests/congure_reno/congure_impl.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2021 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @{
11+
*
12+
* @file
13+
*
14+
* @author Martine Lenders <[email protected]>
15+
*/
16+
#ifndef CONGURE_IMPL_H
17+
#define CONGURE_IMPL_H
18+
19+
#include "congure/reno.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
typedef congure_reno_snd_t congure_test_snd_t;
26+
27+
int congure_test_snd_setup(congure_test_snd_t *c, unsigned id);
28+
unsigned congure_reno_test_get_fr_calls(void);
29+
void congure_reno_test_set_same_wnd_adv_res(bool value);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif /* CONGURE_IMPL_H */
36+
/** @} */

tests/congure_reno/main.c

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* Copyright (C) 2021 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @{
11+
*
12+
* @file
13+
* @author Martine S. Lenders <[email protected]>
14+
*/
15+
16+
#include <assert.h>
17+
#include <stdlib.h>
18+
#include <string.h>
19+
20+
#include "clist.h"
21+
#include "congure/test.h"
22+
#include "fmt.h"
23+
#include "shell.h"
24+
25+
#include "congure_impl.h"
26+
27+
#define SHELL_BUFSIZE 512U
28+
29+
static char _line_buf[SHELL_BUFSIZE];
30+
31+
static int _json_statham(int argc, char **argv);
32+
static int _set_mss(int argc, char **argv);
33+
static int _set_cwnd(int argc, char **argv);
34+
static int _set_ssthresh(int argc, char **argv);
35+
static int _get_fr_calls(int argc, char **argv);
36+
static int _set_same_wnd_adv_res(int argc, char **argv);
37+
38+
static congure_reno_snd_t _congure_state;
39+
static const shell_command_t shell_commands[] = {
40+
{ "state", "Prints current CongURE state object as JSON", _json_statham },
41+
{ "set_cwnd", "Set cwnd member for CongURE state object", _set_cwnd },
42+
{ "set_mss", "Set new MSS for CongURE state object", _set_mss },
43+
{ "set_ssthresh", "Set ssthresh member for CongURE state object",
44+
_set_ssthresh },
45+
{ "get_ff_calls",
46+
"Get the number of calls to fast_retransmit callback of CongURE state "
47+
"object", _get_fr_calls },
48+
{ "set_same_wnd_adv",
49+
"Set the result for the same_window_advertised callback of CongURE state "
50+
"object", _set_same_wnd_adv_res },
51+
{ NULL, NULL, NULL }
52+
};
53+
54+
int main(void)
55+
{
56+
shell_run(shell_commands, _line_buf, SHELL_BUFSIZE);
57+
return 0;
58+
}
59+
60+
congure_test_snd_t *congure_test_get_state(void)
61+
{
62+
return &_congure_state;
63+
}
64+
65+
#define PRINT_FIELD_PTR(obj_ptr, field) \
66+
print_str("\"" #field "\":\"0x"); \
67+
print_u32_hex((intptr_t)((obj_ptr)->field)); \
68+
print_str("\",")
69+
70+
#define PRINT_FIELD_UINT(obj, field) \
71+
print_str("\"" #field "\":"); \
72+
print_u32_dec((obj).field); \
73+
print_str(",")
74+
75+
static void _print_congure_reno_consts(const congure_reno_snd_consts_t *consts)
76+
{
77+
print_str("\"consts\":");
78+
79+
if (consts) {
80+
print_str("{");
81+
PRINT_FIELD_PTR(consts, fr);
82+
PRINT_FIELD_PTR(consts, same_wnd_adv);
83+
PRINT_FIELD_PTR(consts, ss_cwnd_inc);
84+
PRINT_FIELD_PTR(consts, ca_cwnd_inc);
85+
PRINT_FIELD_PTR(consts, fr_cwnd_dec);
86+
PRINT_FIELD_UINT(*consts, init_mss);
87+
PRINT_FIELD_UINT(*consts, cwnd_upper);
88+
PRINT_FIELD_UINT(*consts, cwnd_lower);
89+
PRINT_FIELD_UINT(*consts, init_ssthresh);
90+
PRINT_FIELD_UINT(*consts, frthresh);
91+
print_str("},");
92+
}
93+
else {
94+
print_str("null,");
95+
}
96+
}
97+
98+
static int _json_statham(int argc, char **argv)
99+
{
100+
(void)argc;
101+
(void)argv;
102+
print_str("{");
103+
104+
PRINT_FIELD_UINT(_congure_state.super, cwnd);
105+
_print_congure_reno_consts(_congure_state.consts);
106+
PRINT_FIELD_UINT(_congure_state, mss);
107+
PRINT_FIELD_UINT(_congure_state, last_ack);
108+
PRINT_FIELD_UINT(_congure_state, ssthresh);
109+
PRINT_FIELD_UINT(_congure_state, in_flight_size);
110+
PRINT_FIELD_UINT(_congure_state, dup_acks);
111+
112+
print_str("}\n");
113+
return 0;
114+
}
115+
116+
static int _set_mss(int argc, char **argv)
117+
{
118+
uint32_t tmp;
119+
120+
if (argc < 2) {
121+
print_str("{\"error\":\"`mss` argument expected\"}");
122+
return 1;
123+
}
124+
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
125+
if (tmp > CONGURE_WND_SIZE_MAX) {
126+
print_str("{\"error\":\"`mss` not 16 bit wide\"}\n");
127+
}
128+
congure_reno_set_mss(&_congure_state, (congure_wnd_size_t)tmp);
129+
return 0;
130+
}
131+
132+
static int _set_cwnd(int argc, char **argv)
133+
{
134+
uint32_t tmp;
135+
136+
if (argc < 2) {
137+
print_str("{\"error\":\"`cwnd` argument expected\"}");
138+
return 1;
139+
}
140+
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
141+
if (tmp > CONGURE_WND_SIZE_MAX) {
142+
print_str("{\"error\":\"`cwnd` not 16 bit wide\"}\n");
143+
}
144+
_congure_state.super.cwnd = (congure_wnd_size_t)tmp;
145+
return 0;
146+
}
147+
148+
static int _set_ssthresh(int argc, char **argv)
149+
{
150+
uint32_t tmp;
151+
152+
if (argc < 2) {
153+
print_str("{\"error\":\"`ssthresh` argument expected\"}");
154+
return 1;
155+
}
156+
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
157+
if (tmp > CONGURE_WND_SIZE_MAX) {
158+
print_str("{\"error\":\"`ssthresh` not 16 bit wide\"}\n");
159+
}
160+
_congure_state.ssthresh = (congure_wnd_size_t)tmp;
161+
return 0;
162+
}
163+
164+
static int _get_fr_calls(int argc, char **argv)
165+
{
166+
(void)argc;
167+
(void)argv;
168+
169+
print_str("{\"fr_calls\":");
170+
print_u32_dec(congure_reno_test_get_fr_calls());
171+
print_str("}\n");
172+
return 0;
173+
}
174+
175+
static int _set_same_wnd_adv_res(int argc, char **argv)
176+
{
177+
if (argc < 2) {
178+
print_str("{\"error\":\"`value` argument expected\"}");
179+
return 1;
180+
}
181+
congure_reno_test_set_same_wnd_adv_res(
182+
(bool)scn_u32_dec(argv[1], strlen(argv[1]))
183+
);
184+
return 0;
185+
}
186+
187+
/** @} */

0 commit comments

Comments
 (0)