summaryrefslogtreecommitdiffstats
path: root/mpls/impl/src/test/java/io/fd
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-11-21 13:08:44 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-11-23 12:17:34 +0000
commit69a47bd63d00230a6eb80da1e6358865e2f62a9a (patch)
treee1a44262d74a8ed6234f951e1be0ca10cfbc8bd6 /mpls/impl/src/test/java/io/fd
parent547d7183710378faff73bf7ccc6bdba4c99f0445 (diff)
HC2VPP-259: add support for mpls lookup
Translates pop-and-lookup operation of /hc2vpp-ietf-routing:routing/hc2vpp-ietf-mpl:mpls/ hc2vpp-ietf-mpls-static:static-lsps/static-lsp to mpls_route_add_del call. Configuring mpls lookup-type, as defined in vpp-mpls yang module, is required. Other lookup types (ipv4/ipv6) are not supported yet. Change-Id: If0580c6db69ee6c5f22a32bde031dbb6f852420f Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'mpls/impl/src/test/java/io/fd')
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java (renamed from mpls/impl/src/test/java/io/fd/hc2vpp/mpls/StaticLspCustomizerTest.java)6
-rw-r--r--mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java128
2 files changed, 131 insertions, 3 deletions
diff --git a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/StaticLspCustomizerTest.java b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
index f86685322..59db8426f 100644
--- a/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/StaticLspCustomizerTest.java
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/ImposeAndForwardTest.java
@@ -51,7 +51,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 StaticLspCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class ImposeAndForwardTest extends WriterCustomizerTest implements ByteDataTranslator {
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 123;
@@ -151,7 +151,7 @@ public class StaticLspCustomizerTest extends WriterCustomizerTest implements Byt
request.dstAddress = new byte[] {1, 2, 3, 4};
request.nextHopAddress = new byte[] {5, 6, 7, 8};
request.nextHopNOutLabels = 1;
- request.nextHopViaLabel = StaticLspCustomizer.MPLS_LABEL_INVALID;
+ request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
request.nextHopOutLabelStack = new int[] {111};
return request;
}
@@ -165,7 +165,7 @@ public class StaticLspCustomizerTest extends WriterCustomizerTest implements Byt
request.dstAddress = new byte[] {10, 10, 24, 0};
request.nextHopAddress = new byte[] {10, 10, 12, 2};
request.nextHopNOutLabels = 2;
- request.nextHopViaLabel = StaticLspCustomizer.MPLS_LABEL_INVALID;
+ request.nextHopViaLabel = LspWriter.MPLS_LABEL_INVALID;
request.nextHopOutLabelStack = new int[] {102, 104};
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
new file mode 100644
index 000000000..ef971093d
--- /dev/null
+++ b/mpls/impl/src/test/java/io/fd/hc2vpp/mpls/PopAndMplsLookupTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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.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.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.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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.mpls.rev171120.vpp.label.lookup.attributes.LabelLookupBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class PopAndMplsLookupTest 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 StaticLsp POP_AND_MPLS_LOOKUP = getStaticLsp();
+ private static final int MPLS_TABLE_ID = 456;
+ private static final int LOCAL_LABEL = 102;
+
+ @Mock
+ private FutureJVppCoreFacade jvpp;
+ private StaticLspCustomizer customizer;
+
+ /**
+ * Equivalent of mpls local-label add non-eos 102 mpls-lookup-in-table 456
+ */
+ private static StaticLsp getStaticLsp() {
+ final StaticLsp data = 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.PopAndLookup)
+ .addAugmentation(StaticLspVppLookupAugmentation.class,
+ new StaticLspVppLookupAugmentationBuilder()
+ .setLabelLookup(new LabelLookupBuilder()
+ .setType(LookupType.Mpls)
+ .setMplsLookupInTable((long) MPLS_TABLE_ID).build())
+ .build())
+ .build())
+ .build();
+ return data;
+ }
+
+ @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, POP_AND_MPLS_LOOKUP, writeContext);
+ verify(jvpp).mplsRouteAddDel(getRequestForSimpleLsp(true));
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(IID, POP_AND_MPLS_LOOKUP, writeContext);
+ verify(jvpp).mplsRouteAddDel(getRequestForSimpleLsp(false));
+ }
+
+ private MplsRouteAddDel getRequestForSimpleLsp(final boolean add) {
+ MplsRouteAddDel request = new MplsRouteAddDel();
+ request.mrLabel = LOCAL_LABEL;
+ request.mrEos = 0;
+ request.mrNextHopTableId = MPLS_TABLE_ID;
+ request.mrClassifyTableIndex = -1; // default value used in make test
+ request.mrIsAdd = booleanToByte(add);
+ request.mrNextHopProto = 2; // MPLS data plane protocol index used by VPP
+ request.mrNextHopWeight = 1; // default value used in make test
+ 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];
+ return request;
+ }
+}