From 4e6b846c342b2c9e9443e3d3472685e5acb32fa3 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Wed, 13 Jul 2016 11:52:51 +0200 Subject: HONEYCOMB-122 Update reader registry to share similar APIs as writer + Extract common registry builder base code (Reader registry is not flat, so there is not full control over ordering as with writers but it is sufficient) + Split CompositeReader into CompositeReader, SubtreeReader and GenericReader + No need to build composite structure in ReaderFactories (registry does that internally) + Keep only ReaderCustomizer + ListReaderCustomizer, no root reader (same for writers) Change-Id: Ic4e5bc96ad47a6cbcada4efcc2209db5c16d2a6c Signed-off-by: Maros Marsalek --- .../rev160406/InterfacesHoneycombWriterModule.java | 60 +++--- .../InterfacesStateHoneycombReaderModule.java | 208 ++++++++++----------- .../xml/ns/yang/v3po2vpp/rev160406/Readme.adoc | 42 ++++- .../SubinterfaceAugmentationWriterFactory.java | 17 +- ...SubinterfaceStateAugmentationReaderFactory.java | 139 +++++++------- .../VppClassifierHoneycombWriterModule.java | 8 +- .../VppClassifierStateHoneycombReaderModule.java | 66 ++++--- .../rev160406/VppHoneycombWriterModule.java | 8 +- .../rev160406/VppStateHoneycombReaderModule.java | 127 +++++++------ 9 files changed, 353 insertions(+), 322 deletions(-) (limited to 'v3po/v3po2vpp/src/main/java/org/opendaylight') 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 64f1e8a7c..635c77a0b 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 @@ -20,7 +20,7 @@ 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.v3po.util.NamingContext; -import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry; +import io.fd.honeycomb.v3po.translate.write.registry.ModifiableWriterRegistryBuilder; 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; @@ -106,10 +106,10 @@ public class InterfacesHoneycombWriterModule extends } @Override - public void init(final ModifiableWriterRegistry registry) { + public void init(final ModifiableWriterRegistryBuilder registry) { // Interfaces // Interface = - registry.addWriter(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcContext))); + registry.add(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcContext))); // VppInterfaceAugmentation addVppInterfaceAgmentationWriters(IFC_ID, registry); // Interface1 (ietf-ip augmentation) @@ -119,65 +119,63 @@ public class InterfacesHoneycombWriterModule extends } private void addInterface1AugmentationWriters(final InstanceIdentifier ifcId, - final ModifiableWriterRegistry registry) { + final ModifiableWriterRegistryBuilder registry) { final InstanceIdentifier ifc1AugId = ifcId.augmentation(Interface1.class); // Ipv6(after interface) TODO unfinished customizer = - registry.addWriterAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)), - ifcId); + registry.addAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)), + ifcId); // Ipv4(after interface) final InstanceIdentifier ipv4Id = ifc1AugId.child(Ipv4.class); - registry.addWriterAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)), - ifcId); + registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)), + ifcId); // Address(after Ipv4) = final InstanceIdentifier
ipv4AddressId = ipv4Id.child(Address.class); - registry.addWriterAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)), - ipv4Id); + registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)), + ipv4Id); // Neighbor(after ipv4Address) - registry.addWriterAfter( - new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)), - ipv4AddressId); + registry.addAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)), + ipv4AddressId); } private void addVppInterfaceAgmentationWriters(final InstanceIdentifier ifcId, - final ModifiableWriterRegistry registry) { + final ModifiableWriterRegistryBuilder registry) { // VhostUser(Needs to be executed before Interface customizer) = final InstanceIdentifier vhostId = VPP_IFC_AUG_ID.child(VhostUser.class); - registry.addWriterBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)), - ifcId); + registry.addBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)), + ifcId); // Vxlan(Needs to be executed before Interface customizer) = final InstanceIdentifier vxlanId = VPP_IFC_AUG_ID.child(Vxlan.class); - registry.addWriterBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)), - ifcId); + registry.addBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)), + ifcId); // VxlanGpe(Needs to be executed before Interface customizer) = final InstanceIdentifier vxlanGpeId = VPP_IFC_AUG_ID.child(VxlanGpe.class); - registry.addWriterBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)), - ifcId); + registry.addBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)), + ifcId); // Tap(Needs to be executed before Interface customizer) = final InstanceIdentifier tapId = VPP_IFC_AUG_ID.child(Tap.class); - registry.addWriterBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)), - ifcId); + registry.addBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)), + ifcId); final Set> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId); // Ethernet(No dependency, customizer not finished TODO) = - registry.addWriter(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp))); + registry.add(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp))); // Routing(Execute only after specific interface customizers) = - registry.addWriterAfter( - new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)), - specificIfcTypes); + registry.addAfter( + new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)), + specificIfcTypes); // Routing(Execute only after specific interface customizers) = - registry.addWriterAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcContext, bdContext)), - specificIfcTypes); + registry.addAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcContext, bdContext)), + specificIfcTypes); // ACL (execute after classify table and session writers) // also handles L2Acl, Ip4Acl and Ip6Acl: final InstanceIdentifier aclId = InstanceIdentifier.create(Acl.class); registry - .addSubtreeWriterAfter( + .subtreeAddAfter( Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)), new GenericWriter<>(ACL_ID, new AclCustomizer(jvpp, ifcContext, classifyTableContext)), - Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID) - ); + Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID)); } } diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesStateHoneycombReaderModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesStateHoneycombReaderModule.java index 5c89961b9..83758d828 100644 --- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesStateHoneycombReaderModule.java +++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/InterfacesStateHoneycombReaderModule.java @@ -1,19 +1,10 @@ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406; -import static io.fd.honeycomb.v3po.translate.util.RWUtils.emptyAugReaderList; -import static io.fd.honeycomb.v3po.translate.util.RWUtils.emptyChildReaderList; -import static io.fd.honeycomb.v3po.translate.util.RWUtils.singletonChildReaderList; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeChildReader; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader; -import io.fd.honeycomb.v3po.translate.read.ChildReader; -import io.fd.honeycomb.v3po.translate.util.RWUtils; -import io.fd.honeycomb.v3po.translate.util.read.CloseableReader; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveAugmentReaderCustomizer; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer; +import com.google.common.collect.Sets; +import io.fd.honeycomb.v3po.translate.impl.read.GenericListReader; +import io.fd.honeycomb.v3po.translate.impl.read.GenericReader; +import io.fd.honeycomb.v3po.translate.read.ReaderFactory; +import io.fd.honeycomb.v3po.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.AclCustomizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.EthernetCustomizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceCustomizer; @@ -26,13 +17,10 @@ import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.ip.Ipv4AddressCustomi import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.ip.Ipv4Customizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.ip.Ipv4NeighbourCustomizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.ip.Ipv6Customizer; -import java.util.ArrayList; -import java.util.List; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; @@ -41,6 +29,9 @@ 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.state._interface.ipv4.Neighbor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2; @@ -48,11 +39,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VhostUser; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Vxlan; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpe; -import org.opendaylight.yangtools.yang.binding.Augmentation; -import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.future.FutureJVpp; public class InterfacesStateHoneycombReaderModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractInterfacesStateHoneycombReaderModule { + + public static final InstanceIdentifier IFC_STATE_ID = InstanceIdentifier.create(InterfacesState.class); + static final InstanceIdentifier IFC_ID = IFC_STATE_ID.child(Interface.class); + public InterfacesStateHoneycombReaderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); @@ -72,94 +67,93 @@ public class InterfacesStateHoneycombReaderModule extends @Override public java.lang.AutoCloseable createInstance() { - final List>> - interfaceAugReaders = new ArrayList<>(); - interfaceAugReaders.add(getVppInterfaceStateAugmentationReader()); - interfaceAugReaders.add(getInterface1AugmentationReader()); - interfaceAugReaders.add(SubinterfaceStateAugmentationReaderFactory.createInstance(getVppJvppDependency(), - getInterfaceContextIfcStateDependency(), getBridgeDomainContextIfcStateDependency(), - getClassifyTableContextDependency())); - - final CompositeListReader interfaceReader = - new CompositeListReader<>(Interface.class, - emptyChildReaderList(), - interfaceAugReaders, - new InterfaceCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - return new CloseableReader<>(new CompositeRootReader<>( - InterfacesState.class, - singletonChildReaderList(interfaceReader), - emptyAugReaderList(), - new ReflexiveRootReaderCustomizer<>(InterfacesStateBuilder.class))); - } - - private ChildReader> getInterface1AugmentationReader() { - - final ChildReader neighborReader = new CompositeListReader<>(Neighbor.class, - new Ipv4NeighbourCustomizer(getVppJvppDependency())); - - final ChildReader
addressReader = new CompositeListReader<>(Address.class, - new Ipv4AddressCustomizer(getVppJvppDependency(),getInterfaceContextIfcStateDependency())); - - final ChildReader> ipv4Reader = new CompositeChildReader<>(Ipv4.class, - ImmutableList.of(neighborReader,addressReader), - new Ipv4Customizer(getVppJvppDependency())); - final ChildReader> ipv6Reader = new CompositeChildReader<>(Ipv6.class, - new Ipv6Customizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - final List>> interface1ChildWriters = Lists.newArrayList(); - interface1ChildWriters.add(ipv4Reader); - interface1ChildWriters.add(ipv6Reader); - - return new CompositeChildReader<>(Interface2.class, interface1ChildWriters, - new ReflexiveAugmentReaderCustomizer<>(Interface2Builder.class, Interface2.class)); + return new VppStateReaderFactory(getVppJvppDependency(), + getInterfaceContextIfcStateDependency(), + getBridgeDomainContextIfcStateDependency(), + getClassifyTableContextDependency()); } - - private ChildReader> getVppInterfaceStateAugmentationReader() { - - final ChildReader> ethernetReader = - new CompositeChildReader<>(Ethernet.class, - new EthernetCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - final ChildReader> tapReader = - new CompositeChildReader<>(Tap.class, - new TapCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - final ChildReader> vhostUserReader = - new CompositeChildReader<>(VhostUser.class, - new VhostUserCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - final ChildReader> vxlanReader = - new CompositeChildReader<>(Vxlan.class, - new VxlanCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - final ChildReader> vxlanGpeReader = - new CompositeChildReader<>(VxlanGpe.class, - new VxlanGpeCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency())); - - final ChildReader> aclReader = - new CompositeChildReader<>(Acl.class, - new AclCustomizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency(), getClassifyTableContextDependency())); - - final ChildReader> l2Reader = - new CompositeChildReader<>(L2.class, - new L2Customizer(getVppJvppDependency(), getInterfaceContextIfcStateDependency(), getBridgeDomainContextIfcStateDependency())); - - final List>> childReaders = Lists.newArrayList(); - childReaders.add(ethernetReader); - childReaders.add(tapReader); - childReaders.add(vhostUserReader); - childReaders.add(vxlanReader); - childReaders.add(vxlanGpeReader); - childReaders.add(l2Reader); - childReaders.add(aclReader); - - final ChildReader vppInterfaceStateAugmentationChildReader = - new CompositeChildReader<>(VppInterfaceStateAugmentation.class, - childReaders, - new ReflexiveAugmentReaderCustomizer<>(VppInterfaceStateAugmentationBuilder.class, - VppInterfaceStateAugmentation.class)); - return vppInterfaceStateAugmentationChildReader; + private static final class VppStateReaderFactory implements ReaderFactory, AutoCloseable { + + private NamingContext ifcCtx; + private NamingContext bdCtx; + private NamingContext classifyCtx; + private FutureJVpp jvpp; + + VppStateReaderFactory(final FutureJVpp jvpp, + final NamingContext ifcCtx, + final NamingContext bdCtx, + final NamingContext classifyCtx) { + this.jvpp = jvpp; + this.ifcCtx = ifcCtx; + this.bdCtx = bdCtx; + this.classifyCtx = classifyCtx; + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // InterfacesState(Structural) + registry.addStructuralReader(IFC_STATE_ID, InterfacesStateBuilder.class); + // Interface + registry.add(new GenericListReader<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcCtx))); + + // v3po.yang + initVppIfcAugmentationReaders(registry, IFC_ID); + // ietf-ip.yang + initInterface2AugmentationReaders(registry, IFC_ID); + // vpp-vlan.yang + new SubinterfaceStateAugmentationReaderFactory(jvpp, ifcCtx, bdCtx, classifyCtx).init(registry); + } + + private void initInterface2AugmentationReaders(final ModifiableReaderRegistryBuilder registry, + final InstanceIdentifier ifcId) { + // Interface2Augmentation(Structural) + final InstanceIdentifier ifc2AugId = ifcId.augmentation(Interface2.class); + registry.addStructuralReader(ifc2AugId, Interface2Builder.class); + // Ipv4 + // TODO unfinished customizer + final InstanceIdentifier ipv4Id = ifc2AugId.child(Ipv4.class); + registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp))); + // Address + final InstanceIdentifier
ipv4AddrId = ipv4Id.child(Address.class); + registry.add(new GenericListReader<>(ipv4AddrId, new Ipv4AddressCustomizer(jvpp, ifcCtx))); + // Neighbor + final InstanceIdentifier neighborId = ipv4Id.child(Neighbor.class); + registry.add(new GenericListReader<>(neighborId, new Ipv4NeighbourCustomizer(jvpp))); + // Ipv6 + // TODO unfinished customizer + final InstanceIdentifier ipv6Id = ifc2AugId.child(Ipv6.class); + registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp, ifcCtx))); + } + + private void initVppIfcAugmentationReaders(final ModifiableReaderRegistryBuilder registry, + final InstanceIdentifier ifcId) { + // VppInterfaceStateAugmentation + final InstanceIdentifier vppIfcAugId = ifcId.augmentation(VppInterfaceStateAugmentation.class); + registry.addStructuralReader(vppIfcAugId, VppInterfaceStateAugmentationBuilder.class); + // Ethernet + registry.add(new GenericReader<>(vppIfcAugId.child(Ethernet.class), new EthernetCustomizer(jvpp, ifcCtx))); + // Tap + registry.add(new GenericReader<>(vppIfcAugId.child(Tap.class), new TapCustomizer(jvpp, ifcCtx))); + // VhostUser + registry.add(new GenericReader<>(vppIfcAugId.child(VhostUser.class), new VhostUserCustomizer(jvpp, ifcCtx))); + // Vxlan + registry.add(new GenericReader<>(vppIfcAugId.child(Vxlan.class), new VxlanCustomizer(jvpp, ifcCtx))); + // VxlanGpe + registry.add(new GenericReader<>(vppIfcAugId.child(VxlanGpe.class), new VxlanGpeCustomizer(jvpp, ifcCtx))); + // L2 + registry.add(new GenericReader<>(vppIfcAugId.child(L2.class), new L2Customizer(jvpp, ifcCtx, bdCtx))); + // Acl(Subtree) + final InstanceIdentifier aclIdRelative = InstanceIdentifier.create(Acl.class); + registry.subtreeAdd( + Sets.newHashSet(aclIdRelative.child(L2Acl.class), aclIdRelative.child(Ip4Acl.class), aclIdRelative.child(Ip6Acl.class)), + new GenericReader<>(vppIfcAugId.child(Acl.class), new AclCustomizer(jvpp, ifcCtx, classifyCtx))); + + } + + @Override + public void close() throws Exception { + // unregister not supported + } } } diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/Readme.adoc b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/Readme.adoc index 8917105f5..d6fa3770d 100644 --- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/Readme.adoc +++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/Readme.adoc @@ -15,6 +15,9 @@ Current order of v3po-api writers is: . L2 . Ethernet . Routing +. ClassifySession +. ClassifyTable +. Acl . Ipv6 . Ipv4 . Address @@ -22,9 +25,46 @@ Current order of v3po-api writers is: . L2FibEntry . Rewrite . Address +. Acl To find out current order in runtime, turn on logging for writer registry: log:set TRACE io.fd.honeycomb.v3po.translate.util.write.registry -== Readers \ No newline at end of file +== Readers +There is not a strict order for readers, but current configuration produces approx. this order: + +Contexts +. VppState +. Version +. BridgeDomains +. BridgeDomain +. L2FibTable +. L2FibEntry +. InterfacesState +. Interface +. VppInterfaceStateAugmentation +. Ethernet +. Tap +. VhostUser +. Vxlan +. VxlanGpe +. L2 +. Acl +. Interface2 +. Ipv4 +. Address +. Neighbor +. Ipv6 +. SubinterfaceStateAugmentation +. SubInterfaces +. SubInterface +. L2 +. Rewrite +. Ipv4 +. Address +. Acl +. VppClassifierState +. ClassifyTable +. ClassifySession +. NetconfState \ No newline at end of file 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 60a9c2e2c..034056425 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 @@ -28,7 +28,7 @@ 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.ModifiableWriterRegistry; +import io.fd.honeycomb.v3po.translate.write.registry.ModifiableWriterRegistryBuilder; 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.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl; @@ -74,10 +74,10 @@ final class SubinterfaceAugmentationWriterFactory implements WriterFactory { } @Override - public void init(final ModifiableWriterRegistry registry) { + public void init(final ModifiableWriterRegistryBuilder registry) { // Subinterfaces // Subinterface(Handle only after all interface related stuff gets processed) = - registry.addSubtreeWriterAfter( + registry.subtreeAddAfter( // TODO this customizer covers quite a lot of complex child nodes (maybe refactor ?) Sets.newHashSet( InstanceIdentifier.create(SubInterface.class).child(Tags.class), @@ -89,11 +89,11 @@ final class SubinterfaceAugmentationWriterFactory implements WriterFactory { new GenericListWriter<>(SUB_IFC_ID, new SubInterfaceCustomizer(jvpp, ifcContext)), InterfacesHoneycombWriterModule.IFC_ID); // L2 = - registry.addWriterAfter(new GenericWriter<>(L2_ID, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)), + registry.addAfter(new GenericWriter<>(L2_ID, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)), SUB_IFC_ID); // Rewrite(also handles pushTags + pushTags/dot1qtag) = final InstanceIdentifier rewriteId = L2_ID.child(Rewrite.class); - registry.addSubtreeWriterAfter( + registry.subtreeAddAfter( Sets.newHashSet( InstanceIdentifier.create(Rewrite.class).child(PushTags.class), InstanceIdentifier.create(Rewrite.class).child(PushTags.class) @@ -102,7 +102,7 @@ final class SubinterfaceAugmentationWriterFactory implements WriterFactory { L2_ID); // Ipv4(handled after L2 and L2/rewrite is done) = final InstanceIdentifier
ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class); - registry.addWriterAfter(new GenericListWriter<>(ipv4SubifcAddressId, + registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId, new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)), rewriteId); @@ -110,11 +110,10 @@ final class SubinterfaceAugmentationWriterFactory implements WriterFactory { // also handles L2Acl, Ip4Acl and Ip6Acl: final InstanceIdentifier aclId = InstanceIdentifier.create(Acl.class); registry - .addSubtreeWriterAfter( + .subtreeAddAfter( Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)), new GenericWriter<>(SUBIF_ACL_ID, new SubInterfaceAclCustomizer(jvpp, ifcContext, classifyTableContext)), - Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID) - ); + Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID)); } } diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceStateAugmentationReaderFactory.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceStateAugmentationReaderFactory.java index 7dfe4d289..42e8c5b34 100644 --- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceStateAugmentationReaderFactory.java +++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/SubinterfaceStateAugmentationReaderFactory.java @@ -16,104 +16,91 @@ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406; -import static io.fd.honeycomb.v3po.translate.util.RWUtils.singletonChildReaderList; - -import io.fd.honeycomb.v3po.translate.impl.read.CompositeChildReader; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader; -import io.fd.honeycomb.v3po.translate.read.ChildReader; -import io.fd.honeycomb.v3po.translate.util.RWUtils; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveAugmentReaderCustomizer; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveChildReaderCustomizer; +import com.google.common.collect.Sets; +import io.fd.honeycomb.v3po.translate.impl.read.GenericListReader; +import io.fd.honeycomb.v3po.translate.impl.read.GenericReader; +import io.fd.honeycomb.v3po.translate.read.ReaderFactory; +import io.fd.honeycomb.v3po.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.RewriteCustomizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.SubInterfaceAclCustomizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.SubInterfaceCustomizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.SubInterfaceL2Customizer; import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.ip.SubInterfaceIpv4AddressCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nonnull; +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.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfacesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +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.Acl; 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.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.Ipv4Builder; 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 SubinterfaceStateAugmentationReaderFactory { - - private SubinterfaceStateAugmentationReaderFactory() { - } +final class SubinterfaceStateAugmentationReaderFactory implements ReaderFactory { - private static ChildReader getL2Reader(@Nonnull final FutureJVpp futureJvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext bridgeDomainContext) { - final ChildReader rewriteReader = new CompositeChildReader<>( - Rewrite.class, new RewriteCustomizer(futureJvpp, interfaceContext)); + private final FutureJVpp jvpp; + private final NamingContext ifcCtx; + private final NamingContext bdCtx; + private final NamingContext classifyCtx; - return new CompositeChildReader<>(L2.class, - singletonChildReaderList(rewriteReader), - new SubInterfaceL2Customizer(futureJvpp, interfaceContext, bridgeDomainContext)); + SubinterfaceStateAugmentationReaderFactory(final FutureJVpp jvpp, final NamingContext ifcCtx, + final NamingContext bdCtx, final NamingContext classifyCtx) { + this.jvpp = jvpp; + this.ifcCtx = ifcCtx; + this.bdCtx = bdCtx; + this.classifyCtx = classifyCtx; } - private static ChildReader getIpv4Reader(@Nonnull final FutureJVpp futureJvpp, - @Nonnull final NamingContext interfaceContext) { - - final ChildReader
addressReader = new CompositeListReader<>(Address.class, - new SubInterfaceIpv4AddressCustomizer(futureJvpp, interfaceContext)); - - return new CompositeChildReader<>( - Ipv4.class, - RWUtils.singletonChildReaderList(addressReader), - new ReflexiveChildReaderCustomizer<>(Ipv4Builder.class)); - - } - - private static ChildReader getAclReader(@Nonnull final FutureJVpp futureJvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext classifyTableContext) { - return new CompositeChildReader<>(Acl.class, - new SubInterfaceAclCustomizer(futureJvpp, interfaceContext, classifyTableContext)); - - } - - static ChildReader createInstance( - @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext bridgeDomainContext, - @Nonnull final NamingContext classifyTableContext) { - - List>> childReaders = new ArrayList<>(); - - // TODO can get rid of that cast? - childReaders.add((ChildReader) getL2Reader(futureJvpp, interfaceContext, bridgeDomainContext)); - childReaders.add((ChildReader) getIpv4Reader(futureJvpp, interfaceContext)); - childReaders.add((ChildReader) getAclReader(futureJvpp, interfaceContext, classifyTableContext)); - - final CompositeListReader subInterfaceReader = - new CompositeListReader<>(SubInterface.class, childReaders, new SubInterfaceCustomizer(futureJvpp, - interfaceContext)); - - final ChildReader subInterfacesReader = new CompositeChildReader<>( - SubInterfaces.class, - RWUtils.singletonChildReaderList(subInterfaceReader), - new ReflexiveChildReaderCustomizer<>(SubInterfacesBuilder.class)); - - final ChildReader subinterfaceStateAugmentationReader = - new CompositeChildReader<>(SubinterfaceStateAugmentation.class, - singletonChildReaderList(subInterfacesReader), - new ReflexiveAugmentReaderCustomizer<>( - SubinterfaceStateAugmentationBuilder.class, - SubinterfaceStateAugmentation.class)); - - return subinterfaceStateAugmentationReader; + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // SubinterfaceStateAugmentation(Structural) + final InstanceIdentifier subIfcAugId = + InterfacesStateHoneycombReaderModule.IFC_ID.augmentation(SubinterfaceStateAugmentation.class); + registry.addStructuralReader(subIfcAugId, SubinterfaceStateAugmentationBuilder.class); + // SubInterfaces(Structural) + final InstanceIdentifier subIfcsId = subIfcAugId.child(SubInterfaces.class); + registry.addStructuralReader(subIfcsId, SubInterfacesBuilder.class); + // SubInterface(Subtree) + final InstanceIdentifier subIfcId = subIfcsId.child(SubInterface.class); + registry.subtreeAdd(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 GenericListReader<>(subIfcId, new SubInterfaceCustomizer(jvpp, ifcCtx))); + // L2 + final InstanceIdentifier l2Id = subIfcId.child(L2.class); + registry.add(new GenericReader<>(l2Id, new SubInterfaceL2Customizer(jvpp, ifcCtx, bdCtx))); + // Rewrite(Subtree) + registry.subtreeAdd(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 GenericReader<>(l2Id.child(Rewrite.class), new RewriteCustomizer(jvpp, ifcCtx))); + // Ipv4(Structural) + final InstanceIdentifier ipv4Id = subIfcId.child(Ipv4.class); + registry.addStructuralReader(ipv4Id, Ipv4Builder.class); + // Address + registry.add(new GenericListReader<>(ipv4Id.child(Address.class), new SubInterfaceIpv4AddressCustomizer(jvpp, ifcCtx))); + // Acl(Subtree) + final InstanceIdentifier aclIdRelative = InstanceIdentifier.create(Acl.class); + registry.subtreeAdd( + Sets.newHashSet(aclIdRelative.child(L2Acl.class), aclIdRelative.child(Ip4Acl.class), aclIdRelative.child(Ip6Acl.class)), + new GenericReader<>(subIfcId.child(Acl.class), new SubInterfaceAclCustomizer(jvpp, ifcCtx, classifyCtx))); } } diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierHoneycombWriterModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierHoneycombWriterModule.java index b2fb5454a..ca05b392b 100644 --- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierHoneycombWriterModule.java +++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierHoneycombWriterModule.java @@ -6,8 +6,8 @@ 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.vppclassifier.ClassifySessionWriter; import io.fd.honeycomb.v3po.translate.v3po.vppclassifier.ClassifyTableWriter; -import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry; import io.fd.honeycomb.v3po.translate.write.WriterFactory; +import io.fd.honeycomb.v3po.translate.write.registry.ModifiableWriterRegistryBuilder; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifier; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySession; @@ -66,13 +66,13 @@ public class VppClassifierHoneycombWriterModule extends } @Override - public void init(final ModifiableWriterRegistry registry) { + public void init(final ModifiableWriterRegistryBuilder registry) { - registry.addWriterBefore( + registry.addBefore( new GenericListWriter<>(CLASSIFY_TABLE_ID, new ClassifyTableWriter(jvpp, classifyTableContext)), ACL_ID); - registry.addWriterAfter( + registry.addBefore( new GenericListWriter<>(CLASSIFY_SESSION_ID, new ClassifySessionWriter(jvpp, classifyTableContext)), CLASSIFY_TABLE_ID); } diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierStateHoneycombReaderModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierStateHoneycombReaderModule.java index bea7e0d13..4a91f2679 100644 --- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierStateHoneycombReaderModule.java +++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppClassifierStateHoneycombReaderModule.java @@ -1,23 +1,17 @@ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader; -import io.fd.honeycomb.v3po.translate.read.ChildReader; -import io.fd.honeycomb.v3po.translate.util.read.CloseableReader; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer; +import io.fd.honeycomb.v3po.translate.impl.read.GenericListReader; +import io.fd.honeycomb.v3po.translate.read.ReaderFactory; +import io.fd.honeycomb.v3po.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.vppclassifier.ClassifySessionReader; import io.fd.honeycomb.v3po.translate.v3po.vppclassifier.ClassifyTableReader; -import java.util.ArrayList; -import java.util.List; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifierState; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifierStateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySession; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySessionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySessionKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.state.ClassifyTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.state.ClassifyTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.state.ClassifyTableKey; -import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.future.FutureJVpp; public class VppClassifierStateHoneycombReaderModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractVppClassifierStateHoneycombReaderModule { public VppClassifierStateHoneycombReaderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { @@ -35,24 +29,36 @@ public class VppClassifierStateHoneycombReaderModule extends org.opendaylight.ya @Override public java.lang.AutoCloseable createInstance() { - final CompositeListReader classifySessionReader = - new CompositeListReader<>(ClassifySession.class, - new ClassifySessionReader(getVppJvppDependency(), getClassifyTableContextDependency())); - - final List>> classifyTableChildReaders = new ArrayList<>(); - classifyTableChildReaders.add((ChildReader)classifySessionReader); - final CompositeListReader classifyTableReader = - new CompositeListReader<>( - ClassifyTable.class, - classifyTableChildReaders, - new ClassifyTableReader(getVppJvppDependency(), getClassifyTableContextDependency())); - - final List>> vppClassifierStateChildReaders = new ArrayList<>(); - vppClassifierStateChildReaders.add(classifyTableReader); - return new CloseableReader<>(new CompositeRootReader<>( - VppClassifierState.class, - vppClassifierStateChildReaders, - new ReflexiveRootReaderCustomizer<>(VppClassifierStateBuilder.class))); + return new VppClassifierReaderFactory(getVppJvppDependency(), getClassifyTableContextDependency()); } + private static final class VppClassifierReaderFactory implements ReaderFactory, AutoCloseable { + + private final FutureJVpp jvpp; + private final NamingContext classifyCtx; + + VppClassifierReaderFactory(final FutureJVpp jvpp, + final NamingContext classifyCtx) { + this.jvpp = jvpp; + this.classifyCtx = classifyCtx; + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // VppClassifierState + final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppClassifierState.class); + registry.addStructuralReader(vppStateId, VppClassifierStateBuilder.class); + // ClassifyTable + final InstanceIdentifier classTblId = vppStateId.child(ClassifyTable.class); + registry.add(new GenericListReader<>(classTblId, new ClassifyTableReader(jvpp, classifyCtx))); + // ClassifySession + final InstanceIdentifier classSesId = classTblId.child(ClassifySession.class); + registry.add(new GenericListReader<>(classSesId, new ClassifySessionReader(jvpp, classifyCtx))); + } + + @Override + public void close() throws Exception { + // Noop, no unregister provided + } + } } 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 922b6f9cd..ba42cfba5 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 @@ -5,7 +5,7 @@ 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.ModifiableWriterRegistry; +import io.fd.honeycomb.v3po.translate.write.registry.ModifiableWriterRegistryBuilder; 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; @@ -62,17 +62,17 @@ public class VppHoneycombWriterModule extends } @Override - public void init(final ModifiableWriterRegistry registry) { + public void init(final ModifiableWriterRegistryBuilder registry) { // Vpp has no handlers // BridgeDomains has no handlers // BridgeDomain = final InstanceIdentifier bdId = InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child(BridgeDomain.class); - registry.addWriter(new GenericListWriter<>(bdId, new BridgeDomainCustomizer(jvpp, bdContext))); + registry.add(new GenericListWriter<>(bdId, new BridgeDomainCustomizer(jvpp, bdContext))); // L2FibTable has no handlers // L2FibEntry(handled after BridgeDomain and L2 of ifc and subifc) = final InstanceIdentifier l2FibEntryId = bdId.child(L2FibTable.class).child(L2FibEntry.class); - registry.addWriterAfter( + registry.addAfter( new GenericListWriter<>(l2FibEntryId, new L2FibEntryCustomizer(jvpp, bdContext, ifcContext)), Sets.newHashSet( bdId, diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java index abbde23ab..4634a5b59 100644 --- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java +++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java @@ -1,26 +1,22 @@ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeChildReader; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader; -import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader; -import io.fd.honeycomb.v3po.translate.read.ChildReader; -import io.fd.honeycomb.v3po.translate.util.KeepaliveReaderWrapper; -import io.fd.honeycomb.v3po.translate.util.RWUtils; -import io.fd.honeycomb.v3po.translate.util.read.CloseableReader; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveChildReaderCustomizer; -import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer; +import io.fd.honeycomb.v3po.translate.impl.read.GenericListReader; +import io.fd.honeycomb.v3po.translate.impl.read.GenericReader; +import io.fd.honeycomb.v3po.translate.read.ReaderFactory; +import io.fd.honeycomb.v3po.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.v3po.translate.util.read.KeepaliveReaderWrapper; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.ReadTimeoutException; import io.fd.honeycomb.v3po.translate.v3po.vppstate.BridgeDomainCustomizer; import io.fd.honeycomb.v3po.translate.v3po.vppstate.L2FibEntryCustomizer; import io.fd.honeycomb.v3po.translate.v3po.vppstate.VersionCustomizer; import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.List; import javax.management.Attribute; import javax.management.InstanceNotFoundException; import javax.management.ObjectName; import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.vpp.jvpp.cfg.rev160406.VppJvppImplModule; @@ -30,15 +26,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev 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.L2FibTableBuilder; 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.L2FibEntryBuilder; -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.state.BridgeDomains; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,55 +59,19 @@ public class VppStateHoneycombReaderModule extends @Override public java.lang.AutoCloseable createInstance() { - final FutureJVpp vppApi = getVppJvppDependency(); - - ChildReader versionReader = new CompositeChildReader<>(Version.class, new VersionCustomizer(vppApi)); - // Wrap with keepalive reader to detect connection issues - // TODO keepalive reader wrapper relies on VersionReaderCustomizer (to perform timeout on reads) - // Once readers+customizers are asynchronous, pull the timeout to keepalive executor so that keepalive wrapper - // is truly generic - versionReader = new KeepaliveReaderWrapper<>(versionReader, getKeepaliveExecutorDependency().getExecutor(), - ReadTimeoutException.class, 30, () -> reinitializeJVpp(reinitializationCounter)); - - final CompositeListReader l2FibEntryReader = - new CompositeListReader<>(L2FibEntry.class, - new L2FibEntryCustomizer(vppApi, - getBridgeDomainContextVppStateDependency(), getInterfaceContextVppStateDependency())); - - final ChildReader l2FibTableReader = new CompositeChildReader<>( - L2FibTable.class, - RWUtils.singletonChildReaderList(l2FibEntryReader), - new ReflexiveChildReaderCustomizer<>(L2FibTableBuilder.class)); - - final CompositeListReader bridgeDomainReader = - new CompositeListReader<>(BridgeDomain.class, - RWUtils.singletonChildReaderList((ChildReader) l2FibTableReader), - new BridgeDomainCustomizer(vppApi, - getBridgeDomainContextVppStateDependency())); - - final ChildReader bridgeDomainsReader = new CompositeChildReader<>( - BridgeDomains.class, - RWUtils.singletonChildReaderList(bridgeDomainReader), - new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class)); - - final List>> childVppReaders = new ArrayList<>(); - childVppReaders.add(versionReader); - childVppReaders.add(bridgeDomainsReader); - - return new CloseableReader<>(new CompositeRootReader<>( - VppState.class, - childVppReaders, - RWUtils.emptyAugReaderList(), - new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class))); + return new VppStateHoneycombReaderFactory(getVppJvppDependency(), + getInterfaceContextVppStateDependency(), + getBridgeDomainContextVppStateDependency(), + getKeepaliveExecutorDependency()); } private static long reinitializationCounter; private static final long reinitializationLimit = 10; /** - * In case we detect connection issues with VPP, reinitialize JVpp + * In case we detect connection issues with VPP, reinitialize JVpp. */ - private void reinitializeJVpp(final long currentAttempt) { + private static void reinitializeJVpp(final long currentAttempt) { // FIXME https://jira.fd.io/browse/HONEYCOMB-78 This code correctly re-initializes all the components // starting with jvpp, but jvpp reconnect fails. Test in a JVpp test and then from C LOG.info("Reinitializing JVpp, attempt: {}", currentAttempt); @@ -150,8 +106,7 @@ public class VppStateHoneycombReaderModule extends LOG.info("JVpp reinitialized successfully"); } catch (InstanceNotFoundException | ValidationException e) { LOG.error("Unable to reinitialize JVpp. Honeycomb will not work properly from now on.", e); - throw new IllegalStateException("Unable to find jvpp instance in config subsystem. " + - "Unable to reinitialize JVpp", e); + throw new IllegalStateException("Unable to find jvpp instance in config subsystem. Unable to reinitialize JVpp", e); } catch (ConflictingVersionException e) { LOG.debug("Conflict changes occurred, retrying", e); // Just retry until there's no conflicting change in progress @@ -160,4 +115,56 @@ public class VppStateHoneycombReaderModule extends reinitializationCounter = nextAttempt; } + + + private static final class VppStateHoneycombReaderFactory implements ReaderFactory, AutoCloseable { + + private final FutureJVpp jVpp; + private final NamingContext ifcCtx; + private final NamingContext bdCtx; + private final ScheduledThreadPool keepaliveExecutor; + + public VppStateHoneycombReaderFactory(final FutureJVpp jVpp, + final NamingContext ifcCtx, + final NamingContext bdCtx, + final ScheduledThreadPool keepaliveExecutorDependency) { + this.jVpp = jVpp; + this.ifcCtx = ifcCtx; + this.bdCtx = bdCtx; + this.keepaliveExecutor = keepaliveExecutorDependency; + } + + @Override + public void close() throws Exception { + // TODO unregister not available + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // VppState(Structural) + final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppState.class); + registry.addStructuralReader(vppStateId, VppStateBuilder.class); + // Version + // Wrap with keepalive reader to detect connection issues + // TODO keepalive reader wrapper relies on VersionReaderCustomizer (to perform timeout on reads) + // Once readers+customizers are asynchronous, pull the timeout to keepalive executor so that keepalive wrapper + // is truly generic + registry.add(new KeepaliveReaderWrapper<>( + new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp)), + keepaliveExecutor.getExecutor(), ReadTimeoutException.class, 30, + () -> reinitializeJVpp(reinitializationCounter))); + // BridgeDomains(Structural) + final InstanceIdentifier bridgeDomainsId = vppStateId.child(BridgeDomains.class); + registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class); + // BridgeDomain + final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); + registry.add(new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdCtx))); + // L2FibTable(Structural) + final InstanceIdentifier l2FibTableId = bridgeDomainId.child(L2FibTable.class); + registry.addStructuralReader(l2FibTableId, L2FibTableBuilder.class); + // L2FibEntry + registry.add(new GenericListReader<>(l2FibTableId.child(L2FibEntry.class), + new L2FibEntryCustomizer(jVpp, bdCtx, ifcCtx))); + } + } } -- cgit 1.2.3-korg