samples: net: sockets: tcp: Add a TCP sample and instructions
In order to run the TTCN-3 based sanity check, add a TCP sample app and instructions for running the sanity check. Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
This commit is contained in:
parent
794b32a4fc
commit
e0c151b9cf
14 changed files with 226 additions and 0 deletions
10
samples/net/sockets/tcp/CMakeLists.txt
Normal file
10
samples/net/sockets/tcp/CMakeLists.txt
Normal file
|
@ -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)
|
43
samples/net/sockets/tcp/README.rst
Normal file
43
samples/net/sockets/tcp/README.rst
Normal file
|
@ -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
|
7
samples/net/sockets/tcp/overlay-debug.conf
Normal file
7
samples/net/sockets/tcp/overlay-debug.conf
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
CONFIG_NO_OPTIMIZATIONS=y
|
||||||
|
CONFIG_DEBUG=y
|
||||||
|
|
||||||
|
CONFIG_ASSERT=y
|
||||||
|
CONFIG_STACK_SENTINEL=y
|
||||||
|
|
||||||
|
CONFIG_STACK_CANARIES=y
|
7
samples/net/sockets/tcp/overlay-e1000.conf
Normal file
7
samples/net/sockets/tcp/overlay-e1000.conf
Normal file
|
@ -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
|
6
samples/net/sockets/tcp/overlay-log-extra.conf
Normal file
6
samples/net/sockets/tcp/overlay-log-extra.conf
Normal file
|
@ -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
|
6
samples/net/sockets/tcp/overlay-log-extra2.conf
Normal file
6
samples/net/sockets/tcp/overlay-log-extra2.conf
Normal file
|
@ -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
|
4
samples/net/sockets/tcp/overlay-log-pkt.conf
Normal file
4
samples/net/sockets/tcp/overlay-log-pkt.conf
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
CONFIG_NET_PKT_LOG_LEVEL_DBG=y
|
||||||
|
|
||||||
|
CONFIG_NET_BUF_LOG=y
|
||||||
|
CONFIG_NET_BUF_LOG_LEVEL_DBG=y
|
14
samples/net/sockets/tcp/overlay-log.conf
Normal file
14
samples/net/sockets/tcp/overlay-log.conf
Normal file
|
@ -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
|
10
samples/net/sockets/tcp/overlay-max-stacks.conf
Normal file
10
samples/net/sockets/tcp/overlay-max-stacks.conf
Normal file
|
@ -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
|
1
samples/net/sockets/tcp/overlay-nommu.conf
Normal file
1
samples/net/sockets/tcp/overlay-nommu.conf
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_X86_MMU=n
|
4
samples/net/sockets/tcp/overlay-slip.conf
Normal file
4
samples/net/sockets/tcp/overlay-slip.conf
Normal file
|
@ -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"
|
26
samples/net/sockets/tcp/prj.conf
Normal file
26
samples/net/sockets/tcp/prj.conf
Normal file
|
@ -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
|
3
samples/net/sockets/tcp/sample.yaml
Normal file
3
samples/net/sockets/tcp/sample.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
sample:
|
||||||
|
description: A sample for running TTCN-3 based sanity check for TCP2
|
||||||
|
name: tcp
|
85
samples/net/sockets/tcp/src/main.c
Normal file
85
samples/net/sockets/tcp/src/main.c
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* TCP Sample for TTCN-3 based Sanity Check */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <net/socket.h>
|
||||||
|
|
||||||
|
#include <data/json.h>
|
||||||
|
#include <tp.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue