diff options
author | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-05-04 16:13:09 +0200 |
---|---|---|
committer | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-05-09 14:36:21 +0200 |
commit | 8f9fe3ca424abc56d212a96af4ec5750a29e7673 (patch) | |
tree | c3472885ef0fb57452b88b4ea76f2935f81ca39f /routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java | |
parent | d5883157bff11ee89b95bc1abe7f62fca3509950 (diff) |
HC2VPP-253 - Bump routing models
This patch updates (for support of SRv6 and MPLS) routing models to:
- hc2vpp-ietf-routing@2018-03-13.yang
(RFC 8349, https://tools.ietf.org/html/rfc8349)
- hc2vpp-ietf-ipv4-unicast-routing@2018-03-13.yang (RFC 8349)
- hc2vpp-ietf-ipv6-unicast-routing@2018-03-13.yang (RFC 8349)
- hc2vpp-ietf-ipv6-router-advertisements@2018-03-13 (RFC 8349)
- hc2vpp-ietf-routing-types@2017-12-04
(RFC 8294 ,https://tools.ietf.org/html/rfc8294)
Due to odl bugs these models were changed,
see HC2VPP-298 for more details.
Significant changes in updated models:
- Routing instance was removed, we used vpp-routing-instance
as single instance before, which is no longer needed.
- Routing-protocol and Routing-protocols were refactored to
Control-plane-protocol/s. Control-protocol now uses type and name as key
- Route Key was changed from id to ipPrefix
- Next-hop and Next-Hop-list were refactored
See attached routing_postman_collection.json for updated data structures
and examples for both IPv4 and IPv6 routes.
For router advertisements see routing_advertisments_postman_collection.json
Another fixes in this patch:
- fixes in MPLS module due to Routing model updates
- fixes doc module due to changes in Routing model
Change-Id: I33704a50061aef97dfbd73a7701ff6fe5274d6f0
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java')
-rw-r--r-- | routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java | 140 |
1 files changed, 140 insertions, 0 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 new file mode 100644 index 000000000..372da27c6 --- /dev/null +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/read/ControlPlaneProtocolCustomizer.java @@ -0,0 +1,140 @@ +/* + * 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.read; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.routing.trait.RouteMapper; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Static; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocolsBuilder; +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.ControlPlaneProtocolBuilder; +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.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.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +final class ControlPlaneProtocolCustomizer + implements ListReaderCustomizer<ControlPlaneProtocol, ControlPlaneProtocolKey, ControlPlaneProtocolBuilder>, + RouteMapper { + + private final NamingContext routingProtocolContext; + private final DumpCacheManager<IpFibDetailsReplyDump, Void> ipv4RoutesDumpManager; + private final DumpCacheManager<Ip6FibDetailsReplyDump, Void> ipv6RoutesDumpManager; + + + ControlPlaneProtocolCustomizer(@Nonnull final NamingContext routingProtocolContext, + @Nonnull final DumpCacheManager<IpFibDetailsReplyDump, Void> ipv4RoutesDumpManager, + @Nonnull final DumpCacheManager<Ip6FibDetailsReplyDump, Void> ipv6RoutesDumpManager) { + this.routingProtocolContext = routingProtocolContext; + this.ipv4RoutesDumpManager = ipv4RoutesDumpManager; + this.ipv6RoutesDumpManager = ipv6RoutesDumpManager; + } + + @Nonnull + @Override + public List<ControlPlaneProtocolKey> getAllIds(@Nonnull final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier, + @Nonnull final ReadContext readContext) throws ReadFailedException { + + final ModificationCache modificationCache = readContext.getModificationCache(); + + // builds keys from routing protocol prefix and unique set of table ids + return Stream.of( + ipv4TableIds(instanceIdentifier, modificationCache), + ipv6TableIds(instanceIdentifier, modificationCache)) + .flatMap(Collection::stream) + .map(tableId -> routingProtocolContext.getName(tableId, readContext.getMappingContext())) + .distinct() + .map(name -> new ControlPlaneProtocolKey(name, Static.class)) + .collect(Collectors.toList()); + } + + private List<Integer> ipv4TableIds(final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier, + final ModificationCache modificationCache) throws ReadFailedException { + final Optional<IpFibDetailsReplyDump> + ipv4Routes = ipv4RoutesDumpManager.getDump(instanceIdentifier, modificationCache); + + if (ipv4Routes.isPresent()) { + return ipv4Routes.get().ipFibDetails.stream() + .map(ipFibDetails -> ipFibDetails.tableId) + .collect(Collectors.toList()); + } + return Collections.emptyList(); + } + + private List<Integer> ipv6TableIds(final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier, + final ModificationCache modificationCache) throws ReadFailedException { + final Optional<Ip6FibDetailsReplyDump> + ipv6Routes = ipv6RoutesDumpManager.getDump(instanceIdentifier, modificationCache); + + if (ipv6Routes.isPresent()) { + return ipv6Routes.get().ip6FibDetails.stream() + .map(ipFibDetails -> ipFibDetails.tableId) + .collect(Collectors.toList()); + } + return Collections.emptyList(); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> builder, + @Nonnull final List<ControlPlaneProtocol> list) { + ((ControlPlaneProtocolsBuilder) builder).setControlPlaneProtocol(list); + } + + @Nonnull + @Override + public ControlPlaneProtocolBuilder getBuilder(@Nonnull final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier) { + return new ControlPlaneProtocolBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<ControlPlaneProtocol> instanceIdentifier, + @Nonnull final ControlPlaneProtocolBuilder routingProtocolBuilder, + @Nonnull final ReadContext readContext) throws ReadFailedException { + final ControlPlaneProtocolKey key = instanceIdentifier.firstKeyOf(ControlPlaneProtocol.class); + routingProtocolBuilder + .setName(key.getName()) + .setKey(key) + .setType(Static.class) + .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder().setVppProtocolAttributes( + new VppProtocolAttributesBuilder() + .setPrimaryVrf( + new VniReference( + Long.valueOf(routingProtocolContext.getIndex(key.getName(), + readContext.getMappingContext())))) + .build()) + .build()) + .build(); + } +} |