From 0ddd684ff12b297313331a1c87f36d8308eade8d Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 22 Jan 2021 16:31:20 +0100 Subject: ospf: T3236: add default values --- interface-definitions/include/ospf-metric.xml.i | 6 +- interface-definitions/protocols-ospf.xml.in | 95 ++++++++++--------------- src/conf_mode/protocols_ospf.py | 25 +++++++ 3 files changed, 68 insertions(+), 58 deletions(-) mode change 100644 => 100755 src/conf_mode/protocols_ospf.py diff --git a/interface-definitions/include/ospf-metric.xml.i b/interface-definitions/include/ospf-metric.xml.i index 771fda02d..b2812ba36 100644 --- a/interface-definitions/include/ospf-metric.xml.i +++ b/interface-definitions/include/ospf-metric.xml.i @@ -13,15 +13,16 @@ - OSPF metric type for default routes + OSPF metric type for default routes (default: 2) u32:1-2 - Metric type for default routes (default 2) + Metric type for default routes + 2 @@ -31,3 +32,4 @@ + diff --git a/interface-definitions/protocols-ospf.xml.in b/interface-definitions/protocols-ospf.xml.in index 4d5b84be0..04ad39732 100644 --- a/interface-definitions/protocols-ospf.xml.in +++ b/interface-definitions/protocols-ospf.xml.in @@ -3,7 +3,7 @@ - + Open Shortest Path First protocol (OSPF) parameters 620 @@ -109,7 +109,7 @@ - Nssa-abr + Configure NSSA-ABR (default: candidate) always candidate never @@ -129,6 +129,7 @@ ^(always|candidate|never)$ + candidate @@ -353,7 +354,7 @@ - Calculate OSPF interface cost according to bandwidth + Calculate OSPF interface cost according to bandwidth (default: 100) @@ -361,12 +362,13 @@ Reference bandwidth method to assign OSPF cost u32:1-4294967 - Reference bandwidth cost in Mbits/sec (default 100) + Reference bandwidth cost in Mbits/sec + 100 @@ -386,38 +388,7 @@ - - - OSPF default metric - - u32:0-16777214 - Default metric - - - - - - - - - OSPF metric type for default routes - - u32:1-2 - Metric type for default routes (default 2) - - - - - - - - - Route map reference - - policy route-map - - - + #include @@ -589,27 +560,29 @@ - Dead neighbor polling interval + Dead neighbor polling interval (default: 60) u32:1-65535 - Seconds between dead neighbor polling interval (default 60) + Seconds between dead neighbor polling interval + 60 - Neighbor priority in seconds + Neighbor priority in seconds (default: 0) u32:0-255 - Neighbor priority (default 0) + Neighbor priority + 0 @@ -620,7 +593,7 @@ - OSPF ABR type + OSPF ABR type (default: cisco) cisco ibm shortcut standard @@ -644,6 +617,7 @@ ^(cisco|ibm|shortcut|standard)$ + cisco @@ -674,31 +648,37 @@ Suppress routing updates on an interface + + default + + - <interface> + txt Interface to be passive (i.e. suppress routing updates) default Default to suppress routing updates on all interfaces - - default - - + + ^(br|bond|dum|en|eth|gnv|peth|tun|vti|vxlan|wg|wlan)[0-9]+|lo|default$ + Interface to exclude when using 'passive-interface default' - - <interface> - Interface to be passive (i.e. suppress routing updates) - + + txt + Interface to be passive (i.e. suppress routing updates) + + + ^(br|bond|dum|en|eth|gnv|peth|tun|vti|vxlan|wg|wlan)[0-9]+|lo$ + @@ -793,39 +773,42 @@ - Delay (msec) from first change received till SPF calculation + Delay from first change received till SPF calculation (default: 200) u32:0-600000 - Delay in msec (default 200) + Delay in milliseconds + 200 - Initial hold time(msec) between consecutive SPF calculations + Initial hold time between consecutive SPF calculations (default: 1000) u32:0-600000 - Initial hold time in msec (default 1000) + Initial hold time in milliseconds + 1000 - Maximum hold time (msec) + Maximum hold time (default: 10000) u32:0-600000 - Max hold time in msec (default 10000) + Max hold time in milliseconds + 10000 diff --git a/src/conf_mode/protocols_ospf.py b/src/conf_mode/protocols_ospf.py old mode 100644 new mode 100755 index 73c244571..fc66a884c --- a/src/conf_mode/protocols_ospf.py +++ b/src/conf_mode/protocols_ospf.py @@ -24,6 +24,7 @@ from vyos.template import render from vyos.template import render_to_string from vyos.util import call from vyos.util import dict_search +from vyos.xml import defaults from vyos import ConfigError from vyos import frr from vyos import airbag @@ -43,6 +44,30 @@ def get_config(): conf = Config() base = ['protocols', 'ospf'] ospf = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True) + + # Bail out early if configuration tree does not exist + if not conf.exists(base): + return ospf + + # 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 = defaults(base) + + # We have to cleanup the default dict, as default values could enable features + # which are not explicitly enabled on the CLI. Example: default-information + # originate comes with a default metric-type of 2, which will enable the + # entire default-information originate tree, even when not set via CLI so we + # need to check this first and probably drop that key. + if dict_search('default_information.originate', ospf) is None: + del default_values['default_information'] + if dict_search('area.area_type.nssa', ospf) is None: + del default_values['area']['area_type']['nssa'] + for protocol in ['bgp', 'connected', 'kernel', 'rip', 'static']: + if dict_search(f'redistribute.{protocol}', ospf) is None: + del default_values['redistribute'][protocol] + + ospf = dict_merge(default_values, ospf) + return ospf def verify(ospf): -- cgit v1.2.3