summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-06-29 09:14:51 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-07-13 11:24:26 +0200
commitfb41618f6e78d5f1a20bbf37c45282c5fc15387d (patch)
tree6ac9da72b8a53c01f1ef2f97562a70b838c510f5 /v3po/v3po2vpp/src
parentd222ccedd09b5ee76cdcb367ae96c91f49e5f287 (diff)
HONEYCOMB-94 Reimplement writer registry with better ordering options
Now the registry is flat and allows for full control of writer execution order Change-Id: I864e1d676588ffe59b596145e0829e81b1a1ed2f Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src')
-rw-r--r--v3po/v3po2vpp/src/main/config/default-config.xml14
-rw-r--r--v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesHoneycombWriterModule.java213
-rw-r--r--v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceAugmentationWriterFactory.java130
-rw-r--r--v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppHoneycombWriterModule.java82
-rw-r--r--v3po/v3po2vpp/src/main/yang/v3po2vpp.yang4
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java271
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java63
7 files changed, 226 insertions, 551 deletions
diff --git a/v3po/v3po2vpp/src/main/config/default-config.xml b/v3po/v3po2vpp/src/main/config/default-config.xml
index 1ee177553..6b487a13f 100644
--- a/v3po/v3po2vpp/src/main/config/default-config.xml
+++ b/v3po/v3po2vpp/src/main/config/default-config.xml
@@ -162,14 +162,14 @@
<module>
<type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:utils">prefix:delegating-writer-registry</type>
<name>write-registry</name>
- <root-writers>
- <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:api">prefix:honeycomb-writer</type>
+ <writer-factory>
+ <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:api">prefix:honeycomb-writer-factory</type>
<name>vpp-honeycomb-writer</name>
- </root-writers>
- <root-writers>
- <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:api">prefix:honeycomb-writer</type>
+ </writer-factory>
+ <writer-factory>
+ <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:api">prefix:honeycomb-writer-factory</type>
<name>interfaces-honeycomb-writer</name>
- </root-writers>
+ </writer-factory>
</module>
</modules>
@@ -205,7 +205,7 @@
</instance>
</service>
<service>
- <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:api">prefix:honeycomb-writer</type>
+ <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:translate:api">prefix:honeycomb-writer-factory</type>
<instance>
<name>vpp-honeycomb-writer</name>
<provider>/modules/module[type='vpp-honeycomb-writer'][name='vpp-honeycomb-writer']
diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesHoneycombWriterModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesHoneycombWriterModule.java
index d87370a8b..8cc740a48 100644
--- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesHoneycombWriterModule.java
+++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesHoneycombWriterModule.java
@@ -1,21 +1,24 @@
package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import io.fd.honeycomb.v3po.translate.impl.TraversalType;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
-import io.fd.honeycomb.v3po.translate.util.write.CloseableWriter;
-import io.fd.honeycomb.v3po.translate.util.write.NoopWriterCustomizer;
-import io.fd.honeycomb.v3po.translate.util.write.ReflexiveAugmentWriterCustomizer;
-import io.fd.honeycomb.v3po.translate.v3po.interfaces.*;
+import com.google.common.collect.Sets;
+import io.fd.honeycomb.v3po.translate.impl.write.GenericListWriter;
+import io.fd.honeycomb.v3po.translate.impl.write.GenericWriter;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.EthernetCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.InterfaceCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.L2Customizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.RoutingCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.TapCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.VhostUserCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanGpeCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4AddressCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4Customizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4NeighbourCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv6Customizer;
-import io.fd.honeycomb.v3po.translate.write.ChildWriter;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry;
+import io.fd.honeycomb.v3po.translate.write.WriterFactory;
+import java.util.Set;
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.ip.rev140616.Interface1;
@@ -24,15 +27,18 @@ 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.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.rev150105.VppInterfaceAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.*;
-import org.opendaylight.yangtools.yang.binding.Augmentation;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
-
-import java.util.ArrayList;
-import java.util.List;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Routing;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Tap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Vxlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VxlanGpe;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.future.FutureJVpp;
public class InterfacesHoneycombWriterModule extends
- org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractInterfacesHoneycombWriterModule {
+ org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractInterfacesHoneycombWriterModule {
public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
@@ -52,91 +58,98 @@ public class InterfacesHoneycombWriterModule extends
@Override
public java.lang.AutoCloseable createInstance() {
-
- final List<ChildWriter<? extends Augmentation<Interface>>> ifcAugmentations = Lists.newArrayList();
- ifcAugmentations.add(getVppIfcAugmentationWriter());
- ifcAugmentations.add(getInterface1AugmentationWriter());
- ifcAugmentations.add(
- SubinterfaceAugmentationWriterFactory.createInstance(getVppJvppIfcDependency(), getInterfaceContextDependency(),
- getBridgeDomainContextDependency()));
-
- final ChildWriter<Interface> interfaceWriter = new CompositeListWriter<>(Interface.class,
- RWUtils.emptyChildWriterList(),
- ifcAugmentations,
- new InterfaceCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()),
- // It's important that this customizer is handled in a postorder way, because you first have to handle child nodes
- // e.g. Vxlan before setting other interface or vppInterfaceAugmentation leaves
- TraversalType.POSTORDER);
-
- final List<ChildWriter<? extends ChildOf<Interfaces>>> childWriters = new ArrayList<>();
- childWriters.add(interfaceWriter);
-
- // FIXME if we just return the root writer and cfg subsystem takes care to set it into reader registry,
- // we loose the ordering information for root writers
- // Or can we rely to the order in which readers are configured ?
- return new CloseableWriter<>(new CompositeRootWriter<>(Interfaces.class,
- childWriters, new NoopWriterCustomizer<>()));
+ return new InterfacesWriterFactory(getVppJvppIfcDependency(),
+ getBridgeDomainContextDependency(),
+ getInterfaceContextDependency());
}
- private ChildWriter<? extends Augmentation<Interface>> getInterface1AugmentationWriter() {
-
- final ChildWriter<Neighbor> neighborWriter = new CompositeListWriter<>(Neighbor.class,
- new Ipv4NeighbourCustomizer(getVppJvppIfcDependency(),getInterfaceContextDependency()));
-
- final ChildWriter<Address> addressWriter = new CompositeListWriter<>(Address.class,
- new Ipv4AddressCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()));
- final ChildWriter<Ipv4> ipv4Writer = new CompositeChildWriter<>(Ipv4.class,
- ImmutableList.of(neighborWriter,addressWriter),
- new Ipv4Customizer(getVppJvppIfcDependency(),getInterfaceContextDependency()));
- final ChildWriter<Ipv6> ipv6Writer = new CompositeChildWriter<>(Ipv6.class,
- new Ipv6Customizer(getVppJvppIfcDependency()));
+ private static class InterfacesWriterFactory implements WriterFactory, AutoCloseable {
+
+ private final FutureJVpp jvpp;
+ private final NamingContext bdContext;
+ private final NamingContext ifcContext;
+
+ InterfacesWriterFactory(final FutureJVpp vppJvppIfcDependency,
+ final NamingContext bridgeDomainContextDependency,
+ final NamingContext interfaceContextDependency) {
+ this.jvpp = vppJvppIfcDependency;
+ this.bdContext = bridgeDomainContextDependency;
+ this.ifcContext = interfaceContextDependency;
+ }
+
+ @Override
+ public void close() throws Exception {
+ // unregister is not supported in ModifiableWriterRegistry (not really needed though)
+ }
+
+ @Override
+ public void init(final ModifiableWriterRegistry registry) {
+ // Interfaces
+ // Interface =
+ final InstanceIdentifier<Interface> ifcId = InstanceIdentifier.create(Interfaces.class).child(Interface.class);
+ registry.addWriter(new GenericListWriter<>(ifcId, new InterfaceCustomizer(jvpp, ifcContext)));
+ // VppInterfaceAugmentation
+ addVppInterfaceAgmentationWriters(ifcId, registry);
+ // Interface1 (ietf-ip augmentation)
+ addInterface1AugmentationWriters(ifcId, registry);
+ // SubinterfaceAugmentation TODO make dedicated module for subIfc writer factory
+ new SubinterfaceAugmentationWriterFactory(ifcId, jvpp, ifcContext, bdContext).init(registry);
+ }
+
+ private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId,
+ final ModifiableWriterRegistry registry) {
+ final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class);
+ // Ipv6(after interface) TODO unfinished customizer =
+ registry.addWriterAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)),
+ ifcId);
+ // Ipv4(after interface)
+ final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
+ registry.addWriterAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)),
+ ifcId);
+ // Address(after Ipv4) =
+ final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
+ registry.addWriterAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)),
+ ipv4Id);
+ // Neighbor(after ipv4Address)
+ registry.addWriterAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)),
+ ipv4AddressId);
+ }
+
+ private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId,
+ final ModifiableWriterRegistry registry) {
+ final InstanceIdentifier<VppInterfaceAugmentation> vppIfcAugId = ifcId.augmentation(VppInterfaceAugmentation.class);
+ // VhostUser(Needs to be executed before Interface customizer) =
+ final InstanceIdentifier<VhostUser> vhostId = vppIfcAugId.child(VhostUser.class);
+ registry.addWriterBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)),
+ ifcId);
+ // Vxlan(Needs to be executed before Interface customizer) =
+ final InstanceIdentifier<Vxlan> vxlanId = vppIfcAugId.child(Vxlan.class);
+ registry.addWriterBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)),
+ ifcId);
+ // VxlanGpe(Needs to be executed before Interface customizer) =
+ final InstanceIdentifier<VxlanGpe> vxlanGpeId = vppIfcAugId.child(VxlanGpe.class);
+ registry.addWriterBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)),
+ ifcId);
+ // Tap(Needs to be executed before Interface customizer) =
+ final InstanceIdentifier<Tap> tapId = vppIfcAugId.child(Tap.class);
+ registry.addWriterBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)),
+ ifcId);
+
+ final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId);
+
+ // Ethernet(No dependency, customizer not finished TODO) =
+ registry.addWriter(new GenericWriter<>(vppIfcAugId.child(Ethernet.class), new EthernetCustomizer(jvpp)));
+ // Routing(Execute only after specific interface customizers) =
+ registry.addWriterAfter(
+ new GenericWriter<>(vppIfcAugId.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)),
+ specificIfcTypes);
+ // Routing(Execute only after specific interface customizers) =
+ registry.addWriterAfter(
+ new GenericWriter<>(vppIfcAugId.child(L2.class), new L2Customizer(jvpp, ifcContext, bdContext)),
+ specificIfcTypes);
+ }
- final List<ChildWriter<? extends ChildOf<Interface1>>> interface1ChildWriters = Lists.newArrayList();
- interface1ChildWriters.add(ipv4Writer);
- interface1ChildWriters.add(ipv6Writer);
-
- return new CompositeChildWriter<>(Interface1.class,
- interface1ChildWriters, new ReflexiveAugmentWriterCustomizer<>());
}
- private ChildWriter<VppInterfaceAugmentation> getVppIfcAugmentationWriter() {
-
- final ChildWriter<Ethernet> ethernetWriter = new CompositeChildWriter<>(Ethernet.class,
- new EthernetCustomizer(getVppJvppIfcDependency()));
-
- final ChildWriter<Routing> routingWriter = new CompositeChildWriter<>(Routing.class,
- new RoutingCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()));
-
- final ChildWriter<Vxlan> vxlanWriter = new CompositeChildWriter<>(Vxlan.class,
- new VxlanCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()));
-
- final ChildWriter<VxlanGpe> vxlanGpeWriter = new CompositeChildWriter<>(VxlanGpe.class,
- new VxlanGpeCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()));
-
- final ChildWriter<VhostUser> vhostUserWriter = new CompositeChildWriter<>(VhostUser.class,
- new VhostUserCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()));
-
- final ChildWriter<Tap> tapWriter = new CompositeChildWriter<>(Tap.class,
- new TapCustomizer(getVppJvppIfcDependency(), getInterfaceContextDependency()));
-
- final ChildWriter<L2> l2Writer = new CompositeChildWriter<>(L2.class,
- new L2Customizer(getVppJvppIfcDependency(), getInterfaceContextDependency(),
- getBridgeDomainContextDependency())
- );
-
- final List<ChildWriter<? extends ChildOf<VppInterfaceAugmentation>>> vppIfcChildWriters = Lists.newArrayList();
- vppIfcChildWriters.add(vhostUserWriter);
- vppIfcChildWriters.add(vxlanWriter);
- vppIfcChildWriters.add(vxlanGpeWriter);
- vppIfcChildWriters.add(tapWriter);
- vppIfcChildWriters.add(ethernetWriter);
- vppIfcChildWriters.add(l2Writer);
- vppIfcChildWriters.add(routingWriter);
-
- return new CompositeChildWriter<>(VppInterfaceAugmentation.class,
- vppIfcChildWriters,
- RWUtils.emptyAugWriterList(),
- new ReflexiveAugmentWriterCustomizer<>());
- }
}
diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceAugmentationWriterFactory.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceAugmentationWriterFactory.java
index f24dbf7e0..589ba92be 100644
--- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceAugmentationWriterFactory.java
+++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceAugmentationWriterFactory.java
@@ -16,90 +16,86 @@
package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
-import static io.fd.honeycomb.v3po.translate.util.RWUtils.singletonChildWriterList;
-
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
-import io.fd.honeycomb.v3po.translate.util.write.ReflexiveAugmentWriterCustomizer;
-import io.fd.honeycomb.v3po.translate.util.write.ReflexiveChildWriterCustomizer;
+import com.google.common.collect.Sets;
+import io.fd.honeycomb.v3po.translate.impl.write.GenericListWriter;
+import io.fd.honeycomb.v3po.translate.impl.write.GenericWriter;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.RewriteCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.SubInterfaceCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.SubInterfaceL2Customizer;
import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.SubInterfaceIpv4AddressCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.v3po.translate.write.ChildWriter;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Nonnull;
+import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry;
+import io.fd.honeycomb.v3po.translate.write.WriterFactory;
+import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTagged;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.future.FutureJVpp;
-final class SubinterfaceAugmentationWriterFactory {
-
- private SubinterfaceAugmentationWriterFactory() {
- }
-
- private static ChildWriter<Ipv4> getIp4Writer(
- @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext) {
+final class SubinterfaceAugmentationWriterFactory implements WriterFactory {
- final ChildWriter<Address> addressWriter = new CompositeListWriter<>(
- Address.class,
- new SubInterfaceIpv4AddressCustomizer(futureJvpp, interfaceContext));
+ private final InstanceIdentifier<Interface> ifcId;
+ private final FutureJVpp jvpp;
+ private final NamingContext ifcContext;
+ private final NamingContext bdContext;
- return new CompositeChildWriter<>(
- Ipv4.class,
- RWUtils.singletonChildWriterList(addressWriter),
- new ReflexiveChildWriterCustomizer<>());
+ public SubinterfaceAugmentationWriterFactory(
+ final InstanceIdentifier<Interface> ifcId, final FutureJVpp jvpp,
+ final NamingContext ifcContext, final NamingContext bdContext) {
+ this.ifcId = ifcId;
+ this.jvpp = jvpp;
+ this.ifcContext = ifcContext;
+ this.bdContext = bdContext;
}
- private static ChildWriter<L2> getL2Writer(
- @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext,
- @Nonnull final NamingContext bridgeDomainContext) {
-
- final ChildWriter<? extends ChildOf<L2>> rewriteWriter =
- new CompositeChildWriter<>(Rewrite.class, new RewriteCustomizer(futureJvpp, interfaceContext));
-
- return new CompositeChildWriter<>(
- L2.class,
- singletonChildWriterList(rewriteWriter),
- new SubInterfaceL2Customizer(futureJvpp, interfaceContext, bridgeDomainContext)
- );
- }
-
- static ChildWriter<SubinterfaceAugmentation> createInstance(
- @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext,
- @Nonnull final NamingContext bridgeDomainContext) {
- final List<ChildWriter<? extends ChildOf<SubInterface>>> childWriters = new ArrayList<>();
-
- // TODO L2 is ChildOf<SubInterfaceBaseAttributes>, but SubInterface extends SubInterfaceBaseAttributes
- // If we use containers inside groupings, we need to cast and lose static type checking.
- // Can we get rid of the cast?
- childWriters.add((ChildWriter) getL2Writer(futureJvpp, interfaceContext, bridgeDomainContext));
- childWriters.add((ChildWriter) getIp4Writer(futureJvpp, interfaceContext));
-
- final CompositeListWriter<SubInterface, SubInterfaceKey> subInterfaceWriter = new CompositeListWriter<>(
- SubInterface.class,
- childWriters,
- new SubInterfaceCustomizer(futureJvpp, interfaceContext));
-
- final ChildWriter<SubInterfaces> subInterfacesWriter = new CompositeChildWriter<>(
- SubInterfaces.class,
- singletonChildWriterList(subInterfaceWriter),
- new ReflexiveChildWriterCustomizer<>());
+ @Override
+ public void init(final ModifiableWriterRegistry registry) {
+ final InstanceIdentifier<SubinterfaceAugmentation> subIfcAugId =
+ ifcId.augmentation(SubinterfaceAugmentation.class);
+ // Subinterfaces
+ // Subinterface(Handle only after all interface related stuff gets processed) =
+ final InstanceIdentifier<SubInterface> subIfcId = subIfcAugId.child(SubInterfaces.class).child(SubInterface.class);
+ registry.addSubtreeWriterAfter(
+ // TODO this customizer covers quite a lot of complex child nodes (maybe refactor ?)
+ Sets.newHashSet(
+ InstanceIdentifier.create(SubInterface.class).child(Tags.class),
+ InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
+ InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(
+ Dot1qTag.class),
+ InstanceIdentifier.create(SubInterface.class).child(Match.class),
+ InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
+ new GenericListWriter<>(subIfcId, new SubInterfaceCustomizer(jvpp, ifcContext)),
+ ifcId);
+ // L2 =
+ final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2>
+ l2Id = subIfcId.child(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2.class);
+ registry.addWriterAfter(new GenericWriter<>(l2Id, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)),
+ subIfcId);
+ // Rewrite(also handles pushTags + pushTags/dot1qtag) =
+ final InstanceIdentifier<Rewrite> rewriteId = l2Id.child(Rewrite.class);
+ registry.addSubtreeWriterAfter(
+ Sets.newHashSet(
+ InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
+ InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
+ new GenericWriter<>(rewriteId, new RewriteCustomizer(jvpp, ifcContext)),
+ l2Id);
+ // Ipv4(handled after L2 and L2/rewrite is done) =
+ final InstanceIdentifier<Address> ipv4SubifcAddressId = subIfcId.child(Ipv4.class).child(Address.class);
+ registry.addWriterAfter(new GenericListWriter<>(ipv4SubifcAddressId,
+ new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)),
+ rewriteId);
- return new CompositeChildWriter<>(
- SubinterfaceAugmentation.class,
- singletonChildWriterList(subInterfacesWriter),
- RWUtils.emptyAugWriterList(),
- new ReflexiveAugmentWriterCustomizer<>());
}
}
diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppHoneycombWriterModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppHoneycombWriterModule.java
index 6bf3da104..d9a542bde 100644
--- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppHoneycombWriterModule.java
+++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppHoneycombWriterModule.java
@@ -1,25 +1,18 @@
package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
-import io.fd.honeycomb.v3po.translate.util.write.CloseableWriter;
-import io.fd.honeycomb.v3po.translate.util.write.NoopWriterCustomizer;
-import io.fd.honeycomb.v3po.translate.util.write.ReflexiveChildWriterCustomizer;
+import io.fd.honeycomb.v3po.translate.impl.write.GenericListWriter;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.vpp.BridgeDomainCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.vpp.L2FibEntryCustomizer;
-import io.fd.honeycomb.v3po.translate.write.ChildWriter;
-import java.util.ArrayList;
-import java.util.List;
+import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry;
+import io.fd.honeycomb.v3po.translate.write.WriterFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.future.FutureJVpp;
public class VppHoneycombWriterModule extends
org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractVppHoneycombWriterModule {
@@ -42,38 +35,45 @@ public class VppHoneycombWriterModule extends
@Override
public java.lang.AutoCloseable createInstance() {
- final CompositeListWriter<BridgeDomain, BridgeDomainKey> bridgeDomainWriter = new CompositeListWriter<>(
- BridgeDomain.class,
- RWUtils.singletonChildWriterList(l2FibTableWriter()),
- new BridgeDomainCustomizer(getVppJvppWriterDependency(), getBridgeDomainContextVppDependency()));
-
- final ChildWriter<BridgeDomains> bridgeDomainsWriter = new CompositeChildWriter<>(
- BridgeDomains.class,
- RWUtils.singletonChildWriterList(bridgeDomainWriter),
- new ReflexiveChildWriterCustomizer<>());
-
- final List<ChildWriter<? extends ChildOf<Vpp>>> childWriters = new ArrayList<>();
- childWriters.add(bridgeDomainsWriter);
-
- return new CloseableWriter<>(new CompositeRootWriter<>(
- Vpp.class,
- childWriters,
- new NoopWriterCustomizer<>()));
+ return new VppHoneycombWriterFactory(
+ getVppJvppWriterDependency(),
+ getBridgeDomainContextVppDependency(),
+ getInterfaceContextVppDependency());
}
- private ChildWriter l2FibTableWriter() {
- final CompositeListWriter<L2FibEntry, L2FibEntryKey> l2FibEntryWriter =
- new CompositeListWriter<>(L2FibEntry.class,
- new L2FibEntryCustomizer(getVppJvppWriterDependency(),
- getBridgeDomainContextVppDependency(), getInterfaceContextVppDependency()));
+ private static final class VppHoneycombWriterFactory implements WriterFactory, AutoCloseable {
- final ChildWriter<L2FibTable> l2FibTableWriter = new CompositeChildWriter<>(
- L2FibTable.class,
- RWUtils.singletonChildWriterList(l2FibEntryWriter),
- new ReflexiveChildWriterCustomizer<>());
+ private final FutureJVpp jvpp;
+ private final NamingContext bdContext;
+ private final NamingContext ifcContext;
- return l2FibTableWriter;
- }
+ VppHoneycombWriterFactory(final FutureJVpp vppJvppWriterDependency,
+ final NamingContext bridgeDomainContextVppDependency,
+ final NamingContext interfaceContextVppDependency) {
+ this.jvpp = vppJvppWriterDependency;
+ this.bdContext = bridgeDomainContextVppDependency;
+ this.ifcContext = interfaceContextVppDependency;
+ }
+ @Override
+ public void close() throws Exception {
+ // unregister is not supported in ModifiableWriterRegistry (not really needed though)
+ }
+ @Override
+ public void init(final ModifiableWriterRegistry registry) {
+ // Vpp has no handlers
+ // BridgeDomains has no handlers
+ // BridgeDomain =
+ final InstanceIdentifier<BridgeDomain> bdId =
+ InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child(BridgeDomain.class);
+ registry.addWriter(new GenericListWriter<>(bdId, new BridgeDomainCustomizer(jvpp, bdContext)));
+ // L2FibTable has no handlers
+ // L2FibEntry(handled after BridgeDomain) =
+ final InstanceIdentifier<L2FibEntry> l2FibEntryId = bdId.child(L2FibTable.class).child(L2FibEntry.class);
+ registry.addWriterAfter(
+ new GenericListWriter<>(l2FibEntryId, new L2FibEntryCustomizer(jvpp, bdContext, ifcContext)),
+ bdId);
+ }
+ }
}
diff --git a/v3po/v3po2vpp/src/main/yang/v3po2vpp.yang b/v3po/v3po2vpp/src/main/yang/v3po2vpp.yang
index cf89cbd51..8a5527248 100644
--- a/v3po/v3po2vpp/src/main/yang/v3po2vpp.yang
+++ b/v3po/v3po2vpp/src/main/yang/v3po2vpp.yang
@@ -149,7 +149,7 @@ module v3po2vpp {
identity vpp-honeycomb-writer {
base config:module-type;
- config:provided-service tapi:honeycomb-writer;
+ config:provided-service tapi:honeycomb-writer-factory;
}
augment "/config:modules/config:module/config:configuration" {
@@ -187,7 +187,7 @@ module v3po2vpp {
identity interfaces-honeycomb-writer {
base config:module-type;
- config:provided-service tapi:honeycomb-writer;
+ config:provided-service tapi:honeycomb-writer-factory;
}
augment "/config:modules/config:module/config:configuration" {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
deleted file mode 100644
index e713c623d..000000000
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * 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.honeycomb.v3po.translate.v3po.vpp;
-
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
-import io.fd.honeycomb.v3po.translate.MappingContext;
-import io.fd.honeycomb.v3po.translate.ModificationCache;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
-import io.fd.honeycomb.v3po.translate.util.write.DelegatingWriterRegistry;
-import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.v3po.translate.write.WriteContext;
-import io.fd.honeycomb.v3po.translate.write.Writer;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomainsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.dto.BridgeDomainAddDel;
-import org.openvpp.jvpp.dto.BridgeDomainAddDelReply;
-import org.openvpp.jvpp.future.FutureJVpp;
-
-public class VppTest {
-
- private static final byte ADD_OR_UPDATE_BD = 1;
- private static final byte ZERO = 0;
- private static final String BD_NAME = "bdn1";
- private static final String BD_CONTEXT_NAME = "test-instance";
-
- @Mock
- private FutureJVpp api;
- @Mock
- private WriteContext ctx;
- @Mock
- private MappingContext mappingContext;
-
- private DelegatingWriterRegistry rootRegistry;
- private CompositeRootWriter<Vpp> vppWriter;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- NamingContext bdContext = new NamingContext("generatedBdName", BD_CONTEXT_NAME);
- final ModificationCache toBeReturned = new ModificationCache();
- doReturn(toBeReturned).when(ctx).getModificationCache();
- doReturn(mappingContext).when(ctx).getMappingContext();
-
- vppWriter = VppUtils.getVppWriter(api, bdContext);
- rootRegistry = new DelegatingWriterRegistry(
- Collections.<Writer<? extends DataObject>>singletonList(vppWriter));
- }
-
- private BridgeDomains getBridgeDomains(String... name) {
- final List<BridgeDomain> bdmns = Lists.newArrayList();
- for (String s : name) {
- bdmns.add(new BridgeDomainBuilder()
- .setName(s)
- .setArpTermination(false)
- .setFlood(true)
- .setForward(false)
- .setLearn(true)
- .build());
- }
- return new BridgeDomainsBuilder()
- .setBridgeDomain(bdmns)
- .build();
- }
-
- private void whenBridgeDomainAddDelThenSuccess()
- throws ExecutionException, VppInvocationException, InterruptedException {
- final CompletionStage<BridgeDomainAddDelReply> replyCs = mock(CompletionStage.class);
- final CompletableFuture<BridgeDomainAddDelReply> replyFuture = mock(CompletableFuture.class);
- when(replyCs.toCompletableFuture()).thenReturn(replyFuture);
- final BridgeDomainAddDelReply reply = new BridgeDomainAddDelReply();
- when(replyFuture.get()).thenReturn(reply);
- when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(replyCs);
- }
-
- private void verifyBridgeDomainAddDel(final BridgeDomain bd, final int bdId) throws VppInvocationException {
- final byte arpTerm = BridgeDomainTestUtils.booleanToByte(bd.isArpTermination());
- final byte flood = BridgeDomainTestUtils.booleanToByte(bd.isFlood());
- final byte forward = BridgeDomainTestUtils.booleanToByte(bd.isForward());
- final byte learn = BridgeDomainTestUtils.booleanToByte(bd.isLearn());
- final byte uuf = BridgeDomainTestUtils.booleanToByte(bd.isUnknownUnicastFlood());
-
- // TODO adding equals methods for jvpp DTOs would make ArgumentCaptor usage obsolete
- ArgumentCaptor<BridgeDomainAddDel> argumentCaptor = ArgumentCaptor.forClass(BridgeDomainAddDel.class);
- verify(api).bridgeDomainAddDel(argumentCaptor.capture());
- final BridgeDomainAddDel actual = argumentCaptor.getValue();
- assertEquals(arpTerm, actual.arpTerm);
- assertEquals(flood, actual.flood);
- assertEquals(forward, actual.forward);
- assertEquals(learn, actual.learn);
- assertEquals(uuf, actual.uuFlood);
- assertEquals(ADD_OR_UPDATE_BD, actual.isAdd);
- assertEquals(bdId, actual.bdId);
- }
-
- private void verifyBridgeDomainDeleteWasInvoked(final int bdId) throws VppInvocationException {
- ArgumentCaptor<BridgeDomainAddDel> argumentCaptor = ArgumentCaptor.forClass(BridgeDomainAddDel.class);
- verify(api).bridgeDomainAddDel(argumentCaptor.capture());
- final BridgeDomainAddDel actual = argumentCaptor.getValue();
- assertEquals(bdId, actual.bdId);
- assertEquals(ZERO, actual.arpTerm);
- assertEquals(ZERO, actual.flood);
- assertEquals(ZERO, actual.forward);
- assertEquals(ZERO, actual.learn);
- assertEquals(ZERO, actual.uuFlood);
- assertEquals(ZERO, actual.isAdd);
- }
-
- @Test
- public void writeVppUsingRootRegistry() throws Exception {
- final int bdId = 1;
- final BridgeDomains bdn1 = getBridgeDomains(BD_NAME);
- whenBridgeDomainAddDelThenSuccess();
-
- // Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(getMappingIid(BD_NAME, BD_CONTEXT_NAME).firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(getMappingIid(BD_NAME, BD_CONTEXT_NAME));
-
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- null,
- new VppBuilder().setBridgeDomains(bdn1).build(),
- ctx);
-
- verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
- }
-
- @Test
- public void writeVppUsingVppWriter() throws Exception {
- final int bdId = 1;
- final BridgeDomains bdn1 = getBridgeDomains(BD_NAME);
- whenBridgeDomainAddDelThenSuccess();
-
- // Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(getMappingIid(BD_NAME, BD_CONTEXT_NAME).firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(getMappingIid(BD_NAME, BD_CONTEXT_NAME));
-
- vppWriter.update(InstanceIdentifier.create(Vpp.class),
- null,
- new VppBuilder().setBridgeDomains(bdn1).build(),
- ctx);
-
- verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
- verify(mappingContext).put(getMappingIid(BD_NAME, BD_CONTEXT_NAME), getMapping(BD_NAME, 1).get());
- }
-
- @Test
- public void writeVppFromRoot() throws Exception {
- final BridgeDomains bdn1 = getBridgeDomains(BD_NAME);
- final int bdId = 1;
- final Vpp vpp = new VppBuilder().setBridgeDomains(bdn1).build();
- whenBridgeDomainAddDelThenSuccess();
-
- // Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(getMappingIid(BD_NAME, BD_CONTEXT_NAME).firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(getMappingIid(BD_NAME, BD_CONTEXT_NAME));
-
- rootRegistry.update(Collections.emptyMap(),
- Collections.<InstanceIdentifier<?>, DataObject>singletonMap(InstanceIdentifier.create(Vpp.class),
- vpp), ctx);
-
- verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
- }
-
- @Test
- public void deleteVpp() throws Exception {
- final BridgeDomains bdn1 = getBridgeDomains(BD_NAME);
- final int bdId = 1;
- whenBridgeDomainAddDelThenSuccess();
- doReturn(getMapping(BD_NAME, bdId)).when(mappingContext).read(getMappingIid(BD_NAME, BD_CONTEXT_NAME));
-
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(bdn1).build(),
- null,
- ctx);
-
- verifyBridgeDomainDeleteWasInvoked(bdId);
- }
-
- @Test
- public void updateVppNoActualChange() throws Exception {
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(getBridgeDomains(BD_NAME)).build(),
- new VppBuilder().setBridgeDomains(getBridgeDomains(BD_NAME)).build(),
- ctx);
-
- verifyZeroInteractions(api);
- }
-
- @Test
- public void writeUpdate() throws Exception {
- final int bdn1Id = 1;
- doReturn(getMapping(BD_NAME, bdn1Id)).when(mappingContext).read(getMappingIid(BD_NAME, BD_CONTEXT_NAME));
-
- final BridgeDomains domainsBefore = getBridgeDomains(BD_NAME);
- final BridgeDomain bdn1Before = domainsBefore.getBridgeDomain().get(0);
-
- final BridgeDomain bdn1After = new BridgeDomainBuilder(bdn1Before).setFlood(!bdn1Before.isFlood()).build();
- final BridgeDomains domainsAfter = new BridgeDomainsBuilder()
- .setBridgeDomain(Collections.singletonList(bdn1After))
- .build();
-
- whenBridgeDomainAddDelThenSuccess();
-
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(domainsBefore).build(),
- new VppBuilder().setBridgeDomains(domainsAfter).build(),
- ctx);
-
- // bdn1 is created with negated flood value
- verifyBridgeDomainAddDel(bdn1After, bdn1Id);
- }
-
- // TODO test unkeyed list
- // TODO test update of a child without dedicated writer
-} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java
deleted file mode 100644
index 4b3eb5adc..000000000
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.honeycomb.v3po.translate.v3po.vpp;
-
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
-import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
-import io.fd.honeycomb.v3po.translate.util.write.NoopWriterCustomizer;
-import io.fd.honeycomb.v3po.translate.util.write.ReflexiveChildWriterCustomizer;
-import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.v3po.translate.write.ChildWriter;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
-import org.openvpp.jvpp.future.FutureJVpp;
-
-final class VppUtils {
-
- public VppUtils() {}
-
- /**
- * Create root Vpp writer with all its children wired
- */
- static CompositeRootWriter<Vpp> getVppWriter(@Nonnull final FutureJVpp vppApi, final NamingContext bdContext) {
-
- final CompositeListWriter<BridgeDomain, BridgeDomainKey> bridgeDomainWriter = new CompositeListWriter<>(
- BridgeDomain.class,
- new BridgeDomainCustomizer(vppApi, bdContext));
-
- final ChildWriter<BridgeDomains> bridgeDomainsReader = new CompositeChildWriter<>(
- BridgeDomains.class,
- RWUtils.singletonChildWriterList(bridgeDomainWriter),
- new ReflexiveChildWriterCustomizer<BridgeDomains>());
-
- final List<ChildWriter<? extends ChildOf<Vpp>>> childWriters = new ArrayList<>();
- childWriters.add(bridgeDomainsReader);
-
- return new CompositeRootWriter<>(
- Vpp.class,
- childWriters,
- new NoopWriterCustomizer<Vpp>());
- }
-}