summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/main')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java43
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java40
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;
+ }
}