diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-02-06 16:54:07 +0100 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-02-13 09:42:04 +0000 |
commit | a54c5d0db782ea2dd06cc1a60df46fdbc945d138 (patch) | |
tree | bd0492bd112d6561f4a4ec8c1963752f81a3fae7 /routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizer.java | |
parent | b83a4a9d291991b07034c0889694eda247e9c8cd (diff) |
Add support for RA configuration
Includes:
* ietf-routing model augmentation that addresses
VPP specific RA options (HC2VPP-64)
* writers for RA cfg (HC2VPP-65)
Change-Id: Iea523caaddcf03e38c8e5e7c586f1606a44d335b
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizer.java')
-rw-r--r-- | routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizer.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizer.java new file mode 100644 index 000000000..f33272b70 --- /dev/null +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizer.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.routing.write; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SwInterfaceIp6NdRaConfig; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev140525.routing.routing.instance.interfaces._interface.Ipv6RouterAdvertisements; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev170315.Ipv6RouterAdvertisementsVppAugmentation; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class RouterAdvertisementsCustomizer extends FutureJVppCustomizer + implements WriterCustomizer<Ipv6RouterAdvertisements>, JvppReplyConsumer, ByteDataTranslator { + private static final Logger LOG = LoggerFactory.getLogger(RouterAdvertisementsCustomizer.class); + + private final NamingContext interfaceContext; + + RouterAdvertisementsCustomizer(@Nonnull final FutureJVppCore jvpp, @Nonnull final NamingContext interfaceContext) { + super(jvpp); + this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6RouterAdvertisements> id, + @Nonnull final Ipv6RouterAdvertisements dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Writing RouterAdvertisements {} dataAfter={}", id, dataAfter); + setRouterAdvertisements(id, dataAfter, writeContext, false); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6RouterAdvertisements> id, + @Nonnull final Ipv6RouterAdvertisements dataBefore, + @Nonnull final Ipv6RouterAdvertisements dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Updating RouterAdvertisements {} dataBefore={} dataAfter={}", id, dataBefore, dataAfter); + setRouterAdvertisements(id, dataAfter, writeContext, false); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6RouterAdvertisements> id, + @Nonnull final Ipv6RouterAdvertisements dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Removing RouterAdvertisements {} dataBefore={}", id, dataBefore); + setRouterAdvertisements(id, dataBefore, writeContext, true); + } + + private void setRouterAdvertisements(@Nonnull final InstanceIdentifier<Ipv6RouterAdvertisements> id, + @Nonnull final Ipv6RouterAdvertisements data, + @Nonnull final WriteContext writeContext, + final boolean isDelete) throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int ifcIndex = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + SwInterfaceIp6NdRaConfig request; + if (isDelete) { + request = new SwInterfaceIp6NdRaConfig(); + request.swIfIndex = ifcIndex; + request.suppress = 1; + } else { + request = getRequest(data, ifcIndex); + } + LOG.debug("Updating RouterAdvertisements configuration for interface {}(id={}): {}", ifcName, ifcIndex, request); + getReplyForWrite(getFutureJVpp().swInterfaceIp6NdRaConfig(request).toCompletableFuture(), id); + LOG.debug("RouterAdvertisements: {} configuration updated successfully", id); + } + + private SwInterfaceIp6NdRaConfig getRequest(final Ipv6RouterAdvertisements dataAfter, final int ifcIndex) { + final SwInterfaceIp6NdRaConfig request = new SwInterfaceIp6NdRaConfig(); + request.swIfIndex = ifcIndex; + request.suppress = booleanToByte(!dataAfter.isSendAdvertisements()); + request.managed = booleanToByte(dataAfter.isManagedFlag()); + request.other = booleanToByte(dataAfter.isOtherConfigFlag()); + final Ipv6RouterAdvertisementsVppAugmentation vppAugmentation = + dataAfter.getAugmentation(Ipv6RouterAdvertisementsVppAugmentation.class); + if (vppAugmentation != null) { + request.llOption = booleanToByte(vppAugmentation.isSuppressLinkLayer()); + request.sendUnicast = booleanToByte(vppAugmentation.isSendUnicast()); + request.cease = booleanToByte(vppAugmentation.isCease()); + request.initialCount = vppAugmentation.getInitialCount(); + request.initialInterval = vppAugmentation.getInitialInterval(); + } + request.isNo = 0; + if (dataAfter.getMinRtrAdvInterval() != null) { + request.minInterval = dataAfter.getMinRtrAdvInterval(); + } + if (dataAfter.getMaxRtrAdvInterval() != null) { + request.maxInterval = dataAfter.getMaxRtrAdvInterval(); + } + if (dataAfter.getDefaultLifetime() != null && dataAfter.getDefaultLifetime() != 0) { + request.lifetime = dataAfter.getDefaultLifetime(); + request.defaultRouter = 1; + } + return request; + } +} |