diff --git a/data/templates/frr/eigrpd.frr.j2 b/data/templates/frr/eigrpd.frr.j2 index 3038a0b1d..d16963a51 100644 --- a/data/templates/frr/eigrpd.frr.j2 +++ b/data/templates/frr/eigrpd.frr.j2 @@ -1,21 +1,31 @@ ! -router eigrp {{ local_as }} {{ 'vrf ' ~ vrf if vrf is vyos_defined }} +router eigrp {{ system_as }} {{ 'vrf ' ~ vrf if vrf is vyos_defined }} {% if maximum_paths is vyos_defined %} -maximum-paths {{ maximum_paths }} + maximum-paths {{ maximum_paths }} {% endif %} {% if metric.weights is vyos_defined %} -metric weights {{ metric.weights }} + metric weights {{ metric.weights }} {% endif %} {% if network is vyos_defined %} {% for net in network %} -network {{ net }} + network {{ net }} +{% endfor %} +{% endif %} +{% if passive_interface is vyos_defined %} +{% for interface in passive_interface %} + passive-interface {{ interface }} {% endfor %} {% endif %} {% if redistribute is vyos_defined %} {% for protocol in redistribute %} -redistribute {{ protocol }} + redistribute {{ protocol }} {% endfor %} {% endif %} +{% if router_id is vyos_defined %} + eigrp router-id {{ router_id }} +{% endif %} {% if variance is vyos_defined %} -variance {{ variance }} -{% endif %} \ No newline at end of file + variance {{ variance }} +{% endif %} +exit +! diff --git a/interface-definitions/include/eigrp/protocol-common-config.xml.i b/interface-definitions/include/eigrp/protocol-common-config.xml.i index a21d18424..a8290f772 100644 --- a/interface-definitions/include/eigrp/protocol-common-config.xml.i +++ b/interface-definitions/include/eigrp/protocol-common-config.xml.i @@ -1,124 +1,125 @@ <!-- include start from eigrp/protocol-common-config.xml.i --> -<leafNode name="local-as"> +<leafNode name="system-as"> <properties> <help>Autonomous System Number (ASN)</help> <valueHelp> <format>u32:1-65535</format> <description>Autonomous System Number</description> </valueHelp> <constraint> <validator name="numeric" argument="--range 1-65535"/> </constraint> </properties> </leafNode> <leafNode name="maximum-paths"> <properties> <help>Forward packets over multiple paths</help> <valueHelp> <format>u32:1-32</format> <description>Number of paths</description> </valueHelp> <constraint> <validator name="numeric" argument="--range 1-32"/> </constraint> </properties> </leafNode> <node name="metric"> <properties> <help>Modify metrics and parameters for advertisement</help> </properties> <children> <leafNode name="weights"> <properties> <help>Modify metric coefficients</help> <valueHelp> <format>u32:0-255</format> <description>K1</description> </valueHelp> <constraint> <validator name="numeric" argument="--range 0-255"/> </constraint> </properties> </leafNode> </children> </node> <leafNode name="network"> <properties> <help>Enable routing on an IP network</help> <valueHelp> <format>ipv4net</format> <description>EIGRP network prefix</description> </valueHelp> <constraint> <validator name="ip-prefix"/> </constraint> <multi/> </properties> </leafNode> <leafNode name="passive-interface"> <properties> <help>Suppress routing updates on an interface</help> <completionHelp> <script>${vyos_completion_dir}/list_interfaces</script> </completionHelp> + <multi/> </properties> </leafNode> <leafNode name="redistribute"> <properties> <help>Redistribute information from another routing protocol</help> <valueHelp> <format>bgp</format> <description>Border Gateway Protocol (BGP)</description> </valueHelp> <valueHelp> <format>connected</format> <description>Connected routes</description> </valueHelp> <valueHelp> <format>nhrp</format> <description>Next Hop Resolution Protocol (NHRP)</description> </valueHelp> <valueHelp> <format>ospf</format> <description>Open Shortest Path First (OSPFv2)</description> </valueHelp> <valueHelp> <format>rip</format> <description>Routing Information Protocol (RIP)</description> </valueHelp> <valueHelp> <format>babel</format> <description>Babel routing protocol (Babel)</description> </valueHelp> <valueHelp> <format>static</format> <description>Statically configured routes</description> </valueHelp> <valueHelp> <format>vnc</format> <description>Virtual Network Control (VNC)</description> </valueHelp> <completionHelp> <list>bgp connected nhrp ospf rip static vnc</list> </completionHelp> <constraint> <regex>(bgp|connected|nhrp|ospf|rip|babel|static|vnc)</regex> </constraint> <multi/> </properties> </leafNode> #include <include/router-id.xml.i> -<!-- FRR timers not implemented yet --> +<!-- FRR error: active time not implemented yet --> <leafNode name="variance"> <properties> <help>Control load balancing variance</help> <valueHelp> <format>u32:1-128</format> <description>Metric variance multiplier</description> </valueHelp> <constraint> <validator name="numeric" argument="--range 1-128"/> </constraint> </properties> </leafNode> <!-- include end --> diff --git a/smoketest/scripts/cli/test_protocols_eigrp.py b/smoketest/scripts/cli/test_protocols_eigrp.py new file mode 100644 index 000000000..9ab908d25 --- /dev/null +++ b/smoketest/scripts/cli/test_protocols_eigrp.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2024 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import unittest + +from base_vyostest_shim import VyOSUnitTestSHIM +from vyos.configsession import ConfigSessionError +from vyos.ifconfig import Section +from vyos.utils.process import process_named_running + +PROCESS_NAME = 'eigrpd' +base_path = ['protocols', 'eigrp'] +system_as = '200' + +class TestProtocolsEIGRP(VyOSUnitTestSHIM.TestCase): + @classmethod + def setUpClass(cls): + super(TestProtocolsEIGRP, cls).setUpClass() + + # Retrieve FRR daemon PID - it is not allowed to crash, thus PID must remain the same + cls.daemon_pid = process_named_running(PROCESS_NAME) + + # ensure we can also run this test on a live system - so lets clean + # out the current configuration :) + cls.cli_delete(cls, base_path) + + def tearDown(self): + self.cli_delete(base_path) + self.cli_commit() + + # check process health and continuity + self.assertEqual(self.daemon_pid, process_named_running(PROCESS_NAME)) + + def test_basic(self): + router_id = '5.6.7.8' + + self.cli_set(base_path + ['router-id', router_id]) + + # system-as must be set + with self.assertRaises(ConfigSessionError): + self.cli_commit() + self.cli_set(base_path + ['system-as', system_as]) + + # Commit changes + self.cli_commit() + + # Validate configuration + frrconfig = self.getFRRconfig(f'router eigrp {system_as}', daemon=PROCESS_NAME) + self.assertIn(f'router eigrp {system_as}', frrconfig) + self.assertIn(f' router-id {router_id}', frrconfig) + +if __name__ == '__main__': + unittest.main(verbosity=2, failfast=True) diff --git a/src/conf_mode/protocols_eigrp.py b/src/conf_mode/protocols_eigrp.py index 609b39065..c13e52a3d 100755 --- a/src/conf_mode/protocols_eigrp.py +++ b/src/conf_mode/protocols_eigrp.py @@ -1,111 +1,119 @@ #!/usr/bin/env python3 # # Copyright (C) 2022 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from sys import exit from sys import argv from vyos.config import Config from vyos.configdict import dict_merge +from vyos.configverify import verify_vrf from vyos.template import render_to_string from vyos import ConfigError from vyos import frr from vyos import airbag airbag.enable() def get_config(config=None): if config: conf = config else: conf = Config() vrf = None if len(argv) > 1: vrf = argv[1] base_path = ['protocols', 'eigrp'] # eqivalent of the C foo ? 'a' : 'b' statement base = vrf and ['vrf', 'name', vrf, 'protocols', 'eigrp'] or base_path eigrp = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True, no_tag_node_value_mangle=True) # Assign the name of our VRF context. This MUST be done before the return # statement below, else on deletion we will delete the default instance # instead of the VRF instance. if vrf: eigrp.update({'vrf' : vrf}) if not conf.exists(base): eigrp.update({'deleted' : ''}) if not vrf: # We are running in the default VRF context, thus we can not delete # our main EIGRP instance if there are dependent EIGRP VRF instances. eigrp['dependent_vrfs'] = conf.get_config_dict(['vrf', 'name'], key_mangling=('-', '_'), get_first_key=True, no_tag_node_value_mangle=True) return eigrp # We also need some additional information from the config, prefix-lists # and route-maps for instance. They will be used in verify(). # # XXX: one MUST always call this without the key_mangling() option! See # vyos.configverify.verify_common_route_maps() for more information. tmp = conf.get_config_dict(['policy']) # Merge policy dict into "regular" config dict eigrp = dict_merge(tmp, eigrp) return eigrp def verify(eigrp): - pass + if not eigrp or 'deleted' in eigrp: + return + + if 'system_as' not in eigrp: + raise ConfigError('EIGRP system-as must be defined!') + + if 'vrf' in eigrp: + verify_vrf(eigrp) def generate(eigrp): if not eigrp or 'deleted' in eigrp: return None eigrp['frr_eigrpd_config'] = render_to_string('frr/eigrpd.frr.j2', eigrp) def apply(eigrp): eigrp_daemon = 'eigrpd' # Save original configuration prior to starting any commit actions frr_cfg = frr.FRRConfig() # Generate empty helper string which can be ammended to FRR commands, it # will be either empty (default VRF) or contain the "vrf <name" statement vrf = '' if 'vrf' in eigrp: vrf = ' vrf ' + eigrp['vrf'] frr_cfg.load_configuration(eigrp_daemon) frr_cfg.modify_section(f'^router eigrp \d+{vrf}', stop_pattern='^exit', remove_stop_mark=True) if 'frr_eigrpd_config' in eigrp: frr_cfg.add_before(frr.default_add_before, eigrp['frr_eigrpd_config']) frr_cfg.commit_configuration(eigrp_daemon) return None if __name__ == '__main__': try: c = get_config() verify(c) generate(c) apply(c) except ConfigError as e: print(e) exit(1)