Skip to content

Commit

Permalink
fixup! tests: Initial import of congure_reno tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Feb 11, 2021
1 parent c12a17f commit 072ec55
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 10 deletions.
20 changes: 19 additions & 1 deletion tests/congure_reno/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "congure_impl.h"

static int _json_statham(int argc, char **argv);
static int _set_mss(int argc, char **argv);
static int _set_cwnd(int argc, char **argv);
static int _set_ssthresh(int argc, char **argv);
static int _get_fr_calls(int argc, char **argv);
Expand All @@ -34,6 +35,7 @@ static congure_reno_snd_t _congure_state;
static const shell_command_t shell_commands[] = {
{ "state", "Prints current CongURE state object as JSON", _json_statham },
{ "set_cwnd", "Set cwnd member for CongURE state object", _set_cwnd },
{ "set_mss", "Set new MSS for CongURE state object", _set_mss },
{ "set_ssthresh", "Set ssthresh member for CongURE state object",
_set_ssthresh },
{ "get_ff_calls",
Expand Down Expand Up @@ -108,6 +110,22 @@ static int _json_statham(int argc, char **argv)
return 0;
}

static int _set_mss(int argc, char **argv)
{
uint32_t tmp;

if (argc < 2) {
print_str("{\"error\":\"`mss` argument expected\"}");
return 1;
}
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
if (tmp > CONGURE_WND_SIZE_MAX) {
print_str("{\"error\":\"`mss` not 16 bit wide\"}\n");
}
congure_reno_set_mss(&_congure_state, (congure_wnd_size_t)tmp);
return 0;
}

static int _set_cwnd(int argc, char **argv)
{
uint32_t tmp;
Expand All @@ -118,7 +136,7 @@ static int _set_cwnd(int argc, char **argv)
}
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
if (tmp > CONGURE_WND_SIZE_MAX) {
print_str("{\"error\":\"`ssthresh` not 16 bit wide\"}\n");
print_str("{\"error\":\"`cwnd` not 16 bit wide\"}\n");
}
_congure_state.super.cwnd = (congure_wnd_size_t)tmp;
return 0;
Expand Down
82 changes: 73 additions & 9 deletions tests/congure_reno/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# directory for more details.

import logging
import sys
import unittest

from riotctrl.ctrl import RIOTCtrl
Expand All @@ -17,17 +18,23 @@
class TestCongUREBase(unittest.TestCase):
# pylint: disable=too-many-public-methods
# it's just one more ...
DEBUG = False

@classmethod
def setUpClass(cls):
cls.ctrl = RIOTCtrl()
cls.ctrl.start_term()
if cls.DEBUG:
cls.ctrl.term.logfile = sys.stdout
cls.ctrl.reset()
cls.shell = ShellInteraction(cls.ctrl)
cls.json_parser = RapidJSONShellInteractionParser()
cls.json_parser.set_parser_args(
parse_mode=rapidjson.PM_TRAILING_COMMAS
)
cls.logger = logging.getLogger(cls.__name__)
if cls.DEBUG:
cls.logger.setLevel(logging.DEBUG)

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -89,6 +96,9 @@ def get_ff_calls(self):
def set_same_wnd_adv(self, value):
self.exec_cmd(f'set_same_wnd_adv {value:d}')

def set_mss(self, mss):
self.exec_cmd(f'set_mss {mss}')

def set_cwnd(self, cwnd):
self.exec_cmd(f'set_cwnd {cwnd}')

Expand All @@ -111,17 +121,17 @@ def cong_report_msg_sent(self, msg_size):
def cong_report_msg_discarded(self, msg_size):
return self.cong_report('msg_discarded', msg_size)

def _report_msg_timeout_lost(self, cmd, msgs):
def _report_msgs_timeout_lost(self, cmd, msgs):
args = []
for msg in msgs:
args.extend((msg['send_time'], msg['size'], msg['resends']))
return self.cong_report(cmd, *args)

def cong_report_msg_timeout(self, msgs):
return self._report_msg_timeout_lost('msg_timeout', msgs)
def cong_report_msgs_timeout(self, msgs):
return self._report_msgs_timeout_lost('msgs_timeout', msgs)

def cong_report_msg_lost(self, msgs):
return self._report_msg_timeout_lost('msg_lost', msgs)
def cong_report_msgs_lost(self, msgs):
return self._report_msgs_timeout_lost('msgs_lost', msgs)

def cong_report_msg_acked(self, msg, ack):
if isinstance(ack['clean'], bool):
Expand Down Expand Up @@ -228,6 +238,60 @@ def setUp(self):
self.assertIn('setup', res)
self.cong_init()

def test_mss_2200(self):
"""
https://tools.ietf.org/html/rfc5681#section-3.1
> IW, the initial value of cwnd, MUST be set using the following
> guidelines as an upper bound.
>
> If SMSS > 2190 bytes:
> IW = 2 * SMSS bytes and MUST NOT be more than 2 segments
> If (SMSS > 1095 bytes) and (SMSS <= 2190 bytes):
> IW = 3 * SMSS bytes and MUST NOT be more than 3 segments
> if SMSS <= 1095 bytes:
> IW = 4 * SMSS bytes and MUST NOT be more than 4 segments
"""
self.set_mss(2200)
state = self.cong_state()
self.assertEqual(2200, state['mss'])
# (SMSS > 2190 bytes)
self.assertGreater(state['mss'], state['consts']['cwnd_upper'])
# (SMSS > 1095 bytes)
self.assertGreater(state['mss'], state['consts']['cwnd_lower'])
# as such, IW = 2 * SMSS bytes
self.assertEqual(state['cwnd'], 2 * state['mss'])
# We start with slow start
self.assertSlowStart(state)
self.assertNotInFastRetransmit(state)

def test_mss_1095(self):
"""
https://tools.ietf.org/html/rfc5681#section-3.1
> IW, the initial value of cwnd, MUST be set using the following
> guidelines as an upper bound.
>
> If SMSS > 2190 bytes:
> IW = 2 * SMSS bytes and MUST NOT be more than 2 segments
> If (SMSS > 1095 bytes) and (SMSS <= 2190 bytes):
> IW = 3 * SMSS bytes and MUST NOT be more than 3 segments
> if SMSS <= 1095 bytes:
> IW = 4 * SMSS bytes and MUST NOT be more than 4 segments
"""
self.set_mss(1095)
state = self.cong_state()
self.assertEqual(1095, state['mss'])
# (SMSS < 2190 bytes)
self.assertLess(state['mss'], state['consts']['cwnd_upper'])
# (SMSS < 1095 bytes)
self.assertLessEqual(state['mss'], state['consts']['cwnd_lower'])
# as such, IW = 4 * SMSS bytes
self.assertEqual(state['cwnd'], 4 * state['mss'])
# We start with slow start
self.assertSlowStart(state)
self.assertNotInFastRetransmit(state)

def test_slow_start_increase_small_N(self):
# pylint: disable=invalid-name
# name chosen to be in line with RFC
Expand Down Expand Up @@ -325,7 +389,7 @@ def _send_msg_and_timeout(self, msgs):
flight_size += msg['size']
state = self.cong_state()
self.assertEqual(state['in_flight_size'], flight_size)
res = self.cong_report_msg_timeout(msgs)
res = self.cong_report_msgs_timeout(msgs)
self.assertIsNone(res)

def test_reduce_ssthresh_small_flight_size(self):
Expand Down Expand Up @@ -680,7 +744,7 @@ def test_msg_discarded(self):
state = self.cong_state()
self.assertEqual(state['in_flight_size'], 0)

def test_msg_lost(self):
def test_msgs_lost(self):
"""
RFC 5681 does not say anything about explicitly lost messages.
It's a feature of CongURE. Calling it, should enforce fast retransmit,
Expand All @@ -695,7 +759,7 @@ def test_msg_lost(self):
flight_size += msg['size']
state = self.cong_state()
self.assertEqual(state['in_flight_size'], flight_size)
res = self.cong_report_msg_lost(msgs)
res = self.cong_report_msgs_lost(msgs)
self.assertIsNone(res)
state = self.cong_state()
self.assertEqual(1, self.get_ff_calls())
Expand Down Expand Up @@ -756,7 +820,7 @@ def test_fast_retransmit_decrease(self):
flight_size += msg['size']
state = self.cong_state()
self.assertEqual(state['in_flight_size'], flight_size)
res = self.cong_report_msg_lost(msgs)
res = self.cong_report_msgs_lost(msgs)
self.assertIsNone(res)
state = self.cong_state()
self.assertEqual(state['cwnd'], init_cwnd // 8)
Expand Down

0 comments on commit 072ec55

Please sign in to comment.