diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-15 14:41:25 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-05-15 13:12:49 +0000 |
commit | 400acf46ddab06a23a703f7d5b67cc4f5deeafe4 (patch) | |
tree | 5297889eafee26d3b3018f4461b10ed6bfaf9da4 /v3po/v3po2vpp/src/main/java/io/fd | |
parent | 8e0b7b8b35c2efba5e48219318e6c5a8e48a6d4f (diff) |
HC2VPP-151 - ip table reconfiguration while address present prevention
- fixed ordering - addresses must be written after vrf's
- added check to prevent such scenario in multi-request scenario
Change-Id: Idc233a8ac36fabef306339bfeec57bdc19b0f082
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd')
2 files changed, 82 insertions, 1 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java index 456178b73..564e7f63a 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java @@ -16,20 +16,29 @@ package io.fd.hc2vpp.v3po.interfaces; +import static com.google.common.base.Preconditions.checkState; + +import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +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.future.FutureJVppCore; +import java.util.List; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Routing; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InterfaceRoutingCustomizer extends RoutingCustomizer implements WriterCustomizer<Routing> { - public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi,@Nonnull final NamingContext interfaceContext) { + public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceContext) { super(vppApi, interfaceContext); } @@ -38,6 +47,9 @@ public class InterfaceRoutingCustomizer extends RoutingCustomizer @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { + checkState(isAddressNotPresentForInterface(id, writeContext, true), + "Cannot change routing configuration, if address is present for interface"); + final String ifName = id.firstKeyOf(Interface.class).getName(); setRouting(id, ifName, dataAfter, writeContext); } @@ -47,6 +59,8 @@ public class InterfaceRoutingCustomizer extends RoutingCustomizer @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { + checkState(isAddressNotPresentForInterface(id, writeContext, true), + "Cannot change routing configuration, if address is present for interface"); final String ifName = id.firstKeyOf(Interface.class).getName(); setRouting(id, ifName, dataAfter, writeContext); @@ -56,8 +70,35 @@ public class InterfaceRoutingCustomizer extends RoutingCustomizer public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, @Nonnull final Routing dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { + checkState(isAddressNotPresentForInterface(id, writeContext, false), + "Cannot change routing configuration, if address is present for interface"); + final String ifName = id.firstKeyOf(Interface.class).getName(); disableRouting(id, ifName, writeContext); } + /** + * Returns true if interface does not have v4/v6 addresses configured + */ + private boolean isAddressNotPresentForInterface(@Nonnull final InstanceIdentifier<Routing> id, + @Nonnull final WriteContext ctx, + boolean checkBefore) { + final Optional<Interface> interfaceData = checkBefore + ? ctx.readBefore(RWUtils.cutId(id, Interface.class)) + : ctx.readAfter(RWUtils.cutId(id, Interface.class)); + + if (interfaceData.isPresent()) { + final java.util.Optional<Interface1> augData = java.util.Optional.of(interfaceData.get()) + .map(iface -> iface.getAugmentation(Interface1.class)); + + final boolean v4NotPresent = + augData.map(Interface1::getIpv4).map(Ipv4::getAddress).map(List::isEmpty).orElse(true); + + final boolean v6NotPresent = + augData.map(Interface1::getIpv6).map(Ipv6::getAddress).map(List::isEmpty).orElse(true); + + return v4NotPresent && v6NotPresent; + } + return true; + } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java index 03eceb155..da139e879 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java @@ -16,14 +16,21 @@ package io.fd.hc2vpp.v3po.interfaces; +import static com.google.common.base.Preconditions.checkState; import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameConfig; +import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +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.future.FutureJVppCore; +import java.util.List; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip4.attributes.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip6.attributes.Ipv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.routing.attributes.Routing; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -38,6 +45,8 @@ public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> instanceIdentifier, @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) throws WriteFailedException { + checkState(isAddressNotPresentForSubInterface(instanceIdentifier, writeContext, true), + "Cannot change routing configuration, if address is present for sub-interface"); setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); } @@ -45,6 +54,8 @@ public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> instanceIdentifier, @Nonnull final Routing routing, @Nonnull final Routing d1, @Nonnull final WriteContext writeContext) throws WriteFailedException { + checkState(isAddressNotPresentForSubInterface(instanceIdentifier, writeContext, true), + "Cannot change routing configuration, if address is present for sub-interface"); setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); } @@ -52,6 +63,35 @@ public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> instanceIdentifier, @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) throws WriteFailedException { + checkState(isAddressNotPresentForSubInterface(instanceIdentifier, writeContext, false), + "Cannot change routing configuration, if address is present for sub-interface"); disableRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), writeContext); } + + /** + * Returns true if interface does not have v4/v6 addresses configured + */ + private boolean isAddressNotPresentForSubInterface(@Nonnull final InstanceIdentifier<Routing> id, + @Nonnull final WriteContext ctx, + boolean checkBefore) { + final Optional<SubInterface> subInterfaceData = checkBefore + ? + ctx.readBefore(RWUtils.cutId(id, SubInterface.class)) + : + ctx.readAfter(RWUtils.cutId(id, SubInterface.class)); + + if (subInterfaceData.isPresent()) { + final SubInterface subInterface = subInterfaceData.get(); + + final boolean v4NotPresent = + java.util.Optional.ofNullable(subInterface.getIpv4()).map(Ipv4::getAddress).map(List::isEmpty) + .orElse(true); + + final boolean v6NotPresent = + java.util.Optional.ofNullable(subInterface.getIpv6()).map(Ipv6::getAddress).map(List::isEmpty) + .orElse(true); + return v4NotPresent && v6NotPresent; + } + return true; + } } |