summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/IpRouteRequestProducer.java4
-rw-r--r--bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/MplsRouteRequestProducer.java6
-rw-r--r--bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java9
-rw-r--r--mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java9
-rw-r--r--mpls/impl/src/main/java/io/fd/hc2vpp/mpls/Ipv4LookupWriter.java3
-rw-r--r--mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLookupWriter.java3
-rw-r--r--mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsSwapWriter.java6
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java8
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java3
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java3
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java6
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslator.java56
-rw-r--r--vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslatorTest.java40
13 files changed, 137 insertions, 19 deletions
diff --git a/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/IpRouteRequestProducer.java b/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/IpRouteRequestProducer.java
index 4093a040b..865993d5e 100644
--- a/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/IpRouteRequestProducer.java
+++ b/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/IpRouteRequestProducer.java
@@ -20,7 +20,9 @@ import static com.google.common.base.Preconditions.checkArgument;
import static io.fd.hc2vpp.bgp.prefix.sid.MplsRouteRequestProducer.MPLS_LABEL_INVALID;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
@@ -102,7 +104,7 @@ interface IpRouteRequestProducer {
// TODO(HC2VPP-271): add support for special labels, e.g. implicit null (for PHP).
// Push label received via BGP on packets destined to the prefix it was assigned to:
- request.nextHopOutLabelStack = new int[] {label};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {MplsLabelTranslator.INSTANCE.translate(label)};
request.nextHopNOutLabels = 1;
}
}
diff --git a/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/MplsRouteRequestProducer.java b/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/MplsRouteRequestProducer.java
index 659cb991f..83a07a993 100644
--- a/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/MplsRouteRequestProducer.java
+++ b/bgp/bgp-prefix-sid/src/main/java/io/fd/hc2vpp/bgp/prefix/sid/MplsRouteRequestProducer.java
@@ -19,7 +19,9 @@ package io.fd.hc2vpp.bgp.prefix.sid;
import static com.google.common.base.Preconditions.checkArgument;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
@@ -63,7 +65,7 @@ interface MplsRouteRequestProducer extends Ipv4Translator {
return request;
}
- final class Impl implements Ipv4Translator {
+ final class Impl implements Ipv4Translator, MplsLabelTranslator {
private static MplsRouteAddDel mplsRouteAddDel(final boolean isAdd) {
final MplsRouteAddDel request = new MplsRouteAddDel();
request.mrIsAdd = Ipv4Translator.INSTANCE.booleanToByte(isAdd);
@@ -145,7 +147,7 @@ interface MplsRouteRequestProducer extends Ipv4Translator {
// TODO(HC2VPP-271): add support for special labels, e.g. implicit null (for PHP).
// swap one label to another
- request.mrNextHopOutLabelStack = new int[] {label};
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {MplsLabelTranslator.INSTANCE.translate(label)};
request.mrNextHopNOutLabels = 1;
}
}
diff --git a/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java b/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java
index 93b6ac66c..aefd74af2 100644
--- a/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java
+++ b/bgp/bgp-prefix-sid/src/test/java/io/fd/hc2vpp/bgp/prefix/sid/BgpPrefixSidMplsWriterTest.java
@@ -35,6 +35,7 @@ import io.fd.vpp.jvpp.core.dto.IpAddDelRouteReply;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
@@ -189,7 +190,9 @@ public class BgpPrefixSidMplsWriterTest implements FutureProducer, ByteDataTrans
request.mrLabel = 16102;
- request.mrNextHopOutLabelStack = new int[] {16101};
+ final FibMplsLabel mplsLabel = new FibMplsLabel();
+ mplsLabel.label = 16101;
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {mplsLabel};
request.mrNextHopNOutLabels = 1;
request.mrEos = booleanToByte(isEos);
@@ -209,7 +212,9 @@ public class BgpPrefixSidMplsWriterTest implements FutureProducer, ByteDataTrans
request.nextHopAddress = new byte[] {5, 6, 7, 8};
request.nextHopSwIfIndex = -1;
- request.nextHopOutLabelStack = new int[] {16101};
+ final FibMplsLabel mplsLabel = new FibMplsLabel();
+ mplsLabel.label = 16101;
+ request.nextHopOutLabelStack = new FibMplsLabel[] {mplsLabel};
request.nextHopNOutLabels = 1;
return request;
}
diff --git a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
index 861ab9ddf..40efd75d6 100644
--- a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
+++ b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/ImposeAndForwardWriter.java
@@ -19,11 +19,13 @@ package io.fd.hc2vpp.mpls;
import static com.google.common.base.Preconditions.checkArgument;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -47,7 +49,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 {
+final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator, MplsLabelTranslator {
private final FutureJVppCore vppApi;
private final NamingContext interfaceContext;
@@ -115,7 +117,7 @@ final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator {
final MplsLabel outgoingLabel = path.getOutgoingLabel();
checkArgument(outgoingLabel != null, "Configuring impose-and-forward, but outgoing-label is missing.");
- request.nextHopOutLabelStack = new int[] {outgoingLabel.getValue().intValue()};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {translate(outgoingLabel.getValue())};
request.nextHopNOutLabels = 1;
return path.getOutgoingInterface();
@@ -140,7 +142,8 @@ final class ImposeAndForwardWriter implements LspWriter, Ipv4Translator {
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().mapToInt(label -> label.getValue().intValue()).toArray();
+ request.nextHopOutLabelStack =
+ labels.stream().map(label -> translate(label.getValue())).toArray(FibMplsLabel[]::new);
return paths.getOutgoingInterface();
}
diff --git a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/Ipv4LookupWriter.java b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/Ipv4LookupWriter.java
index 94862c52b..be26166d3 100644
--- a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/Ipv4LookupWriter.java
+++ b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/Ipv4LookupWriter.java
@@ -22,6 +22,7 @@ import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.StaticLspConfig;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp.Config;
@@ -61,7 +62,7 @@ final class Ipv4LookupWriter implements LspWriter, MplsInSegmentTranslator {
request.mrNextHopProto = IPV4_PROTOCOL;
request.mrNextHopWeight = 1;
request.mrNextHop = new byte[0]; // no next hop since we POP
- request.mrNextHopOutLabelStack = new int[0]; // no new labels
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0]; // no new labels
request.mrNextHopSwIfIndex = -1;
request.mrNextHopViaLabel = MPLS_LABEL_INVALID;
diff --git a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLookupWriter.java b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLookupWriter.java
index d5d4872dc..86e7bdee1 100644
--- a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLookupWriter.java
+++ b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsLookupWriter.java
@@ -22,6 +22,7 @@ import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.StaticLspConfig;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp.Config;
@@ -61,7 +62,7 @@ final class MplsLookupWriter implements LspWriter, MplsInSegmentTranslator {
request.mrNextHopProto = MPLS_PROTOCOL;
request.mrNextHopWeight = 1;
request.mrNextHop = new byte[0]; // no next hop since we POP
- request.mrNextHopOutLabelStack = new int[0]; // no new labels
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0]; // no new labels
request.mrNextHopSwIfIndex = -1;
request.mrNextHopViaLabel = MPLS_LABEL_INVALID;
diff --git a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsSwapWriter.java b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsSwapWriter.java
index 8d834fe7c..28aba7aa8 100644
--- a/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsSwapWriter.java
+++ b/mpls/impl/src/main/java/io/fd/hc2vpp/mpls/MplsSwapWriter.java
@@ -19,11 +19,13 @@ package io.fd.hc2vpp.mpls;
import static com.google.common.base.Preconditions.checkArgument;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
@@ -40,7 +42,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
*
* @see <a href="https://git.fd.io/vpp/tree/src/vnet/mpls/mpls.api">mpls_route_add_del</a> definition
*/
-final class MplsSwapWriter implements LspWriter, Ipv4Translator, MplsInSegmentTranslator {
+final class MplsSwapWriter implements LspWriter, Ipv4Translator, MplsInSegmentTranslator, MplsLabelTranslator {
private final FutureJVppCore vppApi;
private final NamingContext interfaceContext;
@@ -83,7 +85,7 @@ final class MplsSwapWriter implements LspWriter, Ipv4Translator, MplsInSegmentTr
final MplsLabel outgoingLabel = path.getOutgoingLabel();
checkArgument(outgoingLabel != null, "Configuring swap-and-forward, but outgoing-label is missing.");
- request.mrNextHopOutLabelStack = new int[] {outgoingLabel.getValue().intValue()};
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {translate(outgoingLabel.getValue())};
request.mrNextHopNOutLabels = 1;
final String outgoingInterface = path.getOutgoingInterface();
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
index c1ced8e1d..6eb559da8 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
@@ -23,11 +23,13 @@ import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
import io.fd.vpp.jvpp.core.dto.IpAddDelRouteReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
@@ -52,7 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator, MplsLabelTranslator {
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
@@ -180,7 +182,7 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
request.nextHopAddress = nextHop;
request.nextHopNOutLabels = 1;
request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
- request.nextHopOutLabelStack = new int[] {label};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {translate(label)};
return request;
}
@@ -194,7 +196,7 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
request.nextHopAddress = new byte[] {10, 10, 12, 2};
request.nextHopNOutLabels = 2;
request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
- request.nextHopOutLabelStack = new int[] {102, 104};
+ request.nextHopOutLabelStack = new FibMplsLabel[] {translate(102), translate(104)};
return request;
}
}
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java
index e924cfaaf..61e1c6d58 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java
@@ -27,6 +27,7 @@ import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.Mpls1;
@@ -119,7 +120,7 @@ public class PopAndIpv4LookupTest extends WriterCustomizerTest implements ByteDa
request.mrNextHop = new byte[0]; // POP, so no next hop
request.mrNextHopSwIfIndex = -1; // this is what CLI is doing
request.mrNextHopViaLabel = LspWriter.MPLS_LABEL_INVALID; // default value used by make test
- request.mrNextHopOutLabelStack = new int[0];
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0];
return request;
}
}
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java
index de32a1907..f5a76974a 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java
@@ -27,6 +27,7 @@ import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.Mpls1;
@@ -119,7 +120,7 @@ public class PopAndMplsLookupTest extends WriterCustomizerTest implements ByteDa
request.mrNextHop = new byte[0]; // POP, so no next hop
request.mrNextHopSwIfIndex = -1; // this is what CLI is doing
request.mrNextHopViaLabel = LspWriter.MPLS_LABEL_INVALID; // default value used by make test
- request.mrNextHopOutLabelStack = new int[0];
+ request.mrNextHopOutLabelStack = new FibMplsLabel[0];
return request;
}
}
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java
index 6fd9e02f5..5b0e124f0 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java
@@ -22,11 +22,13 @@ import static org.mockito.Mockito.when;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.MplsLabelTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDel;
import io.fd.vpp.jvpp.core.dto.MplsRouteAddDelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
@@ -46,7 +48,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class SwapAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class SwapAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator, MplsLabelTranslator {
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
@@ -117,7 +119,7 @@ public class SwapAndForwardTest extends WriterCustomizerTest implements ByteData
request.mrNextHopSwIfIndex = IF_INDEX;
request.mrNextHopViaLabel = LspWriter.MPLS_LABEL_INVALID; // default value used by make test
request.mrNextHopNOutLabels = 1;
- request.mrNextHopOutLabelStack = new int[] {OUT_LABEL};
+ request.mrNextHopOutLabelStack = new FibMplsLabel[] {translate(OUT_LABEL)};
return request;
}
}
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslator.java
new file mode 100644
index 000000000..00653738d
--- /dev/null
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslator.java
@@ -0,0 +1,56 @@
+/*
+ * 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.common.translate.util;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
+import javax.annotation.Nonnull;
+
+/**
+ * Utility for Translating between different representations of MPLS label.
+ */
+public interface MplsLabelTranslator {
+ /**
+ * Make available also from static context.
+ */
+ MplsLabelTranslator INSTANCE = new MplsLabelTranslator() {
+ };
+
+ /**
+ * Builds {@link FibMplsLabel} from its YANG representation.
+ *
+ * @param label YANG representation of MPLS Label
+ * @return VPP representation of MPLS label
+ */
+ default FibMplsLabel translate(@Nonnull final Long label) {
+ checkNotNull(label, "MPLS label should not be null");
+ return translate(label.intValue());
+ }
+
+ /**
+ * Builds {@link FibMplsLabel} from int value.
+ *
+ * @param label MPLS Label value
+ * @return VPP representation of MPLS label
+ */
+ default FibMplsLabel translate(final int label) {
+ final FibMplsLabel fibMplsLabel = new FibMplsLabel();
+ fibMplsLabel.label = label;
+ return fibMplsLabel;
+ }
+}
diff --git a/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslatorTest.java b/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslatorTest.java
new file mode 100644
index 000000000..b0e7dd658
--- /dev/null
+++ b/vpp-common/vpp-translate-utils/src/test/java/io/fd/hc2vpp/common/translate/util/MplsLabelTranslatorTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.common.translate.util;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.vpp.jvpp.core.types.FibMplsLabel;
+import org.junit.Test;
+
+public class MplsLabelTranslatorTest implements MplsLabelTranslator {
+ @Test
+ public void testTranslateLong() {
+ final int expectedLabel = 1048575;
+ final FibMplsLabel expected = new FibMplsLabel();
+ expected.label = expectedLabel;
+ assertEquals(expected, translate(Long.valueOf(1048575)));
+ }
+ @Test
+ public void testTranslateInt() {
+ final int expectedLabel = 11;
+ final FibMplsLabel expected = new FibMplsLabel();
+ expected.label = expectedLabel;
+ assertEquals(expected, translate(expectedLabel));
+ }
+
+}
pan> VppQosMark(self, self.pg2, qem2, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() qm3 = VppQosMark(self, self.pg3, qem3, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() qm4 = VppQosMark(self, self.pg4, qem4, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() self.assertTrue(qm3.query_vpp_config()) self.logger.info(self.vapi.cli("sh qos mark")) # # packets ingress on Pg0 # p_v4 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) p_v6 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_ip6, tc=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) # # Since we have not yet enabled the recording of the input QoS # from the input iP header, the egress packet's ToS will be unchanged # rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 1) rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IPv6].tc, 1) # # Enable QoS recording on IP input for pg0 # qr1 = VppQosRecord(self, self.pg0, self.QOS_SOURCE.QOS_API_SOURCE_IP) qr1.add_vpp_config() self.logger.info(self.vapi.cli("sh qos record")) # # send the same packets, this time expect the input TOS of 1 # to be mapped to pg1's egress value of 254 # rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 254) rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IPv6].tc, 254) # # different input ToS to test the mapping # p_v4[IP].tos = 127 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 128) p_v6[IPv6].tc = 127 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IPv6].tc, 128) p_v4[IP].tos = 254 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 1) p_v6[IPv6].tc = 254 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IPv6].tc, 1) # # send packets out the other interfaces to test the maps are # correctly applied # p_v4[IP].dst = self.pg2.remote_ip4 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg2) for p in rx: self.assertEqual(p[IP].tos, 2) p_v4[IP].dst = self.pg3.remote_ip4 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg3) for p in rx: self.assertEqual(p[IP].tos, 3) p_v6[IPv6].dst = self.pg3.remote_ip6 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg3) for p in rx: self.assertEqual(p[IPv6].tc, 3) # # remove the map on pg2 and pg3, now expect an unchanged IP tos # qm2.remove_vpp_config() qm3.remove_vpp_config() self.logger.info(self.vapi.cli("sh qos mark")) self.assertFalse(qm3.query_vpp_config()) self.logger.info(self.vapi.cli("sh int feat pg2")) p_v4[IP].dst = self.pg2.remote_ip4 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg2) for p in rx: self.assertEqual(p[IP].tos, 254) p_v4[IP].dst = self.pg3.remote_ip4 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg3) for p in rx: self.assertEqual(p[IP].tos, 254) # # still mapping out of pg1 # p_v4[IP].dst = self.pg1.remote_ip4 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 1) # # disable the input recording on pg0 # self.assertTrue(qr1.query_vpp_config()) qr1.remove_vpp_config() # # back to an unchanged TOS value # rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 254) # # enable QoS stroe instead of record # qst1 = VppQosStore(self, self.pg0, self.QOS_SOURCE.QOS_API_SOURCE_IP, 5).add_vpp_config() self.logger.info(self.vapi.cli("sh qos store")) p_v4[IP].dst = self.pg1.remote_ip4 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 250) # # disable the input storing on pg0 # self.assertTrue(qst1.query_vpp_config()) qst1.remove_vpp_config() # # back to an unchanged TOS value # rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 254) # # disable the egress map on pg1 and pg4 # qm1.remove_vpp_config() qm4.remove_vpp_config() # # unchanged Tos on pg1 # rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 254) def test_qos_mpls(self): """ QoS Mark/Record MPLS """ # # 255 QoS for all input values # from_ext = 7 from_ip = 6 from_mpls = 5 from_vlan = 4 output = [scapy.compat.chb(from_ext)] * 256 os1 = b''.join(output) output = [scapy.compat.chb(from_vlan)] * 256 os2 = b''.join(output) output = [scapy.compat.chb(from_mpls)] * 256 os3 = b''.join(output) output = [scapy.compat.chb(from_ip)] * 256 os4 = b''.join(output) rows = [{'outputs': os1}, {'outputs': os2}, {'outputs': os3}, {'outputs': os4}] qem1 = VppQosEgressMap(self, 1, rows).add_vpp_config() # # a route with 1 MPLS label # route_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index, labels=[32])]) route_10_0_0_1.add_vpp_config() # # a route with 3 MPLS labels # route_10_0_0_3 = VppIpRoute(self, "10.0.0.3", 32, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index, labels=[63, 33, 34])]) route_10_0_0_3.add_vpp_config() # # enable IP QoS recording on the input Pg0 and MPLS egress marking # on Pg1 # qr1 = VppQosRecord(self, self.pg0, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() qm1 = VppQosMark(self, self.pg1, qem1, self.QOS_SOURCE.QOS_API_SOURCE_MPLS).add_vpp_config() # # packet that will get one label added and 3 labels added resp. # p_1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IP(src=self.pg0.remote_ip4, dst="10.0.0.1", tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) p_3 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IP(src=self.pg0.remote_ip4, dst="10.0.0.3", tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) rx = self.send_and_expect(self.pg0, p_1 * NUM_PKTS, self.pg1) # # only 3 bits of ToS value in MPLS make sure tos is correct # and the label and EOS bit have not been corrupted # for p in rx: self.assertEqual(p[MPLS].cos, from_ip) self.assertEqual(p[MPLS].label, 32) self.assertEqual(p[MPLS].s, 1) rx = self.send_and_expect(self.pg0, p_3 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[MPLS].cos, from_ip) self.assertEqual(p[MPLS].label, 63) self.assertEqual(p[MPLS].s, 0) h = p[MPLS].payload self.assertEqual(h[MPLS].cos, from_ip) self.assertEqual(h[MPLS].label, 33) self.assertEqual(h[MPLS].s, 0) h = h[MPLS].payload self.assertEqual(h[MPLS].cos, from_ip) self.assertEqual(h[MPLS].label, 34) self.assertEqual(h[MPLS].s, 1) # # enable MPLS QoS recording on the input Pg0 and IP egress marking # on Pg1 # qr2 = VppQosRecord( self, self.pg0, self.QOS_SOURCE.QOS_API_SOURCE_MPLS).add_vpp_config() qm2 = VppQosMark( self, self.pg1, qem1, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() # # MPLS x-connect - COS according to pg1 map # route_32_eos = VppMplsRoute(self, 32, 1, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index, labels=[VppMplsLabel(33)])]) route_32_eos.add_vpp_config() p_m1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / MPLS(label=32, cos=3, ttl=2) / IP(src=self.pg0.remote_ip4, dst="10.0.0.1", tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) rx = self.send_and_expect(self.pg0, p_m1 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[MPLS].cos, from_mpls) self.assertEqual(p[MPLS].label, 33) self.assertEqual(p[MPLS].s, 1) # # MPLS deag - COS is copied from MPLS to IP # route_33_eos = VppMplsRoute(self, 33, 1, [VppRoutePath("0.0.0.0", 0xffffffff, nh_table_id=0)]) route_33_eos.add_vpp_config() route_10_0_0_4 = VppIpRoute(self, "10.0.0.4", 32, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)]) route_10_0_0_4.add_vpp_config() p_m2 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / MPLS(label=33, ttl=2, cos=3) / IP(src=self.pg0.remote_ip4, dst="10.0.0.4", tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) rx = self.send_and_expect(self.pg0, p_m2 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, from_mpls) def test_qos_vlan(self): """QoS mark/record VLAN """ # # QoS for all input values # output = [scapy.compat.chb(0)] * 256 for i in range(0, 255): output[i] = scapy.compat.chb(255 - i) os = b''.join(output) rows = [{'outputs': os}, {'outputs': os}, {'outputs': os}, {'outputs': os}] qem1 = VppQosEgressMap(self, 1, rows).add_vpp_config() sub_if = VppDot1QSubint(self, self.pg0, 11) sub_if.admin_up() sub_if.config_ip4() sub_if.resolve_arp() sub_if.config_ip6() sub_if.resolve_ndp() # # enable VLAN QoS recording/marking on the input Pg0 subinterface and # qr_v = VppQosRecord( self, sub_if, self.QOS_SOURCE.QOS_API_SOURCE_VLAN).add_vpp_config() qm_v = VppQosMark( self, sub_if, qem1, self.QOS_SOURCE.QOS_API_SOURCE_VLAN).add_vpp_config() # # IP marking/recording on pg1 # qr_ip = VppQosRecord( self, self.pg1, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() qm_ip = VppQosMark( self, self.pg1, qem1, self.QOS_SOURCE.QOS_API_SOURCE_IP).add_vpp_config() # # a routes to/from sub-interface # route_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32, [VppRoutePath(sub_if.remote_ip4, sub_if.sw_if_index)]) route_10_0_0_1.add_vpp_config() route_10_0_0_2 = VppIpRoute(self, "10.0.0.2", 32, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)]) route_10_0_0_2.add_vpp_config() route_2001_1 = VppIpRoute(self, "2001::1", 128, [VppRoutePath(sub_if.remote_ip6, sub_if.sw_if_index)]) route_2001_1.add_vpp_config() route_2001_2 = VppIpRoute(self, "2001::2", 128, [VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)]) route_2001_2.add_vpp_config() p_v1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / Dot1Q(vlan=11, prio=1) / IP(src="1.1.1.1", dst="10.0.0.2", tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) p_v2 = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) / IP(src="1.1.1.1", dst="10.0.0.1", tos=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) p_v3 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / Dot1Q(vlan=11, prio=1, id=1) / IP(src="1.1.1.1", dst="10.0.0.2", tos=2) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) rx = self.send_and_expect(self.pg1, p_v2 * NUM_PKTS, self.pg0) for p in rx: self.assertEqual(p[Dot1Q].prio, 7) self.assertEqual(p[Dot1Q].id, 0) rx = self.send_and_expect(self.pg0, p_v3 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 252) rx = self.send_and_expect(self.pg0, p_v1 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IP].tos, 253) p_v1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / Dot1Q(vlan=11, prio=2) / IPv6(src="2001::1", dst="2001::2", tc=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) p_v2 = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) / IPv6(src="3001::1", dst="2001::1", tc=1) / UDP(sport=1234, dport=1234) / Raw(scapy.compat.chb(100) * NUM_PKTS)) rx = self.send_and_expect(self.pg1, p_v2 * NUM_PKTS, self.pg0) for p in rx: self.assertEqual(p[Dot1Q].prio, 7) self.assertEqual(p[Dot1Q].id, 0) rx = self.send_and_expect(self.pg0, p_v1 * NUM_PKTS, self.pg1) for p in rx: self.assertEqual(p[IPv6].tc, 251) # # cleanup # sub_if.unconfig_ip4() sub_if.unconfig_ip6() if __name__ == '__main__': unittest.main(testRunner=VppTestRunner)