summaryrefslogtreecommitdiffstats
path: root/routing
diff options
context:
space:
mode:
authorMichal Cmarada <mcmarada@cisco.com>2019-04-29 13:13:08 +0200
committerMichal Cmarada <mcmarada@cisco.com>2019-04-30 08:32:51 +0200
commitc15641564484bfb16a5fabff3a281d7a6b21861e (patch)
treee5f615821e926c846645002490a5ebe27c399027 /routing
parent7235eeb213a5b4b3ce980b2629e429b7becc4097 (diff)
add routing Table lookup tests
Change-Id: I306e0ee2ed7d5d1983ea4a62728ef663cbaef706 Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'routing')
-rw-r--r--routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv4Test.java116
-rw-r--r--routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv6Test.java130
-rw-r--r--routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithClassifier.json18
-rw-r--r--routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithoutClassifier.json15
-rw-r--r--routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier.json17
-rw-r--r--routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier2.json17
-rw-r--r--routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithoutClassifier.json14
7 files changed, 327 insertions, 0 deletions
diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv4Test.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv4Test.java
new file mode 100644
index 000000000..8b3ac2989
--- /dev/null
+++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv4Test.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2019 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.routing.write.factory;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.util.NamingContextHelper;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.routing.Ipv4RouteData;
+import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper;
+import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
+import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
+import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.test.tools.HoneycombTestRunner;
+import io.fd.honeycomb.test.tools.annotations.InjectTestData;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.jvpp.core.dto.IpAddDelRoute;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.StaticRoutes1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.Route;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.control.plane.protocol.StaticRoutes;
+
+@RunWith(HoneycombTestRunner.class)
+public class TableLookupRequestFactoryIpv4Test
+ implements RouteRequestProducer, RoutingRequestTestHelper, ClassifyTableTestHelper,
+ SchemaContextTestHelper, NamingContextHelper {
+
+ private static final String PARENT_PROTOCOL_4 = "parent-protocol-2";
+ private static final int PARENT_PROTOCOL_4_INDEX = 2;
+ private static final byte[] DEAGRAGATION_ADDRESS = {0, 0, 0, 0};
+ private static final Ipv4Prefix IPV_4_PREFIX = new Ipv4Prefix("192.168.2.1/24");
+ private static final int DST_PREFIX = 24;
+
+ @Mock
+ private VppClassifierContextManager classifierContextManager;
+
+ @Mock
+ private WriteContext writeContext;
+
+ @Mock
+ private MappingContext mappingContext;
+
+ private TableLookupRequestFactory factory;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ final NamingContext interfaceContext = new NamingContext("iface", "interface-context");
+ final NamingContext routingProtocolContextContext =
+ new NamingContext("routingProtocol", "routing-protocol-context");
+ factory = new TableLookupRequestFactory(classifierContextManager, interfaceContext,
+ routingProtocolContextContext);
+
+ addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
+ defineMapping(mappingContext, PARENT_PROTOCOL_4, PARENT_PROTOCOL_4_INDEX, "routing-protocol-context");
+ when(writeContext.getMappingContext()).thenReturn(mappingContext);
+ when(writeContext.readAfter(any())).thenReturn(Optional.of(new TableBuilder().build()));
+ }
+
+ @Test
+ public void testIpv4WithClassifier(
+ @InjectTestData(resourcePath = "/ipv4/tablehop/tableHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH)
+ StaticRoutes routes) {
+ final IpAddDelRoute request = factory.createV4TableLookupRouteRequest(true, PARENT_PROTOCOL_4,
+ extractSingleRoute(routes, IPV_4_PREFIX), writeContext);
+
+ assertEquals(
+ desiredFlaglessResult(1, 0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, DST_PREFIX, DEAGRAGATION_ADDRESS,
+ -1, 0, 2, 0, 2, 1), request);
+ }
+
+ @Test
+ public void testIpv4WithoutClassifier(
+ @InjectTestData(resourcePath = "/ipv4/tablehop/tableHopRouteWithoutClassifier.json", id = STATIC_ROUTE_PATH)
+ StaticRoutes routes) {
+ final IpAddDelRoute request = factory.createV4TableLookupRouteRequest(true, PARENT_PROTOCOL_4,
+ extractSingleRoute(routes, IPV_4_PREFIX), writeContext);
+
+ assertEquals(
+ desiredFlaglessResult(1, 0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, DST_PREFIX, DEAGRAGATION_ADDRESS,
+ -1, 0, 2, 0, 0, 0), request);
+ }
+
+ private Route extractSingleRoute(final StaticRoutes staticRoutes, final Ipv4Prefix id) {
+ return staticRoutes.augmentation(StaticRoutes1.class).getIpv4().getRoute().stream()
+ .filter(route -> route.getDestinationPrefix().getValue().equals(id.getValue()))
+ .collect(RWUtils.singleItemCollector());
+ }
+}
diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv6Test.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv6Test.java
new file mode 100644
index 000000000..027102682
--- /dev/null
+++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactoryIpv6Test.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2019 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.routing.write.factory;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.util.NamingContextHelper;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.routing.Ipv6RouteData;
+import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper;
+import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
+import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
+import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.test.tools.HoneycombTestRunner;
+import io.fd.honeycomb.test.tools.annotations.InjectTestData;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.jvpp.core.dto.IpAddDelRoute;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.StaticRoutes1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.Route;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.control.plane.protocol.StaticRoutes;
+
+@RunWith(HoneycombTestRunner.class)
+public class TableLookupRequestFactoryIpv6Test
+ implements RouteRequestProducer, RoutingRequestTestHelper, ClassifyTableTestHelper,
+ SchemaContextTestHelper, NamingContextHelper {
+
+ private static final String PARENT_PROTOCOL_4 = "parent-protocol-2";
+ private static final int PARENT_PROTOCOL_4_INDEX = 2;
+ private static final byte[] DEAGRAGATION_ADDRESS = {0, 0, 0, 0};
+ private static final Ipv6Prefix IPV_6_PREFIX = new Ipv6Prefix("2001:0db8:0a0b:12f0:0000:0000:0000:0001/64");
+ private static final int DST_PREFIX = 64;
+
+ @Mock
+ private VppClassifierContextManager classifierContextManager;
+
+ @Mock
+ private WriteContext writeContext;
+
+ @Mock
+ private MappingContext mappingContext;
+
+ private TableLookupRequestFactory factory;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ final NamingContext interfaceContext = new NamingContext("iface", "interface-context");
+ final NamingContext routingProtocolContextContext =
+ new NamingContext("routingProtocol", "routing-protocol-context");
+ factory = new TableLookupRequestFactory(classifierContextManager, interfaceContext,
+ routingProtocolContextContext);
+
+ addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
+ defineMapping(mappingContext, PARENT_PROTOCOL_4, PARENT_PROTOCOL_4_INDEX, "routing-protocol-context");
+ when(writeContext.getMappingContext()).thenReturn(mappingContext);
+ when(writeContext.readAfter(any())).thenReturn(Optional.of(new TableBuilder().build()));
+ }
+
+ @Test
+ public void testIpv6WithClassifier(
+ @InjectTestData(resourcePath = "/ipv6/tablehop/tableHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH)
+ StaticRoutes routes) {
+ final IpAddDelRoute request = factory.createV6TableLookupRouteRequest(true, PARENT_PROTOCOL_4,
+ extractSingleRoute(routes, IPV_6_PREFIX), writeContext);
+
+ assertEquals(
+ desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, DST_PREFIX, DEAGRAGATION_ADDRESS,
+ -1, 0, 2, 0, 2, 1), request);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testIpv6WithClassifier2(
+ @InjectTestData(resourcePath = "/ipv6/tablehop/tableHopRouteWithClassifier2.json", id = STATIC_ROUTE_PATH)
+ StaticRoutes routes) {
+ when(writeContext.readAfter(any())).thenReturn(Optional.empty());
+
+ final IpAddDelRoute request = factory.createV6TableLookupRouteRequest(true, PARENT_PROTOCOL_4,
+ extractSingleRoute(routes, IPV_6_PREFIX), writeContext);
+
+ assertEquals(
+ desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, DST_PREFIX, DEAGRAGATION_ADDRESS,
+ -1, 0, 2, 0, 1, 1), request);
+ }
+
+ @Test
+ public void testIpv6WithoutClassifier(
+ @InjectTestData(resourcePath = "/ipv6/tablehop/tableHopRouteWithoutClassifier.json", id = STATIC_ROUTE_PATH)
+ StaticRoutes routes) {
+ final IpAddDelRoute request = factory.createV6TableLookupRouteRequest(true, PARENT_PROTOCOL_4,
+ extractSingleRoute(routes, IPV_6_PREFIX), writeContext);
+
+ assertEquals(
+ desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, DST_PREFIX, DEAGRAGATION_ADDRESS,
+ -1, 0, 2, 0, 0, 0), request);
+ }
+
+ private Route extractSingleRoute(final StaticRoutes staticRoutes, final Ipv6Prefix id) {
+ return staticRoutes.augmentation(StaticRoutes1.class).getIpv6().getRoute().stream()
+ .filter(route -> route.getDestinationPrefix().getValue().equals(id.getValue()))
+ .collect(RWUtils.singleItemCollector());
+ }
+}
diff --git a/routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithClassifier.json b/routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithClassifier.json
new file mode 100644
index 000000000..66e3bfbff
--- /dev/null
+++ b/routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithClassifier.json
@@ -0,0 +1,18 @@
+{
+ "static-routes": {
+ "ipv4": {
+ "route": [
+ {
+ "destination-prefix": "192.168.2.1/24",
+ "next-hop": {
+ "secondary-vrf": 0
+ },
+ "vpp-ipv4-route" : {
+ "classify-table": "classify-table-one"
+ }
+ }
+ ]
+ }
+ }
+}
+
diff --git a/routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithoutClassifier.json b/routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithoutClassifier.json
new file mode 100644
index 000000000..967de4dc1
--- /dev/null
+++ b/routing/routing-impl/src/test/resources/ipv4/tablehop/tableHopRouteWithoutClassifier.json
@@ -0,0 +1,15 @@
+{
+ "static-routes": {
+ "ipv4": {
+ "route": [
+ {
+ "destination-prefix": "192.168.2.1/24",
+ "next-hop": {
+ "secondary-vrf": 0
+ }
+ }
+ ]
+ }
+ }
+}
+
diff --git a/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier.json b/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier.json
new file mode 100644
index 000000000..7c7ed29ec
--- /dev/null
+++ b/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier.json
@@ -0,0 +1,17 @@
+{
+ "static-routes": {
+ "ipv6": {
+ "route": [
+ {
+ "destination-prefix": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64",
+ "next-hop": {
+ "secondary-vrf": 0
+ },
+ "vpp-ipv6-route" : {
+ "classify-table": "classify-table-one"
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier2.json b/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier2.json
new file mode 100644
index 000000000..0f4cf9caa
--- /dev/null
+++ b/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithClassifier2.json
@@ -0,0 +1,17 @@
+{
+ "static-routes": {
+ "ipv6": {
+ "route": [
+ {
+ "destination-prefix": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64",
+ "next-hop": {
+ "secondary-vrf": 0
+ },
+ "vpp-ipv6-route" : {
+ "classify-table": "classify-table-0"
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithoutClassifier.json b/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithoutClassifier.json
new file mode 100644
index 000000000..58ef99c3a
--- /dev/null
+++ b/routing/routing-impl/src/test/resources/ipv6/tablehop/tableHopRouteWithoutClassifier.json
@@ -0,0 +1,14 @@
+{
+ "static-routes": {
+ "ipv6": {
+ "route": [
+ {
+ "destination-prefix": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64",
+ "next-hop": {
+ "secondary-vrf": 0
+ }
+ }
+ ]
+ }
+ }
+}