From e504e0cac55725e93f21322877bb7d0c4f97c992 Mon Sep 17 00:00:00 2001 From: Lucas Christian Date: Thu, 8 Aug 2024 23:30:40 -0700 Subject: T6630: ntp: add "interleave" option --- smoketest/scripts/cli/test_service_ntp.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'smoketest/scripts/cli') diff --git a/smoketest/scripts/cli/test_service_ntp.py b/smoketest/scripts/cli/test_service_ntp.py index ae45fe2f4..fe6b1a529 100755 --- a/smoketest/scripts/cli/test_service_ntp.py +++ b/smoketest/scripts/cli/test_service_ntp.py @@ -165,5 +165,34 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): self.assertIn(f'maxslewrate 1000', config) self.assertIn(f'smoothtime 400 0.001024 leaponly', config) + def test_interleave_option(self): + # "interleave" option differs from some others in that the + # name is not a 1:1 mapping from VyOS config + servers = ['192.0.2.1', '192.0.2.2'] + options = ['prefer'] + offload_interface = 'eth0' + + for server in servers: + for option in options: + self.cli_set(base_path + ['server', server, option]) + self.cli_set(base_path + ['server', server, 'interleave']) + + # 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) + ' xleave', config) + if __name__ == '__main__': unittest.main(verbosity=2) -- cgit v1.2.3 From bf5805c52b7133ec76edeebac33f3c30b56b169f Mon Sep 17 00:00:00 2001 From: Lucas Christian Date: Thu, 8 Aug 2024 23:36:09 -0700 Subject: T6630: ntp: add hardware timestamp offload --- data/templates/chrony/chrony.conf.j2 | 11 ++++++ interface-definitions/service_ntp.xml.in | 60 +++++++++++++++++++++++++++++++ smoketest/scripts/cli/test_service_ntp.py | 30 ++++++++++++++++ 3 files changed, 101 insertions(+) (limited to 'smoketest/scripts/cli') diff --git a/data/templates/chrony/chrony.conf.j2 b/data/templates/chrony/chrony.conf.j2 index 86c20a4d8..838813866 100644 --- a/data/templates/chrony/chrony.conf.j2 +++ b/data/templates/chrony/chrony.conf.j2 @@ -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 %} diff --git a/interface-definitions/service_ntp.xml.in b/interface-definitions/service_ntp.xml.in index eca0ada63..005499abd 100644 --- a/interface-definitions/service_ntp.xml.in +++ b/interface-definitions/service_ntp.xml.in @@ -13,6 +13,66 @@ #include #include #include + + + Configurable offload options + + + + + Enable timestamping of packets in the NIC hardware + + + + + Enable timestamping on all supported interfaces + + + + + + Interface to enable timestamping on + + + + + txt + Interface name + + + #include + + + + + + Selects which inbound packets are timestamped by the NIC + + all ntp none + + + all + All received packets are timestamped + + + ntp + Only NTP packets are timestamped + + + none + No received packets are timestamped + + + (all|ntp|none) + + + + + + + + + Leap second behavior diff --git a/smoketest/scripts/cli/test_service_ntp.py b/smoketest/scripts/cli/test_service_ntp.py index fe6b1a529..644894914 100755 --- a/smoketest/scripts/cli/test_service_ntp.py +++ b/smoketest/scripts/cli/test_service_ntp.py @@ -194,5 +194,35 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): 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) -- cgit v1.2.3 From a5a6e57b3f7ba7d76bffcfb8dcb086d79f51202a Mon Sep 17 00:00:00 2001 From: Lucas Christian Date: Thu, 8 Aug 2024 23:39:00 -0700 Subject: T6630: ntp: add chrony "ntp over ptp" transport --- data/templates/chrony/chrony.conf.j2 | 7 ++++++- interface-definitions/service_ntp.xml.in | 20 ++++++++++++++++-- smoketest/scripts/cli/test_service_ntp.py | 34 +++++++++++++++++++++++++++++++ src/conf_mode/service_ntp.py | 9 ++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) (limited to 'smoketest/scripts/cli') 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 @@ Selects which inbound packets are timestamped by the NIC - all ntp none + all ntp ptp none all @@ -58,12 +58,16 @@ ntp Only NTP packets are timestamped + + ptp + Only PTP packets, or NTP packets using the PTP transport, are timestamped + none No received packets are timestamped - (all|ntp|none) + (all|ntp|ptp|none) @@ -73,6 +77,12 @@ + + + Enables the PTP transport for NTP packets + + + Leap second behavior @@ -146,6 +156,12 @@ + + + Use the PTP transport for the server + + + Use the interleaved mode for the server 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): -- cgit v1.2.3 From 90ab441a55b2ec769e7a6fea1dd57bef89b8857c Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Fri, 20 Sep 2024 08:45:31 +0200 Subject: T6630: ntp: rename ptp-transport to ptp and use defaultValue for port --- data/templates/chrony/chrony.conf.j2 | 6 +++--- interface-definitions/service_ntp.xml.in | 17 +++++++++++------ smoketest/scripts/cli/test_service_ntp.py | 11 +++++++---- src/conf_mode/service_ntp.py | 19 ++++++++++++++----- 4 files changed, 35 insertions(+), 18 deletions(-) (limited to 'smoketest/scripts/cli') diff --git a/data/templates/chrony/chrony.conf.j2 b/data/templates/chrony/chrony.conf.j2 index 1fc488d24..79fa5e3a0 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 }} {{- ' port 319' if config.ptp_transport 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 ' ~ ptp.port if ptp.port is vyos_defined and config.ptp is vyos_defined }} {% endfor %} {% endif %} @@ -78,7 +78,7 @@ hwtimestamp {{ interface }} {{- ' rxfilter ' ~ config.receive_filter if config.r hwtimestamp * {% endif %} -{% if ptp_transport is vyos_defined %} +{% if ptp.port is vyos_defined %} # Enable sending and receiving NTP over PTP packets (PTP transport) -ptpport 319 +ptpport {{ ptp.port }} {% endif %} diff --git a/interface-definitions/service_ntp.xml.in b/interface-definitions/service_ntp.xml.in index c4f3116ff..d6d3e0818 100644 --- a/interface-definitions/service_ntp.xml.in +++ b/interface-definitions/service_ntp.xml.in @@ -77,12 +77,17 @@ - + - Enables the PTP transport for NTP packets - + Enable Precision Time Protocol (PTP) transport - + + #include + + 319 + + + Leap second behavior @@ -156,9 +161,9 @@ - + - Use the PTP transport for the server + Use Precision Time Protocol (PTP) transport for the server diff --git a/smoketest/scripts/cli/test_service_ntp.py b/smoketest/scripts/cli/test_service_ntp.py index a39431c1b..02435bbfb 100755 --- a/smoketest/scripts/cli/test_service_ntp.py +++ b/smoketest/scripts/cli/test_service_ntp.py @@ -21,6 +21,7 @@ from base_vyostest_shim import VyOSUnitTestSHIM from vyos.configsession import ConfigSessionError from vyos.utils.process import cmd from vyos.utils.process import process_named_running +from vyos.xml_ref import default_value PROCESS_NAME = 'chronyd' NTP_CONF = '/run/chrony/chrony.conf' @@ -229,17 +230,19 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): servers = ['192.0.2.1', '192.0.2.2'] options = ['prefer'] + default_ptp_port = default_value(base_path + ['ptp', 'port']) + 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']) + self.cli_set(base_path + ['server', server, 'ptp']) # 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_set(base_path + ['ptp']) self.cli_commit() # Check generated configuration @@ -254,9 +257,9 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): self.assertIn('leapsectz right/UTC', config) for server in servers: - self.assertIn(f'server {server} iburst ' + ' '.join(options) + ' port 319', config) + self.assertIn(f'server {server} iburst ' + ' '.join(options) + f' port {default_ptp_port}', config) - self.assertIn('ptpport 319', config) + self.assertIn(f'ptpport {default_ptp_port}', 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 f7dbc3776..32563aa0e 100755 --- a/src/conf_mode/service_ntp.py +++ b/src/conf_mode/service_ntp.py @@ -17,6 +17,7 @@ import os from vyos.config import Config +from vyos.config import config_dict_merge from vyos.configdict import is_node_changed from vyos.configverify import verify_vrf from vyos.configverify import verify_interface_exists @@ -42,13 +43,21 @@ def get_config(config=None): if not conf.exists(base): return None - ntp = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True, with_defaults=True) + ntp = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True) ntp['config_file'] = config_file ntp['user'] = user_group tmp = is_node_changed(conf, base + ['vrf']) if tmp: ntp.update({'restart_required': {}}) + # We have gathered the dict representation of the CLI, but there are default + # options which we need to update into the dictionary retrived. + default_values = conf.get_config_defaults(**ntp.kwargs, recursive=True) + # Only defined PTP default port, if PTP feature is in use + if 'ptp' not in ntp: + del default_values['ptp'] + + ntp = config_dict_merge(default_values, ntp) return ntp def verify(ntp): @@ -89,10 +98,10 @@ def verify(ntp): 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}') + if 'ptp' in server: + if 'ptp' not in ntp: + raise ConfigError('PTP must be enabled for the NTP service '\ + f'before it can be used for server "{host}"') else: break -- cgit v1.2.3 From 917c658e37b619b1b2cd261ae43dd02f11eef720 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Fri, 20 Sep 2024 22:28:13 +0200 Subject: T6630: ntp: move interface timestamping configuration under ptp node --- data/templates/chrony/chrony.conf.j2 | 13 +++++------ interface-definitions/service_ntp.xml.in | 37 +++++++++++++------------------ smoketest/scripts/cli/test_service_ntp.py | 11 +++++---- 3 files changed, 26 insertions(+), 35 deletions(-) (limited to 'smoketest/scripts/cli') diff --git a/data/templates/chrony/chrony.conf.j2 b/data/templates/chrony/chrony.conf.j2 index 79fa5e3a0..2838f5524 100644 --- a/data/templates/chrony/chrony.conf.j2 +++ b/data/templates/chrony/chrony.conf.j2 @@ -67,16 +67,15 @@ binddevice {{ interface }} {% endif %} {% endif %} -{% if offload.timestamp.interface is vyos_defined %} +{% if ptp.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 }} +{% for iface, iface_config in ptp.timestamp.interface.items() %} +{% if iface == "all" %} +{% set iface = "*" %} +{% endif %} +hwtimestamp {{ iface }} {{- ' rxfilter ' ~ iface_config.receive_filter if iface_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 %} {% if ptp.port is vyos_defined %} # Enable sending and receiving NTP over PTP packets (PTP transport) diff --git a/interface-definitions/service_ntp.xml.in b/interface-definitions/service_ntp.xml.in index d6d3e0818..5dc0cd295 100644 --- a/interface-definitions/service_ntp.xml.in +++ b/interface-definitions/service_ntp.xml.in @@ -13,34 +13,38 @@ #include #include #include - + - Configurable offload options + Enable Precision Time Protocol (PTP) transport + #include + + 319 + Enable timestamping of packets in the NIC hardware - - - Enable timestamping on all supported interfaces - - - Interface to enable timestamping on + all + + all + Select all interfaces + txt Interface name #include + all @@ -52,7 +56,7 @@ all - All received packets are timestamped + All packets are timestamped ntp @@ -60,11 +64,11 @@ ptp - Only PTP packets, or NTP packets using the PTP transport, are timestamped + Only PTP or NTP packets using the PTP transport are timestamped none - No received packets are timestamped + No packet is timestamped (all|ntp|ptp|none) @@ -77,17 +81,6 @@ - - - Enable Precision Time Protocol (PTP) transport - - - #include - - 319 - - - Leap second behavior diff --git a/smoketest/scripts/cli/test_service_ntp.py b/smoketest/scripts/cli/test_service_ntp.py index 02435bbfb..07af4f5eb 100755 --- a/smoketest/scripts/cli/test_service_ntp.py +++ b/smoketest/scripts/cli/test_service_ntp.py @@ -171,7 +171,6 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): # name is not a 1:1 mapping from VyOS config servers = ['192.0.2.1', '192.0.2.2'] options = ['prefer'] - offload_interface = 'eth0' for server in servers: for option in options: @@ -198,13 +197,13 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): def test_offload_timestamp_default(self): # Test offloading of NIC timestamp servers = ['192.0.2.1', '192.0.2.2'] - options = ['prefer'] + ptp_port = '8319' for server in servers: - for option in options: - self.cli_set(base_path + ['server', server, option]) + self.cli_set(base_path + ['server', server, 'ptp']) - self.cli_set(base_path + ['offload', 'timestamp', 'default-enable']) + self.cli_set(base_path + ['ptp', 'port', ptp_port]) + self.cli_set(base_path + ['ptp', 'timestamp', 'interface', 'all']) # commit changes self.cli_commit() @@ -221,7 +220,7 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): self.assertIn('leapsectz right/UTC', config) for server in servers: - self.assertIn(f'server {server} iburst ' + ' '.join(options), config) + self.assertIn(f'server {server} iburst port {ptp_port}', config) self.assertIn('hwtimestamp *', config) -- cgit v1.2.3