summaryrefslogtreecommitdiffstats
path: root/mpls/impl/src/test
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-11-22 17:56:52 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-11-23 12:17:34 +0000
commit82d2da4853410c0e7c00f383c01760cc7f26f75e (patch)
tree2a5fdac137267d8a657eb6325a46909b8c78a731 /mpls/impl/src/test
parent1715b92455356a52e01ff5c4f2a42fe5336b9088 (diff)
HC2VPP-259: add support for mpls swap-and-forward
Limitations: - only IPv4 next hop address - swap is supported only for the last label in the stack - only single outgoing label is supported. Change-Id: I9479e3d322561ed94683bd206e7e7852250d788c Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'mpls/impl/src/test')
-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/MplsInterfaceCustomizerTest.java5
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndIpv4LookupTest.java13
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java13
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java123
5 files changed, 136 insertions, 26 deletions
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 59db8426f..50c86ac26 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
@@ -56,11 +56,9 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
private static final String LSP_NAME = "static-lsp0";
-
private static final InstanceIdentifier<StaticLsp> IID = InstanceIdentifier.create(Routing.class).augmentation
(Routing1.class).child(Mpls.class).augmentation(Mpls1.class).child(StaticLsps.class)
.child(StaticLsp.class, new StaticLspKey(LSP_NAME));
-
private static final StaticLsp SIMPLE_LSP = getSimpleLsp();
private static final StaticLsp COMPLEX_LSP = getComplexLsp();
@@ -69,7 +67,7 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
private StaticLspCustomizer customizer;
private static StaticLsp getSimpleLsp() {
- final StaticLsp data = new StaticLspBuilder()
+ return new StaticLspBuilder()
.setName(LSP_NAME)
.setConfig(new ConfigBuilder()
.setInSegment(new InSegmentBuilder()
@@ -85,11 +83,10 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
.build())
.build())
.build();
- return data;
}
private static StaticLsp getComplexLsp() {
- final StaticLsp data = new StaticLspBuilder()
+ return new StaticLspBuilder()
.setName(LSP_NAME)
.setConfig(new ConfigBuilder()
.setInSegment(new InSegmentBuilder()
@@ -107,7 +104,6 @@ public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDa
.build())
.build())
.build();
- return data;
}
@Override
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/MplsInterfaceCustomizerTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/MplsInterfaceCustomizerTest.java
index 8fa1abf29..21551292b 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/MplsInterfaceCustomizerTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/MplsInterfaceCustomizerTest.java
@@ -44,10 +44,8 @@ public class MplsInterfaceCustomizerTest extends WriterCustomizerTest implements
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
-
private static final Interface MPLS_ENABLED = getInterfaceMpls(true);
private static final Interface MPLS_DISABLED = getInterfaceMpls(false);
-
private static final InstanceIdentifier<Mpls> MPLS_ID = InstanceIdentifier.create(Routing.class).augmentation
(Routing1.class).child(Mpls.class);
private static final InstanceIdentifier<Interface> IID = MPLS_ID.child(Interface.class, new InterfaceKey(IF_NAME));
@@ -57,13 +55,12 @@ public class MplsInterfaceCustomizerTest extends WriterCustomizerTest implements
private MplsInterfaceCustomizer customizer;
private static Interface getInterfaceMpls(final boolean enabled) {
- final Interface data = new InterfaceBuilder()
+ return new InterfaceBuilder()
.setName(IF_NAME)
.setConfig(new ConfigBuilder()
.setEnabled(enabled)
.build())
.build();
- return data;
}
@Override
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 b76daaa04..e924cfaaf 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
@@ -53,14 +53,12 @@ public class PopAndIpv4LookupTest extends WriterCustomizerTest implements ByteDa
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
private static final String LSP_NAME = "static-lsp0";
-
private static final InstanceIdentifier<StaticLsp> IID = InstanceIdentifier.create(Routing.class).augmentation
(Routing1.class).child(Mpls.class).augmentation(Mpls1.class).child(StaticLsps.class)
.child(StaticLsp.class, new StaticLspKey(LSP_NAME));
-
- private static final StaticLsp POP_AND_IP4_LOOKUP = getStaticLsp();
private static final int IP4_TABLE_ID = 456;
private static final int LOCAL_LABEL = 104;
+ private static final StaticLsp POP_AND_IP4_LOOKUP = getStaticLsp();
@Mock
private FutureJVppCoreFacade jvpp;
@@ -70,7 +68,7 @@ public class PopAndIpv4LookupTest extends WriterCustomizerTest implements ByteDa
* Equivalent of mpls local-label add eos 104 ip4-lookup-in-table 456
*/
private static StaticLsp getStaticLsp() {
- final StaticLsp data = new StaticLspBuilder()
+ return new StaticLspBuilder()
.setName(LSP_NAME)
.setConfig(new ConfigBuilder()
.setInSegment(new InSegmentBuilder()
@@ -87,7 +85,6 @@ public class PopAndIpv4LookupTest extends WriterCustomizerTest implements ByteDa
.build())
.build())
.build();
- return data;
}
@Override
@@ -101,16 +98,16 @@ public class PopAndIpv4LookupTest extends WriterCustomizerTest implements ByteDa
@Test
public void testWrite() throws WriteFailedException {
customizer.writeCurrentAttributes(IID, POP_AND_IP4_LOOKUP, writeContext);
- verify(jvpp).mplsRouteAddDel(getRequestForSimpleLsp(true));
+ verify(jvpp).mplsRouteAddDel(getRequest(true));
}
@Test
public void testDelete() throws WriteFailedException {
customizer.deleteCurrentAttributes(IID, POP_AND_IP4_LOOKUP, writeContext);
- verify(jvpp).mplsRouteAddDel(getRequestForSimpleLsp(false));
+ verify(jvpp).mplsRouteAddDel(getRequest(false));
}
- private MplsRouteAddDel getRequestForSimpleLsp(final boolean add) {
+ private MplsRouteAddDel getRequest(final boolean add) {
MplsRouteAddDel request = new MplsRouteAddDel();
request.mrLabel = LOCAL_LABEL;
request.mrEos = 1;
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 ef971093d..de32a1907 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
@@ -53,14 +53,12 @@ public class PopAndMplsLookupTest extends WriterCustomizerTest implements ByteDa
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
private static final String LSP_NAME = "static-lsp0";
-
private static final InstanceIdentifier<StaticLsp> IID = InstanceIdentifier.create(Routing.class).augmentation
(Routing1.class).child(Mpls.class).augmentation(Mpls1.class).child(StaticLsps.class)
.child(StaticLsp.class, new StaticLspKey(LSP_NAME));
-
- private static final StaticLsp POP_AND_MPLS_LOOKUP = getStaticLsp();
private static final int MPLS_TABLE_ID = 456;
private static final int LOCAL_LABEL = 102;
+ private static final StaticLsp POP_AND_MPLS_LOOKUP = getStaticLsp();
@Mock
private FutureJVppCoreFacade jvpp;
@@ -70,7 +68,7 @@ public class PopAndMplsLookupTest extends WriterCustomizerTest implements ByteDa
* Equivalent of mpls local-label add non-eos 102 mpls-lookup-in-table 456
*/
private static StaticLsp getStaticLsp() {
- final StaticLsp data = new StaticLspBuilder()
+ return new StaticLspBuilder()
.setName(LSP_NAME)
.setConfig(new ConfigBuilder()
.setInSegment(new InSegmentBuilder()
@@ -87,7 +85,6 @@ public class PopAndMplsLookupTest extends WriterCustomizerTest implements ByteDa
.build())
.build())
.build();
- return data;
}
@Override
@@ -101,16 +98,16 @@ public class PopAndMplsLookupTest extends WriterCustomizerTest implements ByteDa
@Test
public void testWrite() throws WriteFailedException {
customizer.writeCurrentAttributes(IID, POP_AND_MPLS_LOOKUP, writeContext);
- verify(jvpp).mplsRouteAddDel(getRequestForSimpleLsp(true));
+ verify(jvpp).mplsRouteAddDel(getRequest(true));
}
@Test
public void testDelete() throws WriteFailedException {
customizer.deleteCurrentAttributes(IID, POP_AND_MPLS_LOOKUP, writeContext);
- verify(jvpp).mplsRouteAddDel(getRequestForSimpleLsp(false));
+ verify(jvpp).mplsRouteAddDel(getRequest(false));
}
- private MplsRouteAddDel getRequestForSimpleLsp(final boolean add) {
+ private MplsRouteAddDel getRequest(final boolean add) {
MplsRouteAddDel request = new MplsRouteAddDel();
request.mrLabel = LOCAL_LABEL;
request.mrEos = 0;
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
new file mode 100644
index 000000000..6fd9e02f5
--- /dev/null
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/SwapAndForwardTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2017 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 static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+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.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 org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.Mpls1;
+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.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp_config.InSegmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp_config.in.segment.type.MplsLabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310._static.lsp_config.out.segment.SimplePathBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.routing.mpls.StaticLsps;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.routing.mpls._static.lsps.StaticLsp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.routing.mpls._static.lsps.StaticLspBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls._static.rev170310.routing.mpls._static.lsps.StaticLspKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.mpls.rev170702.Routing1;
+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.rev140524.Routing;
+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 {
+
+ private static final String IF_NAME = "local0";
+ private static final int IF_INDEX = 123;
+ private static final String LSP_NAME = "static-lsp0";
+ private static final InstanceIdentifier<StaticLsp> IID = InstanceIdentifier.create(Routing.class).augmentation
+ (Routing1.class).child(Mpls.class).augmentation(Mpls1.class).child(StaticLsps.class)
+ .child(StaticLsp.class, new StaticLspKey(LSP_NAME));
+ private static final int LOCAL_LABEL = 104;
+ private static final int OUT_LABEL = 104;
+ private static final StaticLsp SWAP_AND_FORWARD = getStaticLsp();
+
+ @Mock
+ private FutureJVppCoreFacade jvpp;
+ private StaticLspCustomizer customizer;
+
+ /**
+ * Equivalent of
+ *
+ * mpls local-label add eos 104 via 10.10.24.4 local0 out-labels 104
+ */
+ private static StaticLsp getStaticLsp() {
+ return new StaticLspBuilder()
+ .setName(LSP_NAME)
+ .setConfig(new ConfigBuilder()
+ .setInSegment(new InSegmentBuilder()
+ .setType(new MplsLabelBuilder().setIncomingLabel(new MplsLabel((long) LOCAL_LABEL))
+ .build())
+ .build()
+ )
+ .setOperation(StaticLspConfig.Operation.SwapAndForward)
+ .setOutSegment(new SimplePathBuilder()
+ .setNextHop(IpAddressBuilder.getDefaultInstance("10.10.24.4"))
+ .setOutgoingInterface(IF_NAME)
+ .setOutgoingLabel(new MplsLabel((long) OUT_LABEL))
+ .build())
+ .build())
+ .build();
+ }
+
+ @Override
+ public void setUpTest() {
+ final String ctxInstanceName = "test-ifc-context";
+ customizer = new StaticLspCustomizer(jvpp, new NamingContext("test-prefix", ctxInstanceName));
+ when(jvpp.mplsRouteAddDel(any())).thenReturn(future(new MplsRouteAddDelReply()));
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, ctxInstanceName);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ customizer.writeCurrentAttributes(IID, SWAP_AND_FORWARD, writeContext);
+ verify(jvpp).mplsRouteAddDel(getRequest(true));
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(IID, SWAP_AND_FORWARD, writeContext);
+ verify(jvpp).mplsRouteAddDel(getRequest(false));
+ }
+
+ private MplsRouteAddDel getRequest(final boolean add) {
+ final MplsRouteAddDel request = new MplsRouteAddDel();
+ request.mrLabel = LOCAL_LABEL;
+ request.mrEos = 1;
+ request.mrClassifyTableIndex = -1; // default value used in make test
+ request.mrIsAdd = booleanToByte(add);
+ request.mrNextHopWeight = 1; // default value used in make test
+ request.mrNextHop = new byte[] {10, 10, 24, 4};
+ 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};
+ return request;
+ }
+}