예제 #1
0
def test_task04(riot_ctrl):
    node = riot_ctrl(0, 'examples/nanocoap_server', Shell, port=TAP)
    host_netif = bridge(TAP)

    # can't use shell interactions here, as there is no shell
    node.riotctrl.term.expect(r"inet6 addr:\s+(fe80::[0-9a-f:]+)")
    node_lladdr = node.riotctrl.term.match.group(1)

    async def client(host, block_size):
        # create async context and wait a couple of seconds
        context = await aiocoap.Context.create_client_context()
        await asyncio.sleep(2)

        # pylint: disable=E1101
        request = aiocoap.Message(code=aiocoap.GET,
                                  uri='coap://{0}/riot/ver'.format(host))

        block_exp = round(math.log(block_size, 2)) - 4
        # pylint: disable=E0237
        request.opt.block2 = aiocoap.optiontypes.BlockOption.BlockwiseTuple(
            0, 0, block_exp)

        return await context.request(request).response

    for block_size in range(16, 1024 + 1, 16):
        print("Testing block size", block_size)
        response = asyncio.get_event_loop().run_until_complete(
            client("[{}%{}]".format(node_lladdr, host_netif), block_size))
        assert str(response.code) == "2.05 Content"
        assert re.search(
            r"This is RIOT \(Version: .*\) running on a "
            r"native board with a native MCU\.", response.payload.decode())
예제 #2
0
def test_task04(riot_ctrl, log_nodes):
    node = riot_ctrl(0, APP, Shell, port='tap0')
    pingers = [pexpect.replwrap.bash() for _ in range(10)]

    _, pinged_addr = lladdr(node.ifconfig_list())
    assert pinged_addr.startswith("fe80::")
    iface = bridge('tap0')
    pinged_addr += "%{}".format(iface)
    ping_cmd = get_ping_cmd()

    futures = []
    for pinger in pingers:
        if log_nodes:
            pinger.child.logfile = sys.stdout
        out = pinger.run_command("{ping_cmd} -f -s 1452 {pinged_addr}"
                                 # pipe to /dev/null because output can go into
                                 # MiB of data ;-)
                                 " 2>&1 > /dev/null"
                                 .format(ping_cmd=ping_cmd,
                                         pinged_addr=pinged_addr),
                                 async_=True, timeout=60 * 60)
        futures.append(out)
    timeout_futures(futures, 60 * 60)

    time.sleep(60)
    assert pktbuf(node).is_empty()
예제 #3
0
def test_task09(riot_ctrl, log_nodes):
    node = riot_ctrl(0, APP, Shell, port=TAP)
    host_netif = bridge(TAP)
    host_lladdr = get_link_local(host_netif)

    node_netifs = NETIF_PARSER.parse(node.ifconfig_list())
    node_netif = next(iter(node_netifs))
    node_hwaddr = node_netifs[node_netif]["hwaddr"]
    node_lladdr = [
        addr["addr"] for addr in node_netifs[node_netif]["ipv6_addrs"]
        if addr["scope"] == "link"
    ][0]
    ip_addr_add(host_netif, "beef::1/64")
    ip_route_add(host_netif, "affe::/64", node_lladdr)
    node.nib_route_add(node_netif, "beef::/64", host_lladdr)
    node.nib_route_add(node_netif, "affe::/64", "fe80::ab25:f123")

    pkt = srp1(Ether(dst=node_hwaddr) /
               IPv6(src="beef::1", dst="affe::1", plen=20) / UDP(dport=48879),
               iface=host_netif,
               timeout=5,
               verbose=log_nodes)
    assert ICMPv6ParamProblem in pkt
    assert pkt[ICMPv6ParamProblem].code == 0
    err_bytes = raw(pkt[IPerror6])
    ptr = pkt[ICMPv6ParamProblem].ptr
    # plen is a 2 byte field in network byte order (big endian)
    ptr_val = (err_bytes[ptr] << 8) | err_bytes[ptr + 1]
    assert ptr_val == 20
    assert pkt[IPv6].src == node_lladdr
예제 #4
0
def test_task01(riot_ctrl, log_nodes):
    node = riot_ctrl(0, GNRC_APP, Shell, port='tap0')
    linux = pexpect.replwrap.bash()

    node_iface, node_addr = lladdr(node.ifconfig_list())
    assert node_addr.startswith("fe80::")
    linux_iface = bridge('tap0')
    linux_addr = get_link_local(linux_iface)
    assert linux_addr.startswith("fe80::")
    ping_cmd = get_ping_cmd()

    if log_nodes:
        linux.child.logfile = sys.stdout
    out = linux.run_command(
        "{ping_cmd} -c 20 -i .5 {node_addr}%{linux_iface}".format(
            ping_cmd=ping_cmd, node_addr=node_addr, linux_iface=linux_iface),
        timeout=20)
    m = re.search(r"\b(\d+)% packet loss", out)
    assert m is not None
    assert int(m.group(1)) < 1
    res = ping6(node,
                "{}%{}".format(linux_addr, node_iface),
                count=20,
                interval=100,
                packet_size=8)
    assert res["stats"]["packet_loss"] < 1
예제 #5
0
def test_task08(riot_ctrl, log_nodes):
    node = riot_ctrl(0, APP, Shell, port=TAP)
    host_netif = bridge(TAP)
    host_lladdr = get_link_local(host_netif)

    node_netifs = NETIF_PARSER.parse(node.ifconfig_list())
    node_netif = next(iter(node_netifs))
    node_hwaddr = node_netifs[node_netif]["hwaddr"]
    node_lladdr = [
        addr["addr"] for addr in node_netifs[node_netif]["ipv6_addrs"]
        if addr["scope"] == "link"
    ][0]
    ip_addr_add(host_netif, "beef::1/64")
    ip_route_add(host_netif, "affe::/64", node_lladdr)
    node.nib_route_add(node_netif, "beef::/64", host_lladdr)
    node.nib_route_add(node_netif, "affe::/64", "fe80::ab25:f123")

    pkt = srp1(Ether(dst=node_hwaddr) /
               IPv6(src="beef::1", dst="affe::1", hlim=1) / UDP(dport=48879),
               iface=host_netif,
               timeout=5,
               verbose=log_nodes)
    assert ICMPv6TimeExceeded in pkt
    assert pkt[ICMPv6TimeExceeded].code == 0
    assert pkt[IPv6].src == node_lladdr
예제 #6
0
def test_task07(riot_ctrl, log_nodes):
    node = riot_ctrl(0,
                     APP,
                     Shell,
                     cflags="-DCONFIG_GNRC_IPV6_NIB_SLAAC=1 "
                     "-DCONFIG_GNRC_IPV6_NIB_QUEUE_PKT=1",
                     termflags="-z [::]:17755",
                     modules="socket_zep netdev_tap",
                     port=TAP)
    host_netif = bridge(TAP)
    host_lladdr = get_link_local(host_netif)

    time.sleep(5)
    node_netifs = NETIF_PARSER.parse(node.ifconfig_list())
    node_netif = [n for n in node_netifs if node_netifs[n]["mtu"] == 1500][0]
    fwd_netif = [n for n in node_netifs if node_netifs[n]["mtu"] < 1500][0]
    node_hwaddr = node_netifs[node_netif]["hwaddr"]
    node_lladdr = [
        addr["addr"] for addr in node_netifs[node_netif]["ipv6_addrs"]
        if addr["scope"] == "link"
    ][0]
    ip_addr_add(host_netif, "beef::1/64")
    ip_route_add(host_netif, "affe::/64", node_lladdr)
    node.nib_route_add(node_netif, "beef::/64", host_lladdr)
    node.nib_route_add(fwd_netif, "affe::/64", "fe80::ab25:f123")

    pkt = srp1(Ether(dst=node_hwaddr) / IPv6(src="beef::1", dst="affe::1") /
               UDP(dport=48879) / ("x" * 1452),
               iface=host_netif,
               timeout=5,
               verbose=log_nodes)
    assert ICMPv6PacketTooBig in pkt
    assert pkt[ICMPv6PacketTooBig].code == 0
    assert node_netifs[fwd_netif]["mtu"] == pkt[ICMPv6PacketTooBig].mtu == 1280
    assert pkt[IPv6].src == node_lladdr
예제 #7
0
def test_task10(riot_ctrl, log_nodes):
    # pylint: disable=R0914
    node = riot_ctrl(0, APP, Shell, port=TAP)
    host_netif = bridge(TAP)
    host_lladdr = get_link_local(host_netif)

    node_netifs = NETIF_PARSER.parse(node.ifconfig_list())
    node_netif = next(iter(node_netifs))
    node_hwaddr = node_netifs[node_netif]["hwaddr"]
    node_lladdr = [
        addr["addr"] for addr in node_netifs[node_netif]["ipv6_addrs"]
        if addr["scope"] == "link"
    ][0]

    ip = IPv6(src=host_lladdr, dst=node_lladdr)
    stop_id = 0xc07c
    test_id = 0xb488
    sniffer = AsyncSniffer(
        stop_filter=lambda p: ICMPv6EchoReply in p and p[ICMPv6EchoReply].id ==
        stop_id,
        iface=host_netif,
    )
    sniffer.start()
    time.sleep(.1)
    max_pkts = _max_encapsulations()
    for i in range(max_pkts):
        start = time.time()
        ips = ip
        for _ in range(i):
            ips /= ip
        sendp(Ether(dst=node_hwaddr) / ips /
              ICMPv6EchoRequest(id=test_id, seq=i),
              iface=host_netif,
              verbose=log_nodes)
        stop = time.time()
        if (stop - start) <= 0.001:
            time.sleep(0.001 - (stop - start))
    # send stop condition for sniffer
    sendp(Ether(dst=node_hwaddr) / ip / ICMPv6EchoRequest(id=stop_id),
          iface=host_netif,
          verbose=log_nodes)
    sniffer.join()
    pkts = sniffer.results
    requests = [
        p for p in pkts
        if ICMPv6EchoRequest in p and p[ICMPv6EchoRequest].id == test_id
    ]
    replies = [
        p for p in pkts
        if ICMPv6EchoReply in p and p[ICMPv6EchoReply].id == test_id
    ]
    assert len(requests) <= max_pkts
    assert len(replies) <= max_pkts
    assert (len(replies) / max_pkts) > .96
    reply_seqs = [r[ICMPv6EchoReply].seq for r in replies]
    reply_seq_occs = [reply_seqs.count(seq) for seq in reply_seqs]
    # no sequence number occurs more than once in the replies
    assert not any(occ > 1 for occ in reply_seq_occs)
예제 #8
0
def test_task03(riot_ctrl, log_nodes):
    node = riot_ctrl(0, APP, Shell, port=TAP)
    host_netif = bridge(TAP)
    host_lladdr = get_link_local(host_netif)

    node_netifs = NETIF_PARSER.parse(node.ifconfig_list())
    node_netif = next(iter(node_netifs))
    node_lladdr = [
        addr["addr"] for addr in node_netifs[node_netif]["ipv6_addrs"]
        if addr["scope"] == "link"
    ][0]
    node_hwaddr = node_netifs[node_netif]["hwaddr"]

    pkt = srp1(Ether(dst=node_hwaddr) / IPv6(src=host_lladdr, dst="fe80::1") /
               UDP(dport=48879),
               iface=host_netif,
               timeout=5,
               verbose=log_nodes)
    assert ICMPv6DestUnreach in pkt
    assert pkt[ICMPv6DestUnreach].code == 3
    assert pkt[IPv6].src == node_lladdr
예제 #9
0
def test_task03(riot_ctrl):
    node = riot_ctrl(0, 'examples/nanocoap_server', Shell, port=TAP)
    host_netif = bridge(TAP)

    # can't use shell interactions here, as there is no shell
    node.riotctrl.term.expect(r"inet6 addr:\s+(fe80::[0-9a-f:]+)")
    node_lladdr = node.riotctrl.term.match.group(1)

    async def client(host, block_size):
        # create async context and wait a couple of seconds
        context = await aiocoap.Context.create_client_context()
        await asyncio.sleep(2)

        payload = (
            b'If one advances confidently in the direction of his dreams,'
            b' he will meet with a success unexpected in common hours.'
        )

        # pylint: disable=E1101
        request = aiocoap.Message(code=aiocoap.POST, payload=payload,
                                  uri='coap://{0}/sha256'.format(host))

        block_exp = round(math.log(block_size, 2)) - 4
        # pylint: disable=E0237
        request.opt.block1 = aiocoap.optiontypes.BlockOption.BlockwiseTuple(
            0, 0, block_exp
        )

        return await context.request(request).response

    for block_size in range(16, 1024 + 1, 16):
        print("Testing block size", block_size)
        response = asyncio.get_event_loop().run_until_complete(
            client("[{}%{}]".format(node_lladdr, host_netif), block_size)
        )
        assert str(response.code) == "2.04 Changed"
        # payload is a sha256 digest
        assert re.match("^[0-9A-Fa-f]{64}$", response.payload.decode())
예제 #10
0
def test_task06(riot_ctrl, log_nodes):
    node = riot_ctrl(0, APP, Shell, port=TAP)
    host_netif = bridge(TAP)
    host_lladdr = get_link_local(host_netif)

    node_netifs = NETIF_PARSER.parse(node.ifconfig_list())
    node_netif = next(iter(node_netifs))
    node_hwaddr = node_netifs[node_netif]["hwaddr"]
    node_lladdr = [
        addr["addr"] for addr in node_netifs[node_netif]["ipv6_addrs"]
        if addr["scope"] == "link"
    ][0]

    pkt = srp1(Ether(dst=node_hwaddr) /
               IPv6(src=host_lladdr, dst=node_lladdr) / UDP(dport=48879) /
               ("x" * 1452),
               iface=host_netif,
               timeout=5,
               verbose=log_nodes)
    assert ICMPv6DestUnreach in pkt
    assert pkt[ICMPv6DestUnreach].code == 4
    assert pkt[IPv6].src == node_lladdr
    assert UDPerror in pkt
    assert len(pkt[UDPerror].payload) <= 1404  # payload was truncated
예제 #11
0
def teardown_function(function):
    if function.__name__ in ["test_task01", "test_task02", "test_task05"]:
        host_netif = bridge(TAP)
        ip_addr_del(host_netif, "{}/64".format(HOST_ULA))
예제 #12
0
def setup_function(function):
    host_netif = bridge(TAP)
    ip_addr_del(host_netif, "beef::1/64")
    ip_route_del(host_netif, "affe::1/64")