def testfunc(child):
    port = generate_port_number()
    shutdown_event = threading.Event()

    server_handle = threading.Thread(target=tcp_server,
                                     args=(port, shutdown_event))
    server_handle.start()

    target_addr = get_host_ll_addr(
        get_host_tap_device()) + '%' + get_riot_if_id(child)

    # Setup RIOT Node to connect to host systems TCP Server
    child.sendline('gnrc_tcp_tcb_init')
    child.sendline('gnrc_tcp_open_active AF_INET6 ' + target_addr + ' ' +
                   str(port) + ' 0')
    child.expect_exact('gnrc_tcp_open_active: returns 0')

    # Close connection and verify that pktbuf is cleared
    shutdown_event.set()
    child.sendline('gnrc_tcp_close')
    server_handle.join()

    verify_pktbuf_empty(child)

    print(os.path.basename(sys.argv[0]) + ': success')
Ejemplo n.º 2
0
def testfunc(child):
    port = generate_port_number()
    shutdown_event = threading.Event()

    # Try to receive 10 bytes sent from the Host System.
    data = 'test_data_'
    data_len = len(data)

    assert (data_len % 2) == 0

    # Verify that RIOT Applications internal buffer can hold test data.
    assert setup_internal_buffer(child) >= data_len

    server_handle = threading.Thread(target=tcp_server,
                                     args=(port, shutdown_event, data))
    server_handle.start()

    target_addr = get_host_ll_addr(
        get_host_tap_device()) + '%' + get_riot_if_id(child)

    # Setup RIOT Node to connect to Hostsystems TCP Server
    child.sendline('gnrc_tcp_tcb_init')
    child.sendline('gnrc_tcp_open_active [{}]:{} 0'.format(
        target_addr, str(port)))
    child.expect_exact('gnrc_tcp_open_active: returns 0')

    # Initiate connection teardown from test host
    shutdown_event.set()

    half_data_len = int(data_len / 2)

    # Read half the test data with timeout. Verify Buffer contents
    child.sendline('gnrc_tcp_recv 1000000 ' + str(half_data_len))
    child.expect_exact('gnrc_tcp_recv: received ' + str(half_data_len))
    assert read_data_from_internal_buffer(
        child, half_data_len) == data[:half_data_len]

    # Read half the test data without timeout. Verify Buffer contents
    child.sendline('gnrc_tcp_recv 0 ' + str(half_data_len))
    child.expect_exact('gnrc_tcp_recv: received ' + str(half_data_len))
    assert read_data_from_internal_buffer(
        child, half_data_len) == data[half_data_len:]

    # Buffer should have been read entirely and the connection was closed, there can be no new data.
    # Reading with a timeout must return 0 not -ETIMEOUT
    child.sendline('gnrc_tcp_recv 1000000 ' + str(half_data_len))
    child.expect_exact('gnrc_tcp_recv: returns 0')

    # Reading without a timeout must return 0 not -EAGAIN.
    child.sendline('gnrc_tcp_recv 0 ' + str(half_data_len))
    child.expect_exact('gnrc_tcp_recv: returns 0')

    # Close connection
    child.sendline('gnrc_tcp_close')
    server_handle.join()

    verify_pktbuf_empty(child)

    # Verify received Data
    print(os.path.basename(sys.argv[0]) + ': success')
Ejemplo n.º 3
0
def test_send_ack_instead_of_syn(child, src_if, src_ll, dst_if, dst_l2, dst_ll,
                                 dst_port):
    # check if any debug output is generated during `@testfunc` decorator
    # execution. If so, send fewer packets to prevent the target node
    # from being overwhelmed by packets and output.
    debug = child.expect(
        [pexpect.TIMEOUT, r'GNRC_TCP: Enter "\S+", File: .+\(\d+\)\s'],
        timeout=1)
    if debug:
        count = 10
    else:
        count = 1000

    # see https://github.com/RIOT-OS/RIOT/pull/12001
    provided_data = base64.b64decode("rwsQf2pekYLaU+exUBBwgPDKAAA=")
    tcp_hdr = TCP(provided_data)
    assert provided_data == raw(tcp_hdr)
    # set destination port to application specific port
    tcp_hdr.dport = dst_port
    sendp(Ether(dst=dst_l2) / IPv6(src=src_ll, dst=dst_ll) / tcp_hdr,
          iface=src_if,
          verbose=0,
          count=count)

    # check if server actually still works
    with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
        sock.settimeout(child.timeout)
        addr_info = socket.getaddrinfo(dst_ll + '%' + src_if,
                                       dst_port,
                                       type=socket.SOCK_STREAM)
        sock.connect(addr_info[0][-1])
        child.expect_exact('gnrc_tcp_open_passive: returns 0')
    verify_pktbuf_empty(child)
Ejemplo n.º 4
0
def testfunc(child):
    port = generate_port_number()
    shutdown_event = threading.Event()

    # Try to send 2000 byte from RIOT to the Host System.
    data = '0123456789' * 200
    data_len = len(data)

    # Verify that RIOT Applications internal buffer can hold test data.
    assert setup_internal_buffer(child) >= data_len

    server_handle = threading.Thread(target=tcp_server, args=(port, shutdown_event, data))
    server_handle.start()

    target_addr = get_host_ll_addr(get_host_tap_device()) + '%' + get_riot_if_id(child)

    # Setup RIOT Node to connect to host systems TCP Server
    child.sendline('gnrc_tcp_tcb_init')
    child.sendline('gnrc_tcp_open_active AF_INET6 ' + target_addr + ' ' + str(port) + ' 0')
    child.expect_exact('gnrc_tcp_open_active: returns 0')

    # Send data from RIOT Node to Linux
    write_data_to_internal_buffer(child, data)
    child.sendline('gnrc_tcp_send 0')
    child.expect_exact('gnrc_tcp_send: sent ' + str(data_len))

    # Close connection and verify that pktbuf is cleared
    shutdown_event.set()
    child.sendline('gnrc_tcp_close')
    server_handle.join()

    verify_pktbuf_empty(child)

    print(os.path.basename(sys.argv[0]) + ': success')
Ejemplo n.º 5
0
def test_short_payload(child, src_if, src_ll, dst_if, dst_l2, dst_ll,
                       dst_port):
    # see https://github.com/RIOT-OS/RIOT/issues/11999
    with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
        sock.settimeout(child.timeout)
        addr_info = socket.getaddrinfo(dst_ll + '%' + src_if,
                                       dst_port,
                                       type=socket.SOCK_STREAM)
        sock.connect(addr_info[0][-1])
        child.expect_exact('gnrc_tcp_open_passive: returns 0')
        child.sendline('gnrc_tcp_recv 1000000 1')
        child.expect_exact('gnrc_tcp_recv: argc=3, '
                           'argv[0] = gnrc_tcp_recv, '
                           'argv[1] = 1000000, argv[2] = 1')
        assert 1 == sock.send(b"f")
        child.expect_exact('gnrc_tcp_recv: received 1', timeout=20)
    verify_pktbuf_empty(child)
Ejemplo n.º 6
0
def test_short_header(child, src_if, src_ll, dst_if, dst_l2, dst_ll, dst_port):
    # see https://github.com/RIOT-OS/RIOT/issues/12086
    tcp_hdr = TCP(dport=dst_port, flags="S", sport=2342, seq=1, dataofs=6)
    # shorten header
    tcp_hdr = raw(tcp_hdr)[:-2]
    sendp(Ether(dst=dst_l2) / IPv6(src=src_ll, dst=dst_ll) / tcp_hdr,
          iface=src_if,
          verbose=0)

    # let server command return to later check packet buffer
    with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
        sock.settimeout(child.timeout)
        addr_info = socket.getaddrinfo(dst_ll + '%' + src_if,
                                       dst_port,
                                       type=socket.SOCK_STREAM)
        sock.connect(addr_info[0][-1])
        child.expect_exact('gnrc_tcp_open_passive: returns 0')
    verify_pktbuf_empty(child)
Ejemplo n.º 7
0
def test_option_parsing_term(child, src_if, src_ll, dst_if, dst_l2, dst_ll,
                             dst_port):
    # see https://github.com/RIOT-OS/RIOT/issues/12086
    tcp_hdr = TCP(dport=dst_port, flags="S", sport=2342, seq=1, dataofs=6)
    sendp(Ether(dst=dst_l2) / IPv6(src=src_ll, dst=dst_ll) / tcp_hdr /
          b"\x50\x00\x00\x00",
          iface=src_if,
          verbose=0)

    # check if server actually still works
    with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
        sock.settimeout(child.timeout)
        addr_info = socket.getaddrinfo(dst_ll + '%' + src_if,
                                       dst_port,
                                       type=socket.SOCK_STREAM)
        sock.connect(addr_info[0][-1])
        child.expect_exact('gnrc_tcp_open_passive: returns 0')
    verify_pktbuf_empty(child)
Ejemplo n.º 8
0
def testfunc(child):
    port = generate_port_number()
    shutdown_event = threading.Event()

    client_handle = threading.Thread(target=tcp_client, args=(get_riot_ll_addr(child), port, shutdown_event))

    # Setup RIOT Node wait for incoming connections from host system
    child.sendline('gnrc_tcp_tcb_init')
    child.sendline('gnrc_tcp_open_passive [::]:{}'.format(str(port)))

    client_handle.start()
    child.expect_exact('gnrc_tcp_open_passive: returns 0')

    # Close connection and verify that pktbuf is cleared
    shutdown_event.set()
    child.sendline('gnrc_tcp_close')
    client_handle.join()

    verify_pktbuf_empty(child)

    print(os.path.basename(sys.argv[0]) + ': success')
Ejemplo n.º 9
0
def test_send_ack_instead_of_syn(child, src_if, src_ll, dst_if, dst_l2, dst_ll,
                                 dst_port):
    # see https://github.com/RIOT-OS/RIOT/pull/12001
    provided_data = base64.b64decode("rwsQf2pekYLaU+exUBBwgPDKAAA=")
    tcp_hdr = TCP(provided_data)
    assert provided_data == raw(tcp_hdr)
    # set destination port to application specific port
    tcp_hdr.dport = dst_port
    sendp(Ether(dst=dst_l2) / IPv6(src=src_ll, dst=dst_ll) / tcp_hdr,
          iface=src_if,
          verbose=0,
          count=1000)

    # check if server actually still works
    with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
        sock.settimeout(child.timeout)
        addr_info = socket.getaddrinfo(dst_ll + '%' + src_if,
                                       dst_port,
                                       type=socket.SOCK_STREAM)
        sock.connect(addr_info[0][-1])
        child.expect_exact('gnrc_tcp_open_passive: returns 0')
    verify_pktbuf_empty(child)
Ejemplo n.º 10
0
def testfunc(child):
    port = generate_port_number()
    shutdown_event = threading.Event()

    # Try to receive 2000 bytes sent from the Host System.
    data = '0123456789' * 200
    data_len = len(data)

    # Verify that RIOT Applications internal buffer can hold test data.
    assert setup_internal_buffer(child) >= data_len

    server_handle = threading.Thread(target=tcp_server,
                                     args=(port, shutdown_event, data))
    server_handle.start()

    target_addr = get_host_ll_addr(
        get_host_tap_device()) + '%' + get_riot_if_id(child)

    # Setup RIOT Node to connect to Hostsystems TCP Server
    child.sendline('gnrc_tcp_tcb_init')
    child.sendline('gnrc_tcp_open_active [{}]:{} 0'.format(
        target_addr, str(port)))
    child.expect_exact('gnrc_tcp_open_active: returns 0')

    # Accept Data sent by the host system
    child.sendline('gnrc_tcp_recv 1000000 ' + str(data_len))
    child.expect_exact('gnrc_tcp_recv: received ' + str(data_len), timeout=20)

    # Close connection and verify that pktbuf is cleared
    shutdown_event.set()
    child.sendline('gnrc_tcp_close')
    server_handle.join()

    verify_pktbuf_empty(child)

    # Verify received Data
    assert read_data_from_internal_buffer(child, data_len) == data

    print(os.path.basename(sys.argv[0]) + ': success')