Skip to content

Commit

Permalink
T6630: ntp: add hardware timestamp offload
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasec committed Aug 10, 2024
1 parent db1efbf commit 70bf748
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
11 changes: 11 additions & 0 deletions data/templates/chrony/chrony.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ bindaddress {{ address }}
binddevice {{ interface }}
{% endif %}
{% endif %}

{% if offload.timestamp.interface is vyos_defined %}
# Enable hardware timestamping on the specified interfaces
{% for interface, config in offload.timestamp.interface.items() %}
hwtimestamp {{ interface }} {{- ' rxfilter ' ~ config.receive_filter if config.receive_filter is vyos_defined }}
{% endfor %}
{% endif %}
{% if offload.timestamp.default_enable is vyos_defined %}
# Enable hardware timestamping on all supported interfaces not otherwise configured
hwtimestamp *
{% endif %}
60 changes: 60 additions & 0 deletions interface-definitions/service_ntp.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,66 @@
#include <include/generic-interface.xml.i>
#include <include/listen-address.xml.i>
#include <include/interface/vrf.xml.i>
<node name="offload">
<properties>
<help>Configurable offload options</help>
</properties>
<children>
<node name="timestamp">
<properties>
<help>Enable timestamping of packets in the NIC hardware</help>
</properties>
<children>
<leafNode name="default-enable">
<properties>
<help>Enable timestamping on all supported interfaces</help>
<valueless/>
</properties>
</leafNode>
<tagNode name="interface">
<properties>
<help>Interface to enable timestamping on</help>
<completionHelp>
<script>${vyos_completion_dir}/list_interfaces</script>
</completionHelp>
<valueHelp>
<format>txt</format>
<description>Interface name</description>
</valueHelp>
<constraint>
#include <include/constraint/interface-name.xml.i>
</constraint>
</properties>
<children>
<leafNode name="receive-filter">
<properties>
<help>Selects which inbound packets are timestamped by the NIC</help>
<completionHelp>
<list>all ntp none</list>
</completionHelp>
<valueHelp>
<format>all</format>
<description>All received packets are timestamped</description>
</valueHelp>
<valueHelp>
<format>ntp</format>
<description>Only NTP packets are timestamped</description>
</valueHelp>
<valueHelp>
<format>none</format>
<description>No received packets are timestamped</description>
</valueHelp>
<constraint>
<regex>(all|ntp|none)</regex>
</constraint>
</properties>
</leafNode>
</children>
</tagNode>
</children>
</node>
</children>
</node>
<leafNode name="leap-second">
<properties>
<help>Leap second behavior</help>
Expand Down
30 changes: 30 additions & 0 deletions smoketest/scripts/cli/test_service_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,35 @@ def test_interleave_option(self):
for server in servers:
self.assertIn(f'server {server} iburst ' + ' '.join(options) + ' xleave', config)

def test_offload_timestamp_default(self):
# Test offloading of NIC timestamp
servers = ['192.0.2.1', '192.0.2.2']
options = ['prefer']

for server in servers:
for option in options:
self.cli_set(base_path + ['server', server, option])

self.cli_set(base_path + ['offload', 'timestamp', 'default-enable'])

# commit changes
self.cli_commit()

# Check generated configuration
# this file must be read with higher permissions
config = cmd(f'sudo cat {NTP_CONF}')
self.assertIn('driftfile /run/chrony/drift', config)
self.assertIn('dumpdir /run/chrony', config)
self.assertIn('ntsdumpdir /run/chrony', config)
self.assertIn('clientloglimit 1048576', config)
self.assertIn('rtcsync', config)
self.assertIn('makestep 1.0 3', config)
self.assertIn('leapsectz right/UTC', config)

for server in servers:
self.assertIn(f'server {server} iburst ' + ' '.join(options), config)

self.assertIn('hwtimestamp *', config)

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 70bf748

Please sign in to comment.