summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Christian <lucas@lucasec.com>2024-08-08 23:39:00 -0700
committerChristian Breunig <christian@breunig.cc>2024-09-21 08:51:28 +0200
commita5a6e57b3f7ba7d76bffcfb8dcb086d79f51202a (patch)
treea5c399d95be3f3846aff2b541e0a96f552cbb60f
parentbf5805c52b7133ec76edeebac33f3c30b56b169f (diff)
downloadvyos-1x-a5a6e57b3f7ba7d76bffcfb8dcb086d79f51202a.tar.gz
vyos-1x-a5a6e57b3f7ba7d76bffcfb8dcb086d79f51202a.zip
T6630: ntp: add chrony "ntp over ptp" transport
-rw-r--r--data/templates/chrony/chrony.conf.j27
-rw-r--r--interface-definitions/service_ntp.xml.in20
-rwxr-xr-xsmoketest/scripts/cli/test_service_ntp.py34
-rwxr-xr-xsrc/conf_mode/service_ntp.py9
4 files changed, 67 insertions, 3 deletions
diff --git a/data/templates/chrony/chrony.conf.j2 b/data/templates/chrony/chrony.conf.j2
index 838813866..1fc488d24 100644
--- a/data/templates/chrony/chrony.conf.j2
+++ b/data/templates/chrony/chrony.conf.j2
@@ -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 %}
@@ -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 %}
diff --git a/interface-definitions/service_ntp.xml.in b/interface-definitions/service_ntp.xml.in
index 005499abd..c4f3116ff 100644
--- a/interface-definitions/service_ntp.xml.in
+++ b/interface-definitions/service_ntp.xml.in
@@ -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>
@@ -59,11 +59,15 @@
<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>
@@ -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>
@@ -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>
diff --git a/smoketest/scripts/cli/test_service_ntp.py b/smoketest/scripts/cli/test_service_ntp.py
index 644894914..a39431c1b 100755
--- a/smoketest/scripts/cli/test_service_ntp.py
+++ b/smoketest/scripts/cli/test_service_ntp.py
@@ -224,5 +224,39 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase):
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)
diff --git a/src/conf_mode/service_ntp.py b/src/conf_mode/service_ntp.py
index 83880fd72..f7dbc3776 100755
--- a/src/conf_mode/service_ntp.py
+++ b/src/conf_mode/service_ntp.py
@@ -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):