Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task06: provide test scripts #5

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions 06-single-hop-udp/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import argparse

from testutils import Board
from mixins import GNRC, GNRC_UDP,PktBuf
from time import sleep


#Declare node
class SixLoWPANNode(Board, GNRC, GNRC_UDP, PktBuf):
pass


def print_results(results):
packet_losses = [results[i][0] for i in range(len(results))]
print("Summary of {packet losses, source pktbuf sanity, dest pktbuf sanity}:")
for i in range(len(results)):
print("Run {}: {} {} {}".format(i+1, packet_losses[i], results[i][1], results[i][2]))
print("")
print("Average packet losses: {}".format(sum(packet_losses)/len(packet_losses)))


def udp_send(source, dest, ip_dest, port, count, payload_size, delay):
source.reboot()
dest.reboot()

dest.udp_server_start(port)
source.udp_send(ip_dest, port, payload_size, count, delay)
packet_loss = dest.udp_server_check_output(count, delay)
dest.udp_server_stop()

return packet_loss, source.is_empty(), dest.is_empty()


argparser = argparse.ArgumentParser()
argparser.add_argument("--runs", "-n", help="Number of runs", type=int,
default=1)
argparser.add_argument("riotbase", help="Location of RIOT directory")
65 changes: 65 additions & 0 deletions 06-single-hop-udp/task01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env python3
# Copyright (C) 2018 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.

import sys
import os

PORT = 1337
COUNT = 1000
PAYLOAD_SIZE = 1024
DELAY = 1000 # ms
ERROR_TOLERANCE = 5 # %


def task01(riotbase, runs=1):
os.chdir(os.path.join(riotbase, "tests/gnrc_udp"))
try:
exp = IoTLABExperiment("RIOT-release-test-06-01",
[IoTLABNode(site="lille",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked Lille for both experiments, because Grenoble is most often too noisy to get 1000 packets of >10 fragments through at such a low error tolerance (see RIOT-OS#53).

extra_modules=["gnrc_pktbuf_cmd"]),
IoTLABNode(site="lille",
extra_modules=["gnrc_pktbuf_cmd"])])
except Exception as e:
print(str(e))
print("Can't start experiment")
return

try:
addrs = exp.nodes_addresses
iotlab_cmd = "make IOTLAB_NODE={} BOARD=iotlab-m3 term"
source = SixLoWPANNode(iotlab_cmd.format(addrs[0]))
dest = SixLoWPANNode(iotlab_cmd.format(addrs[1]))
results = []

for run in range(runs):
print("Run {}/{}: ".format(run + 1, runs), end="")
packet_loss, buf_source, buf_dest = udp_send(source, dest,
dest.get_ip_addr(),
PORT, COUNT,
PAYLOAD_SIZE, DELAY)
results.append([packet_loss, buf_source, buf_dest])

assert(packet_loss < ERROR_TOLERANCE)
assert(buf_source)
assert(buf_dest)
print("OK")
print_results(results)
except Exception as e:
print("FAILED")
print(str(e))
finally:
exp.stop()


if __name__ == "__main__":
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"../", "testutils"))
from iotlab import IoTLABNode, IoTLABExperiment
from common import argparser, SixLoWPANNode, udp_send, print_results

args = argparser.parse_args()
task01(**vars(args))
65 changes: 65 additions & 0 deletions 06-single-hop-udp/task02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env python3
# Copyright (C) 2018 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.

import sys
import os

PORT = 61616
COUNT = 1000
PAYLOAD_SIZE = 1024
DELAY = 1000 # ms
ERROR_TOLERANCE = 5 # %


def task02(riotbase, runs=1):
os.chdir(os.path.join(riotbase, "tests/gnrc_udp"))
try:
exp = IoTLABExperiment("RIOT-release-test-06-01",
[IoTLABNode(site="lille",
extra_modules=["gnrc_pktbuf_cmd"]),
IoTLABNode(site="lille",
extra_modules=["gnrc_pktbuf_cmd"])])
except Exception as e:
print(str(e))
print("Can't start experiment")
return

try:
addrs = exp.nodes_addresses
iotlab_cmd = "make IOTLAB_NODE={} BOARD=iotlab-m3 term"
source = SixLoWPANNode(iotlab_cmd.format(addrs[0]))
dest = SixLoWPANNode(iotlab_cmd.format(addrs[1]))
results = []

for run in range(runs):
print("Run {}/{}: ".format(run + 1, runs), end="")
packet_loss, buf_source, buf_dest = udp_send(source, dest,
dest.get_ip_addr(),
PORT, COUNT,
PAYLOAD_SIZE, DELAY)
results.append([packet_loss, buf_source, buf_dest])

assert(packet_loss < ERROR_TOLERANCE)
assert(buf_source)
assert(buf_dest)
print("OK")
print_results(results)
except Exception as e:
print("FAILED")
print(str(e))
finally:
exp.stop()


if __name__ == "__main__":
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"../", "testutils"))
from iotlab import IoTLABNode, IoTLABExperiment
from common import argparser, SixLoWPANNode, udp_send, print_results

args = argparser.parse_args()
task02(**vars(args))
2 changes: 1 addition & 1 deletion testutils/iotlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IoTLABNode(object):
"samr21-xpro": {"archi": "samr21", "radio": "at86rf233"},
"arduino-zero": {"archi": "arduino-zero", "radio": "xbee"},
}
SITES = ["grenoble", "saclay"]
SITES = ["grenoble", "lille", "saclay"]

def __init__(self, board="iotlab-m3", site="grenoble",
extra_modules=[]):
Expand Down
52 changes: 52 additions & 0 deletions testutils/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,58 @@ def ping(self, count, dest_addr, payload_size, delay):

return packet_loss

class GNRC_UDP:
def udp_server_start(self, port):
self.pexpect.sendline("udp server start {}".format(port))
self.pexpect.expect_exact(
"Success: started UDP server on port {}".format(port)
)

def udp_server_stop(self):
self.pexpect.sendline("udp server stop")

def udp_server_check_output(self, count, delay_ms):
packets_lost = 0
for i in range(count):
exp = self.pexpect.expect([
r"Packets received: \d+",
r"PKTDUMP: data received:\n"
r"~~ SNIP 0 - size: \d+ byte, type: NETTYPE_UNDEF \(\d+\)\n"
r".*\n"
r"~~ SNIP 1 - size: 8 byte, type: NETTYPE_UDP \(\d+\)\n"
r" src-port: \d+ dst-port: \d+\n"
r" length: \d+ cksum: 0x[0-9A-Fa-f]+\n"
r"~~ SNIP 2 - size: 40 byte, type: NETTYPE_IPV6 \(\d+\)\n"
r".*\n"
r"~~ SNIP 3 - size: 20 byte, type: NETTYPE_NETIF \(-1\)\n"
r"if_pid: \d.*"
r"~~ PKT - 4 snips, total size: \d+ byte",
pexpect.TIMEOUT
], timeout=(delay_ms / 1000) * 2)
if exp in [0, 1]:
print(".", end="", flush=True)
else:
packets_lost += 0
print("x", end="", flush=True)
return int((packets_lost / count) * 100)

def udp_send(self, dest_addr, port, payload, count=1, delay_ms=1000):
self.pexpect.sendline(
"udp send {} {} {} {} {}".format(
dest_addr, port, payload, count, delay_ms * 1000))
try:
payload = int(payload)
bytes = payload
except ValueError:
bytes = len(payload)
for i in range(count):
exp = self.pexpect.expect([
"Success: sent {} byte\(s\) to \[{}\]:{}".format(
bytes, dest_addr, port),
"Success: send {} byte to \[{}\]:{}".format(
bytes, dest_addr, port)
])


class PktBuf:
def is_empty(self):
Expand Down