Skip to content

Commit 59b3c16

Browse files
committed
samples: net: gptp: Sample application for gPTP support
The application does not do much, it just registers to a callback in order to get information about gPTP. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 7b06ec7 commit 59b3c16

File tree

7 files changed

+541
-0
lines changed

7 files changed

+541
-0
lines changed

samples/net/gptp/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)
2+
3+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
4+
project(NONE)
5+
6+
target_sources(app PRIVATE src/main.c)
7+
8+
include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake)

samples/net/gptp/Kconfig

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Kconfig - Private config options for gPTP sample app
2+
3+
#
4+
# Copyright (c) 2018 Intel Corporation
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
#
8+
9+
# This sample application will have three network interfaces.
10+
# gPTP protocol will run in the non-VLAN interface and then there
11+
# will be two VLAN interface for other use. This is just an example
12+
# how to do this kind of setup. See also VLAN sample application
13+
# for vlan-setup-linux.sh script that can be used to setup the
14+
# VLAN IP addressing in Linux side (if that is desired).
15+
16+
mainmenu "gPTP sample application"
17+
18+
config ZEPHYR_BASE
19+
string
20+
option env="ZEPHYR_BASE"
21+
22+
source "$ZEPHYR_BASE/Kconfig.zephyr"
23+
24+
if NET_GPTP
25+
26+
config NET_SAMPLE_IFACE2_MY_IPV6_ADDR
27+
string "My IPv6 address for second interface"
28+
help
29+
The value depends on your network setup.
30+
31+
config NET_SAMPLE_IFACE2_MY_IPV4_ADDR
32+
string "My IPv4 address for second interface"
33+
help
34+
The value depends on your network setup.
35+
36+
config NET_SAMPLE_IFACE2_VLAN_TAG
37+
int "VLAN tag for second interface"
38+
default 100
39+
range 0 4094
40+
depends on NET_VLAN
41+
help
42+
Set VLAN (virtual LAN) tag (id) that is used in the sample
43+
application.
44+
45+
config NET_SAMPLE_IFACE3_MY_IPV6_ADDR
46+
string "My IPv6 address for third interface"
47+
help
48+
The value depends on your network setup.
49+
50+
config NET_SAMPLE_IFACE3_MY_IPV4_ADDR
51+
string "My IPv4 address for third interface"
52+
help
53+
The value depends on your network setup.
54+
55+
config NET_SAMPLE_IFACE3_VLAN_TAG
56+
int "VLAN tag for third interface"
57+
default 200
58+
range 0 4094
59+
depends on NET_VLAN
60+
help
61+
Set VLAN (virtual LAN) tag (id) that is used in the sample
62+
application.
63+
64+
endif

samples/net/gptp/README.rst

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
.. _gptp-sample:
2+
3+
gPTP Sample Application
4+
#######################
5+
6+
Overview
7+
********
8+
9+
The gPTP sample application for Zephyr will enable gPTP support, registers
10+
gPTP phase discontinuity callback, enable traffic class support (TX multi
11+
queues) and setup VLANs (if enabled). The net-shell is also enabled so that
12+
user can monitor gPTP functionality.
13+
14+
The source code for this sample application can be found at:
15+
:file:`samples/net/gptp`.
16+
17+
Requirements
18+
************
19+
20+
- :ref:`networking_with_qemu`
21+
22+
Building and Running
23+
********************
24+
25+
A good way to run this sample is to run this gPTP application inside QEMU
26+
as described in :ref:`networking_with_qemu` or with embedded device like
27+
FRDM-K64F. Note that gPTP is only supported for boards that have ethernet port
28+
and which has support for collecting timestamps for sent and received
29+
ethernet frames.
30+
31+
Follow these steps to build the gPTP sample application:
32+
33+
.. zephyr-app-commands::
34+
:zephyr-app: samples/net/gptp
35+
:board: <board to use>
36+
:conf: prj.conf
37+
:goals: build
38+
:compact:
39+
40+
The net-shell command "net gptp" will print out general gPTP information.
41+
For port 1, the command "net gptp 1" will print detailed information about
42+
port 1 statistics etc. Note that executing the shell command could affect
43+
the timing of the gPTP packets and the grandmaster might mark the device
44+
as non AS capable and disable it.
45+
46+
Setting up Linux Host
47+
=====================
48+
49+
If you need VLAN support in your network, then the
50+
:file:`samples/net/vlan/vlan-setup-linux.sh` provides a script that can be
51+
executed on the Linux host. It creates two VLANs on the Linux host and creates
52+
routes to Zephyr.
53+
54+
The OpenAVNU repository at https://github.com/AVnu/OpenAvnu contains gPTP
55+
daemon that can be run in Linux host and which can act as a grandmaster for
56+
the IEEE 801.1AS network.
57+
58+
After downloading the source code, compile it like this in Linux:
59+
60+
.. code-block:: console
61+
62+
mkdir build
63+
cd build
64+
cmake ..
65+
cp daemons/gptp/gptp_cfg.ini build/daemons/gptp/
66+
cd build/daemons/gptp
67+
68+
Edit the gptp_cfg.ini file and set the neighborPropDelayThresh to 10000
69+
as the default value 800 is too low if you run the gPTP in FRDM-K64F.
70+
71+
Then execute the daemon with correct network interface and the configuration
72+
file.
73+
74+
.. code-block:: console
75+
76+
sudo ./gptp enp0s25 -F gptp_cfg.ini
77+
78+
Note that here the example network interface enp0s25 is the name of the
79+
non-VLAN network interface that is connected to your Zephyr device.
80+
81+
If everything is configured correctly, you should see following kind of
82+
messages from gptp:
83+
84+
.. code-block:: console
85+
86+
INFO : GPTP [13:01:14:837] gPTP starting
87+
INFO : GPTP [13:01:14:838] priority1 = 248
88+
INFO : GPTP [13:01:14:838] announceReceiptTimeout: 3
89+
INFO : GPTP [13:01:14:838] syncReceiptTimeout: 3
90+
INFO : GPTP [13:01:14:838] LINKSPEED_100MB - PHY delay
91+
TX: 1044 | RX: 2133
92+
INFO : GPTP [13:01:14:838] LINKSPEED_1G - PHY delay
93+
TX: 184 | RX: 382
94+
INFO : GPTP [13:01:14:838] neighborPropDelayThresh: 10000
95+
INFO : GPTP [13:01:14:838] syncReceiptThreshold: 8
96+
ERROR : GPTP [13:01:14:838] Using clock device: /dev/ptp0
97+
STATUS : GPTP [13:01:14:838] Starting PDelay
98+
STATUS : GPTP [13:01:14:838] Link Speed: 1000000 kb/sec
99+
STATUS : GPTP [13:01:14:871] AsCapable: Enabled
100+
STATUS : GPTP [13:01:16:497] New Grandmaster "3C:97:0E:FF:FE:23:F2:32" (previous "00:00:00:00:00:00:00:00")
101+
STATUS : GPTP [13:01:16:497] Switching to Master
102+
103+
If Zephyr syncs properly with gptp daemon, then this is printed:
104+
105+
.. code-block:: console
106+
107+
STATUS : GPTP [13:01:25:965] AsCapable: Enabled
108+
109+
By default gPTP in Zephyr will not print any gPTP debug messages to console.
110+
One can enable debug prints by setting CONFIG_NET_DEBUG_GPTP=y in config file.

samples/net/gptp/prj.conf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
CONFIG_NETWORKING=y
2+
CONFIG_NET_LOG=y
3+
CONFIG_NET_IPV6=y
4+
CONFIG_NET_IPV4=y
5+
CONFIG_NET_DHCPV4=n
6+
CONFIG_NET_UDP=y
7+
CONFIG_NET_TCP=y
8+
CONFIG_NET_STATISTICS=y
9+
10+
CONFIG_TEST_RANDOM_GENERATOR=y
11+
12+
CONFIG_NET_PKT_RX_COUNT=32
13+
CONFIG_NET_PKT_TX_COUNT=32
14+
CONFIG_NET_BUF_RX_COUNT=32
15+
CONFIG_NET_BUF_TX_COUNT=32
16+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=5
17+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
18+
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
19+
CONFIG_NET_MAX_CONTEXTS=10
20+
21+
CONFIG_INIT_STACKS=y
22+
CONFIG_PRINTK=y
23+
CONFIG_NET_SHELL=y
24+
25+
# Ethernet is needed for gPTP
26+
CONFIG_NET_L2_ETHERNET=y
27+
28+
CONFIG_NET_APP_SERVER=y
29+
CONFIG_NET_APP_NEED_IPV6=y
30+
CONFIG_NET_APP_NEED_IPV4=y
31+
CONFIG_NET_APP_SETTINGS=y
32+
33+
# There will be three network interfaces. gPTP will
34+
# run in non-VLAN interface and then there are two extra
35+
# VLAN interface for other use. This is just an example
36+
# how to do this kind of setup.
37+
38+
# First ethernet interface will use these settings
39+
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
40+
CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2"
41+
CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
42+
CONFIG_NET_APP_PEER_IPV4_ADDR="192.0.2.2"
43+
44+
# Second ethernet interface will have these settings
45+
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR="2001:db8:100::1"
46+
CONFIG_NET_SAMPLE_IFACE2_PEER_IPV6_ADDR="2001:db8:100::2"
47+
# TEST-NET-2 from RFC 5737
48+
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR="198.51.100.1"
49+
CONFIG_NET_SAMPLE_IFACE2_PEER_IPV4_ADDR="198.51.100.2"
50+
# VLAN tag for the second interface
51+
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG=100
52+
53+
# Settings for the third network interface
54+
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR="2001:db8:200::1"
55+
CONFIG_NET_SAMPLE_IFACE3_PEER_IPV6_ADDR="2001:db8:200::2"
56+
# TEST-NET-3 from RFC 5737
57+
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR="203.0.113.1"
58+
CONFIG_NET_SAMPLE_IFACE3_PEER_IPV4_ADDR="203.0.113.2"
59+
# VLAN tag for the second interface
60+
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG=200
61+
62+
# Logging
63+
CONFIG_SYS_LOG_SHOW_COLOR=y
64+
CONFIG_SYS_LOG_NET_LEVEL=4
65+
66+
CONFIG_NET_DEBUG_NET_PKT=y
67+
CONFIG_NET_DEBUG_L2_ETHERNET=n
68+
CONFIG_NET_DEBUG_ARP=n
69+
CONFIG_NET_DEBUG_CORE=n
70+
CONFIG_NET_DEBUG_IF=n
71+
CONFIG_NET_DEBUG_GPTP=n
72+
73+
# VLAN settings. We will have three VLANs, but the one running gPTP protocol
74+
# will not have any tags (see IEEE 802.11AS chapter 11.3.3 for details)
75+
CONFIG_NET_VLAN=y
76+
CONFIG_NET_VLAN_COUNT=3
77+
78+
# gPTP settings
79+
CONFIG_NET_GPTP=y
80+
CONFIG_NET_GPTP_STATISTICS=y
81+
82+
# How many traffic classes to enable
83+
CONFIG_NET_TC_TX_COUNT=6
84+
CONFIG_NET_TC_RX_COUNT=4
85+
86+
# Enable priority support in net_context
87+
CONFIG_NET_CONTEXT_PRIORITY=y
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
CONFIG_NETWORKING=y
2+
CONFIG_NET_LOG=y
3+
CONFIG_NET_IPV6=y
4+
CONFIG_NET_IPV4=y
5+
CONFIG_NET_DHCPV4=n
6+
CONFIG_NET_UDP=y
7+
CONFIG_NET_TCP=y
8+
CONFIG_NET_STATISTICS=y
9+
10+
CONFIG_TEST_RANDOM_GENERATOR=y
11+
12+
CONFIG_NET_PKT_RX_COUNT=32
13+
CONFIG_NET_PKT_TX_COUNT=32
14+
CONFIG_NET_BUF_RX_COUNT=32
15+
CONFIG_NET_BUF_TX_COUNT=32
16+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=5
17+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
18+
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
19+
CONFIG_NET_MAX_CONTEXTS=10
20+
21+
CONFIG_INIT_STACKS=y
22+
CONFIG_PRINTK=y
23+
CONFIG_NET_SHELL=y
24+
25+
# Ethernet is needed for gPTP
26+
CONFIG_NET_L2_ETHERNET=y
27+
28+
CONFIG_NET_APP_SERVER=y
29+
CONFIG_NET_APP_NEED_IPV6=y
30+
CONFIG_NET_APP_NEED_IPV4=y
31+
CONFIG_NET_APP_SETTINGS=y
32+
33+
# There will be three network interfaces. gPTP will
34+
# run in non-VLAN interface and then there are two extra
35+
# VLAN interface for other use. This is just an example
36+
# how to do this kind of setup.
37+
38+
# First ethernet interface will use these settings
39+
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
40+
CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2"
41+
CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
42+
CONFIG_NET_APP_PEER_IPV4_ADDR="192.0.2.2"
43+
44+
# Second ethernet interface will have these settings
45+
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR="2001:db8:100::1"
46+
CONFIG_NET_SAMPLE_IFACE2_PEER_IPV6_ADDR="2001:db8:100::2"
47+
# TEST-NET-2 from RFC 5737
48+
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR="198.51.100.1"
49+
CONFIG_NET_SAMPLE_IFACE2_PEER_IPV4_ADDR="198.51.100.2"
50+
# VLAN tag for the second interface
51+
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG=100
52+
53+
# Settings for the third network interface
54+
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR="2001:db8:200::1"
55+
CONFIG_NET_SAMPLE_IFACE3_PEER_IPV6_ADDR="2001:db8:200::2"
56+
# TEST-NET-3 from RFC 5737
57+
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR="203.0.113.1"
58+
CONFIG_NET_SAMPLE_IFACE3_PEER_IPV4_ADDR="203.0.113.2"
59+
# VLAN tag for the second interface
60+
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG=200
61+
62+
# Logging
63+
CONFIG_SYS_LOG_SHOW_COLOR=y
64+
CONFIG_SYS_LOG_NET_LEVEL=4
65+
66+
CONFIG_NET_DEBUG_NET_PKT=y
67+
CONFIG_NET_DEBUG_L2_ETHERNET=n
68+
CONFIG_NET_DEBUG_ARP=n
69+
CONFIG_NET_DEBUG_CORE=n
70+
CONFIG_NET_DEBUG_IF=n
71+
CONFIG_NET_DEBUG_GPTP=n
72+
#CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG=n
73+
74+
# VLAN settings. We will have three VLANs, but the one running gPTP protocol
75+
# will not have any tags (see IEEE 802.11AS chapter 11.3.3 for details)
76+
CONFIG_NET_VLAN=y
77+
CONFIG_NET_VLAN_COUNT=3
78+
79+
# gPTP settings
80+
CONFIG_NET_GPTP=y
81+
CONFIG_NET_GPTP_STATISTICS=y
82+
83+
# MCUX driver settings
84+
CONFIG_ETH_MCUX=y
85+
CONFIG_PTP_CLOCK_MCUX=y
86+
87+
# Optionally you can use fixed MAC address
88+
CONFIG_ETH_MCUX_0_RANDOM_MAC=n
89+
CONFIG_ETH_MCUX_0_MAC3=0xBC
90+
CONFIG_ETH_MCUX_0_MAC4=0x8C
91+
CONFIG_ETH_MCUX_0_MAC5=0xAE
92+
93+
# How many traffic classes to enable
94+
CONFIG_NET_TC_TX_COUNT=8
95+
CONFIG_NET_TC_RX_COUNT=8
96+
97+
# Enable priority support in net_context
98+
CONFIG_NET_CONTEXT_PRIORITY=y

samples/net/gptp/sample.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
common:
2+
harness: net
3+
tags: net gptp
4+
sample:
5+
description: Test gPTP functionality
6+
name: gPTP sample app
7+
tests:
8+
test:
9+
platform_whitelist: qemu_x86 frdm_k64f
10+
depends_on: netif

0 commit comments

Comments
 (0)