diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-02-23 08:38:18 +0100 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-02-23 08:39:34 +0100 |
commit | 210b21cf903da53b91cf8143be9a5be295139f17 (patch) | |
tree | 85c53470923f0f4eda9e9516ed1d353a079ee5f1 | |
parent | 27922cc77498479eabe58cf82647b31aa880a0cc (diff) |
HC2VPP-83 - table id setup for special routes
Added primary/secondary table id setup for special v4/v6 routes
Change-Id: Id3ef3d383b5ad7b5b905a04f7f594fdf4b7a4104
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
10 files changed, 143 insertions, 116 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizer.java index 6252b8d3a..a1975a10c 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizer.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizer.java @@ -84,7 +84,8 @@ public class Ipv4RouteCustomizer extends FutureJVppCustomizer SimpleHopRequestFactory.forContexts(classifierContextManager, interfaceContext, routingProtocolContext); multipathHopRequestFactory = MultipathHopRequestFactory .forContexts(classifierContextManager, interfaceContext, routingProtocolContext); - specialNextHopRequestFactory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager); + specialNextHopRequestFactory = SpecialNextHopRequestFactory.forContexts(classifierContextManager, + interfaceContext, routingProtocolContext); routeNamesFactory = new Ipv4RouteNamesFactory(interfaceContext, routingProtocolContext); } @@ -141,7 +142,7 @@ public class Ipv4RouteCustomizer extends FutureJVppCustomizer removeMappingForEachHop(routeName, writeContext, createdHops); } } else if (route.getNextHopOptions() instanceof SpecialNextHop) { - writeSpecialHopRoute(identifier, route, writeContext, isAdd); + writeSpecialHopRoute(identifier, route, parentProtocolName, writeContext, isAdd); } else { throw new IllegalArgumentException("Unsupported next-hop type"); } @@ -193,13 +194,14 @@ public class Ipv4RouteCustomizer extends FutureJVppCustomizer private void writeSpecialHopRoute(final @Nonnull InstanceIdentifier<Route> identifier, final @Nonnull Route route, - final @Nonnull WriteContext writeContext, final boolean isAdd) + final @Nonnull String parentProtocolName, final @Nonnull WriteContext writeContext, + final boolean isAdd) throws WriteFailedException { final SpecialNextHop hop = SpecialNextHop.class.cast(route.getNextHopOptions()); final MappingContext mappingContext = writeContext.getMappingContext(); final IpAddDelRoute request = specialNextHopRequestFactory - .createIpv4SpecialHopRequest(isAdd, route, mappingContext, hop.getSpecialNextHop()); + .createIpv4SpecialHopRequest(isAdd, parentProtocolName, route, mappingContext, hop.getSpecialNextHop()); writeRoute(request, identifier); } diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizer.java index aa7138624..4c4a6e7d6 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizer.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizer.java @@ -84,7 +84,8 @@ public class Ipv6RouteCustomizer extends FutureJVppCustomizer SimpleHopRequestFactory.forContexts(classifierContextManager, interfaceContext, routingProtocolContext); multipathHopRequestFactory = MultipathHopRequestFactory .forContexts(classifierContextManager, interfaceContext, routingProtocolContext); - specialNextHopRequestFactory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager); + specialNextHopRequestFactory = SpecialNextHopRequestFactory.forContexts(classifierContextManager, interfaceContext, + routingProtocolContext); namesFactory = new Ipv6RouteNamesFactory(interfaceContext, routingProtocolContext); } @@ -141,7 +142,7 @@ public class Ipv6RouteCustomizer extends FutureJVppCustomizer removeMappingForEachHop(routeName, writeContext, createdHops); } } else if (route.getNextHopOptions() instanceof SpecialNextHop) { - writeSpecialHopRoute(identifier, route, writeContext, isAdd); + writeSpecialHopRoute(identifier, route, parentProtocolName, writeContext, isAdd); } else { throw new IllegalArgumentException("Unsupported next-hop type"); } @@ -177,13 +178,14 @@ public class Ipv6RouteCustomizer extends FutureJVppCustomizer private void writeSpecialHopRoute(final @Nonnull InstanceIdentifier<Route> identifier, final @Nonnull Route route, - final @Nonnull WriteContext writeContext, final boolean isAdd) + final @Nonnull String parentProtocolName, final @Nonnull WriteContext writeContext, + final boolean isAdd) throws WriteFailedException { final SpecialNextHop hop = SpecialNextHop.class.cast(route.getNextHopOptions()); final MappingContext mappingContext = writeContext.getMappingContext(); final IpAddDelRoute request = specialNextHopRequestFactory - .createIpv6SpecialHopRequest(isAdd, route, mappingContext, hop.getSpecialNextHop()); + .createIpv6SpecialHopRequest(isAdd, parentProtocolName, route, mappingContext, hop.getSpecialNextHop()); writeRoute(request, identifier); } diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java index 2a5ab9821..e9c9c63ee 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java @@ -16,31 +16,41 @@ package io.fd.hc2vpp.routing.write.factory; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.routing.write.factory.base.ClassifierContextHolder; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.routing.write.factory.base.BasicHopRequestFactory; import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer; import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.translate.MappingContext; import io.fd.vpp.jvpp.core.dto.IpAddDelRoute; -import javax.annotation.Nonnull; 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.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev161214.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev161214.VppRouteAttributes; + +import javax.annotation.Nonnull; +import java.util.Optional; -public class SpecialNextHopRequestFactory extends ClassifierContextHolder +import static com.google.common.base.Preconditions.checkNotNull; + +public class SpecialNextHopRequestFactory extends BasicHopRequestFactory implements RouteRequestProducer { - private SpecialNextHopRequestFactory(final VppClassifierContextManager classifierContextManager) { - super(classifierContextManager); + private SpecialNextHopRequestFactory(final VppClassifierContextManager classifierContextManager, + final NamingContext interfaceContext, + final NamingContext routingProtocolContext) { + super(classifierContextManager,interfaceContext,routingProtocolContext); } - public static SpecialNextHopRequestFactory forClassifierContext( - @Nonnull final VppClassifierContextManager classifierContextManager) { - return new SpecialNextHopRequestFactory(classifierContextManager); + public static SpecialNextHopRequestFactory forContexts( + @Nonnull final VppClassifierContextManager classifierContextManager, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext routingProtocolContext) { + return new SpecialNextHopRequestFactory(classifierContextManager, interfaceContext, routingProtocolContext); } public IpAddDelRoute createIpv4SpecialHopRequest(final boolean add, + @Nonnull final String parentProtocolName, @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.Route route, @Nonnull final MappingContext mappingContext, @Nonnull final SpecialNextHopGrouping.SpecialNextHop flagsVariant) { @@ -48,10 +58,18 @@ public class SpecialNextHopRequestFactory extends ClassifierContextHolder checkNotNull(mappingContext, "Mapping Context cannot be null"); checkNotNull(flagsVariant, "Flags variant cannot be null"); - return resolveFlags(getSpecialHopRequest(add, route.getDestinationPrefix()), flagsVariant); + final int parentProtocolTableId = getRoutingProtocolContext().getIndex(parentProtocolName,mappingContext); + final byte secondaryTableId = Optional.ofNullable(route.getVppIpv4Route()) + .map(VppRouteAttributes::getSecondaryVrf) + .map(VniReference::getValue) + .map(Long::byteValue) + .orElse(DEFAULT_VNI); + + return resolveFlags(getSpecialHopRequest(add, route.getDestinationPrefix(), (byte) parentProtocolTableId, secondaryTableId), flagsVariant); } public IpAddDelRoute createIpv6SpecialHopRequest(final boolean add, + @Nonnull final String parentProtocolName, @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev140525.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv6.Route route, @Nonnull final MappingContext mappingContext, @Nonnull final SpecialNextHopGrouping.SpecialNextHop flagsVariant) { @@ -60,20 +78,29 @@ public class SpecialNextHopRequestFactory extends ClassifierContextHolder checkNotNull(mappingContext, "Mapping Context cannot be null"); checkNotNull(flagsVariant, "Flags variant cannot be null"); - return resolveFlags(getSpecialHopRequest(add, route.getDestinationPrefix()), flagsVariant); + final int parentProtocolTableId = getRoutingProtocolContext().getIndex(parentProtocolName,mappingContext); + final byte secondaryTableId = Optional.ofNullable(route.getVppIpv6Route()) + .map(VppRouteAttributes::getSecondaryVrf) + .map(VniReference::getValue) + .map(Long::byteValue) + .orElse(DEFAULT_VNI); + + return resolveFlags(getSpecialHopRequest(add, route.getDestinationPrefix(), (byte) parentProtocolTableId, secondaryTableId), flagsVariant); } - private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress) { + private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress, + final byte primaryTableId, final byte secondaryTableId) { return flaglessAddDelRouteRequest(booleanToByte(isAdd), 0, null, DEFAULT_HOP_WEIGHT, BYTE_TRUE, ipv6AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE, - DEFAULT_VNI, DEFAULT_VNI, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE); + primaryTableId, secondaryTableId, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE); } - private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress) { + private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress, + final byte primaryTableId, final byte secondaryTableId) { return flaglessAddDelRouteRequest(booleanToByte(isAdd), 0, null, DEFAULT_HOP_WEIGHT, BYTE_FALSE, ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE, - DEFAULT_VNI, DEFAULT_VNI, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE); + primaryTableId, secondaryTableId, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE); } private IpAddDelRoute resolveFlags(IpAddDelRoute request, diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java index abaf0fa84..740c30c21 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java @@ -16,17 +16,19 @@ package io.fd.hc2vpp.routing.write.factory.base; -import static com.google.common.base.Preconditions.checkNotNull; - import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; + import javax.annotation.Nonnull; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Extension to {@code ClassifierContextHolder} to hold also {@code NamingContext} */ -public abstract class BasicHopRequestFactory extends ClassifierContextHolder { +public abstract class BasicHopRequestFactory { + private final VppClassifierContextManager classifierContextManager; private final NamingContext interfaceNamingContext; private final NamingContext routingProtocolContext; @@ -34,11 +36,15 @@ public abstract class BasicHopRequestFactory extends ClassifierContextHolder { @Nonnull final VppClassifierContextManager classifierContextManager, @Nonnull final NamingContext interfaceContext, @Nonnull final NamingContext routingProtocolContext) { - super(classifierContextManager); + this.classifierContextManager = checkNotNull(classifierContextManager, "Classifier context cannot be null"); this.interfaceNamingContext = checkNotNull(interfaceContext, "Interface context cannot be null"); this.routingProtocolContext = checkNotNull(routingProtocolContext, "Routing protocol context cannot be null"); } + protected VppClassifierContextManager getVppClassifierContextManager() { + return this.classifierContextManager; + } + protected NamingContext getInterfaceNamingContext() { return interfaceNamingContext; } diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/ClassifierContextHolder.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/ClassifierContextHolder.java deleted file mode 100644 index 0b11a9b3b..000000000 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/ClassifierContextHolder.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016 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.base; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; -import javax.annotation.Nonnull; - -/** - * Holds reference for - */ -public abstract class ClassifierContextHolder { - - private final VppClassifierContextManager classifierContextManager; - - protected ClassifierContextHolder(@Nonnull final VppClassifierContextManager classifierContextManager) { - this.classifierContextManager = checkNotNull(classifierContextManager, "Classifier context cannot be null"); - } - - protected VppClassifierContextManager getVppClassifierContextManager() { - return this.classifierContextManager; - } -} diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java index 7c3ddee2e..47f53494b 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java @@ -72,9 +72,11 @@ public interface RoutingRequestTestHelper extends ByteDataTranslator, FutureProd final int isDrop, final int isReceive, final int isUnreach, - final int isProhibit) { + final int isProhibit, + final int protocolTableId, + final int secondaryTableId) { // verifiaction of special request that has only destination address and flag - return desiredResult(add, ipv6, 0, destinationAddress, destinationPrefixLength, null, 0, 0, 0, 1, 0, 0, 0, + return desiredResult(add, ipv6, 0, destinationAddress, destinationPrefixLength, null, 0, 0, protocolTableId, 1, secondaryTableId, 0, 0, isDrop, isReceive, isUnreach, isProhibit); } diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java index 9cefb345a..a34b3debb 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv4RouteCustomizerTest.java @@ -17,6 +17,8 @@ package io.fd.hc2vpp.routing.write; +import static io.fd.hc2vpp.routing.Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY; +import static io.fd.hc2vpp.routing.Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY; import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_INDEX; import static io.fd.hc2vpp.routing.helpers.InterfaceTestHelper.INTERFACE_NAME; import static org.junit.Assert.assertTrue; @@ -28,7 +30,6 @@ import com.google.common.collect.ImmutableList; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.MultiNamingContext; 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; @@ -57,6 +58,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4RouteCustomizerTest extends WriterCustomizerTest implements ClassifyTableTestHelper, RoutingRequestTestHelper, SchemaContextTestHelper { + private static final int ROUTE_PROTOCOL_INDEX = 1; @Captor private ArgumentCaptor<IpAddDelRoute> requestCaptor; @@ -89,7 +91,7 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest namesFactory = new Ipv4RouteNamesFactory(interfaceContext, routingProtocolContext); defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); - defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context"); + defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, ROUTE_PROTOCOL_INDEX, "routing-protocol-context"); addMapping(classifyManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); whenAddRouteThenSuccess(api); } @@ -103,8 +105,8 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest customizer.writeCurrentAttributes(validId, route1, writeContext); verifyInvocation(1, ImmutableList - .of(desiredFlaglessResult(1, 0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, - Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, 1, 1, 0, + .of(desiredFlaglessResult(1, 0, 0, FIRST_ADDRESS_AS_ARRAY, 24, + SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @@ -119,11 +121,11 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest customizer.writeCurrentAttributes(validId, route1, writeContext); verifyInvocation(2, ImmutableList.of( - desiredFlaglessResult(1, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, - Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 1, 0, + desiredFlaglessResult(1, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, + FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1), - desiredFlaglessResult(1, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, - Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 3, 1, 1, 0, + desiredFlaglessResult(1, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, + SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 3, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); @@ -148,7 +150,7 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest customizer.writeCurrentAttributes(validId, route1, writeContext); verifyInvocation(1, ImmutableList - .of(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0)), api, + .of(desiredSpecialResult(1, 0, FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, ROUTE_PROTOCOL_INDEX, 0)), api, requestCaptor); } @@ -173,9 +175,9 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest throws WriteFailedException { customizer.deleteCurrentAttributes(validId, getIpv4RouteWithId(route, 1L), writeContext); verifyInvocation(1, ImmutableList - .of(desiredFlaglessResult(0, 0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, - Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, - 0, 1, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); + .of(desiredFlaglessResult(0, 0, 0, FIRST_ADDRESS_AS_ARRAY, 24, + SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, + 0, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @Test @@ -188,11 +190,11 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest customizer.deleteCurrentAttributes(validId, route1, writeContext); verifyInvocation(2, ImmutableList.of( - desiredFlaglessResult(0, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, - Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 1, 0, + desiredFlaglessResult(0, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, + FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1), - desiredFlaglessResult(0, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, - new byte[]{-64, -88, 2, 2}, INTERFACE_INDEX, 3, 1, 1, 0, + desiredFlaglessResult(0, 0, 1, FIRST_ADDRESS_AS_ARRAY, 24, + new byte[]{-64, -88, 2, 2}, INTERFACE_INDEX, 3, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); verify(routeHopContext, times(1)) @@ -214,7 +216,7 @@ public class Ipv4RouteCustomizerTest extends WriterCustomizerTest customizer.deleteCurrentAttributes(validId, getIpv4RouteWithId(route, 1L), writeContext); verifyInvocation(1, - ImmutableList.of(desiredSpecialResult(0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0)), api, + ImmutableList.of(desiredSpecialResult(0, 0, FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, ROUTE_PROTOCOL_INDEX, 0)), api, requestCaptor); } } diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java index 6ba973340..15c836411 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/Ipv6RouteCustomizerTest.java @@ -52,6 +52,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv6RouteCustomizerTest extends WriterCustomizerTest implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper { + private static final int ROUTE_PROTOCOL_INDEX = 1; @Captor private ArgumentCaptor<IpAddDelRoute> requestCaptor; @@ -86,7 +87,7 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); addMapping(classifyManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); - defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context"); + defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, ROUTE_PROTOCOL_INDEX, "routing-protocol-context"); } @Test @@ -97,7 +98,7 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest customizer.writeCurrentAttributes(validId, getIpv6RouteWithId(route, 1L), writeContext); verifyInvocation(1, ImmutableList .of(desiredFlaglessResult(1, 1, 0, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, 1, + Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @@ -110,10 +111,10 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest verifyInvocation(2, ImmutableList.of( desiredFlaglessResult(1, 1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 1, 0, + Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1), desiredFlaglessResult(1, 1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 64, - Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 1, 0, + Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, ROUTE_PROTOCOL_INDEX, 1, 0, CLASSIFY_TABLE_INDEX, 1)), api, requestCaptor); } @@ -139,7 +140,7 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest customizer.deleteCurrentAttributes(validId, getIpv6RouteWithId(route, 1L), writeContext); verifyInvocation(1, ImmutableList - .of(desiredSpecialResult(0, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0)), api, + .of(desiredSpecialResult(0, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, ROUTE_PROTOCOL_INDEX, 0)), api, requestCaptor); } @@ -180,7 +181,7 @@ public class Ipv6RouteCustomizerTest extends WriterCustomizerTest customizer.writeCurrentAttributes(validId, getIpv6RouteWithId(route, 1L), writeContext); verifyInvocation(1, ImmutableList - .of(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0)), api, + .of(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, ROUTE_PROTOCOL_INDEX, 0)), api, requestCaptor); } } diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv4Test.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv4Test.java index 253a1b1a9..d93a4bf1c 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv4Test.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv4Test.java @@ -16,11 +16,8 @@ package io.fd.hc2vpp.routing.write.factory; -import static org.junit.Assert.assertEquals; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Prohibit; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Receive; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Unreachable; - +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; @@ -42,10 +39,17 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicas import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol.StaticRoutes; +import static io.fd.hc2vpp.routing.write.factory.SpecialNextHopRequestFactory.forContexts; +import static org.junit.Assert.assertEquals; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.*; + @RunWith(HoneycombTestRunner.class) public class SpecialNextHopRequestFactoryIpv4Test implements RouteRequestProducer, RoutingRequestTestHelper, ClassifyTableTestHelper, - SchemaContextTestHelper { + SchemaContextTestHelper,NamingContextHelper { + + private static final String PARENT_PROTOCOL_4 = "parent-protocol-4"; + private static final int PARENT_PROTOCOL_4_INDEX = 4; @Mock private VppClassifierContextManager classifierContextManager; @@ -53,14 +57,21 @@ public class SpecialNextHopRequestFactoryIpv4Test @Mock private MappingContext mappingContext; + private NamingContext interfaceContext; + private NamingContext routingProtocolContextContext; + private SpecialNextHopRequestFactory factory; @Before public void init() { MockitoAnnotations.initMocks(this); - factory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager); + + interfaceContext = new NamingContext("iface", "interface-context"); + routingProtocolContextContext = new NamingContext("routingProtocol", "routing-protocol-context"); + factory = forContexts(classifierContextManager, interfaceContext, routingProtocolContextContext); addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); + defineMapping(mappingContext, PARENT_PROTOCOL_4, PARENT_PROTOCOL_4_INDEX, "routing-protocol-context"); } @Test @@ -68,10 +79,10 @@ public class SpecialNextHopRequestFactoryIpv4Test @InjectTestData(resourcePath = "/ipv4/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, + factory.createIpv4SpecialHopRequest(true, PARENT_PROTOCOL_4, extractSingleRoute(routes, 1L), mappingContext, SpecialNextHopGrouping.SpecialNextHop.Blackhole); - assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0), request); + assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, PARENT_PROTOCOL_4_INDEX, DEFAULT_VNI), request); } @Test @@ -79,9 +90,9 @@ public class SpecialNextHopRequestFactoryIpv4Test @InjectTestData(resourcePath = "/ipv4/specialhop/specialHopRouteReceive.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Receive); + factory.createIpv4SpecialHopRequest(true, PARENT_PROTOCOL_4, extractSingleRoute(routes, 1L), mappingContext, Receive); - assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0), request); + assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0, PARENT_PROTOCOL_4_INDEX, DEFAULT_VNI), request); } @Test @@ -89,9 +100,9 @@ public class SpecialNextHopRequestFactoryIpv4Test @InjectTestData(resourcePath = "/ipv4/specialhop/specialHopRouteUnreachable.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Unreachable); + factory.createIpv4SpecialHopRequest(true, PARENT_PROTOCOL_4, extractSingleRoute(routes, 1L), mappingContext, Unreachable); - assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0), request); + assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0, PARENT_PROTOCOL_4_INDEX, DEFAULT_VNI), request); } @Test @@ -99,9 +110,9 @@ public class SpecialNextHopRequestFactoryIpv4Test @InjectTestData(resourcePath = "/ipv4/specialhop/specialHopRouteProhibited.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Prohibit); + factory.createIpv4SpecialHopRequest(true,PARENT_PROTOCOL_4, extractSingleRoute(routes, 1L), mappingContext, Prohibit); - assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1), request); + assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1, PARENT_PROTOCOL_4_INDEX, DEFAULT_VNI), request); } private Route extractSingleRoute(final StaticRoutes staticRoutes, final long id) { diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv6Test.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv6Test.java index d5f504094..fcd97da54 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv6Test.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactoryIpv6Test.java @@ -16,12 +16,15 @@ package io.fd.hc2vpp.routing.write.factory; +import static io.fd.hc2vpp.routing.write.trait.RouteRequestProducer.DEFAULT_VNI; import static org.junit.Assert.assertEquals; import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Blackhole; import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Prohibit; import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Receive; import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Unreachable; +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; @@ -43,7 +46,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev @RunWith(HoneycombTestRunner.class) public class SpecialNextHopRequestFactoryIpv6Test - implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper { + implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper, NamingContextHelper { + + private static final String PARENT_PROTOCOL_6 = "parent-protocol-6"; + private static final int PARENT_PROTOCOL_6_INDEX = 6; @Mock private VppClassifierContextManager classifierContextManager; @@ -51,14 +57,20 @@ public class SpecialNextHopRequestFactoryIpv6Test @Mock private MappingContext mappingContext; + private NamingContext interfaceContext; + private NamingContext routingProtocolContextContext; + private SpecialNextHopRequestFactory factory; @Before public void init() { MockitoAnnotations.initMocks(this); - factory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager); + interfaceContext = new NamingContext("iface", "interface-context"); + routingProtocolContextContext = new NamingContext("routingProtocol", "routing-protocol-context"); + factory = SpecialNextHopRequestFactory.forContexts(classifierContextManager, interfaceContext, routingProtocolContextContext); addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext); + defineMapping(mappingContext, PARENT_PROTOCOL_6, PARENT_PROTOCOL_6_INDEX, "routing-protocol-context"); } @Test @@ -66,9 +78,9 @@ public class SpecialNextHopRequestFactoryIpv6Test @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Blackhole); + factory.createIpv6SpecialHopRequest(true, PARENT_PROTOCOL_6, extractSingleRoute(routes, 1L), mappingContext, Blackhole); - assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0), + assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0, PARENT_PROTOCOL_6_INDEX, DEFAULT_VNI), request); } @@ -77,9 +89,9 @@ public class SpecialNextHopRequestFactoryIpv6Test @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteReceive.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Receive); + factory.createIpv6SpecialHopRequest(true, PARENT_PROTOCOL_6, extractSingleRoute(routes, 1L), mappingContext, Receive); - assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0), request); + assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0, PARENT_PROTOCOL_6_INDEX, DEFAULT_VNI), request); } @Test @@ -87,9 +99,9 @@ public class SpecialNextHopRequestFactoryIpv6Test @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteUnreachable.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Unreachable); + factory.createIpv6SpecialHopRequest(true, PARENT_PROTOCOL_6, extractSingleRoute(routes, 1L), mappingContext, Unreachable); - assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0), request); + assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0, PARENT_PROTOCOL_6_INDEX, DEFAULT_VNI), request); } @Test @@ -97,9 +109,9 @@ public class SpecialNextHopRequestFactoryIpv6Test @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteProhibited.json", id = STATIC_ROUTE_PATH) StaticRoutes routes) { final IpAddDelRoute request = - factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Prohibit); + factory.createIpv6SpecialHopRequest(true, PARENT_PROTOCOL_6, extractSingleRoute(routes, 1L), mappingContext, Prohibit); - assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1), request); + assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1, PARENT_PROTOCOL_6_INDEX, DEFAULT_VNI), request); } private Route extractSingleRoute(final StaticRoutes staticRoutes, final long id) { |