diff options
author | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-06-22 11:02:27 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-06-22 10:53:36 +0000 |
commit | 4e8127d8f74726b2ffdf8af89ae879cfa79466f6 (patch) | |
tree | 7e0b7932decf0c67781a4f556db6089cb0bec818 /routing/routing-impl/src/main | |
parent | b9e58bf303a099805ecb24ca3a97027b3c34a211 (diff) |
HC2VPP-344: Add FIB table management for routing
- update models with FIB table management
- fixes implementation for FIB table management
Change-Id: I5cf397d6e827cb14df970e14ee268ef870931bd4
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'routing/routing-impl/src/main')
9 files changed, 140 insertions, 101 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java index 372da27c6..deb32d382 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java @@ -40,7 +40,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.vpp.routing.rev180319.RoutingProtocolVppAttr; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.RoutingProtocolVppAttrBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.routing.control.plane.protocols.control.plane.protocol.VppProtocolAttributesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -133,6 +133,8 @@ final class ControlPlaneProtocolCustomizer new VniReference( Long.valueOf(routingProtocolContext.getIndex(key.getName(), readContext.getMappingContext())))) + // address family is not being set because Control plane protocol can contain both IPv4 and IPv6 + // protocols. Address family is resolved by static route type. .build()) .build()) .build(); diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv4RoutePathParser.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv4RoutePathParser.java index f1217ee73..b0b33471a 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv4RoutePathParser.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv4RoutePathParser.java @@ -43,7 +43,8 @@ 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.rev180313.next.hop.content.next.hop.options.next.hop.list.next.hop.list.NextHopBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv4.unicast.routing.rev180319.VppIpv4NextHopAugmentation; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv4.unicast.routing.rev180319.VppIpv4NextHopAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; public interface Ipv4RoutePathParser extends RouteMapper { @@ -65,7 +66,9 @@ public interface Ipv4RoutePathParser extends RouteMapper { static NextHopOptions tableLookup() { return new TableLookupCaseBuilder() // TODO - https://jira.fd.io/browse/VPP-994 - .setSecondaryVrf(new VniReference(0L)).build(); + .setSecondaryVrf(new VniReference(0L)) + .setAddressFamily(Ipv4.class) + .build(); } static SpecialNextHop specialHop(final FibPath singlePath) { diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv6RoutePathParser.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv6RoutePathParser.java index 27b5edf5d..14dbc8820 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv6RoutePathParser.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/trait/Ipv6RoutePathParser.java @@ -43,7 +43,8 @@ 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.rev180313.next.hop.content.next.hop.options.next.hop.list.next.hop.list.NextHopBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv6.unicast.routing.rev180319.VppIpv6NextHopAugmentation; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv6.unicast.routing.rev180319.VppIpv6NextHopAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; public interface Ipv6RoutePathParser extends RouteMapper { @@ -65,7 +66,9 @@ public interface Ipv6RoutePathParser extends RouteMapper { static NextHopOptions tableLookup() { return new TableLookupCaseBuilder() // TODO - https://jira.fd.io/browse/VPP-994 - .setSecondaryVrf(new VniReference(0L)).build(); + .setSecondaryVrf(new VniReference(0L)) + .setAddressFamily(Ipv6.class) + .build(); } static SpecialNextHop specialHop(final FibPath fibPath) { diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java index b68a503be..67a907326 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java @@ -20,9 +20,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.fib.management.services.FibTableService; +import io.fd.hc2vpp.fib.management.FibManagementIIds; import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -31,66 +30,36 @@ 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.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.RoutingProtocolVppAttr; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Customizer for handling of write operations for {@link ControlPlaneProtocol} */ final class ControlPlaneProtocolCustomizer implements ListWriterCustomizer<ControlPlaneProtocol, ControlPlaneProtocolKey> { - private static final Logger LOG = LoggerFactory.getLogger(ControlPlaneProtocolCustomizer.class); private final NamingContext routingProtocolContext; - private final FibTableService fibTableService; - ControlPlaneProtocolCustomizer(@Nonnull final NamingContext routingProtocolContext, - FibTableService fibTableService) { + ControlPlaneProtocolCustomizer(@Nonnull final NamingContext routingProtocolContext) { this.routingProtocolContext = routingProtocolContext; - this.fibTableService = fibTableService; } - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier, - @Nonnull final ControlPlaneProtocol routingProtocol, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - checkIsStatic(routingProtocol); + static Long extractTableId(final ControlPlaneProtocol protocol) { + final RoutingProtocolVppAttr vppAttr = protocol.getAugmentation(RoutingProtocolVppAttr.class); - final int tableId = extractTableId(routingProtocol); - final MappingContext mappingContext = writeContext.getMappingContext(); - final String newProtocolName = routingProtocol.getName(); + checkState(vppAttr != null && vppAttr.getVppProtocolAttributes() != null, + "Vpp routing protocol attributes not defined"); - // enclosed in synchronized block to prevent change of state after containsName/before addName - synchronized (routingProtocolContext) { - if (!routingProtocolContext.containsName(tableId, mappingContext)) { - // Todo HC2VPP-317: A proper solution for Fib table management should be implemented. This is a - // temporary workaround. + return vppAttr.getVppProtocolAttributes().getPrimaryVrf().getValue(); + } - // if not present in mapping,create assignment to table id, then create ip v4/v6 fib table on device - try { - fibTableService.checkTableExist(tableId, writeContext.getModificationCache()); - } catch (ReadFailedException e) { - LOG.error("VRF Fib table read failed for table {} with iid: {}. Aborting write operation", tableId, - instanceIdentifier); - throw new WriteFailedException(instanceIdentifier, e); - } catch (FibTableService.FibTableDoesNotExistException e) { - LOG.trace("VRF Fib table does not exist. creating new entry for Fib table.", e); - // Write IPv4 and IPv6 Fib table for this VRF - fibTableService.write(instanceIdentifier, tableId, "Vrf-IPv4-" + tableId, false); - fibTableService.write(instanceIdentifier, tableId, "Vrf-IPv6-" + tableId, true); - } - routingProtocolContext.addName(tableId, newProtocolName, mappingContext); - } else { - // prevent to fail while restoring data(trying to remap already mapped name) - if (!newProtocolName.equals(routingProtocolContext.getName(tableId, mappingContext))) { - throw new IllegalStateException(String.format( - "An attempt to assign protocol %s to table id %s. Table id already assigned to protocol %s", - newProtocolName, tableId, routingProtocolContext.getName(tableId, mappingContext))); - } - } - } + static boolean isTablePresent(@Nonnull final TableKey tableKey, @Nonnull final WriteContext writeContext) { + return writeContext.readAfter(FibManagementIIds.FM_FIB_TABLES.child(Table.class, tableKey)).isPresent(); } @Override @@ -108,12 +77,38 @@ final class ControlPlaneProtocolCustomizer checkArgument(routingProtocol.getType() == Static.class, "Only static routes are allowed"); } - private int extractTableId(final ControlPlaneProtocol protocol) { - final RoutingProtocolVppAttr vppAttr = protocol.getAugmentation(RoutingProtocolVppAttr.class); + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier, + @Nonnull final ControlPlaneProtocol routingProtocol, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + checkIsStatic(routingProtocol); - checkState(vppAttr != null && vppAttr.getVppProtocolAttributes() != null, - "Vpp routing protocol attributes not defined"); + final Long tableId = extractTableId(routingProtocol); + final MappingContext mappingContext = writeContext.getMappingContext(); + final String newProtocolName = routingProtocol.getName(); - return vppAttr.getVppProtocolAttributes().getPrimaryVrf().getValue().intValue(); + // enclosed in synchronized block to prevent change of state after containsName/before addName + synchronized (routingProtocolContext) { + if (!routingProtocolContext.containsName(tableId.intValue(), mappingContext)) { + // Protocol supports both IPv4/IPv6, therefore checking if at least one exists. Proper table is checked + // afterwards in Ipv6 or IPv4 customizers + if (!isTablePresent(new TableKey(Ipv4.class, new VniReference(tableId)), writeContext) && + !isTablePresent(new TableKey(Ipv6.class, new VniReference(tableId)), writeContext)) { + throw new WriteFailedException(instanceIdentifier, + String.format("VRF lookup table: %s not found for protocol: %s", tableId, + instanceIdentifier)); + } + routingProtocolContext.addName(tableId.intValue(), newProtocolName, mappingContext); + } else { + // prevent to fail while restoring data(trying to remap already mapped name) + if (!newProtocolName.equals(routingProtocolContext.getName(tableId.intValue(), mappingContext))) { + throw new IllegalStateException(String.format( + "An attempt to assign protocol %s to table id %s. Table id already assigned to protocol %s", + newProtocolName, tableId, + routingProtocolContext.getName(tableId.intValue(), mappingContext))); + } + } + } } } 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 1eb249f04..a9a058cb8 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 @@ -16,6 +16,8 @@ package io.fd.hc2vpp.routing.write; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.MultiNamingContext; @@ -29,6 +31,7 @@ import io.fd.hc2vpp.routing.write.factory.TableLookupRequestFactory; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.IpAddDelRoute; @@ -46,6 +49,8 @@ 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.rev180313.next.hop.content.next.hop.options.TableLookupCase; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.next.hop.content.next.hop.options.next.hop.list.next.hop.list.NextHop; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,6 +105,18 @@ public class Ipv4RouteCustomizer extends FutureJVppCustomizer @Nonnull final WriteContext writeContext) throws WriteFailedException { final String parentProtocolName = instanceIdentifier.firstKeyOf(ControlPlaneProtocol.class).getName(); final String routeName = routeNamesFactory.uniqueRouteName(parentProtocolName, route); + Optional<ControlPlaneProtocol> protocolOptional = + writeContext.readAfter(RWUtils.cutId(instanceIdentifier, ControlPlaneProtocol.class)); + Preconditions.checkArgument(protocolOptional.isPresent(), "Control protocol cannot be null for route: {}", + instanceIdentifier); + TableKey key = new TableKey( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4.class, + new VniReference(ControlPlaneProtocolCustomizer.extractTableId(protocolOptional.get()))); + + if (!ControlPlaneProtocolCustomizer.isTablePresent(key, writeContext)) { + throw new WriteFailedException(instanceIdentifier, "IPv4 FIB table does not exist!"); + } + writeRoute(instanceIdentifier, parentProtocolName, routeName, route, writeContext, true); // maps new route by next available index, @@ -149,11 +166,8 @@ public class Ipv4RouteCustomizer extends FutureJVppCustomizer } else if (route.getNextHop().getNextHopOptions() instanceof SpecialNextHop) { writeSpecialHopRoute(identifier, route, parentProtocolName, writeContext, isAdd); } else if (route.getNextHop().getNextHopOptions() instanceof TableLookupCase) { - writeRoute(tableLookupRequestFactory.createV4TableLookupRouteRequest(isAdd, - parentProtocolName, - route, - writeContext.getMappingContext()), - identifier); + writeRoute(tableLookupRequestFactory + .createV4TableLookupRouteRequest(isAdd, parentProtocolName, route, writeContext), identifier); } else { throw new IllegalArgumentException("Unsupported next-hop type"); } 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 e30c38fae..7c7e89f8f 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 @@ -17,6 +17,8 @@ package io.fd.hc2vpp.routing.write; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.MultiNamingContext; @@ -30,6 +32,7 @@ import io.fd.hc2vpp.routing.write.factory.TableLookupRequestFactory; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.IpAddDelRoute; @@ -47,6 +50,8 @@ 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.rev180313.next.hop.content.next.hop.options.TableLookupCase; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.next.hop.content.next.hop.options.next.hop.list.next.hop.list.NextHop; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,6 +107,18 @@ public class Ipv6RouteCustomizer extends FutureJVppCustomizer @Nonnull final WriteContext writeContext) throws WriteFailedException { final String parentProtocolName = instanceIdentifier.firstKeyOf(ControlPlaneProtocol.class).getName(); final String routeName = namesFactory.uniqueRouteName(parentProtocolName, route); + Optional<ControlPlaneProtocol> protocolOptional = + writeContext.readAfter(RWUtils.cutId(instanceIdentifier, ControlPlaneProtocol.class)); + Preconditions.checkArgument(protocolOptional.isPresent(), "Control protocol cannot be null for route: {}", + instanceIdentifier); + TableKey key = new TableKey( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6.class, + new VniReference(ControlPlaneProtocolCustomizer.extractTableId(protocolOptional.get()))); + + if (!ControlPlaneProtocolCustomizer.isTablePresent(key, writeContext)) { + throw new WriteFailedException(instanceIdentifier, "Ipv6 FIB table does not exist!"); + } + writeRoute(instanceIdentifier, parentProtocolName, routeName, route, writeContext, true); // maps new route by next available index, @@ -142,9 +159,8 @@ public class Ipv6RouteCustomizer extends FutureJVppCustomizer } else if (route.getNextHop().getNextHopOptions() instanceof SpecialNextHop) { writeSpecialHopRoute(identifier, route, parentProtocolName, writeContext, isAdd); } else if (route.getNextHop().getNextHopOptions() instanceof TableLookupCase) { - writeRoute(tableLookupRequestFactory.createV6TableLookupRouteRequest(isAdd, parentProtocolName, route, - writeContext.getMappingContext()), - identifier); + writeRoute(tableLookupRequestFactory + .createV6TableLookupRouteRequest(isAdd, parentProtocolName, route, writeContext), identifier); } else { throw new IllegalArgumentException("Unsupported next-hop type"); } diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java index 4af6f5579..05d6916cb 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java @@ -25,7 +25,6 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import io.fd.hc2vpp.common.translate.util.MultiNamingContext; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.fib.management.services.FibTableService; import io.fd.hc2vpp.routing.Ipv4RoutingNodes; import io.fd.hc2vpp.routing.Ipv6RoutingNodes; import io.fd.hc2vpp.routing.RoutingConfiguration; @@ -64,9 +63,6 @@ public final class RoutingWriterFactory implements WriterFactory, Ipv4RoutingNod private RoutingConfiguration configuration; @Inject - private FibTableService fibTableService; - - @Inject @Named("interface-context") private NamingContext interfaceContext; @@ -93,7 +89,7 @@ public final class RoutingWriterFactory implements WriterFactory, Ipv4RoutingNod new GenericWriter<>(RoutingIIds.ROUTING, new RoutingCustomizer())); registry.subtreeAdd(routingProtocolHandledChildren(),new GenericWriter<>(RoutingIIds.RT_CPS_CP, - new ControlPlaneProtocolCustomizer(routingProtocolContext, fibTableService))); + new ControlPlaneProtocolCustomizer(routingProtocolContext))); registry.subtreeAddAfter(ipv4RoutingHandledChildren(RoutingIIds.RT_CPS_CP_SR_SRV4_IPV4_RT_PARENT), new GenericWriter<>(RoutingIIds.RT_CPS_CP_SR_SRV4_IPV4_RT, diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactory.java index 8a11adc8f..99b2b1f10 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactory.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/TableLookupRequestFactory.java @@ -17,24 +17,29 @@ package io.fd.hc2vpp.routing.write.factory; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.fib.management.FibManagementIIds; import io.fd.hc2vpp.routing.write.factory.base.BasicHopRequestFactory; import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; -import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.write.WriteContext; import io.fd.vpp.jvpp.core.dto.IpAddDelRoute; import java.util.Optional; 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.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.next.hop.content.NextHopOptions; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.next.hop.content.next.hop.options.TableLookupCase; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv4.unicast.routing.rev180319.VppIpv4RouteAttributesAugmentation; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv4.unicast.routing.rev180319.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.route.VppIpv4Route; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv6.unicast.routing.rev180319.VppIpv6RouteAttributesAugmentation; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.ipv6.unicast.routing.rev180319.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.route.VppIpv6Route; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev180319.VppRouteAttributes; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.types.rev180406.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; public class TableLookupRequestFactory extends BasicHopRequestFactory implements RouteRequestProducer { @@ -50,20 +55,27 @@ public class TableLookupRequestFactory extends BasicHopRequestFactory implements public IpAddDelRoute createV4TableLookupRouteRequest(final boolean add, @Nonnull final String parentProtocolName, @Nonnull final Route route, - @Nonnull final MappingContext mappingContext) { + @Nonnull final WriteContext writeContext) { final Ipv4Prefix prefix = route.getDestinationPrefix(); final byte[] destinationAddress = ipv4AddressPrefixToArray(prefix); final byte destinationPrefix = extractPrefix(prefix); - final int primaryTableId = getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext); - final byte secondaryTableId = Optional.ofNullable(route.getNextHop().getNextHopOptions()) + final int primaryTableId = getRoutingProtocolContext().getIndex(parentProtocolName, + writeContext.getMappingContext()); + final Long secondaryTableId = Optional.ofNullable(route.getNextHop().getNextHopOptions()) .filter(nextHopOptions -> nextHopOptions instanceof TableLookupCase) .map(TableLookupCase.class::cast) .map(TableLookupCase::getSecondaryVrf) .map(VniReference::getValue) - .map(Long::byteValue) .orElseThrow(() -> new IllegalArgumentException("Table lookup option not specified correctly")); + TableKey key = new TableKey(Ipv4.class, new VniReference(secondaryTableId)); + KeyedInstanceIdentifier<Table, TableKey> fibIid = FibManagementIIds.FM_FIB_TABLES.child(Table.class, key); + if (!writeContext.readAfter(fibIid).isPresent()) { + throw new IllegalArgumentException( + String.format("Lookup table: %s not found for route: %s", secondaryTableId, route)); + } + VppIpv4Route vppIpv4Route = route.getAugmentation(VppIpv4RouteAttributesAugmentation.class) != null ? route.getAugmentation( VppIpv4RouteAttributesAugmentation.class).getVppIpv4Route() : null; @@ -71,42 +83,53 @@ public class TableLookupRequestFactory extends BasicHopRequestFactory implements final Optional<String> optClassifyTable = Optional.ofNullable(vppIpv4Route) .map(VppRouteAttributes::getClassifyTable); final byte classifyTableSet = booleanToByte(optClassifyTable.isPresent()); - final byte classifyTableIndex = optClassifyTable.map(tableName -> classifyTableIndex(tableName, getVppClassifierContextManager(), mappingContext)) + final byte classifyTableIndex = optClassifyTable + .map(tableName -> classifyTableIndex(tableName, getVppClassifierContextManager(), + writeContext.getMappingContext())) .map(Integer::byteValue) .orElse(DEFAULT_CLASSIFY_TABLE_INDEX); - return flaglessAddDelRouteRequest(booleanToByte(add), ~0, DEAGRAGATION_ADDRESS, (byte) 0, (byte) 0, destinationAddress, - destinationPrefix, (byte) 0, primaryTableId, secondaryTableId, classifyTableIndex, classifyTableSet); + return flaglessAddDelRouteRequest(booleanToByte(add), ~0, DEAGRAGATION_ADDRESS, (byte) 0, (byte) 0, + destinationAddress, destinationPrefix, (byte) 0, primaryTableId, secondaryTableId.intValue(), + classifyTableIndex, classifyTableSet); } public IpAddDelRoute createV6TableLookupRouteRequest(final boolean add, @Nonnull final String parentProtocolName, @Nonnull final 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 route, - @Nonnull final MappingContext mappingContext) { + @Nonnull final WriteContext writeContext) { final Ipv6Prefix prefix = route.getDestinationPrefix(); final byte[] destinationAddress = ipv6AddressPrefixToArray(prefix); final byte destinationPrefix = extractPrefix(prefix); - final int primaryTableId = getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext); - final byte secondaryTableId = Optional.ofNullable(route.getNextHop().getNextHopOptions()) + final int primaryTableId = + getRoutingProtocolContext().getIndex(parentProtocolName, writeContext.getMappingContext()); + final Long secondaryTableId = Optional.ofNullable(route.getNextHop().getNextHopOptions()) .filter(nextHopOptions -> nextHopOptions instanceof TableLookupCase) .map(TableLookupCase.class::cast) .map(TableLookupCase::getSecondaryVrf) .map(VniReference::getValue) - .map(Long::byteValue) .orElseThrow(() -> new IllegalArgumentException("Table lookup option not specified correctly")); + TableKey key = new TableKey(Ipv6.class, new VniReference(secondaryTableId)); + KeyedInstanceIdentifier<Table, TableKey> fibIid = FibManagementIIds.FM_FIB_TABLES.child(Table.class, key); + if (!writeContext.readAfter(fibIid).isPresent()) { + throw new IllegalArgumentException( + String.format("Lookup table: %s not found for route: %s", secondaryTableId, route)); + } + VppIpv6Route vppIpv6Route = route.getAugmentation(VppIpv6RouteAttributesAugmentation.class) != null ? route.getAugmentation(VppIpv6RouteAttributesAugmentation.class).getVppIpv6Route() : null; final Optional<String> optClassifyTable = Optional.ofNullable(vppIpv6Route) .map(VppRouteAttributes::getClassifyTable); final byte classifyTableSet = booleanToByte(optClassifyTable.isPresent()); - final byte classifyTableIndex = optClassifyTable.map(tableName -> classifyTableIndex(tableName, getVppClassifierContextManager(), mappingContext)) - .map(Integer::byteValue) - .orElse(DEFAULT_CLASSIFY_TABLE_INDEX); + final byte classifyTableIndex = optClassifyTable + .map(tableName -> classifyTableIndex(tableName, getVppClassifierContextManager(), + writeContext.getMappingContext())).map(Integer::byteValue).orElse(DEFAULT_CLASSIFY_TABLE_INDEX); - return flaglessAddDelRouteRequest(booleanToByte(add), ~0, DEAGRAGATION_ADDRESS, (byte) 0, (byte) 1, destinationAddress, - destinationPrefix, (byte) 0, primaryTableId, secondaryTableId, classifyTableIndex, classifyTableSet); + return flaglessAddDelRouteRequest(booleanToByte(add), ~0, DEAGRAGATION_ADDRESS, (byte) 0, (byte) 1, + destinationAddress, destinationPrefix, (byte) 0, primaryTableId, secondaryTableId.intValue(), + classifyTableIndex, classifyTableSet); } } diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/trait/RouteRequestProducer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/trait/RouteRequestProducer.java index f1a97aa22..449a925b0 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/trait/RouteRequestProducer.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/trait/RouteRequestProducer.java @@ -17,8 +17,6 @@ package io.fd.hc2vpp.routing.write.trait; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.Objects.isNull; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import com.google.common.collect.ImmutableSet.Builder; @@ -32,7 +30,6 @@ import java.util.Set; import java.util.regex.Pattern; 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.vpp.routing.types.rev180406.VniReference; /** @@ -49,16 +46,6 @@ public interface RouteRequestProducer extends ByteDataTranslator, AddressTransla int MPLS_LABEL_INVALID = 0x100000; - default int mandatoryVni(final VniReference vniReference) { - return checkNotNull(vniReference, "Vni reference cannot be null").getValue().intValue(); - } - - default int optionalVni(final VniReference vniReference) { - return isNull(vniReference) - ? DEFAULT_VNI - : vniReference.getValue().intValue(); - } - default byte extractPrefix(final String value) { checkArgument( allowedPrefixPatterns.stream().anyMatch(pattern -> Pattern.compile(pattern).matcher(value).matches()), |