diff --git a/samples/net/sockets/tcp/CMakeLists.txt b/samples/net/sockets/tcp/CMakeLists.txt new file mode 100644 index 00000000000..8d4e0c8ce8f --- /dev/null +++ b/samples/net/sockets/tcp/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(tcp) + +target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/subsys/net/ip) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/net/sockets/tcp/README.rst b/samples/net/sockets/tcp/README.rst new file mode 100644 index 00000000000..36ce6d92808 --- /dev/null +++ b/samples/net/sockets/tcp/README.rst @@ -0,0 +1,43 @@ +.. _sockets-tcp-sample: + +TCP Sample for TTCN-3 based Sanity Check +######################################## + +Overview +******** + +This application is used together with the TTCN-3 based sanity check +to validate the functionality of the experimental TCP (TCP2). + +Building, Running and executing TTCN-3 based Sanity Check for TCP2 +****************************************************************** + +Compile and start the `net-test-tools`_: + +.. code-block:: console + + ./autogen.sh + make + ./loop-slipcat.sh + +Build the TCP sample app: + +.. code-block:: console + + cd samples/net/sockets/tcp + mkdir build && cd build + cmake -DBOARD=qemu_x86 -DOVERLAY_CONFIG="overlay-slip.conf" .. + make run + +Compile and run the TCP2 sanity check `net-test-suites`_: + +.. code-block:: console + + . titan-install.sh + . titan-env.sh + cd src + . make.sh + ttcn3_start test_suite tcp2_check_3_runs.cfg + +.. _`net-test-tools`: https://github.com/intel/net-test-tools +.. _`net-test-suites`: https://github.com/intel/net-test-suites diff --git a/samples/net/sockets/tcp/overlay-debug.conf b/samples/net/sockets/tcp/overlay-debug.conf new file mode 100644 index 00000000000..5c06c052056 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-debug.conf @@ -0,0 +1,7 @@ +CONFIG_NO_OPTIMIZATIONS=y +CONFIG_DEBUG=y + +CONFIG_ASSERT=y +CONFIG_STACK_SENTINEL=y + +CONFIG_STACK_CANARIES=y diff --git a/samples/net/sockets/tcp/overlay-e1000.conf b/samples/net/sockets/tcp/overlay-e1000.conf new file mode 100644 index 00000000000..9e362c98b3b --- /dev/null +++ b/samples/net/sockets/tcp/overlay-e1000.conf @@ -0,0 +1,7 @@ +# Overlay for experimental TCP as qemu_x86 with E1000 + +CONFIG_PCIE=y +CONFIG_ETH_E1000=y + +CONFIG_NET_L2_ETHERNET=y +CONFIG_NET_QEMU_ETHERNET=y diff --git a/samples/net/sockets/tcp/overlay-log-extra.conf b/samples/net/sockets/tcp/overlay-log-extra.conf new file mode 100644 index 00000000000..c10f0e1725f --- /dev/null +++ b/samples/net/sockets/tcp/overlay-log-extra.conf @@ -0,0 +1,6 @@ +#CONFIG_NET_IF_LOG_LEVEL_DBG=y +#CONFIG_NET_L2_ETHERNET_LOG_LEVEL_DBG=y + +#CONFIG_SLIP_LOG_LEVEL_DBG=y + +CONFIG_ETHERNET_LOG_LEVEL_DBG=y diff --git a/samples/net/sockets/tcp/overlay-log-extra2.conf b/samples/net/sockets/tcp/overlay-log-extra2.conf new file mode 100644 index 00000000000..6bd2a49ff64 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-log-extra2.conf @@ -0,0 +1,6 @@ +#CONFIG_NET_IF_LOG_LEVEL_DBG=y +#CONFIG_NET_L2_ETHERNET_LOG_LEVEL_DBG=y + +CONFIG_SLIP_LOG_LEVEL_DBG=y + +CONFIG_ETH_E1000_VERBOSE_DEBUG=y diff --git a/samples/net/sockets/tcp/overlay-log-pkt.conf b/samples/net/sockets/tcp/overlay-log-pkt.conf new file mode 100644 index 00000000000..3f1b93d56b2 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-log-pkt.conf @@ -0,0 +1,4 @@ +CONFIG_NET_PKT_LOG_LEVEL_DBG=y + +CONFIG_NET_BUF_LOG=y +CONFIG_NET_BUF_LOG_LEVEL_DBG=y diff --git a/samples/net/sockets/tcp/overlay-log.conf b/samples/net/sockets/tcp/overlay-log.conf new file mode 100644 index 00000000000..fa6e1085301 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-log.conf @@ -0,0 +1,14 @@ +CONFIG_LOG=y +CONFIG_LOG_IMMEDIATE=y +CONFIG_LOG_BACKEND_SHOW_COLOR=n + +CONFIG_NET_LOG=y + +#CONFIG_NET_IF_LOG_LEVEL_DBG=y +#CONFIG_NET_L2_ETHERNET_LOG_LEVEL_DBG=y + +CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y +CONFIG_NET_CONN_LOG_LEVEL_DBG=y +CONFIG_NET_CONTEXT_LOG_LEVEL_DBG=y + +CONFIG_NET_TCP_LOG_LEVEL_DBG=y diff --git a/samples/net/sockets/tcp/overlay-max-stacks.conf b/samples/net/sockets/tcp/overlay-max-stacks.conf new file mode 100644 index 00000000000..9ae3d692c97 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-max-stacks.conf @@ -0,0 +1,10 @@ +CONFIG_NET_MGMT_EVENT_STACK_SIZE=65535 +CONFIG_PRIVILEGED_STACK_SIZE=65535 +CONFIG_NET_TX_STACK_SIZE=130944 +CONFIG_NET_RX_STACK_SIZE=130944 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=65535 +CONFIG_MAIN_STACK_SIZE=65535 +CONFIG_IDLE_STACK_SIZE=65535 +CONFIG_ISR_STACK_SIZE=65535 +CONFIG_OFFLOAD_WORKQUEUE_STACK_SIZE=65535 +CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=65535 diff --git a/samples/net/sockets/tcp/overlay-nommu.conf b/samples/net/sockets/tcp/overlay-nommu.conf new file mode 100644 index 00000000000..9f31dfe6c42 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-nommu.conf @@ -0,0 +1 @@ +CONFIG_X86_MMU=n diff --git a/samples/net/sockets/tcp/overlay-slip.conf b/samples/net/sockets/tcp/overlay-slip.conf new file mode 100644 index 00000000000..ba7d05d7ec3 --- /dev/null +++ b/samples/net/sockets/tcp/overlay-slip.conf @@ -0,0 +1,4 @@ +# Overlay for experimental TCP as qemu_x86 target against the sanity check + +CONFIG_NET_SLIP_TAP=y +CONFIG_SLIP_MAC_ADDR="00:00:00:00:00:01" diff --git a/samples/net/sockets/tcp/prj.conf b/samples/net/sockets/tcp/prj.conf new file mode 100644 index 00000000000..3dbda10593e --- /dev/null +++ b/samples/net/sockets/tcp/prj.conf @@ -0,0 +1,26 @@ +CONFIG_NEWLIB_LIBC=y + +CONFIG_NETWORKING=y + +CONFIG_NET_SOCKETS=y +CONFIG_NET_SOCKETS_POSIX_NAMES=y + +CONFIG_NET_IPV4=y +CONFIG_NET_IPV6=y + +CONFIG_NET_CONFIG_SETTINGS=y + +CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" + +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" + +CONFIG_NET_TCP=y +CONFIG_NET_TCP2=y + +CONFIG_HEAP_MEM_POOL_SIZE=8192 + +CONFIG_JSON_LIBRARY=y + +CONFIG_NET_TEST_PROTOCOL=y diff --git a/samples/net/sockets/tcp/sample.yaml b/samples/net/sockets/tcp/sample.yaml new file mode 100644 index 00000000000..4988106ac52 --- /dev/null +++ b/samples/net/sockets/tcp/sample.yaml @@ -0,0 +1,3 @@ +sample: + description: A sample for running TTCN-3 based sanity check for TCP2 + name: tcp diff --git a/samples/net/sockets/tcp/src/main.c b/samples/net/sockets/tcp/src/main.c new file mode 100644 index 00000000000..88e6e790010 --- /dev/null +++ b/samples/net/sockets/tcp/src/main.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2020 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* TCP Sample for TTCN-3 based Sanity Check */ + +#include +#include +#include + +#include + +#include +#include + +#define UDP_PORT 4242 + +#define perror(fmt, args...) \ +do { \ + printf("Error: " fmt "(): %s\n" ## args, strerror(errno)); \ + exit(errno); \ +} while (0) \ + +/* + * This application is used together with the TTCN-3 based sanity check + * to validate the functionality of the experimental TCP (TCP2). + * + * samples/net/sockets/tcp/README.rst + * + * Eventually UDP based test protocol might be terminated in the user space + * (see udp() below), but at the moment it's just a dummy loop + * to keep the sample running in order to execute TTCN-3 TCP2 sanity check. + */ +void main(void) +{ + while (true) { + k_sleep(K_SECONDS(1)); + } +} + +void udp(void) +{ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + + if (fd < 0) { + perror("socket"); + } + + { + struct sockaddr_in sin; + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_ANY); + sin.sin_port = htons(UDP_PORT); + + if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + perror("bind"); + } + + printf("Listening on UDP port %d\n", UDP_PORT); + } + + { +#ifndef BUF_SIZE +#define BUF_SIZE 4096 +#endif + char *buf = malloc(BUF_SIZE); + + if (buf == NULL) { + perror("malloc"); + } + + for (;;) { + ssize_t len = recv(fd, buf, BUF_SIZE, 0); + + if (len < 0) { + perror("recv"); + } + + printf("Received %ld bytes\n", (long)len); + } + } +}