diff options
Diffstat (limited to 'acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read')
11 files changed, 643 insertions, 530 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizer.java new file mode 100644 index 000000000..5f6ca36b3 --- /dev/null +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizer.java @@ -0,0 +1,133 @@ +/* + * 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.hc2vpp.acl.read; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +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.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.AclDump; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.Arrays; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +abstract class AbstractAclCustomizer extends FutureJVppAclCustomizer implements JvppReplyConsumer { + + final NamingContext interfaceContext; + final AclContextManager standardAclContext; + + final DumpCacheManager<AclInterfaceListDetailsReplyDump, Integer> aclReferenceDumpManager; + final DumpCacheManager<AclDetailsReplyDump, Integer> aclDumpManager; + + protected AbstractAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade, + @Nonnull final NamingContext interfaceContext, + @Nonnull final AclContextManager standardAclContext) { + super(jVppAclFacade); + this.interfaceContext = interfaceContext; + this.standardAclContext = standardAclContext; + + aclReferenceDumpManager = + new DumpCacheManagerBuilder<AclInterfaceListDetailsReplyDump, Integer>() + .withExecutor(createAclReferenceDumpExecutor()) + // Key needs to contain interface ID to distinguish dumps between interfaces + .withCacheKeyFactory( + new TypeAwareIdentifierCacheKeyFactory(AclInterfaceListDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + + aclDumpManager = new DumpCacheManagerBuilder<AclDetailsReplyDump, Integer>() + .withExecutor(createAclExecutor()) + .acceptOnly(AclDetailsReplyDump.class) + .build(); + } + + private EntityDumpExecutor<AclDetailsReplyDump, Integer> createAclExecutor() { + return (identifier, params) -> { + AclDump request = new AclDump(); + request.aclIndex = params; + return getReplyForRead(getjVppAclFacade().aclDump(request).toCompletableFuture(), identifier); + }; + } + + private EntityDumpExecutor<AclInterfaceListDetailsReplyDump, Integer> createAclReferenceDumpExecutor() { + return (identifier, params) -> { + AclInterfaceListDump dumpRequest = new AclInterfaceListDump(); + dumpRequest.swIfIndex = params; + return getReplyForRead(getjVppAclFacade().aclInterfaceListDump(dumpRequest).toCompletableFuture(), + identifier); + }; + } + + Stream<AclSetKey> getStandardAclSetKeys(@Nonnull final ReadContext readContext, + final Optional<AclInterfaceListDetailsReplyDump> dumpReply, + final boolean isIngress) { + if (dumpReply.isPresent() && !dumpReply.get().aclInterfaceListDetails.isEmpty()) { + // if dumpReply is present, then aclInterfaceListDetails contains single element (actually it should not be + // dump message in vpp) + final AclInterfaceListDetails aclDetails = dumpReply.get().aclInterfaceListDetails.get(0); + + if (isIngress) { + return Arrays.stream(aclDetails.acls).limit(aclDetails.nInput) + .mapToObj(aclIndex -> standardAclContext.getAclName(aclIndex, readContext.getMappingContext())) + .map(AclSetKey::new); + } else { + return Arrays.stream(aclDetails.acls).skip(aclDetails.nInput) + .mapToObj(aclIndex -> standardAclContext.getAclName(aclIndex, readContext.getMappingContext())) + .map(AclSetKey::new); + } + } else { + return Stream.empty(); + } + } + + void parseStandardAclSet(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final AclSetBuilder aclSetBuilder, final String aclName, + final MappingContext mappingContext, final ModificationCache modificationCache) + throws ReadFailedException { + final int aclIndex = standardAclContext.getAclIndex(aclName, mappingContext); + + final Optional<AclDetailsReplyDump> dumpReply = + aclDumpManager.getDump(instanceIdentifier, modificationCache, aclIndex); + + if (dumpReply.isPresent() && !dumpReply.get().aclDetails.isEmpty()) { + aclSetBuilder.setName(aclName); + } else { + throw new ReadFailedException(instanceIdentifier, + new IllegalArgumentException(String.format("Acl with name %s not found", aclName))); + } + } +} 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 deleted file mode 100644 index c6d61f653..000000000 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java +++ /dev/null @@ -1,180 +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.hc2vpp.acl.read; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.acl.util.AclContextManager; -import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -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.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; -import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; -import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; -import java.util.Collections; -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.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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -abstract class AbstractVppAclCustomizer extends FutureJVppAclCustomizer - implements InitializingListReaderCustomizer<VppAcls, VppAclsKey, VppAclsBuilder>, JvppReplyConsumer, - ByteDataTranslator { - - private final NamingContext interfaceContext; - private final AclContextManager standardAclContext; - - private final DumpCacheManager<AclInterfaceListDetailsReplyDump, Integer> aclReferenceDumpManager; - private final DumpCacheManager<AclDetailsReplyDump, Integer> aclDumpManager; - - protected AbstractVppAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade, - @Nonnull final NamingContext interfaceContext, - @Nonnull final AclContextManager standardAclContext) { - super(jVppAclFacade); - this.interfaceContext = interfaceContext; - this.standardAclContext = standardAclContext; - - aclReferenceDumpManager = - new DumpCacheManagerBuilder<AclInterfaceListDetailsReplyDump, Integer>() - .withExecutor(createAclReferenceDumpExecutor()) - // Key needs to contain interface ID to distinguish dumps between interfaces - .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(AclInterfaceListDetailsReplyDump.class, - ImmutableSet.of(Interface.class))) - .build(); - - aclDumpManager = new DumpCacheManagerBuilder<AclDetailsReplyDump, Integer>() - .withExecutor(createAclExecutor()) - .acceptOnly(AclDetailsReplyDump.class) - .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(); - request.aclIndex = params; - return getReplyForRead(getjVppAclFacade().aclDump(request).toCompletableFuture(), identifier); - }; - } - - private EntityDumpExecutor<AclInterfaceListDetailsReplyDump, Integer> createAclReferenceDumpExecutor() { - return (identifier, params) -> { - AclInterfaceListDump dumpRequest = new AclInterfaceListDump(); - dumpRequest.swIfIndex = params; - return getReplyForRead(getjVppAclFacade().aclInterfaceListDump(dumpRequest).toCompletableFuture(), - identifier); - }; - } - - @Nonnull - @Override - public final List<VppAclsKey> getAllIds(@Nonnull final InstanceIdentifier<VppAcls> id, - @Nonnull final ReadContext context) - throws ReadFailedException { - - final String parentInterfaceName = id.firstKeyOf(Interface.class).getName(); - final int parentInterfaceIndex = interfaceContext.getIndex(parentInterfaceName, context.getMappingContext()); - - final Optional<AclInterfaceListDetailsReplyDump> dumpReply = - aclReferenceDumpManager.getDump(id, context.getModificationCache(), parentInterfaceIndex); - - if (dumpReply.isPresent() && !dumpReply.get().aclInterfaceListDetails.isEmpty()) { - // if dumpReply is present, then aclInterfaceListDetails contains single element (actually it should not be - // dump message in vpp) - final AclInterfaceListDetails aclDetails = dumpReply.get().aclInterfaceListDetails.get(0); - return filterAcls(aclDetails) - .mapToObj(aclIndex -> standardAclContext.getAclName(aclIndex, context.getMappingContext())) - .map(aclName -> new VppAclsKey(aclName, VppAcl.class)) - .collect(Collectors.toList()); - } else { - return Collections.emptyList(); - } - } - - /** - * Streams ids of ACLs. - * - * @param aclDetails describes ACLs assigned to interface - * @return sequence of acl ids - */ - protected abstract IntStream filterAcls(@Nonnull final AclInterfaceListDetails aclDetails); - - @Nonnull - @Override - public final VppAclsBuilder getBuilder(@Nonnull final InstanceIdentifier<VppAcls> id) { - return new VppAclsBuilder(); - } - - @Override - public final void readCurrentAttributes(@Nonnull final InstanceIdentifier<VppAcls> id, - @Nonnull final VppAclsBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - final VppAclsKey vppAclsKey = id.firstKeyOf(VppAcls.class); - final String aclName = vppAclsKey.getName(); - final int aclIndex = standardAclContext.getAclIndex(aclName, ctx.getMappingContext()); - - final Optional<AclDetailsReplyDump> dumpReply = - aclDumpManager.getDump(id, ctx.getModificationCache(), aclIndex); - - if (dumpReply.isPresent() && !dumpReply.get().aclDetails.isEmpty()) { - builder.setName(aclName); - builder.setType(vppAclsKey.getType()); - } else { - throw new ReadFailedException(id, - 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/AclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AclCustomizer.java index 0ebc938ea..e1f0ccf14 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AclCustomizer.java @@ -41,16 +41,13 @@ import java.util.ArrayList; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessListsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAclAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAclAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAcl; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppAclAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppAclAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.AclsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.Acl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.AcesBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -119,7 +116,7 @@ public class AclCustomizer extends FutureJVppAclCustomizer if (vppAclDump.isPresent()) { vppAclDump.get().aclDetails.stream() .map(details -> standardAclContext.getAclName(details.aclIndex, context.getMappingContext())) - .forEach(name -> keys.add(new AclKey(name, VppAcl.class))); + .forEach(name -> keys.add(new AclKey(name))); } final Optional<MacipAclDetailsReplyDump> macipAclDump = @@ -127,7 +124,7 @@ public class AclCustomizer extends FutureJVppAclCustomizer if (macipAclDump.isPresent()) { macipAclDump.get().macipAclDetails.stream() .map(details -> macipAclContext.getAclName(details.aclIndex, context.getMappingContext())) - .forEach(name -> keys.add(new AclKey(name, VppMacipAcl.class))); + .forEach(name -> keys.add(new AclKey(name))); } return keys; @@ -135,7 +132,7 @@ public class AclCustomizer extends FutureJVppAclCustomizer @Override public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<Acl> readData) { - ((AccessListsBuilder)builder).setAcl(readData); + ((AclsBuilder) builder).setAcl(readData); } @Nonnull @@ -149,10 +146,9 @@ public class AclCustomizer extends FutureJVppAclCustomizer @Nonnull final ReadContext ctx) throws ReadFailedException { final AclKey key = id.firstKeyOf(Acl.class); builder.withKey(key); - final Class<? extends AclBase> aclType = key.getAclType(); - final String name = key.getAclName(); + final String name = key.getName(); - if (aclType.equals(VppAcl.class)) { + if (standardAclContext.containsAcl(name, ctx.getMappingContext())) { final int index = standardAclContext.getAclIndex(name, ctx.getMappingContext()); final Optional<AclDetailsReplyDump> dump = vppAclDumpManager.getDump(id, ctx.getModificationCache(), index); @@ -162,12 +158,12 @@ public class AclCustomizer extends FutureJVppAclCustomizer if (detail.isPresent()) { final AclDetails aclDetails = detail.get(); setTag(builder, aclDetails.tag); - builder.setAccessListEntries(new AccessListEntriesBuilder() + builder.setAces(new AcesBuilder() .setAce(toStandardAces(name, aclDetails.r, standardAclContext, ctx.getMappingContext())) .build()); } } - } else if (aclType.equals(VppMacipAcl.class)) { + } else if (macipAclContext.containsAcl(name, ctx.getMappingContext())) { final int index = macipAclContext.getAclIndex(name, ctx.getMappingContext()); final Optional<MacipAclDetailsReplyDump> dump = macipAclDumpManager.getDump(id, ctx.getModificationCache(), index); @@ -178,13 +174,13 @@ public class AclCustomizer extends FutureJVppAclCustomizer final MacipAclDetails macipAclDetails = detail.get(); setTag(builder, macipAclDetails.tag); if (detail.isPresent()) { - builder.setAccessListEntries(new AccessListEntriesBuilder() + builder.setAces(new AcesBuilder() .setAce(toMacIpAces(name, macipAclDetails.r, macipAclContext, ctx.getMappingContext())) .build()); } } } else { - throw new IllegalArgumentException("Unsupported acl type: " + aclType); + throw new IllegalArgumentException("Unsupported acl: " + id); } } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressAclCustomizer.java new file mode 100644 index 000000000..59990d5ea --- /dev/null +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressAclCustomizer.java @@ -0,0 +1,102 @@ +/* + * 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.hc2vpp.acl.read; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +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.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class EgressAclCustomizer extends AbstractAclCustomizer + implements InitializingListReaderCustomizer<AclSet, AclSetKey, AclSetBuilder>, JvppReplyConsumer { + + public EgressAclCustomizer(final FutureJVppAclFacade futureAclFacade, final NamingContext interfaceContext, + final AclContextManager standardAclContext) { + super(futureAclFacade, interfaceContext, standardAclContext); + } + + @Nonnull + @Override + public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final AclSet aclSet, + @Nonnull final ReadContext readContext) { + return Initialized.create(instanceIdentifier, aclSet); + } + + @Nonnull + @Override + public List<AclSetKey> getAllIds(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final ReadContext readContext) throws ReadFailedException { + final String parentInterfaceName = instanceIdentifier.firstKeyOf(Interface.class).getInterfaceId(); + final int parentInterfaceIndex = + interfaceContext.getIndex(parentInterfaceName, readContext.getMappingContext()); + + //TODO stdDumpReply keys need to be filtered as egress only + final Optional<AclInterfaceListDetailsReplyDump> stdDumpReply = + aclReferenceDumpManager + .getDump(instanceIdentifier, readContext.getModificationCache(), parentInterfaceIndex); + + return getStandardAclSetKeys(readContext, stdDumpReply, false).collect(Collectors.toList()); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<AclSet> list) { + ((AclSetsBuilder) builder).setAclSet(list); + } + + @Nonnull + @Override + public AclSetBuilder getBuilder(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier) { + return new AclSetBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final AclSetBuilder aclSetBuilder, + @Nonnull final ReadContext readContext) + throws ReadFailedException { + final AclSetKey vppAclsKey = instanceIdentifier.firstKeyOf(AclSet.class); + final String aclName = vppAclsKey.getName(); + final MappingContext mappingContext = readContext.getMappingContext(); + ModificationCache modificationCache = readContext.getModificationCache(); + + if (standardAclContext.containsAcl(aclName, mappingContext)) { + parseStandardAclSet(instanceIdentifier, aclSetBuilder, aclName, mappingContext, modificationCache); + } + + } +} 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 deleted file mode 100644 index 8e5d0dfce..000000000 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizer.java +++ /dev/null @@ -1,60 +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.hc2vpp.acl.read; - -import io.fd.hc2vpp.acl.util.AclContextManager; -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 { - - public EgressVppAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade, - @Nonnull final NamingContext interfaceContext, - @Nonnull final AclContextManager standardAclContext) { - super(jVppAclFacade, interfaceContext, standardAclContext); - } - - @Override - protected IntStream filterAcls(@Nonnull final AclInterfaceListDetails aclDetails) { - return Arrays.stream(aclDetails.acls).skip(aclDetails.nInput); - } - - @Override - 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/IngressAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressAclCustomizer.java new file mode 100644 index 000000000..467c4e5db --- /dev/null +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressAclCustomizer.java @@ -0,0 +1,226 @@ +/* + * 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.hc2vpp.acl.read; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Streams; +import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +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.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.EntityDumpExecutor; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGet; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGetReply; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDetails; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDump; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IngressAclCustomizer extends AbstractAclCustomizer + implements InitializingListReaderCustomizer<AclSet, AclSetKey, AclSetBuilder>, JvppReplyConsumer { + @VisibleForTesting + protected static final int ACL_NOT_ASSIGNED = -1; + private static final Logger LOG = LoggerFactory.getLogger(IngressAclCustomizer.class); + + private final AclContextManager macIpAclContext; + + private final DumpCacheManager<MacipAclDetailsReplyDump, Integer> macIpAclDumpManager; + private final DumpCacheManager<MacipAclInterfaceGetReply, Void> interfaceMacIpAclDumpManager; + private final DumpCacheManager<MacipAclInterfaceListDetailsReplyDump, Integer> macAclReferenceDumpManager; + + public IngressAclCustomizer(final FutureJVppAclFacade futureAclFacade, final NamingContext interfaceContext, + final AclContextManager standardAclContext, final AclContextManager macIpAClContext) { + super(futureAclFacade, interfaceContext, standardAclContext); + this.macIpAclContext = macIpAClContext; + + macAclReferenceDumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<MacipAclInterfaceListDetailsReplyDump, Integer>() + .withExecutor(createMacIpAclReferenceDumpExecutor()) + // Key needs to contain interface ID to distinguish dumps between interfaces + .withCacheKeyFactory( + new TypeAwareIdentifierCacheKeyFactory(MacipAclInterfaceListDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + + // for dumping of Mac-ip details + macIpAclDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<MacipAclDetailsReplyDump, Integer>() + .withExecutor(createMacIpDumpExecutor()) + .acceptOnly(MacipAclDetailsReplyDump.class) + .build(); + + // for dumping of reference on interface + interfaceMacIpAclDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<MacipAclInterfaceGetReply, Void>() + .withExecutor(createInterfaceMacIpDumpExecutor()) + .acceptOnly(MacipAclInterfaceGetReply.class) + .build(); + } + + @Nonnull + @Override + public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final AclSet aclSet, + @Nonnull final ReadContext readContext) { + return Initialized.create(instanceIdentifier, aclSet); + } + + @Nonnull + @Override + public List<AclSetKey> getAllIds(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final ReadContext readContext) throws ReadFailedException { + final String parentInterfaceName = instanceIdentifier.firstKeyOf(Interface.class).getInterfaceId(); + final int parentInterfaceIndex = + interfaceContext.getIndex(parentInterfaceName, readContext.getMappingContext()); + + //TODO stdDumpReply keys need to be filtered as ingress only + final Optional<AclInterfaceListDetailsReplyDump> stdDumpReply = + aclReferenceDumpManager + .getDump(instanceIdentifier, readContext.getModificationCache(), parentInterfaceIndex); + final Optional<MacipAclInterfaceListDetailsReplyDump> macipDumpReply = + macAclReferenceDumpManager + .getDump(instanceIdentifier, readContext.getModificationCache(), parentInterfaceIndex); + + Stream<AclSetKey> macIpAclSetKeys = getMacIpAclSetKeys(readContext, macipDumpReply); + Stream<AclSetKey> standardAclSetKeys = getStandardAclSetKeys(readContext, stdDumpReply, true); + + return Streams.concat(standardAclSetKeys, macIpAclSetKeys).distinct().collect(Collectors.toList()); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<AclSet> list) { + ((AclSetsBuilder) builder).setAclSet(list); + } + + @Nonnull + @Override + public AclSetBuilder getBuilder(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier) { + return new AclSetBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final AclSetBuilder aclSetBuilder, + @Nonnull final ReadContext readContext) throws ReadFailedException { + final AclSetKey vppAclsKey = instanceIdentifier.firstKeyOf(AclSet.class); + final String interfaceName = instanceIdentifier.firstKeyOf(Interface.class).getInterfaceId(); + final String aclName = vppAclsKey.getName(); + final MappingContext mappingContext = readContext.getMappingContext(); + ModificationCache modificationCache = readContext.getModificationCache(); + + if (standardAclContext.containsAcl(aclName, mappingContext)) { + parseStandardAclSet(instanceIdentifier, aclSetBuilder, aclName, mappingContext, modificationCache); + } else if (macIpAclContext.containsAcl(aclName, mappingContext)) { + parseMacIpAclSet(instanceIdentifier, aclSetBuilder, interfaceName, mappingContext, modificationCache); + } + } + + public void parseMacIpAclSet(@Nonnull final InstanceIdentifier<AclSet> instanceIdentifier, + @Nonnull final AclSetBuilder aclSetBuilder, + final String interfaceName, final MappingContext mappingContext, + final ModificationCache modificationCache) + throws ReadFailedException { + final Optional<MacipAclInterfaceGetReply> interfacesMacIpDumpReply = + interfaceMacIpAclDumpManager.getDump(instanceIdentifier, modificationCache); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, mappingContext); + MacipAclInterfaceGetReply reply = interfacesMacIpDumpReply.get(); + if (reply.acls == null || reply.acls.length == 0) { + LOG.debug("No MacACls found for interface. Iid: {}", instanceIdentifier); + return; + } + final int aclIndex = reply.acls[interfaceIndex]; + if (aclIndex != ACL_NOT_ASSIGNED) { + final Optional<MacipAclDetailsReplyDump> macIpDumpReply = + macIpAclDumpManager.getDump(instanceIdentifier, modificationCache, aclIndex); + + if (macIpDumpReply.isPresent() && !macIpDumpReply.get().macipAclDetails.isEmpty()) { + aclSetBuilder.setName(macIpAclContext.getAclName(aclIndex, mappingContext)); + } else { + // this is invalid state(Interface in VPP will act as "deny-all" for security reasons), but generally + // it should not happen + throw new ReadFailedException(instanceIdentifier, + new IllegalStateException(String.format("ACE with index %s not found in VPP", aclIndex))); + } + } + } + + private EntityDumpExecutor<MacipAclInterfaceListDetailsReplyDump, Integer> createMacIpAclReferenceDumpExecutor() { + return (identifier, params) -> { + MacipAclInterfaceListDump dumpRequest = new MacipAclInterfaceListDump(); + dumpRequest.swIfIndex = params; + return getReplyForRead(getjVppAclFacade().macipAclInterfaceListDump(dumpRequest).toCompletableFuture(), + identifier); + }; + } + + private EntityDumpExecutor<MacipAclDetailsReplyDump, Integer> createMacIpDumpExecutor() { + return (identifier, params) -> { + MacipAclDump request = new MacipAclDump(); + request.aclIndex = params; + + return getReplyForRead(getjVppAclFacade().macipAclDump(request).toCompletableFuture(), identifier); + }; + } + + private EntityDumpExecutor<MacipAclInterfaceGetReply, Void> createInterfaceMacIpDumpExecutor() { + return (identifier, params) -> getReplyForRead( + getjVppAclFacade().macipAclInterfaceGet(new MacipAclInterfaceGet()).toCompletableFuture(), + identifier); + } + + + private Stream<AclSetKey> getMacIpAclSetKeys(@Nonnull final ReadContext readContext, + final Optional<MacipAclInterfaceListDetailsReplyDump> dumpReply) { + if (dumpReply.isPresent() && !dumpReply.get().macipAclInterfaceListDetails.isEmpty()) { + // if dumpReply is present, then aclInterfaceListDetails contains single element (actually it should not be + // dump message in vpp) + final MacipAclInterfaceListDetails aclDetails = dumpReply.get().macipAclInterfaceListDetails.get(0); + + return Arrays.stream(aclDetails.acls).limit(aclDetails.count) + .mapToObj(aclIndex -> macIpAclContext.getAclName(aclIndex, readContext.getMappingContext())) + .map(AclSetKey::new); + } else { + return Stream.empty(); + } + } +} 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 deleted file mode 100644 index 598066282..000000000 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizer.java +++ /dev/null @@ -1,60 +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.hc2vpp.acl.read; - -import io.fd.hc2vpp.acl.util.AclContextManager; -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 { - - public IngressVppAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade, - @Nonnull final NamingContext interfaceContext, - @Nonnull final AclContextManager standardAclContext) { - super(jVppAclFacade, interfaceContext, standardAclContext); - } - - @Override - protected IntStream filterAcls(@Nonnull final AclInterfaceListDetails aclDetails) { - return Arrays.stream(aclDetails.acls).limit(aclDetails.nInput); - } - - @Override - 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/InterfaceAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/InterfaceAclCustomizer.java new file mode 100644 index 000000000..64720de5d --- /dev/null +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/InterfaceAclCustomizer.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2018 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.hc2vpp.acl.read; + +import com.google.common.base.Optional; +import com.google.common.collect.Streams; +import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer; +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.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDump; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AttachmentPointsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceAclCustomizer extends FutureJVppAclCustomizer implements + InitializingListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder>, JvppReplyConsumer { + private final NamingContext interfaceContext; + + private final DumpCacheManager<MacipAclInterfaceListDetailsReplyDump, Void> macipAclInterfaceListDumpManager; + private final DumpCacheManager<AclInterfaceListDetailsReplyDump, Void> aclInterfaceListDumpManager; + + public InterfaceAclCustomizer(final FutureJVppAclFacade futureAclFacade, final NamingContext interfaceContext) { + super(futureAclFacade); + this.interfaceContext = interfaceContext; + + //list all standard ACL interfaces + AclInterfaceListDump aclInterfaceListDump = new AclInterfaceListDump(); + aclInterfaceListDump.swIfIndex = -1; + aclInterfaceListDumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<AclInterfaceListDetailsReplyDump, Void>() + .withExecutor((identifier, params) -> getReplyForRead( + getjVppAclFacade().aclInterfaceListDump(aclInterfaceListDump).toCompletableFuture(), + identifier)) + .acceptOnly(AclInterfaceListDetailsReplyDump.class) + .build(); + + //list all macIp ACL interfaces + MacipAclInterfaceListDump macipAclInterfaceListDump = new MacipAclInterfaceListDump(); + macipAclInterfaceListDump.swIfIndex = 0; + macipAclInterfaceListDumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<MacipAclInterfaceListDetailsReplyDump, Void>() + .withExecutor((identifier, params) -> getReplyForRead( + getjVppAclFacade().macipAclInterfaceListDump(macipAclInterfaceListDump) + .toCompletableFuture(), + identifier)) + .acceptOnly(MacipAclInterfaceListDetailsReplyDump.class) + .build(); + } + + @Nonnull + @Override + public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<Interface> instanceIdentifier, + @Nonnull final Interface anInterface, + @Nonnull final ReadContext readContext) { + return Initialized.create(instanceIdentifier, anInterface); + } + + @Nonnull + @Override + public List<InterfaceKey> getAllIds(@Nonnull final InstanceIdentifier<Interface> instanceIdentifier, + @Nonnull final ReadContext readContext) throws ReadFailedException { + final Optional<AclInterfaceListDetailsReplyDump> stdIfcDumpReply = + aclInterfaceListDumpManager.getDump(instanceIdentifier, readContext.getModificationCache()); + + final Optional<MacipAclInterfaceListDetailsReplyDump> macIpIfcDumpReply = + macipAclInterfaceListDumpManager.getDump(instanceIdentifier, readContext.getModificationCache()); + + Stream<InterfaceKey> stdAclIfcKeys = stdIfcDumpReply.asSet().stream() + .map(dump -> dump.aclInterfaceListDetails) + .flatMap(Collection::stream) + .filter(aclInterfaceListDetails -> aclInterfaceListDetails.acls.length != 0) + .map(details -> getInterfaceKey(readContext, details.swIfIndex)); + + Stream<InterfaceKey> macIpAclIfcKeys = macIpIfcDumpReply.asSet().stream() + .map(dump -> dump.macipAclInterfaceListDetails) + .flatMap(Collection::stream) + .map(details -> getInterfaceKey(readContext, details.swIfIndex)); + return Streams.concat(stdAclIfcKeys, macIpAclIfcKeys).distinct().collect(Collectors.toList()); + } + + private InterfaceKey getInterfaceKey(@Nonnull final ReadContext readContext, final int swIfIndex) { + return new InterfaceKey(interfaceContext.getName(swIfIndex, readContext.getMappingContext())); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<Interface> list) { + ((AttachmentPointsBuilder) builder).setInterface(list); + } + + @Nonnull + @Override + public InterfaceBuilder getBuilder(@Nonnull final InstanceIdentifier<Interface> instanceIdentifier) { + return new InterfaceBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> instanceIdentifier, + @Nonnull final InterfaceBuilder interfaceBuilder, + @Nonnull final ReadContext readContext) + throws ReadFailedException { + interfaceBuilder.withKey(instanceIdentifier.firstKeyOf(Interface.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 deleted file mode 100644 index 0ae05826c..000000000 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java +++ /dev/null @@ -1,160 +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.hc2vpp.acl.read; - -import static io.fd.hc2vpp.acl.read.AbstractVppAclCustomizer.getAclCfgId; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import io.fd.hc2vpp.acl.util.AclContextManager; -import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -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.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.MacipAclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.MacipAclDump; -import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGet; -import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGetReply; -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.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; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer - implements InitializingReaderCustomizer<VppMacipAcl, VppMacipAclBuilder>, JvppReplyConsumer, ByteDataTranslator { - - private static final Logger LOG = LoggerFactory.getLogger(VppMacIpAclCustomizer.class); - @VisibleForTesting - protected static final int ACL_NOT_ASSIGNED = -1; - - private final DumpCacheManager<MacipAclDetailsReplyDump, Integer> macIpAclDumpManager; - private final DumpCacheManager<MacipAclInterfaceGetReply, Void> interfaceMacIpAclDumpManager; - private final NamingContext interfaceContext; - private final AclContextManager macIpAclContext; - - public VppMacIpAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade, - @Nonnull final NamingContext interfaceContext, - @Nonnull final AclContextManager macIpAclContext) { - super(jVppAclFacade); - - // for dumping of Mac-ip details - macIpAclDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<MacipAclDetailsReplyDump, Integer>() - .withExecutor(createMacIpDumpExecutor()) - .acceptOnly(MacipAclDetailsReplyDump.class) - .build(); - - // for dumping of reference on interface - interfaceMacIpAclDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<MacipAclInterfaceGetReply, Void>() - .withExecutor(createInterfaceMacIpDumpExecutor()) - .acceptOnly(MacipAclInterfaceGetReply.class) - .build(); - this.interfaceContext = interfaceContext; - 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(); - request.aclIndex = params; - - return getReplyForRead(getjVppAclFacade().macipAclDump(request).toCompletableFuture(), identifier); - }; - } - - private EntityDumpExecutor<MacipAclInterfaceGetReply, Void> createInterfaceMacIpDumpExecutor() { - return (identifier, params) -> getReplyForRead( - getjVppAclFacade().macipAclInterfaceGet(new MacipAclInterfaceGet()).toCompletableFuture(), - identifier); - } - - @Nonnull - @Override - public VppMacipAclBuilder getBuilder(@Nonnull final InstanceIdentifier<VppMacipAcl> id) { - return new VppMacipAclBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier<VppMacipAcl> id, - @Nonnull final VppMacipAclBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final MappingContext mappingContext = ctx.getMappingContext(); - final int interfaceIndex = interfaceContext.getIndex(interfaceName, mappingContext); - final ModificationCache modificationCache = ctx.getModificationCache(); - final Optional<MacipAclInterfaceGetReply> interfacesMacIpDumpReply = - interfaceMacIpAclDumpManager.getDump(id, modificationCache); - - if (interfacesMacIpDumpReply.isPresent() && interfaceIndex < interfacesMacIpDumpReply.get().count) { - final int aclIndex = interfacesMacIpDumpReply.get().acls[interfaceIndex]; - if (aclIndex != ACL_NOT_ASSIGNED) { - final Optional<MacipAclDetailsReplyDump> macIpDumpReply = - macIpAclDumpManager.getDump(id, modificationCache, aclIndex); - - if (macIpDumpReply.isPresent() && !macIpDumpReply.get().macipAclDetails.isEmpty()) { - builder.setName(macIpAclContext.getAclName(aclIndex, mappingContext)); - builder.setType( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAcl.class); - return; - } else { - // this is invalid state(Interface in VPP will act as "deny-all" for security reasons), but generally - // it should not happen - throw new ReadFailedException(id, - new IllegalStateException(String.format("ACE with index %s not found in VPP", aclIndex))); - } - } - } - // this is valid state, so just logging - LOG.debug("No Mac-ip ACL specified for Interface name={},index={}", interfaceName, interfaceIndex); - } - - @Override - public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, - @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/AclReaderFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/AclReaderFactory.java index 34352e8f3..6a743ca80 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/AclReaderFactory.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/AclReaderFactory.java @@ -16,27 +16,23 @@ package io.fd.hc2vpp.acl.read.factory; -import static io.fd.hc2vpp.acl.read.factory.InterfaceAclReaderFactory.ACL_EGRESS_IID; -import static io.fd.hc2vpp.acl.read.factory.InterfaceAclReaderFactory.ACL_INGRESS_IID; +import static io.fd.hc2vpp.acl.AclIIds.vppAclChildren; import com.google.common.collect.ImmutableSet; import com.google.inject.Inject; import com.google.inject.name.Named; +import io.fd.hc2vpp.acl.AclIIds; import io.fd.hc2vpp.acl.AclModule; import io.fd.hc2vpp.acl.read.AclCustomizer; import io.fd.hc2vpp.acl.util.AclContextManager; -import io.fd.hc2vpp.acl.util.factory.AclFactory; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; 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.access.control.list.rev160708.AccessLists; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessListsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.AclsBuilder; -public class AclReaderFactory implements ReaderFactory, AclFactory { +public class AclReaderFactory implements ReaderFactory { @Inject private FutureJVppAclFacade futureAclFacade; @@ -49,16 +45,13 @@ public class AclReaderFactory implements ReaderFactory, AclFactory { @Named(AclModule.MAC_IP_ACL_CONTEXT_NAME) private AclContextManager macIpAClContext; - private static final InstanceIdentifier<AccessLists> ACLS_ID = InstanceIdentifier.create(AccessLists.class); - private static final InstanceIdentifier<Acl> ACL_ID = ACLS_ID.child(Acl.class); - @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.addStructuralReader(ACLS_ID, AccessListsBuilder.class); + registry.addStructuralReader(AclIIds.ACLS, AclsBuilder.class); - registry.subtreeAddBefore(vppAclChildren(InstanceIdentifier.create(Acl.class)), - new GenericInitListReader<>(ACL_ID, + registry.subtreeAddBefore(vppAclChildren(AclIIds.ACL), + new GenericInitListReader<>(AclIIds.ACLS_ACL, new AclCustomizer(futureAclFacade, standardAclContext, macIpAClContext)), - ImmutableSet.of(ACL_INGRESS_IID, ACL_EGRESS_IID)); + ImmutableSet.of(AclIIds.ACLS_AP_INT_ING, AclIIds.ACLS_AP_INT_EGR)); } } 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 173223648..1c4f0d982 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 @@ -18,31 +18,22 @@ package io.fd.hc2vpp.acl.read.factory; import com.google.inject.Inject; import com.google.inject.name.Named; +import io.fd.hc2vpp.acl.AclIIds; import io.fd.hc2vpp.acl.AclModule; -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.acl.read.InterfaceAclCustomizer; +import io.fd.hc2vpp.acl.read.EgressAclCustomizer; +import io.fd.hc2vpp.acl.read.IngressAclCustomizer; import io.fd.hc2vpp.acl.util.AclContextManager; import io.fd.hc2vpp.common.translate.util.NamingContext; 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; import javax.annotation.Nonnull; -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.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceStateAugmentationBuilder; -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.AclBuilder; -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._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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAcl; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AttachmentPointsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.EgressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.IngressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; public class InterfaceAclReaderFactory implements ReaderFactory { @@ -61,27 +52,23 @@ public class InterfaceAclReaderFactory implements ReaderFactory { @Named("interface-context") private NamingContext interfaceContext; - private static final InstanceIdentifier<Interface> - IFC_ID = InstanceIdentifier.create(InterfacesState.class).child(Interface.class); - private static final InstanceIdentifier<VppAclInterfaceStateAugmentation> VPP_ACL_AUG_IID = - IFC_ID.augmentation(VppAclInterfaceStateAugmentation.class); - static final InstanceIdentifier<Acl> ACL_IID = VPP_ACL_AUG_IID.child(Acl.class); - static final InstanceIdentifier<Ingress> ACL_INGRESS_IID = ACL_IID.child(Ingress.class); - static final InstanceIdentifier<Egress> ACL_EGRESS_IID = ACL_IID.child(Egress.class); - @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.addStructuralReader(VPP_ACL_AUG_IID, VppAclInterfaceStateAugmentationBuilder.class); - registry.addStructuralReader(ACL_IID, AclBuilder.class); + registry.addStructuralReader(AclIIds.ACLS_AP, AttachmentPointsBuilder.class); + + registry.addAfter(new GenericInitListReader<>(AclIIds.ACLS_AP_INT, + new InterfaceAclCustomizer(futureAclFacade, interfaceContext)), + AclIIds.IFC_STATE); - registry.addStructuralReader(ACL_INGRESS_IID, IngressBuilder.class); - registry.addAfter(new GenericInitListReader<>(ACL_INGRESS_IID.child(VppAcls.class), - new IngressVppAclCustomizer(futureAclFacade, interfaceContext, standardAclContext)), IFC_ID); - registry.addAfter(new GenericInitReader<>(ACL_INGRESS_IID.child(VppMacipAcl.class), - new VppMacIpAclCustomizer(futureAclFacade, interfaceContext, macIpAClContext)), IFC_ID); + registry.addStructuralReader(AclIIds.ACLS_AP_INT_ING, IngressBuilder.class); + registry.addStructuralReader(AclIIds.ACLS_AP_INT_EGR, EgressBuilder.class); + registry.addStructuralReader(AclIIds.ACLS_AP_INT_ING_ACLS, AclSetsBuilder.class); + registry.addStructuralReader(AclIIds.ACLS_AP_INT_EGR_ACLS, AclSetsBuilder.class); - registry.addStructuralReader(ACL_EGRESS_IID, EgressBuilder.class); - registry.addAfter(new GenericInitListReader<>(ACL_EGRESS_IID.child(VppAcls.class), - new EgressVppAclCustomizer(futureAclFacade, interfaceContext, standardAclContext)), IFC_ID); + registry.addAfter(new GenericInitListReader<>(AclIIds.ACLS_AP_INT_ING_ACLS_ACL, + new IngressAclCustomizer(futureAclFacade, interfaceContext, standardAclContext, macIpAClContext)), + AclIIds.ACLS_AP_INT); + registry.addAfter(new GenericInitListReader<>(AclIIds.ACLS_AP_INT_EGR_ACLS_ACL, + new EgressAclCustomizer(futureAclFacade, interfaceContext, standardAclContext)), AclIIds.ACLS_AP_INT); } } |