From 08c2a057917c357ccf6fac7b51e05d5dae780fc3 Mon Sep 17 00:00:00 2001
From: Cheeze_It <none@none.com>
Date: Fri, 7 Oct 2022 21:27:47 -0700
Subject: isis: T4739: ISIS segment routing being refactored

This is to refactor ISIS segment routing to match up with OSPF segment routing.
---
 data/templates/frr/isisd.frr.j2                    |  4 +-
 .../include/isis/high-low-label-value.xml.i        |  2 +-
 .../include/isis/protocol-common-config.xml.i      |  6 ---
 .../include/ospf/high-low-label-value.xml.i        |  6 +--
 .../include/version/isis-version.xml.i             |  2 +-
 smoketest/scripts/cli/test_protocols_isis.py       |  9 ++---
 src/migration-scripts/isis/1-to-2                  | 46 ++++++++++++++++++++++
 7 files changed, 56 insertions(+), 19 deletions(-)
 create mode 100755 src/migration-scripts/isis/1-to-2

diff --git a/data/templates/frr/isisd.frr.j2 b/data/templates/frr/isisd.frr.j2
index e0f3b393e..194dbcb07 100644
--- a/data/templates/frr/isisd.frr.j2
+++ b/data/templates/frr/isisd.frr.j2
@@ -107,9 +107,6 @@ router isis VyOS {{ 'vrf ' + vrf if vrf is vyos_defined }}
  mpls-te inter-as{{ level }}
 {% endif %}
 {% if segment_routing is vyos_defined %}
-{%     if segment_routing.enable is vyos_defined %}
- segment-routing on
-{%     endif %}
 {%     if segment_routing.maximum_label_depth is vyos_defined %}
  segment-routing node-msd {{ segment_routing.maximum_label_depth }}
 {%     endif %}
@@ -144,6 +141,7 @@ router isis VyOS {{ 'vrf ' + vrf if vrf is vyos_defined }}
 {%             endif %}
 {%         endfor %}
 {%     endif %}
+ segment-routing on
 {% endif %}
 {% if spf_delay_ietf.init_delay is vyos_defined %}
  spf-delay-ietf init-delay {{ spf_delay_ietf.init_delay }} short-delay {{ spf_delay_ietf.short_delay }} long-delay {{ spf_delay_ietf.long_delay }} holddown {{ spf_delay_ietf.holddown }} time-to-learn {{ spf_delay_ietf.time_to_learn }}
diff --git a/interface-definitions/include/isis/high-low-label-value.xml.i b/interface-definitions/include/isis/high-low-label-value.xml.i
index adc28417d..7026b03dd 100644
--- a/interface-definitions/include/isis/high-low-label-value.xml.i
+++ b/interface-definitions/include/isis/high-low-label-value.xml.i
@@ -4,7 +4,7 @@
     <help>MPLS label lower bound</help>
     <valueHelp>
       <format>u32:16-1048575</format>
-      <description>Label value</description>
+      <description>Label value - Suggested minimum value: 100</description>
     </valueHelp>
     <constraint>
       <validator name="numeric" argument="--range 16-1048575"/>
diff --git a/interface-definitions/include/isis/protocol-common-config.xml.i b/interface-definitions/include/isis/protocol-common-config.xml.i
index 75a0355d4..57ee19300 100644
--- a/interface-definitions/include/isis/protocol-common-config.xml.i
+++ b/interface-definitions/include/isis/protocol-common-config.xml.i
@@ -233,12 +233,6 @@
     <help>Segment-Routing (SPRING) settings</help>
   </properties>
   <children>
-    <leafNode name="enable">
-      <properties>
-        <help>Enable segment-routing functionality</help>
-        <valueless/>
-      </properties>
-    </leafNode>
     <node name="global-block">
       <properties>
         <help>Segment Routing Global Block label range</help>
diff --git a/interface-definitions/include/ospf/high-low-label-value.xml.i b/interface-definitions/include/ospf/high-low-label-value.xml.i
index 4b6779922..9e2ef6efb 100644
--- a/interface-definitions/include/ospf/high-low-label-value.xml.i
+++ b/interface-definitions/include/ospf/high-low-label-value.xml.i
@@ -3,8 +3,8 @@
   <properties>
     <help>MPLS label lower bound</help>
     <valueHelp>
-      <format>u32:100-1048575</format>
-      <description>Label value</description>
+      <format>u32:16-1048575</format>
+      <description>Label value - Suggested minimum value: 100</description>
     </valueHelp>
     <constraint>
       <validator name="numeric" argument="--range 16-1048575"/>
@@ -15,7 +15,7 @@
   <properties>
     <help>MPLS label upper bound</help>
     <valueHelp>
-      <format>u32:100-1048575</format>
+      <format>u32:16-1048575</format>
       <description>Label value</description>
     </valueHelp>
     <constraint>
diff --git a/interface-definitions/include/version/isis-version.xml.i b/interface-definitions/include/version/isis-version.xml.i
index 4a8fef39c..7bf12e81a 100644
--- a/interface-definitions/include/version/isis-version.xml.i
+++ b/interface-definitions/include/version/isis-version.xml.i
@@ -1,3 +1,3 @@
 <!-- include start from include/version/isis-version.xml.i -->
-<syntaxVersion component='isis' version='1'></syntaxVersion>
+<syntaxVersion component='isis' version='2'></syntaxVersion>
 <!-- include end -->
diff --git a/smoketest/scripts/cli/test_protocols_isis.py b/smoketest/scripts/cli/test_protocols_isis.py
index e4bb9e1f8..c26028253 100755
--- a/smoketest/scripts/cli/test_protocols_isis.py
+++ b/smoketest/scripts/cli/test_protocols_isis.py
@@ -263,10 +263,10 @@ class TestProtocolsISIS(VyOSUnitTestSHIM.TestCase):
             self.assertIn(f' isis bfd profile {bfd_profile}', tmp)
 
     def test_isis_07_segment_routing_configuration(self):
-        global_block_low = "1000"
-        global_block_high = "1999"
-        local_block_low = "2000"
-        local_block_high = "2999"
+        global_block_low = "100"
+        global_block_high = "199"
+        local_block_low = "200"
+        local_block_high = "299"
         interface = 'lo'
         maximum_stack_size = '5'
         prefix_one = '192.168.0.1/32'
@@ -280,7 +280,6 @@ class TestProtocolsISIS(VyOSUnitTestSHIM.TestCase):
 
         self.cli_set(base_path + ['net', net])
         self.cli_set(base_path + ['interface', interface])
-        self.cli_set(base_path + ['segment-routing', 'enable'])
         self.cli_set(base_path + ['segment-routing', 'maximum-label-depth', maximum_stack_size])
         self.cli_set(base_path + ['segment-routing', 'global-block', 'low-label-value', global_block_low])
         self.cli_set(base_path + ['segment-routing', 'global-block', 'high-label-value', global_block_high])
diff --git a/src/migration-scripts/isis/1-to-2 b/src/migration-scripts/isis/1-to-2
new file mode 100755
index 000000000..f914ea995
--- /dev/null
+++ b/src/migration-scripts/isis/1-to-2
@@ -0,0 +1,46 @@
+#!/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/>.
+
+# T4739 refactor, and remove "on" from segment routing from the configuration
+
+from sys import argv
+from sys import exit
+
+from vyos.configtree import ConfigTree
+
+if (len(argv) < 1):
+    print("Must specify file name!")
+    exit(1)
+
+file_name = argv[1]
+
+with open(file_name, 'r') as f:
+    config_file = f.read()
+
+config = ConfigTree(config_file)
+
+# Check if ISIS segment routing is configured. Then check if segment routing "on" exists, then delete the "on" as it is no longer needed. This is for global configuration.
+if config.exists(['protocols', 'isis']):
+    if config.exists(['protocols', 'isis', 'segment-routing']):
+        if config.exists(['protocols', 'isis', 'segment-routing', 'enable']):
+            config.delete(['protocols', 'isis', 'segment-routing', 'enable'])
+
+try:
+    with open(file_name, 'w') as f:
+        f.write(config.to_string())
+except OSError as e:
+    print(f'Failed to save the modified config: {e}')
+    exit(1)
-- 
cgit v1.2.3