Commit 67b4c5d5 authored by Jukka Rissanen's avatar Jukka Rissanen
Browse files

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: default avatarJukka Rissanen <jukka.rissanen@linux.intel.com>
parent 45b06a25
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)

macro(set_conf_file)
  if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf)
    set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf")
  elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf)
    set(CONF_FILE
      "prj_base.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf")
  else()
    set(CONF_FILE "prj_base.conf")
  endif()
endmacro()

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

target_sources(app PRIVATE src/main.c)
+64 −0
Original line number Diff line number Diff line
# Kconfig - Private config options for gPTP sample app

#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

# This sample application will have three network interfaces.
# gPTP protocol will run in the non-VLAN interface and then there
# will be two VLAN interface for other use. This is just an example
# how to do this kind of setup. See also VLAN sample application
# for vlan-setup-linux.sh script that can be used to setup the
# VLAN IP addressing in Linux side (if that is desired).

mainmenu "gPTP sample application"

config ZEPHYR_BASE
	string
	option env="ZEPHYR_BASE"

source "$ZEPHYR_BASE/Kconfig.zephyr"

if NET_GPTP

config NET_SAMPLE_IFACE2_MY_IPV6_ADDR
	string "My IPv6 address for second interface"
	help
	  The value depends on your network setup.

config NET_SAMPLE_IFACE2_MY_IPV4_ADDR
	string "My IPv4 address for second interface"
	help
	  The value depends on your network setup.

config NET_SAMPLE_IFACE2_VLAN_TAG
	int "VLAN tag for second interface"
	default 100
	range 0 4094
	depends on NET_VLAN
	help
	  Set VLAN (virtual LAN) tag (id) that is used in the sample
	  application.

config NET_SAMPLE_IFACE3_MY_IPV6_ADDR
	string "My IPv6 address for third interface"
	help
	  The value depends on your network setup.

config NET_SAMPLE_IFACE3_MY_IPV4_ADDR
	string "My IPv4 address for third interface"
	help
	  The value depends on your network setup.

config NET_SAMPLE_IFACE3_VLAN_TAG
	int "VLAN tag for third interface"
	default 200
	range 0 4094
	depends on NET_VLAN
	help
	  Set VLAN (virtual LAN) tag (id) that is used in the sample
	  application.

endif
+110 −0
Original line number Diff line number Diff line
.. _gptp-sample:

gPTP Sample Application
#######################

Overview
********

The gPTP sample application for Zephyr will enable gPTP support, registers
gPTP phase discontinuity callback, enable traffic class support (TX multi
queues) and setup VLANs (if enabled). The net-shell is also enabled so that
user can monitor gPTP functionality.

The source code for this sample application can be found at:
:file:`samples/net/gptp`.

Requirements
************

- :ref:`networking_with_qemu`

Building and Running
********************

A good way to run this sample is to run this gPTP application inside QEMU
as described in :ref:`networking_with_qemu` or with embedded device like
FRDM-K64F. Note that gPTP is only supported for boards that have ethernet port
and which has support for collecting timestamps for sent and received
ethernet frames.

Follow these steps to build the gPTP sample application:

.. zephyr-app-commands::
   :zephyr-app: samples/net/gptp
   :board: <board to use>
   :conf: prj.conf
   :goals: build
   :compact:

The net-shell command "net gptp" will print out general gPTP information.
For port 1, the command "net gptp 1" will print detailed information about
port 1 statistics etc. Note that executing the shell command could affect
the timing of the gPTP packets and the grandmaster might mark the device
as non AS capable and disable it.

Setting up Linux Host
=====================

If you need VLAN support in your network, then the
:file:`samples/net/vlan/vlan-setup-linux.sh` provides a script that can be
executed on the Linux host. It creates two VLANs on the Linux host and creates
routes to Zephyr.

The OpenAVNU repository at https://github.com/AVnu/OpenAvnu contains gPTP
daemon that can be run in Linux host and which can act as a grandmaster for
the IEEE 801.1AS network.

After downloading the source code, compile it like this in Linux:

.. code-block:: console

    mkdir build
    cd build
    cmake ..
    cp daemons/gptp/gptp_cfg.ini build/daemons/gptp/
    cd build/daemons/gptp

Edit the gptp_cfg.ini file and set the neighborPropDelayThresh to 10000
as the default value 800 is too low if you run the gPTP in FRDM-K64F.

Then execute the daemon with correct network interface and the configuration
file.

.. code-block:: console

    sudo ./gptp enp0s25 -F gptp_cfg.ini

Note that here the example network interface enp0s25 is the name of the
non-VLAN network interface that is connected to your Zephyr device.

If everything is configured correctly, you should see following kind of
messages from gptp:

.. code-block:: console

    INFO     : GPTP [13:01:14:837] gPTP starting
    INFO     : GPTP [13:01:14:838] priority1 = 248
    INFO     : GPTP [13:01:14:838] announceReceiptTimeout: 3
    INFO     : GPTP [13:01:14:838] syncReceiptTimeout: 3
    INFO     : GPTP [13:01:14:838] LINKSPEED_100MB - PHY delay
			TX: 1044 | RX: 2133
    INFO     : GPTP [13:01:14:838] LINKSPEED_1G - PHY delay
			TX: 184 | RX: 382
    INFO     : GPTP [13:01:14:838] neighborPropDelayThresh: 10000
    INFO     : GPTP [13:01:14:838] syncReceiptThreshold: 8
    ERROR    : GPTP [13:01:14:838] Using clock device: /dev/ptp0
    STATUS   : GPTP [13:01:14:838] Starting PDelay
    STATUS   : GPTP [13:01:14:838] Link Speed: 1000000 kb/sec
    STATUS   : GPTP [13:01:14:871] AsCapable: Enabled
    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")
    STATUS   : GPTP [13:01:16:497] Switching to Master

If Zephyr syncs properly with gptp daemon, then this is printed:

.. code-block:: console

    STATUS   : GPTP [13:01:25:965] AsCapable: Enabled

By default gPTP in Zephyr will not print any gPTP debug messages to console.
One can enable debug prints by setting CONFIG_NET_DEBUG_GPTP=y in config file.
+1 −0
Original line number Diff line number Diff line
CONFIG_USERSPACE=n
+84 −0
Original line number Diff line number Diff line
CONFIG_NETWORKING=y
CONFIG_NET_LOG=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
CONFIG_NET_DHCPV4=n
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
CONFIG_NET_STATISTICS=y
CONFIG_NET_STATISTICS_USER_API=y

CONFIG_TEST_RANDOM_GENERATOR=y

CONFIG_NET_PKT_RX_COUNT=32
CONFIG_NET_PKT_TX_COUNT=32
CONFIG_NET_BUF_RX_COUNT=32
CONFIG_NET_BUF_TX_COUNT=32
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=5
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
CONFIG_NET_MAX_CONTEXTS=10

CONFIG_INIT_STACKS=y
CONFIG_PRINTK=y
CONFIG_NET_SHELL=y

# Ethernet is needed for gPTP
CONFIG_NET_L2_ETHERNET=y

CONFIG_NET_APP_SERVER=y
CONFIG_NET_APP_NEED_IPV6=y
CONFIG_NET_APP_NEED_IPV4=y
CONFIG_NET_APP_SETTINGS=y

# There will be three network interfaces. gPTP will
# run in non-VLAN interface and then there are two extra
# VLAN interface for other use. This is just an example
# how to do this kind of setup.

# First ethernet interface will use these settings
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2"
CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_APP_PEER_IPV4_ADDR="192.0.2.2"

# Second ethernet interface will have these settings
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR="2001:db8:100::1"
# TEST-NET-2 from RFC 5737
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR="198.51.100.1"
# VLAN tag for the second interface
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG=100

# Settings for the third network interface
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR="2001:db8:200::1"
# TEST-NET-3 from RFC 5737
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR="203.0.113.1"
# VLAN tag for the second interface
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG=200

# Logging
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_SYS_LOG_NET_LEVEL=4

CONFIG_NET_DEBUG_NET_PKT=y
CONFIG_NET_DEBUG_L2_ETHERNET=n
CONFIG_NET_DEBUG_ARP=n
CONFIG_NET_DEBUG_CORE=n
CONFIG_NET_DEBUG_IF=n
CONFIG_NET_DEBUG_GPTP=n

# VLAN settings. We will have three VLANs, but the one running gPTP protocol
# will not have any tags (see IEEE 802.11AS chapter 11.3.3 for details)
CONFIG_NET_VLAN=y
CONFIG_NET_VLAN_COUNT=3

# gPTP settings
CONFIG_NET_GPTP=y
CONFIG_NET_GPTP_STATISTICS=y

# How many traffic classes to enable
CONFIG_NET_TC_TX_COUNT=6
CONFIG_NET_TC_RX_COUNT=4

# Enable priority support in net_context
CONFIG_NET_CONTEXT_PRIORITY=y
Loading