Skip to content

[WIP] IEEE 802.1AS gPTP support #6570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 52 commits into from
Closed

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Mar 12, 2018

This PR implements gPTP (generic Precision Time Protocol) support found in IEEE 802.1AS. This protocol can be used for time synchronization in ethernet networks. This PR is still very much work-in-progress and
it builds on top of other not-yet merged code:

There are lot of patches in this PR, but if reviewing the code, the patch named "net: if: Add TX timestamp callback support" is the first one in this gPTP series.

The gPTP support has been developed on FRDM-K64F which has PTP and hw time-stamp supported in the HAL driver.

@jukkar jukkar added area: Networking RFC Request For Comments: want input from the community labels Mar 12, 2018
@jukkar jukkar requested a review from tbursztyka March 12, 2018 11:36
@codecov-io
Copy link

codecov-io commented Mar 12, 2018

Codecov Report

Merging #6570 into master will increase coverage by 0.32%.
The diff coverage is 60.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6570      +/-   ##
==========================================
+ Coverage   53.89%   54.21%   +0.32%     
==========================================
  Files         440      440              
  Lines       41712    42706     +994     
  Branches     7949     8121     +172     
==========================================
+ Hits        22481    23155     +674     
- Misses      16030    16215     +185     
- Partials     3201     3336     +135
Impacted Files Coverage Δ
tests/net/lib/dns_resolve/src/main.c 73.43% <ø> (+0.1%) ⬆️
tests/net/vlan/src/main.c 92.92% <ø> (ø)
include/net/net_ip.h 62.5% <ø> (ø) ⬆️
tests/net/iface/src/main.c 78.89% <ø> (+0.19%) ⬆️
include/net/net_context.h 93.02% <ø> (ø) ⬆️
tests/net/rpl/src/main.c 77.17% <ø> (ø) ⬆️
tests/net/traffic_class/src/main.c 88.54% <ø> (ø)
subsys/net/ip/net_private.h 35.71% <ø> (ø) ⬆️
subsys/net/lib/app/server.c 27.27% <0%> (ø) ⬆️
subsys/net/ip/icmpv4.c 42.95% <0%> (-0.89%) ⬇️
... and 68 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e421230...3759332. Read the comment docs.

support must be enabled in ethernet drivers.

Boards supported:
- NXP FRDM-K64F
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a blank line before a list


Boards supported:
- NXP FRDM-K64F
- Qemu (emulated, limited capabilities due to lack of hardware clock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Qemu/QEMU/

Enabling the stack
******************

In menuconfig, following configuration must me enabled:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the following configuration must be


Only two Application Interfaces as defined in section 9 of the standard
are available:
-ClockTargetPhaseDiscontinuity interface (gptp_event_capture)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a blank line before this first list item


#ifndef __GPTP_H
#define __GPTP_H

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to define a doxygen defgroup to have this API show up in the documentation (and need a reference added to one of the .rst files in doc/api)

@jukkar
Copy link
Member Author

jukkar commented Mar 14, 2018

Added gptp support to native-posix board

jukkar added 17 commits March 19, 2018 11:10
Create infrastructure that allows ethernet device driver to tell
if it supports network packet checksum offloading. This applies only
to IPv4, UDP or TCP checksums. The driver can enable/disable checksum
offloading separately for Tx and Rx network packets.

Fixes zephyrproject-rtos#2987

Signed-off-by: Jukka Rissanen <[email protected]>
If the device (ethernet in this case) can calculate the network
packet checksum for IPv4, UDP or TCP, then do not calculate the
corresponding checksum by the stack itself.

Signed-off-by: Jukka Rissanen <[email protected]>
Test that if the checksum offloading is enabled, then we do not
calculate the checksum. Also the normal case, where offloading is
disabled and we need to calculate the checksum, is tested.

Signed-off-by: Jukka Rissanen <[email protected]>
Move IP address settings from net_if to separate structs.
This is needed for VLAN support.

Signed-off-by: Jukka Rissanen <[email protected]>
Instead of always allocating both IPv6 and IPv4 address information
to every network interface, allow more fine grained address
configuration. So it is possible to have IPv6 or IPv4 only network
interfaces.

This commit introduces two new config options:
CONFIG_NET_IF_MAX_IPV4_COUNT and CONFIG_NET_IF_MAX_IPV6_COUNT
which tell how many IP address information structs are allocated
statically. At runtime when network interface is setup, it is then
possible to attach this IP address info struct to a specific
network interface. This can save considerable amount of memory
as the IP address information struct can be quite large (depends
on how many IP addresses user configures in the system).

Note that the value of CONFIG_NET_IF_MAX_IPV4_COUNT and
CONFIG_NET_IF_MAX_IPV6_COUNT should reflect the estimated number of
network interfaces in the system. So if if CONFIG_NET_IF_MAX_IPV6_COUNT
is set to 1 and there are two network interfaces that need IPv6
addresses, then the system will not be able to setup IPv6 addresses to
the second network interface in this case. This scenario might be
just fine if the second network interface is IPv4 only. The net_if.c
will print a warning during startup if mismatch about the counts and
the actual number of network interface is detected.

Signed-off-by: Jukka Rissanen <[email protected]>
Add context option support and implement PRIORITY option that
can be used to classify the network traffic to different trafic
classes according to said priority value.

Signed-off-by: Jukka Rissanen <[email protected]>
Allow caller to create array of thread stacks using
NET_STACK_ARRAY_DEFINE() macro. This allows more debug information
to be printed by "net stacks" command.

Signed-off-by: Jukka Rissanen <[email protected]>
With this commit it is possible to add priority to sent or received
network packets. So user is able to send or receive higher priority
packets faster than lower level packets.
The traffic class support is activated by CONFIG_NET_TC_COUNT option.
The TC support uses work queues to separate the traffic. The
priority of the work queue thread specifies the ordering of the
network traffic. Each work queue thread handles traffic to one specific
work queue. Note that you should not enable traffic classes unless
you really need them by your application. Each TC thread needs
stack so this feature requires more memory.

It is possible to disable transmit traffic class support and keep the
receive traffic class support, or vice versa. If both RX and TX traffic
classes are enabled, then both will use the same number of queues
defined by CONFIG_NET_TC_COUNT option.

Fixes zephyrproject-rtos#6588

Signed-off-by: Jukka Rissanen <[email protected]>
Test that we can set the priority of the network packet and
that high priority packets are sent before low priority ones.

Signed-off-by: Jukka Rissanen <[email protected]>
Calculate network packet total length once and then use that
value instead of calculating it many times in a row.

Signed-off-by: Jukka Rissanen <[email protected]>
Add statistics for number of packets and bytes to each traffic
class. Print this information in net-shell.

Signed-off-by: Jukka Rissanen <[email protected]>
The "net stacks" command was printing TX or RX thread values so
that it was not possible to use the values in debugging easily.
Add traffic class value when printing the info so that it is
easy to see what TX or RX queue is doing.

Signed-off-by: Jukka Rissanen <[email protected]>
This demostrates how to classify the network traffic when sending
data. The application will create similar functionality as
echo-client so user can use echo-server running in remote host to
test this sample application.

Signed-off-by: Jukka Rissanen <[email protected]>
As the config file disables ARC we can use its RAM and ROM in x86 side.

Signed-off-by: Jukka Rissanen <[email protected]>
As the config file disables ARC we can use its RAM and ROM in
x86 side.

Signed-off-by: Jukka Rissanen <[email protected]>
This avoids this crashing in qemu_x86

***** Stack Check Fail! *****
Current thread ID = 0x004015e0
Faulting segment:address = 0x0008:0x00003593
eax: 0x0041e930, ebx: 0x00000000, ecx: 0x004170bc, edx: 0x0000dff8
esi: 0xffffffff, edi: 0x0041e930, ebp: 0x00417010, esp: 0x00416ffc
eflags: 0x216
Fatal fault in essential thread! Spinning...
Terminate emulator due to fatal kernel error

Signed-off-by: Jukka Rissanen <[email protected]>
This allows creation of virtual lan (VLAN) networks. VLAN support is
only available for ethernet network technology.

Fixes zephyrproject-rtos#3234

Signed-off-by: Jukka Rissanen <[email protected]>
jukkar and others added 24 commits March 19, 2018 11:18
Instead of always using default interface, use the IPv4 target
address to select the correct network interface when sending
IPv4 ping request.

Signed-off-by: Jukka Rissanen <[email protected]>
If we have multiple network interface (like in VLAN), then we need
to select the proper local interface based on destination address.

Signed-off-by: Jukka Rissanen <[email protected]>
As the l2_data section might contain different size context elements
like "struct ethernet_context" for Ethernet and "void *" for
Dummy L2, remove the __net_l2_start and __net_l2_end variables so
that user does not accidentally try to use them as that would not work.

Signed-off-by: Jukka Rissanen <[email protected]>
In IPv4 we need to select the network interface, where the packet
is to be sent, using the IPv4 address instead of default network
interface.

Signed-off-by: Jukka Rissanen <[email protected]>
User is able to take a network interface down or bring it up.
The command syntax is "net iface [up|down] [index]"

Signed-off-by: Jukka Rissanen <[email protected]>
Allow creation of TX timestamp thread which will collect TX timestamp
information from device drivers. If the callback is registered, then
it will pass that timestamp information to the relevant party for further
processing. This support will be used by gPTP code in subsequent
commits.

Signed-off-by: Jukka Rissanen <[email protected]>
Signed-off-by: Julien Chevrier <[email protected]>
Defines a PTP clock driver that can be implemented in those network
interface drivers that provide gPTP support.

Signed-off-by: Jukka Rissanen <[email protected]>
Signed-off-by: Julien Chevrier <[email protected]>
Core IEEE 802.1AS (gPTP) support and application interface.

Signed-off-by: Jukka Rissanen <[email protected]>
Signed-off-by: Julien Chevrier <[email protected]>
Fix timestamping in MCUX external library. The nanosecond part of the
frame timestamp wasn't saved.

Signed-off-by: Julien Chevrier <[email protected]>
If the mcux driver has PTP support, then enable
ENET_ENHANCEDBUFFERDESCRIPTOR_MODE in HAL.

Signed-off-by: Jukka Rissanen <[email protected]>
We need to use only four low order bits from first byte of PTP message
as that contains the message type value.

Signed-off-by: Jukka Rissanen <[email protected]>
This adds packet timestammping support to the driver and configures
various PTP options in ENET.

Signed-off-by: Jukka Rissanen <[email protected]>
Signed-off-by: Julien Chevrier <[email protected]>
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]>
Test that Tx timestamp callback code is called properly if network
packet timestamping is enabled.

Signed-off-by: Jukka Rissanen <[email protected]>
This will give some extra info about gPTP status and support if
gPTP support is enabled in config file.

Signed-off-by: Jukka Rissanen <[email protected]>
Add gPTP information to documentation.

Signed-off-by: Jukka Rissanen <[email protected]>
Signed-off-by: Julien Chevrier <[email protected]>
Allow this setup as Linux supports this too.

Signed-off-by: Jukka Rissanen <[email protected]>
If VLAN is enabled for specific PTP interface, then manipulate
the ethernet header properly in this case.

Signed-off-by: Jukka Rissanen <[email protected]>
By default gPTP is not run over VLAN but if needed that can be
done by uncommenting statement at the beginning of the file.

Signed-off-by: Jukka Rissanen <[email protected]>
Use priority 3 (critial app) for outgoing event messages (Sync,
Pdelay_Req and Pdelay_Resp). Use priority 6 (Internetwork Control)
for all other outgoing packets.
See IEEE 802.1Q chapter 8.4.4 for more details.

Signed-off-by: Jukka Rissanen <[email protected]>
Set the received PTP packet priority high so that those packets
will be handled first.

Signed-off-by: Jukka Rissanen <[email protected]>
This is not very scientific but can give some hint how much we
are spending in TX and RX paths.

Signed-off-by: Jukka Rissanen <[email protected]>
For debugging purposes it is useful to know which interface
the dropped packet was received.

Signed-off-by: Jukka Rissanen <[email protected]>
Allow gPTP code to be run as a linux process and communicate
with gPTP daemon running in linux host.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar
Copy link
Member Author

jukkar commented Mar 19, 2018

Rebase against master

@jukkar
Copy link
Member Author

jukkar commented Mar 21, 2018

Lets remove this for time being as this seems to confuse people and is too early.

@jukkar jukkar closed this Mar 21, 2018
@jukkar jukkar deleted the gptp branch March 21, 2018 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking RFC Request For Comments: want input from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants