Skip to content

Commit

Permalink
T6630: ntp: add chrony "ntp over ptp" transport
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasec committed Aug 9, 2024
1 parent 2f77d57 commit d97176b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
7 changes: 6 additions & 1 deletion data/templates/chrony/chrony.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ user {{ user }}
{% if config.pool is vyos_defined %}
{% set association = 'pool' %}
{% endif %}
{{ association }} {{ server | replace('_', '-') }} iburst {{- ' nts' if config.nts is vyos_defined }} {{- ' noselect' if config.noselect is vyos_defined }} {{- ' prefer' if config.prefer is vyos_defined }} {{- ' xleave' if config.interleave is vyos_defined }}
{{ association }} {{ server | replace('_', '-') }} iburst {{- ' nts' if config.nts is vyos_defined }} {{- ' noselect' if config.noselect is vyos_defined }} {{- ' prefer' if config.prefer is vyos_defined }} {{- ' xleave' if config.interleave is vyos_defined }} {{- ' port 319' if config.ptp_transport is vyos_defined }}
{% endfor %}
{% endif %}

Expand Down Expand Up @@ -77,3 +77,8 @@ hwtimestamp {{ interface }} {{- ' rxfilter ' ~ config.receive_filter if config.r
# Enable hardware timestamping on all supported interfaces not otherwise configured
hwtimestamp *
{% endif %}

{% if ptp_transport is vyos_defined %}
# Enable sending and receiving NTP over PTP packets (PTP transport)
ptpport 319
{% endif %}
20 changes: 18 additions & 2 deletions interface-definitions/service_ntp.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<properties>
<help>Selects which inbound packets are timestamped by the NIC</help>
<completionHelp>
<list>all ntp none</list>
<list>all ntp ptp none</list>
</completionHelp>
<valueHelp>
<format>all</format>
Expand All @@ -58,12 +58,16 @@
<format>ntp</format>
<description>Only NTP packets are timestamped</description>
</valueHelp>
<valueHelp>
<format>ptp</format>
<description>Only PTP packets, or NTP packets using the PTP transport, are timestamped</description>
</valueHelp>
<valueHelp>
<format>none</format>
<description>No received packets are timestamped</description>
</valueHelp>
<constraint>
<regex>(all|ntp|none)</regex>
<regex>(all|ntp|ptp|none)</regex>
</constraint>
</properties>
</leafNode>
Expand All @@ -73,6 +77,12 @@
</node>
</children>
</node>
<leafNode name="ptp-transport">
<properties>
<help>Enables the PTP transport for NTP packets</help>
<valueless/>
</properties>
</leafNode>
<leafNode name="leap-second">
<properties>
<help>Leap second behavior</help>
Expand Down Expand Up @@ -146,6 +156,12 @@
<valueless/>
</properties>
</leafNode>
<leafNode name="ptp-transport">
<properties>
<help>Use the PTP transport for the server</help>
<valueless/>
</properties>
</leafNode>
<leafNode name="interleave">
<properties>
<help>Use the interleaved mode for the server</help>
Expand Down
34 changes: 34 additions & 0 deletions smoketest/scripts/cli/test_service_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,39 @@ def test_offload_timestamp_default(self):

self.assertIn('hwtimestamp *', config)

def test_ptp_transport(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 + ['server', server, 'ptp-transport'])

# commit changes (expected to fail)
with self.assertRaises(ConfigSessionError):
self.cli_commit()

# add the required top-level option and commit
self.cli_set(base_path + ['ptp-transport'])
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) + ' port 319', config)

self.assertIn('ptpport 319', config)

if __name__ == '__main__':
unittest.main(verbosity=2)
9 changes: 9 additions & 0 deletions src/conf_mode/service_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def verify(ntp):
if ipv6_addresses > 1:
raise ConfigError(f'NTP Only admits one ipv6 value for listen-address parameter ')

if 'server' in ntp:
for host, server in ntp['server'].items():
if 'ptp_transport' in server:
if 'ptp_transport' not in ntp:
raise ConfigError('ptp-transport must be enabled on the service '\
f'before it can be used with server {host}')
else:
break

return None

def generate(ntp):
Expand Down

0 comments on commit d97176b

Please sign in to comment.