Remove workarounds from ietf-routing-types related to MDSAL-269 99/13499/2
authorMarek Gradzki <[email protected]>
Tue, 17 Jul 2018 06:57:41 +0000 (08:57 +0200)
committerMarek Gradzki <[email protected]>
Tue, 17 Jul 2018 08:57:42 +0000 (10:57 +0200)
Change-Id: Iadd17a3a44a20711e58c272934fb15dfe89bf2be
Signed-off-by: Marek Gradzki <[email protected]>
12 files changed:
mpls/api/src/main/yang/[email protected]
mpls/api/src/main/yang/[email protected]
mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsInSegmentTranslator.java
mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLabelReader.java [new file with mode: 0644]
mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsSwapWriter.java
mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java
mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java
mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java
routing/routing-api/src/main/yang/[email protected] [moved from routing/routing-api/src/main/yang/[email protected] with 97% similarity]
srv6/srv6-api/src/main/yang/[email protected]

index 9da4bb9..17e9cb5 100755 (executable)
@@ -19,7 +19,7 @@ module hc2vpp-ietf-mpls-static {
     prefix "rt";
   }
 
-  import hc2vpp-ietf-routing-types {
+  import ietf-routing-types {
     prefix "rt-types";
   }
 
index 5ca6981..a4dd231 100644 (file)
@@ -16,7 +16,7 @@ module hc2vpp-ietf-mpls {
     prefix "if";
   }
 
-  import hc2vpp-ietf-routing-types {
+  import ietf-routing-types {
     prefix "rt-types";
   }
 
index 6a09b3e..3402f85 100644 (file)
@@ -50,7 +50,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  *
  * @see <a href="https://git.fd.io/vpp/tree/src/vnet/ip/ip.api">ip_add_del_route</a> definition
  */
-final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator, MplsLabelTranslator {
+final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator, MplsLabelReader, MplsLabelTranslator {
     private final FutureJVppCore vppApi;
     private final NamingContext interfaceContext;
 
@@ -119,7 +119,7 @@ final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator, MplsLab
 
         final MplsLabel outgoingLabel = path.getSimplePath().getConfig().getOutgoingLabel();
         checkArgument(outgoingLabel != null, "Configuring impose-and-forward, but outgoing-label is missing.");
-        request.nextHopOutLabelStack = new FibMplsLabel[] {translate(outgoingLabel.getValue())};
+        request.nextHopOutLabelStack = new FibMplsLabel[] {translate(getLabelValue(outgoingLabel))};
         request.nextHopNOutLabels = 1;
 
         return path.getSimplePath().getConfig().getOutgoingInterface();
@@ -145,8 +145,9 @@ final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator, MplsLab
         checkArgument(numberOfLabels > 0 && numberOfLabels < MAX_LABELS, "Number of labels (%s) not in range (0, %s].",
             numberOfLabels, MAX_LABELS, numberOfLabels);
         request.nextHopNOutLabels = (byte) numberOfLabels;
-        request.nextHopOutLabelStack = labels.stream().map(label -> translate(label.getConfig().getLabel().getValue()))
-                .toArray(FibMplsLabel[]::new);
+        request.nextHopOutLabelStack = labels.stream()
+            .map(label -> translate(getLabelValue(label.getConfig().getLabel())))
+            .toArray(FibMplsLabel[]::new);
 
         return paths.getPath().get(0).getConfig().getOutgoingInterface();
     }
index e15e50a..110d371 100644 (file)
@@ -27,12 +27,12 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._stati
 /**
  * Mixin that translates {@link InSegment} of {@link MplsLabel} type to {@link MplsRouteAddDel} message.
  */
-interface MplsInSegmentTranslator {
+interface MplsInSegmentTranslator extends MplsLabelReader {
+
     default void translate(@Nonnull final InSegment inSegment, @Nonnull final MplsRouteAddDel request) {
         checkArgument(inSegment != null, "Missing in-segment");
         final Type type = inSegment.getConfig().getType();
         checkArgument(type instanceof MplsLabel, "Expecting in-segment of type mpls-label, but %s given.", type);
-        final Long label = ((MplsLabel) type).getIncomingLabel().getValue();
-        request.mrLabel = label.intValue();
+        request.mrLabel = getLabelValue(((MplsLabel) type).getIncomingLabel());
     }
 }
diff --git a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLabelReader.java b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLabelReader.java
new file mode 100644 (file)
index 0000000..0644cc8
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.mpls;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.EntropyLabelIndicator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.ExtensionLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.GalLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.ImplicitNullLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Ipv4ExplicitNullLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Ipv6ExplicitNullLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabelSpecialPurposeValue;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.OamAlertLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.RouterAlertLabel;
+
+/**
+ * Mixin that reads integer value of {@link MplsLabel}.
+ */
+interface MplsLabelReader {
+
+    default int getLabelValue(final MplsLabel label) {
+        if (label.getMplsLabelGeneralUse() != null) {
+            return label.getMplsLabelGeneralUse().getValue().intValue();
+        } else if (label.getMplsLabelSpecialPurpose() != null ) {
+            final Class<? extends MplsLabelSpecialPurposeValue> specialLabel =
+                label.getMplsLabelSpecialPurpose();
+            // Encoding of labels 0-3
+            // https://tools.ietf.org/html/rfc3032#section-2.1
+            if (Ipv4ExplicitNullLabel.class.equals(specialLabel)) {
+                return 0;
+            } else if (RouterAlertLabel.class.equals(specialLabel)) {
+                return 1;
+            } else if (Ipv6ExplicitNullLabel.class.equals(specialLabel)) {
+                return 2;
+            } else if (ImplicitNullLabel.class.equals(specialLabel)) {
+                return 3;
+            } else if (EntropyLabelIndicator.class.equals(specialLabel)) {
+                // https://tools.ietf.org/html/rfc6790#section-3
+                return 7;
+            } else if (GalLabel.class.equals(specialLabel)) {
+                // https://tools.ietf.org/html/rfc5586#section-4
+                return 13;
+            } else if (OamAlertLabel.class.equals(specialLabel)) {
+                // https://tools.ietf.org/html/rfc3429#section-3
+                return 14;
+            } else if (ExtensionLabel.class.equals(specialLabel)) {
+                // https://tools.ietf.org/html/rfc7274#section-3.1
+                return 15;
+            } else {
+                throw new IllegalArgumentException("Unsupported special purpose MPLS label: " + specialLabel);
+            }
+        } else {
+            throw new IllegalArgumentException("Unsupported MPLS label: " + label);
+        }
+    }
+}
index c8b47b8..170cffd 100644 (file)
@@ -85,7 +85,7 @@ final class MplsSwapWriter implements LspWriter, Ipv4Translator, MplsInSegmentTr
 
         final MplsLabel outgoingLabel = path.getSimplePath().getConfig().getOutgoingLabel();
         checkArgument(outgoingLabel != null, "Configuring swap-and-forward, but outgoing-label is missing.");
-        request.mrNextHopOutLabelStack = new FibMplsLabel[] {translate(outgoingLabel.getValue())};
+        request.mrNextHopOutLabelStack = new FibMplsLabel[] {translate(getLabelValue(outgoingLabel))};
         request.mrNextHopNOutLabels = 1;
 
         final String outgoingInterface = path.getSimplePath().getConfig().getOutgoingInterface();
index 12312af..bcd888b 100644 (file)
@@ -54,6 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170702.routing.Mpls;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabelGeneralUse;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator, MplsLabelTranslator {
@@ -91,7 +92,7 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
                         new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702._static.lsp.paths.out.segment.simple.path.simple.path.ConfigBuilder()
                             .setNextHop(nextHop)
                             .setOutgoingInterface(IF_NAME)
-                            .setOutgoingLabel(new MplsLabel(label))
+                            .setOutgoingLabel(new MplsLabel(new MplsLabelGeneralUse(label)))
                             .build()).build())
                     .build())
             .build();
@@ -133,13 +134,13 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
                                         new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.path.outgoing.labels.outgoing.labels.OutgoingLabelsBuilder()
                                             .setIndex((short) 0)
                                             .setConfig(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.path.outgoing.labels.outgoing.labels.outgoing.labels.ConfigBuilder()
-                                                           .setLabel(new MplsLabel(102L))
+                                                           .setLabel(new MplsLabel(new MplsLabelGeneralUse(102L)))
                                                            .build())
                                             .build(),
                                         new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.path.outgoing.labels.outgoing.labels.OutgoingLabelsBuilder()
                                             .setIndex((short) 1)
                                             .setConfig(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.path.outgoing.labels.outgoing.labels.outgoing.labels.ConfigBuilder()
-                                                           .setLabel(new MplsLabel(104L))
+                                                           .setLabel(new MplsLabel(new MplsLabelGeneralUse(104L)))
                                                            .build())
                                             .build()))
                                     .build())
index 627c329..8ee6f1b 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170702.routing.Mpls;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabelGeneralUse;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.LookupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.StaticLspVppLookupAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.StaticLspVppLookupAugmentationBuilder;
@@ -76,9 +77,8 @@ public class PopAndIpv4LookupTest extends WriterCustomizerTest implements ByteDa
                     new InSegmentBuilder()
                         .setConfig(
                             new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.in.segment.in.segment.ConfigBuilder()
-                                .setType(new MplsLabelBuilder()
-                                             .setIncomingLabel(new MplsLabel((long) LOCAL_LABEL))
-                                             .build())
+                                .setType(new MplsLabelBuilder().setIncomingLabel(
+                                    new MplsLabel(new MplsLabelGeneralUse((long) LOCAL_LABEL))).build())
                                 .build())
 
                     .build()
index ab06910..1b347e2 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170702.routing.Mpls;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabelGeneralUse;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.LookupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.StaticLspVppLookupAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.StaticLspVppLookupAugmentationBuilder;
@@ -76,7 +77,7 @@ public class PopAndMplsLookupTest extends WriterCustomizerTest implements ByteDa
                     new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.in.segment.in.segment.ConfigBuilder()
                         .setType(
                             new MplsLabelBuilder()
-                                .setIncomingLabel(new MplsLabel((long) LOCAL_LABEL))
+                                .setIncomingLabel(new MplsLabel(new MplsLabelGeneralUse((long) LOCAL_LABEL)))
                                 .build())
                         .build())
                     .build()
index 677bb09..0ed0709 100644 (file)
@@ -46,6 +46,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170702.routing.Mpls;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.MplsLabelGeneralUse;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class SwapAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator, MplsLabelTranslator {
@@ -77,8 +78,9 @@ public class SwapAndForwardTest extends WriterCustomizerTest implements ByteData
                     new InSegmentBuilder()
                         .setConfig(
                             new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702.in.segment.in.segment.ConfigBuilder()
-                                .setType(new MplsLabelBuilder().setIncomingLabel(new MplsLabel((long) LOCAL_LABEL))
-                                             .build())
+                                .setType(new MplsLabelBuilder()
+                                    .setIncomingLabel(new MplsLabel(new MplsLabelGeneralUse((long) LOCAL_LABEL)))
+                                    .build())
                                 .build())
                     .build()
                 )
@@ -92,7 +94,7 @@ public class SwapAndForwardTest extends WriterCustomizerTest implements ByteData
                                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170702._static.lsp.paths.out.segment.simple.path.simple.path.ConfigBuilder()
                                     .setNextHop(IpAddressBuilder.getDefaultInstance("10.10.24.4"))
                                     .setOutgoingInterface(IF_NAME)
-                                    .setOutgoingLabel(new MplsLabel((long) OUT_LABEL))
+                                    .setOutgoingLabel(new MplsLabel(new MplsLabelGeneralUse((long) OUT_LABEL)))
                                     .build())
                             .build())
                     .build())
@@ -1,14 +1,8 @@
-module hc2vpp-ietf-routing-types {
+module ietf-routing-types {
 
   namespace "urn:ietf:params:xml:ns:yang:ietf-routing-types";
   prefix rt-types;
 
-  /*
-     This models was modified due to ODL bugs described here: https://jira.fd.io/browse/HC2VPP-298.
-     Affected sections are renamed or commented, see comments below.
-     TODO: revert these changes and rename model to ietf-routing-types once bugs are fixed.
-  */
-
   import ietf-yang-types {
     prefix yang;
   }
@@ -684,17 +678,10 @@ module hc2vpp-ietf-routing-types {
   }
 
   typedef mpls-label {
-    /*
-    TODO: binding generator creates invalid type bindings, so we changed type to uint32.
-    Change back after https://jira.opendaylight.org/browse/MDSAL-269 is resolved.
     type union {
       type mpls-label-special-purpose;
       type mpls-label-general-use;
     }
-    */
-    type uint32 {
-        range "0..1048575";
-    }
     description
       "The 20-bit label value in an MPLS label stack as specified
        in RFC 3032.  This label value does not include the
index 4d41b45..3a60767 100644 (file)
@@ -15,12 +15,10 @@ module hc2vpp-ietf-srv6-base {
     prefix "yang";
   }
 
-  // TODO: hc2vpp-298 - Renamed imports, because hc2vpp uses modified versions of these models.
-  import hc2vpp-ietf-routing-types {
+  import ietf-routing-types {
      prefix "rt-types";
   }
 
-
   // TODO: hc2vpp-298 - Renamed imports, because hc2vpp uses modified versions of these models.
   import hc2vpp-ietf-routing {
     prefix "rt";