diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2016-12-23 08:03:10 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-12-23 09:17:24 +0100 |
commit | 7f961994184897bba90003e2d6d324e1041946af (patch) | |
tree | 72cdb45545b69368706ff984761acb6da8624bd2 /acl/acl-impl/src/main/java | |
parent | cfcc0585d9801a15ec4b36ac627662dc7f0fe789 (diff) |
HONEYCOMB-310: initializers for interface acl assignment
Change-Id: I6dcc1ef1abc9d314906d6d4fcc746dcfd28ec5fc
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'acl/acl-impl/src/main/java')
5 files changed, 73 insertions, 9 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java index ed853eeea..782c1c007 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java @@ -24,7 +24,8 @@ import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; @@ -41,8 +42,11 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.annotation.Nonnull; +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.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsKey; @@ -50,7 +54,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl. import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; abstract class AbstractVppAclCustomizer extends FutureJVppAclCustomizer - implements ListReaderCustomizer<VppAcls, VppAclsKey, VppAclsBuilder>, JvppReplyConsumer, ByteDataTranslator { + implements InitializingListReaderCustomizer<VppAcls, VppAclsKey, VppAclsBuilder>, JvppReplyConsumer, + ByteDataTranslator { private final NamingContext interfaceContext; private final NamingContext standardAclContext; @@ -79,6 +84,15 @@ abstract class AbstractVppAclCustomizer extends FutureJVppAclCustomizer .build(); } + protected static InstanceIdentifier<Acl> getAclCfgId( + final InstanceIdentifier<Acl> id) { + return InstanceIdentifier.create(Interfaces.class).child( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey( + id.firstKeyOf(Interface.class).getName())).augmentation(VppAclInterfaceAugmentation.class) + .child(Acl.class); + } + private EntityDumpExecutor<AclDetailsReplyDump, Integer> createAclExecutor() { return (identifier, params) -> { AclDump request = new AclDump(); @@ -160,4 +174,14 @@ abstract class AbstractVppAclCustomizer extends FutureJVppAclCustomizer new IllegalArgumentException(String.format("Acl with name %s not found", aclName))); } } + + @Nonnull + @Override + public Initialized<VppAcls> init(@Nonnull final InstanceIdentifier<VppAcls> id, + @Nonnull final VppAcls vppAcls, + @Nonnull final ReadContext readContext) { + return Initialized.create(getCfgId(id), vppAcls); + } + + protected abstract InstanceIdentifier<VppAcls> getCfgId(final InstanceIdentifier<VppAcls> id); } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizer.java index 536b27fcc..eaabb0bff 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizer.java @@ -17,16 +17,20 @@ package io.fd.hc2vpp.acl.read; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.util.RWUtils; import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; import java.util.Arrays; import java.util.List; import java.util.stream.IntStream; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Egress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.EgressBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class EgressVppAclCustomizer extends AbstractVppAclCustomizer { @@ -45,4 +49,11 @@ public final class EgressVppAclCustomizer extends AbstractVppAclCustomizer { public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<VppAcls> readData) { EgressBuilder.class.cast(builder).setVppAcls(readData); } + + @Override + protected InstanceIdentifier<VppAcls> getCfgId( + final InstanceIdentifier<VppAcls> id) { + return getAclCfgId(RWUtils.cutId(id, Acl.class)).child(Egress.class) + .child(VppAcls.class, id.firstKeyOf(VppAcls.class)); + } } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizer.java index 8a31032d7..e8c79c967 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizer.java @@ -17,16 +17,20 @@ package io.fd.hc2vpp.acl.read; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.util.RWUtils; import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; import java.util.Arrays; import java.util.List; import java.util.stream.IntStream; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class IngressVppAclCustomizer extends AbstractVppAclCustomizer { @@ -45,4 +49,11 @@ public final class IngressVppAclCustomizer extends AbstractVppAclCustomizer { public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<VppAcls> readData) { IngressBuilder.class.cast(builder).setVppAcls(readData); } + + @Override + protected InstanceIdentifier<VppAcls> getCfgId( + final InstanceIdentifier<VppAcls> id) { + return getAclCfgId(RWUtils.cutId(id, Acl.class)).child(Ingress.class) + .child(VppAcls.class, id.firstKeyOf(VppAcls.class)); + } } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java index 7786afee5..81799e1fa 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java @@ -16,6 +16,7 @@ package io.fd.hc2vpp.acl.read; +import static io.fd.hc2vpp.acl.read.AbstractVppAclCustomizer.getAclCfgId; import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; import com.google.common.base.Optional; @@ -27,7 +28,9 @@ import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; import io.fd.vpp.jvpp.acl.dto.MacipAclDetails; @@ -39,6 +42,8 @@ import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; import javax.annotation.Nonnull; 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.yang.types.rev130715.HexString; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAcl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAclBuilder; @@ -49,7 +54,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer - implements ReaderCustomizer<VppMacipAcl, VppMacipAclBuilder>, JvppReplyConsumer, ByteDataTranslator { + implements InitializingReaderCustomizer<VppMacipAcl, VppMacipAclBuilder>, JvppReplyConsumer, ByteDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(VppMacIpAclCustomizer.class); @@ -78,6 +83,11 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer this.macIpAclContext = macIpAclContext; } + private static InstanceIdentifier<VppMacipAcl> getCfgId( + final InstanceIdentifier<VppMacipAcl> id) { + return getAclCfgId(RWUtils.cutId(id, Acl.class)).child(Ingress.class).child(VppMacipAcl.class); + } + private EntityDumpExecutor<MacipAclDetailsReplyDump, Integer> createMacIpDumpExecutor() { return (identifier, params) -> { MacipAclDump request = new MacipAclDump(); @@ -142,4 +152,12 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer @Nonnull final VppMacipAcl readValue) { IngressBuilder.class.cast(parentBuilder).setVppMacipAcl(readValue); } + + @Nonnull + @Override + public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<VppMacipAcl> id, + @Nonnull final VppMacipAcl readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), readValue); + } } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/InterfaceAclReaderFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/InterfaceAclReaderFactory.java index 691479e64..5b627fbc3 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/InterfaceAclReaderFactory.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/InterfaceAclReaderFactory.java @@ -23,8 +23,8 @@ import io.fd.hc2vpp.acl.read.EgressVppAclCustomizer; import io.fd.hc2vpp.acl.read.IngressVppAclCustomizer; import io.fd.hc2vpp.acl.read.VppMacIpAclCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.impl.read.GenericListReader; -import io.fd.honeycomb.translate.impl.read.GenericReader; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericInitReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; @@ -73,14 +73,14 @@ public class InterfaceAclReaderFactory implements ReaderFactory { final InstanceIdentifier<Ingress> ingressInstanceIdentifier = ACL_IID.child(Ingress.class); registry.addStructuralReader(ingressInstanceIdentifier, IngressBuilder.class); - registry.addAfter(new GenericListReader<>(ingressInstanceIdentifier.child(VppAcls.class), + registry.addAfter(new GenericInitListReader<>(ingressInstanceIdentifier.child(VppAcls.class), new IngressVppAclCustomizer(futureAclFacade, interfaceContext, standardAclContext)), IFC_ID); - registry.addAfter(new GenericReader<>(ingressInstanceIdentifier.child(VppMacipAcl.class), + registry.addAfter(new GenericInitReader<>(ingressInstanceIdentifier.child(VppMacipAcl.class), new VppMacIpAclCustomizer(futureAclFacade, interfaceContext, macIpAClContext)), IFC_ID); final InstanceIdentifier<Egress> egressInstanceIdentifier = ACL_IID.child(Egress.class); registry.addStructuralReader(egressInstanceIdentifier, EgressBuilder.class); - registry.addAfter(new GenericListReader<>(egressInstanceIdentifier.child(VppAcls.class), + registry.addAfter(new GenericInitListReader<>(egressInstanceIdentifier.child(VppAcls.class), new EgressVppAclCustomizer(futureAclFacade, interfaceContext, standardAclContext)), IFC_ID); } } |