summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java6
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java7
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv4WriterFactory.java5
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv6WriterFactory.java5
-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
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java60
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java41
8 files changed, 202 insertions, 5 deletions
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java
index cc784bb9e..dec6e93db 100644
--- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java
@@ -17,7 +17,9 @@
package io.fd.hc2vpp.l3.write.factory;
import static io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory.IFC_ID;
+import static io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory.VPP_IFC_AUG_ID;
+import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.hc2vpp.common.translate.util.NamingContext;
@@ -34,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
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.ipv4.Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor;
+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 Ipv4WriterFactory implements WriterFactory {
@@ -52,8 +55,9 @@ public class Ipv4WriterFactory implements WriterFactory {
// Ipv4(after interface)
final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
+ // changing ip table for interface that has ip address assigned is illegal action(internal vpp behaviour)
registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp)),
- IFC_ID);
+ ImmutableSet.of(IFC_ID, VPP_IFC_AUG_ID.child(Routing.class)));
// Address(after Ipv4) =
final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcNamingContext)),
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java
index d9bee8177..1793450c4 100644
--- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java
@@ -17,7 +17,9 @@
package io.fd.hc2vpp.l3.write.factory;
import static io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory.IFC_ID;
+import static io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory.VPP_IFC_AUG_ID;
+import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.hc2vpp.common.translate.util.NamingContext;
@@ -37,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
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.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Routing;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy;
@@ -59,7 +62,9 @@ public class Ipv6WriterFactory implements WriterFactory {
// Ipv6(after interface) =
final InstanceIdentifier<Ipv6> ipv6Id = ifc1AugId.child(Ipv6.class);
- registry.addAfter(new GenericWriter<>(ipv6Id, new Ipv6Customizer(jvpp)), IFC_ID);
+ // changing ip table for interface that has ip address assigned is illegal action(internal vpp behaviour)
+ registry.addAfter(new GenericWriter<>(ipv6Id, new Ipv6Customizer(jvpp)), ImmutableSet
+ .of(IFC_ID, VPP_IFC_AUG_ID.child(Routing.class)));
final InstanceIdentifier<Address>
ipv6AddressId = ipv6Id.child(Address.class);
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv4WriterFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv4WriterFactory.java
index fedb8eec5..44e08b724 100644
--- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv4WriterFactory.java
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv4WriterFactory.java
@@ -20,6 +20,7 @@ package io.fd.hc2vpp.l3.write.factory;
import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.L2_ID;
import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.SUB_IFC_ID;
+import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.hc2vpp.common.translate.util.NamingContext;
@@ -34,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan
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.ip4.attributes.ipv4.Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip4.attributes.ipv4.Neighbor;
+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;
public class SubInterfaceIpv4WriterFactory implements WriterFactory{
@@ -53,7 +55,8 @@ public class SubInterfaceIpv4WriterFactory implements WriterFactory{
// Ipv4(handled after L2 and L2/rewrite is done) =
final InstanceIdentifier<Address> ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class);
registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId,
- new SubInterfaceIpv4AddressCustomizer(jvpp, ifcNamingContext)), rewriteId);
+ new SubInterfaceIpv4AddressCustomizer(jvpp, ifcNamingContext)),
+ ImmutableSet.of(rewriteId, SUB_IFC_ID.child(Routing.class)));
final InstanceIdentifier<Neighbor> ipv4NeighborId = SUB_IFC_ID.child(Ipv4.class).child(Neighbor.class);
registry.addAfter(new GenericListWriter<>(ipv4NeighborId,
new SubInterfaceIpv4NeighbourCustomizer(jvpp, ifcNamingContext)), rewriteId);
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv6WriterFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv6WriterFactory.java
index b4d019164..ab02d25cc 100644
--- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv6WriterFactory.java
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/SubInterfaceIpv6WriterFactory.java
@@ -20,6 +20,7 @@ package io.fd.hc2vpp.l3.write.factory;
import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.L2_ID;
import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.SUB_IFC_ID;
+import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.hc2vpp.common.translate.util.NamingContext;
@@ -33,6 +34,7 @@ import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.l2.Rewrite;
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.ip6.attributes.ipv6.Address;
+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;
public class SubInterfaceIpv6WriterFactory implements WriterFactory {
@@ -54,7 +56,8 @@ public class SubInterfaceIpv6WriterFactory implements WriterFactory {
ipv6SubifcAddressId = SUB_IFC_ID.child(Ipv6.class)
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip6.attributes.ipv6.Address.class);
registry.addAfter(new GenericListWriter<>(ipv6SubifcAddressId,
- new SubInterfaceIpv6AddressCustomizer(jvpp, ifcNamingContext)), rewriteId);
+ new SubInterfaceIpv6AddressCustomizer(jvpp, ifcNamingContext)), ImmutableSet
+ .of(rewriteId, SUB_IFC_ID.child(Routing.class)));
final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip6.attributes.ipv6.Neighbor>
ipv6NeighborId = SUB_IFC_ID.child(Ipv6.class)
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip6.attributes.ipv6.Neighbor.class);
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;
+ }
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
index 89c4cd1eb..4f7b4a659 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
@@ -20,15 +20,24 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTable;
import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTableReply;
+import java.util.Collections;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
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.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+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.Interface1Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Routing;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.RoutingBuilder;
@@ -52,6 +61,7 @@ public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest {
@Test
public void testWrite() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final int vrfId = 123;
when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext);
@@ -60,18 +70,67 @@ public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest {
@Test(expected = WriteFailedException.class)
public void testWriteFailed() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
customizer.writeCurrentAttributes(IID, routing(213), writeContext);
}
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailedIpv4Present() throws WriteFailedException {
+ when(writeContext.readBefore(RWUtils.cutId(IID, Interface.class)))
+ .thenReturn(Optional.of(ifaceWithV4Address()));
+ customizer.writeCurrentAttributes(IID, routing(213), writeContext);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailedIpv6Present() throws WriteFailedException {
+ when(writeContext.readBefore(RWUtils.cutId(IID, Interface.class)))
+ .thenReturn(Optional.of(ifaceWithV6Address()));
+ customizer.writeCurrentAttributes(IID, routing(213), writeContext);
+ }
+
+ @Test
+ public void testWriteEmptyIfaceData() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(new InterfaceBuilder().build()));
+ final int vrfId = 123;
+ when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
+ customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext);
+ verify(api).swInterfaceSetTable(expectedRequest(vrfId));
+ }
+
+ private static Interface ifaceWithV4Address() {
+ return new InterfaceBuilder()
+ .addAugmentation(Interface1.class, new Interface1Builder()
+ .setIpv4(new Ipv4Builder()
+ .setAddress(Collections.singletonList(new AddressBuilder().build()))
+ .build())
+ .build())
+ .build();
+ }
+
+
+ private static Interface ifaceWithV6Address() {
+ return new InterfaceBuilder()
+ .addAugmentation(Interface1.class, new Interface1Builder()
+ .setIpv6(new Ipv6Builder()
+ .setAddress(Collections.singletonList(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressBuilder()
+ .build()))
+ .build())
+ .build())
+ .build();
+ }
+
@Test(expected = WriteFailedException.class)
public void testUpdateFailed() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
customizer.updateCurrentAttributes(IID, routing(123L), routing(321L), writeContext);
}
@Test
public void testDelete() throws WriteFailedException {
+ when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
verify(api).swInterfaceSetTable(expectedRequest(0));
@@ -79,6 +138,7 @@ public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest {
@Test(expected = WriteFailedException.DeleteFailedException.class)
public void testDeleteFailed() throws WriteFailedException {
+ when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java
index 6c2ed7f49..fdbb68722 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
@@ -39,7 +40,11 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.SubinterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.SubInterfaces;
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.interfaces._interface.sub.interfaces.SubInterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip4.attributes.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip4.attributes.ipv4.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip6.attributes.Ipv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.routing.attributes.Routing;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.routing.attributes.RoutingBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -74,8 +79,23 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
}
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailedV4AddressPresent() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(v4AddressPresent()));
+ final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(4L).build();
+ customizer.writeCurrentAttributes(VALID_ID, v4Routing, writeContext);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailedV6AddressPresent() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(v6AddressPresent()));
+ final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(4L).build();
+ customizer.writeCurrentAttributes(VALID_ID, v4Routing, writeContext);
+ }
+
@Test
public void testWriteIpv4Vrf() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(4L).build();
customizer.writeCurrentAttributes(VALID_ID, v4Routing, writeContext);
verifySetTableRequest(1, Collections.singleton(request(false, SUBIF_INDEX, 4)));
@@ -84,6 +104,7 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
@Test
public void testWriteIpv6Vrf() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final Routing v6Routing = new RoutingBuilder().setIpv6VrfId(3L).build();
customizer.writeCurrentAttributes(VALID_ID, v6Routing, writeContext);
verifySetTableRequest(1, Collections.singleton(request(true, SUBIF_INDEX, 3)));
@@ -91,6 +112,7 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
@Test
public void testUpdateIpv4Vrf() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final Routing routingBefore = new RoutingBuilder().setIpv6VrfId(3L).setIpv4VrfId(4L).build();
final Routing routingAfter = new RoutingBuilder().setIpv6VrfId(3L).setIpv4VrfId(5L).build();
customizer.updateCurrentAttributes(VALID_ID, routingBefore, routingAfter, writeContext);
@@ -100,6 +122,7 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
@Test
public void testUpdateIpv6Vrf() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final Routing routingBefore = new RoutingBuilder().setIpv6VrfId(3L).setIpv4VrfId(4L).build();
final Routing routingAfter = new RoutingBuilder().setIpv6VrfId(8L).setIpv4VrfId(4L).build();
customizer.updateCurrentAttributes(VALID_ID, routingBefore, routingAfter, writeContext);
@@ -109,6 +132,7 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
@Test
public void testDeleteIpv4Vrf() throws WriteFailedException {
+ when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(4L).build();
customizer.deleteCurrentAttributes(VALID_ID, v4Routing, writeContext);
verifySetTableRequest(1, Collections.singleton(request(false, SUBIF_INDEX, DISABLE_VRF)));
@@ -117,6 +141,7 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
@Test
public void testDeleteIpv6Vrf() throws WriteFailedException {
+ when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final Routing v6Routing = new RoutingBuilder().setIpv6VrfId(3L).build();
customizer.deleteCurrentAttributes(VALID_ID, v6Routing, writeContext);
verifySetTableRequest(1, Collections.singleton(request(true, SUBIF_INDEX, DISABLE_VRF)));
@@ -134,4 +159,20 @@ public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest impl
verify(api, times(times)).swInterfaceSetTable(requestCaptor.capture());
requestCaptor.getAllValues().containsAll(requests);
}
+
+ private static SubInterface v4AddressPresent() {
+ return new SubInterfaceBuilder()
+ .setIpv4(new Ipv4Builder()
+ .setAddress(Collections.singletonList(new AddressBuilder().build()))
+ .build())
+ .build();
+ }
+
+ private static SubInterface v6AddressPresent(){
+ return new SubInterfaceBuilder()
+ .setIpv6(new Ipv6Builder()
+ .setAddress(Collections.singletonList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.ip6.attributes.ipv6.AddressBuilder().build()))
+ .build())
+ .build();
+ }
}