summaryrefslogtreecommitdiffstats
path: root/acl/acl-impl/src/main/java/io/fd
diff options
context:
space:
mode:
authorMichal Cmarada <mcmarada@cisco.com>2018-11-19 14:59:14 +0100
committerMichal Cmarada <mcmarada@cisco.com>2018-11-19 14:59:14 +0100
commit718e9a3c7cac01860f3e3fe6174fcc1bd33fb4eb (patch)
tree34fae7680450e166e845f0c2db84ed8c3215930f /acl/acl-impl/src/main/java/io/fd
parentf9acfac8b701f9903a28edc98db127c36d73384f (diff)
HC2VPP-291: ACL model bump
- bump ACL yang models - fix ACL module implementation and validation - fix ACL Unit tests - update postman collection Change-Id: Iaab64e6d92d17babc3ccef7921b41070c3716516 Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'acl/acl-impl/src/main/java/io/fd')
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclIIds.java116
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclModule.java4
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizer.java133
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java180
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AclCustomizer.java36
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressAclCustomizer.java102
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizer.java60
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressAclCustomizer.java226
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizer.java60
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/InterfaceAclCustomizer.java136
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java160
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/AclReaderFactory.java23
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/factory/InterfaceAclReaderFactory.java57
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManager.java2
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManagerImpl.java24
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/AceConverter.java129
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java140
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java234
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java39
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/factory/AclFactory.java71
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java176
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducer.java285
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclCustomizer.java (renamed from acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclCustomizer.java)38
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclValidator.java233
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java155
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclMacIpCustomizer.java69
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclValidator.java178
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AbstractAclWriterFactory.java6
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AclWriterFactory.java39
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/InterfaceAclWriterFactory.java35
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/VppAclWriterFactory.java46
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/AclAddReplaceRequest.java (renamed from acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclWriter.java)66
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/AclInterfaceAssignmentRequest.java (renamed from acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java)20
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/MacIpInterfaceAssignmentRequest.java (renamed from acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequest.java)13
34 files changed, 1806 insertions, 1485 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclIIds.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclIIds.java
new file mode 100644
index 000000000..ad4bcae68
--- /dev/null
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclIIds.java
@@ -0,0 +1,116 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+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.VppIcmpAceAugmentation;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppTcpAceAugmentation;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acl.icmp.header.fields.IcmpCodeRange;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acl.icmp.header.fields.IcmpTypeRange;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acls.acl.aces.ace.matches.l4.icmp.icmp.VppIcmpAce;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acls.acl.aces.ace.matches.l4.tcp.tcp.VppTcpAce;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Acls;
+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.AttachmentPoints;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.Aces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.Actions;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.Matches;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.eth.Eth;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.icmp.Icmp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.Tcp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.DestinationPort;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.SourcePort;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.Udp;
+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.Egress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.Ingress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSets;
+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.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AclIIds {
+ public final static InstanceIdentifier<Acls> ACLS = InstanceIdentifier.create(Acls.class);
+ public final static InstanceIdentifier<Acl> ACLS_ACL = ACLS.child(Acl.class);
+ public final static InstanceIdentifier<Acl> ACL = InstanceIdentifier.create(Acl.class);
+
+ public final static InstanceIdentifier<AttachmentPoints> ACLS_AP = ACLS.child(AttachmentPoints.class);
+ public final static InstanceIdentifier<Interface> ACLS_AP_INT = ACLS_AP.child(Interface.class);
+ public static final InstanceIdentifier<Ingress> ACLS_AP_INT_ING = ACLS_AP_INT.child(Ingress.class);
+ public static final InstanceIdentifier<AclSets> ACLS_AP_INT_ING_ACLS = ACLS_AP_INT_ING.child(AclSets.class);
+ public static final InstanceIdentifier<AclSet> ACLS_AP_INT_ING_ACLS_ACL = ACLS_AP_INT_ING_ACLS.child(AclSet.class);
+ public static final InstanceIdentifier<Egress> ACLS_AP_INT_EGR = ACLS_AP_INT.child(Egress.class);
+ public static final InstanceIdentifier<AclSets> ACLS_AP_INT_EGR_ACLS = ACLS_AP_INT_EGR.child(AclSets.class);
+ public static final InstanceIdentifier<AclSet> ACLS_AP_INT_EGR_ACLS_ACL = ACLS_AP_INT_EGR_ACLS.child(AclSet.class);
+ public final static InstanceIdentifier<Interface> IFC_ACL = InstanceIdentifier.create(Interface.class);
+ public final static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface>
+ IFC = InstanceIdentifier.create(Interfaces.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface.class);
+ public static final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface>
+ IFC_STATE = InstanceIdentifier.create(InterfacesState.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class);
+
+
+ public static Set<InstanceIdentifier<?>> vppAclChildren(final InstanceIdentifier<Acl> parentId) {
+ final InstanceIdentifier<Matches> matchesIid =
+ parentId.child(Aces.class).child(Ace.class).child(Matches.class);
+ return ImmutableSet.of(
+ parentId.augmentation(VppAclAugmentation.class),
+ parentId.child(Aces.class),
+ parentId.child(Aces.class).child(Ace.class),
+ parentId.child(Aces.class).child(Ace.class).child(Actions.class),
+ matchesIid,
+ matchesIid.child(Eth.class),
+ matchesIid.child(Ipv4.class),
+ matchesIid.child(Ipv6.class),
+ matchesIid.child(Tcp.class),
+ matchesIid.child(Tcp.class).augmentation(VppTcpAceAugmentation.class),
+ matchesIid.child(Tcp.class).augmentation(VppTcpAceAugmentation.class).child(VppTcpAce.class),
+ matchesIid.child(Tcp.class).child(DestinationPort.class),
+ matchesIid.child(Tcp.class).child(SourcePort.class),
+ matchesIid.child(Udp.class),
+ matchesIid.child(Udp.class).child(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.DestinationPort.class),
+ matchesIid.child(Udp.class).child(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.SourcePort.class),
+ matchesIid.child(Icmp.class),
+ matchesIid.child(Icmp.class).augmentation(VppIcmpAceAugmentation.class),
+ matchesIid.child(Icmp.class).augmentation(VppIcmpAceAugmentation.class).child(VppIcmpAce.class),
+ matchesIid.child(Icmp.class).augmentation(VppIcmpAceAugmentation.class).child(VppIcmpAce.class)
+ .child(IcmpTypeRange.class),
+ matchesIid.child(Icmp.class).augmentation(VppIcmpAceAugmentation.class).child(VppIcmpAce.class)
+ .child(IcmpCodeRange.class)
+ );
+ }
+
+ public static Set<InstanceIdentifier<?>> aclHandledChildren(final InstanceIdentifier<Interface> parentId) {
+ return ImmutableSet.of(
+ parentId.child(Ingress.class),
+ parentId.child(Ingress.class).child(AclSets.class),
+ parentId.child(Ingress.class).child(AclSets.class).child(AclSet.class),
+ parentId.child(Egress.class),
+ parentId.child(Egress.class).child(AclSets.class),
+ parentId.child(Egress.class).child(AclSets.class).child(AclSet.class));
+ }
+}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclModule.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclModule.java
index afb7da669..a21978e73 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclModule.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/AclModule.java
@@ -26,8 +26,8 @@ import io.fd.hc2vpp.acl.read.factory.AclReaderFactory;
import io.fd.hc2vpp.acl.read.factory.InterfaceAclReaderFactory;
import io.fd.hc2vpp.acl.util.AclContextManager;
import io.fd.hc2vpp.acl.util.AclContextManagerImpl;
+import io.fd.hc2vpp.acl.write.factory.AclWriterFactory;
import io.fd.hc2vpp.acl.write.factory.InterfaceAclWriterFactory;
-import io.fd.hc2vpp.acl.write.factory.VppAclWriterFactory;
import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
@@ -72,7 +72,7 @@ public class AclModule extends AbstractModule {
final Multibinder<WriterFactory> writerFactoryMultibinder =
Multibinder.newSetBinder(binder(), WriterFactory.class);
- writerFactoryMultibinder.addBinding().to(VppAclWriterFactory.class);
+ writerFactoryMultibinder.addBinding().to(AclWriterFactory.class);
writerFactoryMultibinder.addBinding().to(InterfaceAclWriterFactory.class);
final Multibinder<ReaderFactory> readerFactoryMultibinder =
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);
}
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManager.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManager.java
index 377d4e1dc..1b590cb7b 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManager.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManager.java
@@ -19,7 +19,7 @@ package io.fd.hc2vpp.acl.util;
import io.fd.honeycomb.translate.MappingContext;
import java.util.List;
import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
/**
* Manages metadata for acl plugin
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManagerImpl.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManagerImpl.java
index aa25c3eb1..a96680897 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManagerImpl.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/AclContextManagerImpl.java
@@ -29,18 +29,18 @@ import java.util.List;
import java.util.stream.Collector;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.VppAclContextAugmentation;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.VppAclMappings;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.VppAclContext;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.VppAclContextKey;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.AclMapping;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.AclMappingBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.AclMappingKey;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.acl.mapping.AceMapping;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.acl.mapping.AceMappingBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.acl.mapping.AceMappingKey;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.VppAclContextAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.VppAclMappings;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.VppAclContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.VppAclContextKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.AclMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.AclMappingBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.AclMappingKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.acl.mapping.AceMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.acl.mapping.AceMappingBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev170104.vpp.acl.context.attributes.vpp.acl.mappings.vpp.acl.context.acl.mapping.AceMappingKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@@ -77,7 +77,7 @@ public final class AclContextManagerImpl implements AclContextManager {
final List<AceMapping> mappings = new ArrayList<>(aces.size());
int aceIndex = 0;
for (final Ace ace : aces) {
- mappings.add(new AceMappingBuilder().setName(ace.getRuleName()).setIndex(aceIndex++).build());
+ mappings.add(new AceMappingBuilder().setName(ace.getName()).setIndex(aceIndex++).build());
}
aclMapping.setAceMapping(mappings);
ctx.put(mappingIid, aclMapping.build());
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/AceConverter.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/AceConverter.java
index db5efb4d6..8e774104a 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/AceConverter.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/AceConverter.java
@@ -16,6 +16,7 @@
package io.fd.hc2vpp.acl.util.ace;
+import com.google.common.base.Preconditions;
import io.fd.hc2vpp.acl.util.AclContextManager;
import io.fd.hc2vpp.acl.util.ace.extractor.MacIpAceDataExtractor;
import io.fd.hc2vpp.acl.util.ace.extractor.StandardAceDataExtractor;
@@ -27,16 +28,16 @@ import java.util.ArrayList;
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.rev160708.access.lists.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.AceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.AceKey;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.MatchesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.VppMacipAceNodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.AceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.AceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.MatchesBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L3;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.EthBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.eth.Eth;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.SourceNetwork;
/**
* Convert between Ace's and vpp rules.
@@ -45,23 +46,55 @@ public interface AceConverter extends MacIpAceDataExtractor, StandardAceDataExtr
default MacipAclRule[] toMacIpAclRules(@Nonnull final List<Ace> aces) {
return aces.stream()
+ .filter(ace -> ace.getMatches() != null && ace.getMatches().getL2() != null)
+ .filter(ace -> ace.getMatches().getL2().getImplementedInterface()
+ .equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.Eth.class))
.map(ace -> {
- final VppMacipAce macIpAce = fromMacIpAce(ace);
-
MacipAclRule rule = new MacipAclRule();
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.Eth
+ l2 =
+ (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.Eth) ace
+ .getMatches().getL2();
+
+ Eth eth = Preconditions
+ .checkNotNull(l2.getEth(), "Cannot parse eth for MacIpAcl ACE rule: {}", ace);
- rule.srcMac = sourceMacAsBytes(macIpAce);
- rule.srcMacMask = sourceMacMaskAsBytes(macIpAce);
+ rule.srcMac = sourceMacAsBytes(eth.getSourceMacAddress());
+ rule.srcMacMask = sourceMacMaskAsBytes(eth.getSourceMacAddressMask());
rule.isPermit = macIpAction(ace);
- if (macIpIsIpv6(macIpAce)) {
- rule.isIpv6 = 1;
- rule.srcIpAddr = ipv6Address(macIpAce);
- rule.srcIpPrefixLen = ipv6AddressPrefix(macIpAce);
+ L3 l3 = ace.getMatches().getL3();
+
+ if (l3 != null && l3.getImplementedInterface()
+ .equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4.class)) {
+ Ipv4 ipv4 =
+ ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4) l3)
+ .getIpv4();
+ if (ipv4 != null && ipv4.getSourceNetwork() != null) {
+ // IPv4 is set for MacIpAcl
+ SourceNetwork sourceNetwork = ipv4.getSourceNetwork();
+ rule.isIpv6 = 0;
+ rule.srcIpAddr = ipv4Address(sourceNetwork);
+ rule.srcIpPrefixLen = ipv4AddressPrefix(sourceNetwork);
+ }
+ } else if (l3 != null && l3.getImplementedInterface()
+ .equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6.class)) {
+ Ipv6 ipv6 =
+ ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6) l3)
+ .getIpv6();
+ if (ipv6 != null && ipv6.getSourceNetwork() != null) {
+ // IPv6 is set for MacIpAcl
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.SourceNetwork
+ sourceNetwork = ipv6.getSourceNetwork();
+ rule.isIpv6 = 1;
+ rule.srcIpAddr = ipv6Address(sourceNetwork);
+ rule.srcIpPrefixLen = ipv6AddressPrefix(sourceNetwork);
+ }
} else {
+ // No IP is set for MacIpAcl
rule.isIpv6 = 0;
- rule.srcIpAddr = ipv4Address(macIpAce);
- rule.srcIpPrefixLen = ipv4AddressPrefix(macIpAce);
+ rule.srcIpAddr = new byte[4];
+ rule.srcIpPrefixLen = 0;
}
return rule;
@@ -72,26 +105,25 @@ public interface AceConverter extends MacIpAceDataExtractor, StandardAceDataExtr
default AclRule[] toStandardAclRules(@Nonnull final List<Ace> aces) {
return aces.stream()
+ .filter(ace -> ace.getMatches() != null)
.map(ace -> {
- final VppAce standardAce = fromStandardAce(ace);
-
// pre-bind rule with protocol based attributes (if present)
- AclRule rule = createPreBindRule(standardAce);
+ AclRule rule = createPreBindRule(ace);
rule.isPermit = standardAction(ace);
- if (standardIsIpv6(standardAce, ace.getMatches())) {
+ if (standardIsIpv6(ace.getMatches())) {
rule.isIpv6 = 1;
- rule.srcIpAddr = ipv6SourceAddress(standardAce);
- rule.srcIpPrefixLen = ipv6SourceAddressPrefix(standardAce);
- rule.dstIpAddr = ipv6DestinationAddress(standardAce);
- rule.dstIpPrefixLen = ipv6DestinationAddressPrefix(standardAce);
+ rule.srcIpAddr = ipv6SourceAddress(ace.getMatches());
+ rule.srcIpPrefixLen = ipv6SourceAddressPrefix(ace.getMatches());
+ rule.dstIpAddr = ipv6DestinationAddress(ace.getMatches());
+ rule.dstIpPrefixLen = ipv6DestinationAddressPrefix(ace.getMatches());
} else {
rule.isIpv6 = 0;
- rule.srcIpAddr = ipv4SourceAddress(standardAce);
- rule.srcIpPrefixLen = ipv4SourceAddressPrefix(standardAce);
- rule.dstIpAddr = ipv4DestinationAddress(standardAce);
- rule.dstIpPrefixLen = ipv4DestinationAddressPrefix(standardAce);
+ rule.srcIpAddr = ipv4SourceAddress(ace.getMatches());
+ rule.srcIpPrefixLen = ipv4SourceAddressPrefix(ace.getMatches());
+ rule.dstIpAddr = ipv4DestinationAddress(ace.getMatches());
+ rule.dstIpPrefixLen = ipv4DestinationAddressPrefix(ace.getMatches());
}
return rule;
@@ -107,18 +139,20 @@ public interface AceConverter extends MacIpAceDataExtractor, StandardAceDataExtr
int i = 0;
for (final MacipAclRule rule : rules) {
final AceBuilder ace = new AceBuilder();
- final VppMacipAceBuilder aceType = new VppMacipAceBuilder();
- final VppMacipAceNodesBuilder nodes = new VppMacipAceNodesBuilder();
- nodes.setAceIpVersion(ipVersion(rule));
- nodes.setSourceMacAddress(sourceMac(rule));
- nodes.setSourceMacAddressMask(sourceMacMask(rule));
- aceType.setVppMacipAceNodes(nodes.build());
-
- ace.setMatches(new MatchesBuilder().setAceType(aceType.build()).build());
+ ace.setMatches(
+ new MatchesBuilder()
+ .setL3(parseMacIpAceL3(rule))
+ .setL2(new EthBuilder()
+ .setEth(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.eth.EthBuilder()
+ .setSourceMacAddress(sourceMac(rule))
+ .setSourceMacAddressMask(sourceMacMask(rule))
+ .build())
+ .build())
+ .build());
ace.setActions(actions(rule.isPermit));
final String aceName = macipAclContext.getAceName(aclName, i++, mappingContext);
- ace.setRuleName(aceName);
+ ace.setName(aceName);
ace.withKey(new AceKey(aceName));
aces.add(ace.build());
@@ -133,17 +167,14 @@ public interface AceConverter extends MacIpAceDataExtractor, StandardAceDataExtr
int i = 0;
for (final AclRule rule : rules) {
final AceBuilder ace = new AceBuilder();
- final VppAceBuilder aceType = new VppAceBuilder();
- final VppAceNodesBuilder nodes = new VppAceNodesBuilder();
- nodes.setAceIpVersion(ipVersion(rule));
- nodes.setIpProtocol(parseProtocol(rule));
- aceType.setVppAceNodes(nodes.build());
-
- ace.setMatches(new MatchesBuilder().setAceType(aceType.build()).build());
+ ace.setMatches(new MatchesBuilder()
+ .setL3(parseStandardAceL3(rule))
+ .setL4(parseProtocol(rule))
+ .build());
ace.setActions(actions(rule.isPermit));
final String aceName = standardAclContext.getAceName(aclName, i++, mappingContext);
- ace.setRuleName(aceName);
+ ace.setName(aceName);
ace.withKey(new AceKey(aceName));
aces.add(ace.build());
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java
index ddb41ee3c..0c7d761a0 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java
@@ -21,84 +21,67 @@ import io.fd.hc2vpp.common.translate.util.MacTranslator;
import io.fd.vpp.jvpp.acl.types.MacipAclRule;
import java.util.Optional;
import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Matches;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.Deny;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.Permit;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Accept;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.Actions;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L3;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6Builder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.SourceNetwork;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6NetworkBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAceEthHeaderFields;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAceIpv4HeaderFields;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAceIpv6HeaderFields;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.VppMacipAceNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.AceIpVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6Builder;
public interface MacIpAceDataExtractor extends AddressExtractor, MacTranslator {
- default VppMacipAce fromMacIpAce(@Nonnull final Ace ace) {
- return Optional.ofNullable(ace.getMatches())
- .map(Matches::getAceType)
- .map(VppMacipAce.class::cast)
- .orElseThrow(
- () -> new IllegalArgumentException(String.format("Unable to create VppMacipAce from %s", ace)));
- }
-
- default boolean macIpIsIpv6(@Nonnull final VppMacipAce ace) {
- return Optional.ofNullable(ace.getVppMacipAceNodes())
- .map(VppMacipAceNodes::getAceIpVersion)
- .map(aceIpVersion -> aceIpVersion instanceof AceIpv6)
- .orElse(false);
- }
-
- default byte[] sourceMacAsBytes(@Nonnull final VppMacipAce ace) {
- return macToByteArray(Optional.ofNullable(ace.getVppMacipAceNodes())
- .map(VppMacipAceEthHeaderFields::getSourceMacAddress)
+ default byte[] sourceMacAsBytes(final MacAddress mac) {
+ return macToByteArray(Optional.ofNullable(mac)
.map(MacAddress::getValue)
.orElse(Impl.DEFAULT_MAC));
}
- default byte[] sourceMacMaskAsBytes(@Nonnull final VppMacipAce ace) {
- return macToByteArray(Optional.ofNullable(ace.getVppMacipAceNodes())
- .map(VppMacipAceEthHeaderFields::getSourceMacAddressMask)
+ default byte[] sourceMacMaskAsBytes(final MacAddress mac) {
+ return macToByteArray(Optional.ofNullable(mac)
.map(MacAddress::getValue)
.orElse(Impl.DEFAULT_MAC_MASK));
}
- default byte[] ipv4Address(@Nonnull final VppMacipAce ace) {
- return extractIp4Address(extractV4NetworkAddressOrNull(ace));
+ default byte[] ipv4Address(@Nonnull final SourceNetwork network) {
+ return extractIp4Address(extractV4NetworkAddressOrNull(network));
}
- default byte ipv4AddressPrefix(@Nonnull final VppMacipAce ace) {
- return extractIp4AddressPrefix(extractV4NetworkAddressOrNull(ace));
+ default byte ipv4AddressPrefix(@Nonnull final SourceNetwork network) {
+ return extractIp4AddressPrefix(extractV4NetworkAddressOrNull(network));
}
- static Ipv4Prefix extractV4NetworkAddressOrNull(final @Nonnull VppMacipAce ace) {
- return Optional.ofNullable(ace.getVppMacipAceNodes())
- .map(VppMacipAceNodes::getAceIpVersion)
- .map(VppMacipAceIpv4HeaderFields.class::cast)
- .map(VppMacipAceIpv4HeaderFields::getSourceIpv4Network)
+ static Ipv4Prefix extractV4NetworkAddressOrNull(final @Nonnull SourceNetwork network) {
+ return Optional.of(network).filter(net -> net instanceof SourceIpv4Network)
+ .map(SourceIpv4Network.class::cast)
+ .map(SourceIpv4Network::getSourceIpv4Network)
.orElse(null);
}
- default byte[] ipv6Address(@Nonnull final VppMacipAce ace) {
- return extractIp6Address(extractV6NetworkAddressOrNull(ace));
+ default byte[] ipv6Address(
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.SourceNetwork network) {
+ return extractIp6Address(extractV6NetworkAddressOrNull(network));
}
- default byte ipv6AddressPrefix(@Nonnull final VppMacipAce ace) {
- return extractIp6AddressPrefix(extractV6NetworkAddressOrNull(ace));
+ default byte ipv6AddressPrefix(
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.SourceNetwork network) {
+ return extractIp6AddressPrefix(extractV6NetworkAddressOrNull(network));
}
- default Ipv6Prefix extractV6NetworkAddressOrNull(@Nonnull final VppMacipAce ace) {
- return Optional.ofNullable(ace.getVppMacipAceNodes())
- .map(VppMacipAceNodes::getAceIpVersion)
- .map(VppMacipAceIpv6HeaderFields.class::cast)
- .map(VppMacipAceIpv6HeaderFields::getSourceIpv6Network)
+ default Ipv6Prefix extractV6NetworkAddressOrNull(
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.SourceNetwork network) {
+ return Optional.of(network).filter(net -> net instanceof SourceIpv6Network)
+ .map(SourceIpv6Network.class::cast)
+ .map(SourceIpv6Network::getSourceIpv6Network)
.orElse(null);
}
@@ -107,41 +90,54 @@ public interface MacIpAceDataExtractor extends AddressExtractor, MacTranslator {
*/
default byte macIpAction(@Nonnull final Ace ace) {
// action choice itself has default, but nothing stops us from not defining actions container itself
- final PacketHandling action = Optional.ofNullable(ace.getActions()).orElseThrow(
- () -> new IllegalArgumentException(String.format("Unable to extract Action from %s", ace)))
- .getPacketHandling();
- if (action instanceof Permit) {
- return 1;
- } else if (action instanceof Deny) {
- return 0;
+ Actions actions = Optional.ofNullable(ace.getActions()).orElseThrow(
+ () -> new IllegalArgumentException(String.format("Unable to extract Action from %s", ace)));
+ if (actions.getForwarding() != null) {
+ if (ace.getActions().getForwarding().equals(Accept.class)) {
+ return 1;
+ } else {
+ return 0;
+ }
} else {
throw new IllegalArgumentException(
- String.format("Unsupported packet-handling action %s for ACE %s", action, ace));
+ String.format("Unsupported packet-handling action %s for ACE %s", actions, ace));
}
}
- default AceIpVersion ipVersion(@Nonnull final MacipAclRule rule) {
+ default L3 parseMacIpAceL3(@Nonnull final MacipAclRule rule) {
if (rule.isIpv6 == 0) {
- return ip4Ace(rule);
+ return ip4L3(rule);
} else {
- return ip6Ace(rule);
+ return ip6L3(rule);
}
}
- default AceIpVersion ip4Ace(@Nonnull final MacipAclRule rule) {
- final AceIpv4Builder ipVersion = new AceIpv4Builder();
+ default Ipv4 ip4L3(@Nonnull final MacipAclRule rule) {
+ final Ipv4Builder ipv4Builder = new Ipv4Builder();
+
if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) {
- ipVersion.setSourceIpv4Network(toIpv4Prefix(truncateIp4Array(rule.srcIpAddr), rule.srcIpPrefixLen));
+ ipv4Builder.setIpv4(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder()
+ .setSourceNetwork(new SourceIpv4NetworkBuilder()
+ .setSourceIpv4Network(
+ toIpv4Prefix(truncateIp4Array(rule.srcIpAddr), rule.srcIpPrefixLen))
+ .build())
+ .build());
}
- return ipVersion.build();
+ return ipv4Builder.build();
}
- default AceIpVersion ip6Ace(@Nonnull final MacipAclRule rule) {
- final AceIpv6Builder ipVersion = new AceIpv6Builder();
+ default Ipv6 ip6L3(@Nonnull final MacipAclRule rule) {
+ final Ipv6Builder ipv6Builder = new Ipv6Builder();
if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) {
- ipVersion.setSourceIpv6Network(toIpv6Prefix(rule.srcIpAddr, rule.srcIpPrefixLen));
+ ipv6Builder.setIpv6(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder()
+ .setSourceNetwork(new SourceIpv6NetworkBuilder()
+ .setSourceIpv6Network(toIpv6Prefix(rule.srcIpAddr, rule.srcIpPrefixLen))
+ .build())
+ .build());
}
- return ipVersion.build();
+ return ipv6Builder.build();
}
default MacAddress sourceMac(@Nonnull final MacipAclRule rule) {
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java
index 8f463aef5..9f454fd38 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java
@@ -24,147 +24,148 @@ import java.util.Map;
import java.util.Optional;
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.access.lists.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Actions;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.ActionsBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Matches;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.Deny;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.Permit;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.PermitBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.AcceptAndReflect;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Accept;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Drop;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.ForwardingAction;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Reject;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.Actions;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.ActionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.Matches;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L3;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6Builder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.AclIpv4HeaderFields;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.AclIpv6HeaderFields;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.AclIpProtocolHeaderFields;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.actions.packet.handling.Stateful;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.actions.packet.handling.StatefulBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.AceIpVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpV6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.AclIpv4HeaderFields;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.AclIpv6HeaderFields;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.destination.network.DestinationIpv4Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.destination.network.DestinationIpv4NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.destination.network.DestinationIpv6Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.destination.network.DestinationIpv6NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6NetworkBuilder;
public interface StandardAceDataExtractor extends AddressExtractor, ProtoPreBindRuleProducer, IpProtocolReader {
/**
* Allowed packet-processing actions for Acl's
*/
- Map<Class<? extends PacketHandling>, Integer> ACTION_VALUE_PAIRS = ImmutableMap.of(Deny.class, 0, Permit.class, 1,
- Stateful.class, 2);
-
- default VppAce fromStandardAce(@Nonnull final Ace ace) {
- return Optional.ofNullable(ace.getMatches())
- .map(Matches::getAceType)
- .map(VppAce.class::cast)
- .orElseThrow(() -> new IllegalArgumentException(String.format("Unable to create VppAce from %s", ace)));
- }
-
- default boolean standardIsIpv6(@Nonnull final VppAce ace, @Nullable final Matches matches) {
- final Optional<AceIpVersion> aceIpVersion = Optional.ofNullable(matches)
- .map(Matches::getAceType)
- .map(VppAce.class::cast)
- .map(VppAce::getVppAceNodes)
- .map(VppAceNodes::getAceIpVersion);
-
- // tries to detect version by ace-ip-version
- if(aceIpVersion.isPresent()){
- return aceIpVersion
- .map(version -> version instanceof AceIpv6)
- .orElse(false);
- }
+ Map<Class<? extends ForwardingAction>, Integer> ACTION_VALUE_PAIRS =
+ ImmutableMap.of(Drop.class, 0, Reject.class, 0, Accept.class, 1, AcceptAndReflect.class, 2);
- // otherwise goes by ip-protocol
- return Optional.ofNullable(ace.getVppAceNodes())
- .map(AclIpProtocolHeaderFields::getIpProtocol)
- .map(ipProtocol -> ipProtocol instanceof IcmpV6)
- .orElse(false);
+ default boolean standardIsIpv6(@Nullable final Matches matches) {
+ return Optional.ofNullable(matches)
+ .map(Matches::getL3)
+ .filter(l3 -> l3.getImplementedInterface().equals(Ipv6.class))
+ .map(Ipv6.class::cast)
+ .map(Ipv6::getIpv6)
+ .isPresent();
}
- default byte[] ipv4SourceAddress(@Nonnull final VppAce ace) {
- return extractIp4Address(
- extractV4SourceAddressOrNull(ace));
+ default byte[] ipv4SourceAddress(@Nonnull final Matches matches) {
+ return extractIp4Address(extractV4SourceAddressOrNull(matches));
}
- default byte ipv4SourceAddressPrefix(@Nonnull final VppAce ace) {
- return extractIp4AddressPrefix(
- extractV4SourceAddressOrNull(ace));
+ default byte ipv4SourceAddressPrefix(@Nonnull final Matches matches) {
+ return extractIp4AddressPrefix(extractV4SourceAddressOrNull(matches));
}
- static Ipv4Prefix extractV4SourceAddressOrNull(@Nonnull final VppAce ace) {
- return Optional.ofNullable(ace.getVppAceNodes())
- .map(VppAceNodes::getAceIpVersion)
- .map(AclIpv4HeaderFields.class::cast)
- .map(AclIpv4HeaderFields::getSourceIpv4Network)
+ static Ipv4Prefix extractV4SourceAddressOrNull(@Nonnull final Matches matches) {
+ return getIpv4Optional(matches)
+ .map(AclIpv4HeaderFields::getSourceNetwork)
+ .filter(network -> network instanceof SourceIpv4Network)
+ .map(SourceIpv4Network.class::cast)
+ .map(SourceIpv4Network::getSourceIpv4Network)
.orElse(null);
}
- default byte[] ipv4DestinationAddress(@Nonnull final VppAce ace) {
- return extractIp4Address(extractV4DestinationAddressOrNull(ace));
+ default byte[] ipv4DestinationAddress(@Nonnull final Matches matches) {
+ return extractIp4Address(extractV4DestinationAddressOrNull(matches));
}
- default byte ipv4DestinationAddressPrefix(@Nonnull final VppAce ace) {
- return extractIp4AddressPrefix(extractV4DestinationAddressOrNull(ace));
+ default byte ipv4DestinationAddressPrefix(@Nonnull final Matches matches) {
+ return extractIp4AddressPrefix(extractV4DestinationAddressOrNull(matches));
}
- static Ipv4Prefix extractV4DestinationAddressOrNull(@Nonnull final VppAce ace) {
- return Optional.ofNullable(ace.getVppAceNodes())
- .map(VppAceNodes::getAceIpVersion)
- .map(AclIpv4HeaderFields.class::cast)
- .map(AclIpv4HeaderFields::getDestinationIpv4Network)
+ static Ipv4Prefix extractV4DestinationAddressOrNull(@Nonnull final Matches matches) {
+ return getIpv4Optional(matches)
+ .map(AclIpv4HeaderFields::getDestinationNetwork)
+ .filter(destinationNetwork -> destinationNetwork instanceof DestinationIpv4Network)
+ .map(DestinationIpv4Network.class::cast)
+ .map(DestinationIpv4Network::getDestinationIpv4Network)
.orElse(null);
}
- default byte[] ipv6SourceAddress(@Nonnull final VppAce ace) {
- return extractIp6Address(extractV6SourceAddressOrNull(ace));
+ static Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4> getIpv4Optional(
+ @Nonnull final Matches matches) {
+ return Optional.ofNullable(matches.getL3())
+ .filter(l3 -> l3.getImplementedInterface().equals(Ipv4.class))
+ .map(Ipv4.class::cast)
+ .map(Ipv4::getIpv4);
+ }
+
+ default byte[] ipv6SourceAddress(@Nonnull final Matches matches) {
+ return extractIp6Address(extractV6SourceAddressOrNull(matches));
}
- default byte ipv6SourceAddressPrefix(@Nonnull final VppAce ace) {
- return extractIp6AddressPrefix(extractV6SourceAddressOrNull(ace));
+ default byte ipv6SourceAddressPrefix(@Nonnull final Matches matches) {
+ return extractIp6AddressPrefix(extractV6SourceAddressOrNull(matches));
}
- static Ipv6Prefix extractV6SourceAddressOrNull(@Nonnull final VppAce ace) {
- return Optional.ofNullable(ace.getVppAceNodes())
- .map(VppAceNodes::getAceIpVersion)
- .map(AclIpv6HeaderFields.class::cast)
- .map(AclIpv6HeaderFields::getSourceIpv6Network)
+ static Ipv6Prefix extractV6SourceAddressOrNull(@Nonnull final Matches matches) {
+ return getIpv6Optional(matches)
+ .map(AclIpv6HeaderFields::getSourceNetwork)
+ .filter(sourceNetwork -> sourceNetwork instanceof SourceIpv6Network)
+ .map(SourceIpv6Network.class::cast)
+ .map(SourceIpv6Network::getSourceIpv6Network)
.orElse(null);
}
- default byte[] ipv6DestinationAddress(@Nonnull final VppAce ace) {
- return extractIp6Address(extractV6DestinationAddressOrNull(ace));
+ default byte[] ipv6DestinationAddress(@Nonnull final Matches matches) {
+ return extractIp6Address(extractV6DestinationAddressOrNull(matches));
}
- default byte ipv6DestinationAddressPrefix(@Nonnull final VppAce ace) {
- return extractIp6AddressPrefix(extractV6DestinationAddressOrNull(ace));
+ default byte ipv6DestinationAddressPrefix(@Nonnull final Matches matches) {
+ return extractIp6AddressPrefix(extractV6DestinationAddressOrNull(matches));
}
- static Ipv6Prefix extractV6DestinationAddressOrNull(@Nonnull final VppAce ace) {
- return Optional.ofNullable(ace.getVppAceNodes())
- .map(VppAceNodes::getAceIpVersion)
- .map(AclIpv6HeaderFields.class::cast)
- .map(AclIpv6HeaderFields::getDestinationIpv6Network)
+ static Ipv6Prefix extractV6DestinationAddressOrNull(@Nonnull final Matches matches) {
+ return getIpv6Optional(matches)
+ .map(AclIpv6HeaderFields::getDestinationNetwork)
+ .filter(destinationNetwork -> destinationNetwork instanceof DestinationIpv6Network)
+ .map(DestinationIpv6Network.class::cast)
+ .map(DestinationIpv6Network::getDestinationIpv6Network)
.orElse(null);
}
+ static Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6> getIpv6Optional(
+ @Nonnull final Matches matches) {
+ return Optional.ofNullable(matches.getL3())
+ .filter(l3 -> l3.getImplementedInterface().equals(Ipv6.class))
+ .map(Ipv6.class::cast)
+ .map(Ipv6::getIpv6);
+ }
+
default byte standardAction(@Nonnull final Ace ace) {
- // default == deny
- final PacketHandling action = Optional.ofNullable(ace.getActions())
+ Class<? extends ForwardingAction> forwarding = Optional.ofNullable(ace.getActions())
.orElseThrow(() -> new IllegalArgumentException(String.format("Unable to extract Action from %s", ace)))
- .getPacketHandling();
+ .getForwarding();
return ACTION_VALUE_PAIRS.get(ACTION_VALUE_PAIRS.keySet().stream()
- .filter(aClass -> aClass.isInstance(action))
+ .filter(aClass -> aClass.equals(forwarding))
.findAny()
.orElseThrow(() -> new IllegalArgumentException(
- String.format("Unsupported packet-handling action %s for ACE %s", action,
- ace.getRuleName())))).byteValue();
+ String.format("Unsupported packet-handling action %s for ACE %s", forwarding,
+ ace.getName())))).byteValue();
}
- default AceIpVersion ipVersion(@Nonnull final AclRule rule) {
+ default L3 parseStandardAceL3(@Nonnull final AclRule rule) {
if (rule.isIpv6 == 0) {
return ip4Ace(rule);
} else {
@@ -172,40 +173,55 @@ public interface StandardAceDataExtractor extends AddressExtractor, ProtoPreBind
}
}
- default AceIpVersion ip4Ace(@Nonnull final AclRule rule) {
- final AceIpv4Builder ipVersion = new AceIpv4Builder();
+ default org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4 ip4Ace(
+ @Nonnull final AclRule rule) {
+ Ipv4Builder ipv4Builder = new Ipv4Builder();
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder
+ ip4Builder =
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder();
if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) {
- ipVersion.setSourceIpv4Network(toIpv4Prefix(truncateIp4Array(rule.srcIpAddr), rule.srcIpPrefixLen));
+ ip4Builder.setSourceNetwork(new SourceIpv4NetworkBuilder()
+ .setSourceIpv4Network(toIpv4Prefix(truncateIp4Array(rule.srcIpAddr), rule.srcIpPrefixLen))
+ .build());
}
if (rule.dstIpAddr != null && rule.dstIpAddr.length != 0) {
- ipVersion.setDestinationIpv4Network(toIpv4Prefix(truncateIp4Array(rule.dstIpAddr), rule.dstIpPrefixLen));
+ ip4Builder.setDestinationNetwork(new DestinationIpv4NetworkBuilder()
+ .setDestinationIpv4Network(toIpv4Prefix(truncateIp4Array(rule.dstIpAddr), rule.dstIpPrefixLen))
+ .build());
}
- return ipVersion.build();
+ return ipv4Builder.setIpv4(ip4Builder.build()).build();
}
- default AceIpVersion ip6Ace(@Nonnull final AclRule rule) {
- final AceIpv6Builder ipVersion = new AceIpv6Builder();
+ default org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6 ip6Ace(
+ @Nonnull final AclRule rule) {
+ Ipv6Builder ipv6Builder = new Ipv6Builder();
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder
+ ip6Builder =
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder();
+
if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) {
- ipVersion.setSourceIpv6Network(toIpv6Prefix(rule.srcIpAddr, rule.srcIpPrefixLen));
+ ip6Builder.setSourceNetwork(new SourceIpv6NetworkBuilder()
+ .setSourceIpv6Network(toIpv6Prefix(rule.srcIpAddr, rule.srcIpPrefixLen))
+ .build());
}
if (rule.dstIpAddr != null && rule.dstIpAddr.length != 0) {
- ipVersion.setDestinationIpv6Network(toIpv6Prefix(rule.dstIpAddr, rule.dstIpPrefixLen));
+ ip6Builder.setDestinationNetwork(new DestinationIpv6NetworkBuilder()
+ .setDestinationIpv6Network(toIpv6Prefix(rule.dstIpAddr, rule.dstIpPrefixLen))
+ .build());
}
- return ipVersion.build();
+ return ipv6Builder.setIpv6(ip6Builder.build()).build();
}
default Actions actions(final byte isPermit) {
final ActionsBuilder actions = new ActionsBuilder();
switch (isPermit) {
case 0:
- actions.setPacketHandling(new DenyBuilder().setDeny(true).build());
+ actions.setForwarding(Drop.class);
break;
case 1:
- actions.setPacketHandling(new PermitBuilder().setPermit(true).build());
- break;
- case 2:
- actions.setPacketHandling(new StatefulBuilder().setPermitAndReflect(true).build());
+ actions.setForwarding(Accept.class);
break;
+
default:
throw new IllegalArgumentException("Unsupported action: " + isPermit);
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java
index 5f75ae306..977dd4062 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java
@@ -16,16 +16,19 @@
package io.fd.hc2vpp.acl.util.acl;
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.acl.write.AclValidator;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
-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.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Matches;
-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.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppAcl;
+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.VppMacipAcl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.AclBase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Ipv4AclType;
+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.acl.aces.Ace;
/**
* Extracts data from Acls.
@@ -34,31 +37,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.
public interface AclDataExtractor {
/**
- * Checks if provided {@link Acl} has aces of type {@link VppAce}
+ * Checks if provided {@link Acl} has aces of type {@link Ipv4AclType} or {@link VppAcl}
*/
default boolean isStandardAcl(@Nonnull final Acl acl) {
- return acl.getAccessListEntries().getAce().stream()
- .map(Ace::getMatches)
- .map(Matches::getAceType)
- .filter(aceType -> aceType instanceof VppAce)
- .findAny()
- .isPresent();
+ Class<? extends AclBase> type =
+ Preconditions.checkNotNull(acl.getType(), "Type is not set for ACL:{}", acl);
+ return type.equals(VppAcl.class);
}
/**
- * Checks if provided {@link Acl} has aces of type {@link VppMacipAce}
+ * Checks if provided {@link Acl} has aces of type {@link VppMacipAcl}
*/
default boolean isMacIpAcl(@Nonnull final Acl acl) {
- return acl.getAccessListEntries().getAce().stream()
- .map(Ace::getMatches)
- .map(Matches::getAceType)
- .filter(aceType -> aceType instanceof VppMacipAce)
- .findAny()
- .isPresent();
+ Class<? extends AclBase> type =
+ Preconditions.checkNotNull(acl.getType(), "Type is not set for ACL:{}", acl);
+ return type.equals(VppMacipAcl.class);
}
default List<Ace> getAces(@Nonnull final Acl acl) {
- return Optional.ofNullable(acl.getAccessListEntries()).orElseThrow(() ->
+ return Optional.ofNullable(acl.getAces()).orElseThrow(() ->
new IllegalArgumentException(String.format("Unable to extract aces from %s", acl))).getAce();
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/factory/AclFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/factory/AclFactory.java
deleted file mode 100644
index 474a52844..000000000
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/factory/AclFactory.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2017 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.util.factory;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Set;
-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.acl.AccessListEntries;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Actions;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Matches;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRange;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRange;
-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.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.VppMacipAceNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.icmp.header.fields.IcmpCodeRange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.icmp.header.fields.IcmpTypeRange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.icmp.IcmpNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.icmp.v6.IcmpV6Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.other.OtherNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.tcp.TcpNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.udp.UdpNodes;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public interface AclFactory {
-
- default Set<InstanceIdentifier<?>> vppAclChildren(final InstanceIdentifier<Acl> parentId) {
- final InstanceIdentifier<Matches> matchesIid =
- parentId.child(AccessListEntries.class).child(Ace.class).child(Matches.class);
- return ImmutableSet.of(
- parentId.augmentation(VppAclAugmentation.class),
- parentId.child(AccessListEntries.class),
- parentId.child(AccessListEntries.class).child(Ace.class),
- parentId.child(AccessListEntries.class).child(Ace.class).child(Matches.class),
- parentId.child(AccessListEntries.class).child(Ace.class).child(Actions.class),
- matchesIid,
- matchesIid.child(VppMacipAceNodes.class),
- matchesIid.child(VppAceNodes.class),
- matchesIid.child(VppAceNodes.class).child(IcmpNodes.class),
- matchesIid.child(VppAceNodes.class).child(IcmpNodes.class).child(IcmpCodeRange.class),
- matchesIid.child(VppAceNodes.class).child(IcmpNodes.class).child(IcmpTypeRange.class),
- matchesIid.child(VppAceNodes.class).child(IcmpV6Nodes.class),
- matchesIid.child(VppAceNodes.class).child(IcmpV6Nodes.class).child(IcmpCodeRange.class),
- matchesIid.child(VppAceNodes.class).child(IcmpV6Nodes.class).child(IcmpTypeRange.class),
- matchesIid.child(VppAceNodes.class).child(UdpNodes.class),
- matchesIid.child(VppAceNodes.class).child(UdpNodes.class).child(SourcePortRange.class),
- matchesIid.child(VppAceNodes.class).child(UdpNodes.class).child(DestinationPortRange.class),
- matchesIid.child(VppAceNodes.class).child(TcpNodes.class),
- matchesIid.child(VppAceNodes.class).child(TcpNodes.class).child(SourcePortRange.class),
- matchesIid.child(VppAceNodes.class).child(TcpNodes.class).child(DestinationPortRange.class),
- matchesIid.child(VppAceNodes.class).child(OtherNodes.class)
-
- );
- }
-
-}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java
index 9c8b99b45..3207ecd4b 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java
@@ -21,40 +21,42 @@ import static io.fd.hc2vpp.acl.util.protocol.ProtoPreBindRuleProducer.ICMP_INDEX
import static io.fd.hc2vpp.acl.util.protocol.ProtoPreBindRuleProducer.TCP_INDEX;
import static io.fd.hc2vpp.acl.util.protocol.ProtoPreBindRuleProducer.UDP_INDEX;
+import com.google.common.annotations.VisibleForTesting;
import io.fd.vpp.jvpp.acl.types.AclRule;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppIcmpAceAugmentation;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppIcmpAceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppTcpAceAugmentation;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppTcpAceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acl.icmp.header.fields.IcmpCodeRange;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acl.icmp.header.fields.IcmpCodeRangeBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acl.icmp.header.fields.IcmpTypeRange;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acl.icmp.header.fields.IcmpTypeRangeBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acls.acl.aces.ace.matches.l4.icmp.icmp.VppIcmpAceBuilder;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.acls.acl.aces.ace.matches.l4.tcp.tcp.VppTcpAceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Icmp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.IcmpBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Tcp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.TcpBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Udp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.UdpBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.DestinationPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.SourcePortBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.source.port.source.port.RangeOrOperatorBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRange;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRangeBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRange;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRangeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.icmp.header.fields.IcmpCodeRange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.icmp.header.fields.IcmpCodeRangeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.icmp.header.fields.IcmpTypeRange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.icmp.header.fields.IcmpTypeRangeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.IpProtocol;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Icmp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpV6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpV6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Other;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.OtherBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Tcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.TcpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Udp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.UdpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.icmp.IcmpNodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.icmp.v6.IcmpV6NodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.other.OtherNodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.tcp.TcpNodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.udp.UdpNodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.AclTcpHeaderFields;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.port.range.or.operator.PortRangeOrOperator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.port.range.or.operator.port.range.or.operator.Range;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.port.range.or.operator.port.range.or.operator.RangeBuilder;
/**
* Utility for parsing IpProtocol DO based on data returned by vpp as {@link AclRule}.
*/
public interface IpProtocolReader {
- default IpProtocol parseProtocol(final AclRule rule) {
+ default L4 parseProtocol(final AclRule rule) {
switch (rule.proto) {
+ case ICMPV6_INDEX:
case ICMP_INDEX: {
return Impl.parseIcmp(rule);
}
@@ -66,14 +68,8 @@ public interface IpProtocolReader {
case UDP_INDEX: {
return Impl.parseUdp(rule);
}
-
- case ICMPV6_INDEX: {
- return Impl.parseIcmp6(rule);
- }
- default: {
- return Impl.parse(rule);
- }
}
+ return null;
}
class Impl {
@@ -91,51 +87,107 @@ public interface IpProtocolReader {
}
private static Icmp parseIcmp(final AclRule rule) {
- final IcmpNodesBuilder nodes = new IcmpNodesBuilder();
- nodes.setIcmpCodeRange(parseIcmpCodeRange(rule));
- nodes.setIcmpTypeRange(parseIcmpTypeRange(rule));
- return new IcmpBuilder().setIcmpNodes(nodes.build()).build();
+ return new IcmpBuilder().setIcmp(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.icmp.IcmpBuilder()
+ .addAugmentation(VppIcmpAceAugmentation.class,
+ new VppIcmpAceAugmentationBuilder()
+ .setVppIcmpAce(new VppIcmpAceBuilder()
+ .setIcmpCodeRange(parseIcmpCodeRange(rule))
+ .setIcmpTypeRange(parseIcmpTypeRange(rule))
+ .build())
+ .build())
+ .build())
+ .build();
}
- private static DestinationPortRange parseDstPortRange(final AclRule rule) {
- return new DestinationPortRangeBuilder()
- .setLowerPort(new PortNumber(Short.toUnsignedInt(rule.dstportOrIcmpcodeFirst)))
- .setUpperPort(new PortNumber(Short.toUnsignedInt(rule.dstportOrIcmpcodeLast))).build();
+ private static PortRangeOrOperator parseDstPortRange(final AclRule rule) {
+ return new RangeBuilder()
+ .setLowerPort(new PortNumber(Short.toUnsignedInt(rule.dstportOrIcmpcodeFirst)))
+ .setUpperPort(new PortNumber(Short.toUnsignedInt(rule.dstportOrIcmpcodeLast))).build();
}
- private static SourcePortRange parseSrcPortRange(final AclRule rule) {
- return new SourcePortRangeBuilder()
+ private static Range parseSrcPortRange(final AclRule rule) {
+ return new RangeBuilder()
.setLowerPort(new PortNumber(Short.toUnsignedInt(rule.srcportOrIcmptypeFirst)))
.setUpperPort(new PortNumber(Short.toUnsignedInt(rule.srcportOrIcmptypeLast))).build();
}
private static Tcp parseTcp(final AclRule rule) {
- final TcpNodesBuilder nodes = new TcpNodesBuilder();
- nodes.setDestinationPortRange(parseDstPortRange(rule));
- nodes.setSourcePortRange(parseSrcPortRange(rule));
- nodes.setTcpFlagsMask((short) Byte.toUnsignedInt(rule.tcpFlagsMask));
- nodes.setTcpFlagsValue((short) Byte.toUnsignedInt(rule.tcpFlagsValue));
- return new TcpBuilder().setTcpNodes(nodes.build()).build();
+ return new TcpBuilder().setTcp(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.TcpBuilder()
+ .setFlags(parseTcpFlags((short) Byte.toUnsignedInt(rule.tcpFlagsValue)))
+ .addAugmentation(VppTcpAceAugmentation.class, new VppTcpAceAugmentationBuilder()
+ .setVppTcpAce(new VppTcpAceBuilder()
+ .setFlagsMask(
+ parseTcpFlagsMask((short) Byte.toUnsignedInt(rule.tcpFlagsMask)))
+ .build())
+ .build())
+ .setSourcePort(new SourcePortBuilder()
+ .setSourcePort(new RangeOrOperatorBuilder()
+ .setPortRangeOrOperator(parseSrcPortRange(rule))
+ .build())
+ .build())
+ .setDestinationPort(new DestinationPortBuilder()
+ .setDestinationPort(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperatorBuilder()
+ .setPortRangeOrOperator(parseDstPortRange(rule))
+ .build())
+ .build())
+ .build())
+ .build();
}
- private static Udp parseUdp(final AclRule rule) {
- final UdpNodesBuilder nodes = new UdpNodesBuilder();
- nodes.setDestinationPortRange(parseDstPortRange(rule));
- nodes.setSourcePortRange(parseSrcPortRange(rule));
- return new UdpBuilder().setUdpNodes(nodes.build()).build();
+ @VisibleForTesting
+ private static org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.AclTcpHeaderFields.FlagsMask parseTcpFlagsMask(
+ final short tcpFlagsMask) {
+ // Flags from bit on position 1 to 8
+ final Boolean cwr = (tcpFlagsMask & 0b00000001) == 1;
+ final Boolean ece = (tcpFlagsMask & 0b00000010) >> 1 == 1;
+ final Boolean urg = (tcpFlagsMask & 0b00000100) >> 2 == 1;
+ final Boolean ack = (tcpFlagsMask & 0b00001000) >> 3 == 1;
+ final Boolean psh = (tcpFlagsMask & 0b00010000) >> 4 == 1;
+ final Boolean rst = (tcpFlagsMask & 0b00100000) >> 5 == 1;
+ final Boolean syn = (tcpFlagsMask & 0b01000000) >> 6 == 1;
+ final Boolean fin = (tcpFlagsMask & 0b10000000) >> 7 == 1;
+
+ return new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.AclTcpHeaderFields.FlagsMask(
+ ack, cwr, ece, fin, psh, rst, syn, urg);
}
- private static IcmpV6 parseIcmp6(final AclRule rule) {
- final IcmpV6NodesBuilder nodes = new IcmpV6NodesBuilder();
- nodes.setIcmpCodeRange(parseIcmpCodeRange(rule));
- nodes.setIcmpTypeRange(parseIcmpTypeRange(rule));
- return new IcmpV6Builder().setIcmpV6Nodes(nodes.build()).build();
+ @VisibleForTesting
+ private static AclTcpHeaderFields.Flags parseTcpFlags(final short tcpFlagsValue) {
+ // Flags from bit on position 1 to 8
+ final Boolean cwr = (tcpFlagsValue & 0b00000001) == 1;
+ final Boolean ece = (tcpFlagsValue & 0b00000010) >> 1 == 1;
+ final Boolean urg = (tcpFlagsValue & 0b00000100) >> 2 == 1;
+ final Boolean ack = (tcpFlagsValue & 0b00001000) >> 3 == 1;
+ final Boolean psh = (tcpFlagsValue & 0b00010000) >> 4 == 1;
+ final Boolean rst = (tcpFlagsValue & 0b00100000) >> 5 == 1;
+ final Boolean syn = (tcpFlagsValue & 0b01000000) >> 6 == 1;
+ final Boolean fin = (tcpFlagsValue & 0b10000000) >> 7 == 1;
+
+ return new AclTcpHeaderFields.Flags(ack, cwr, ece, fin, psh, rst, syn, urg);
}
- private static Other parse(final AclRule rule) {
- final OtherNodesBuilder nodes = new OtherNodesBuilder();
- nodes.setProtocol((short) Short.toUnsignedInt(rule.proto));
- return new OtherBuilder().setOtherNodes(nodes.build()).build();
+ private static Udp parseUdp(final AclRule rule) {
+ return new UdpBuilder().setUdp(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.UdpBuilder()
+ .setSourcePort(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.SourcePortBuilder()
+ .setSourcePort(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.source.port.source.port.RangeOrOperatorBuilder()
+ .setPortRangeOrOperator(parseSrcPortRange(rule))
+ .build())
+ .build())
+ .setDestinationPort(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.DestinationPortBuilder()
+ .setDestinationPort(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.destination.port.destination.port.RangeOrOperatorBuilder()
+ .setPortRangeOrOperator(parseDstPortRange(rule))
+ .build())
+ .build())
+ .build())
+ .build();
}
}
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducer.java
index 582da0357..3ca18d6e6 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducer.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducer.java
@@ -16,31 +16,27 @@
package io.fd.hc2vpp.acl.util.protocol;
-import static com.google.common.base.Preconditions.checkArgument;
-import static io.fd.hc2vpp.acl.util.protocol.ProtoPreBindRuleProducer.ProtocolPair.pair;
-
-import com.google.common.collect.ImmutableSet;
+import com.google.common.base.Preconditions;
import io.fd.vpp.jvpp.acl.types.AclRule;
-import java.util.Optional;
-import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.ValueRange;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppIcmpAceAugmentation;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppTcpAceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.icmp.Icmp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.Tcp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.DestinationPort;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.source.port.SourcePort;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.source.port.source.port.RangeOrOperator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.Udp;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRange;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.ValueRange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.IpProtocol;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Icmp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpV6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Other;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Tcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Udp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.icmp.IcmpNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.icmp.v6.IcmpV6Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.tcp.TcpNodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.udp.UdpNodes;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.AclTcpHeaderFields;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.port.range.or.operator.PortRangeOrOperator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.port.range.or.operator.port.range.or.operator.Range;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
/**
* Creates ACL rules pre-bind with protocol-related fields.<br>
@@ -53,89 +49,41 @@ public interface ProtoPreBindRuleProducer {
int TCP_INDEX = 6;
int UDP_INDEX = 17;
int ICMPV6_INDEX = 58;
- short MAX_PORT_NUMBER = (short)65535;
-
- Set<ProtocolPair> PROTOCOL_PAIRS = ImmutableSet.of(pair(Icmp.class, ICMP_INDEX), pair(Tcp.class, TCP_INDEX),
- pair(Udp.class, UDP_INDEX), pair(IcmpV6.class, ICMPV6_INDEX));
-
- class ProtocolPair {
- private final Class<? extends IpProtocol> protocolClass;
- private final int index;
+ short MAX_PORT_NUMBER = (short) 65535;
- private ProtocolPair(final Class<? extends IpProtocol> protocolClass, final int index) {
- this.protocolClass = protocolClass;
- this.index = index;
- }
-
- static ProtocolPair pair(@Nonnull final Class<? extends IpProtocol> protocolClass, @Nonnull final int index) {
- return new ProtocolPair(protocolClass, index);
- }
+ static AclRule bindIcmpVppFields(AclRule rule, Icmp icmp) {
+ VppIcmpAceAugmentation vppIcmp = icmp.augmentation(VppIcmpAceAugmentation.class);
+ Preconditions.checkNotNull(vppIcmp.getVppIcmpAce(), "Cannot determine VPP ICMP attributes!");
+ final ValueRange typesRange = vppIcmp.getVppIcmpAce().getIcmpTypeRange();
+ final ValueRange codesRange = vppIcmp.getVppIcmpAce().getIcmpCodeRange();
- boolean match(@Nonnull final Class<? extends IpProtocol> protocolClass) {
- return this.protocolClass.isAssignableFrom(protocolClass);
+ if (typesRange != null) {
+ rule.srcportOrIcmptypeFirst = Preconditions.checkNotNull(typesRange.getFirst());
+ rule.srcportOrIcmptypeLast = Preconditions.checkNotNull(typesRange.getLast());
}
- int getIndex() {
- return this.index;
+ if (codesRange != null) {
+ rule.dstportOrIcmpcodeFirst = Preconditions.checkNotNull(codesRange.getFirst());
+ rule.dstportOrIcmpcodeLast = Preconditions.checkNotNull(codesRange.getLast());
}
- }
-
- static byte protocol(final IpProtocol ipProtocol) {
- final Optional<ProtocolPair> optPair = PROTOCOL_PAIRS.stream()
- .filter(protocolPair -> protocolPair.match(ipProtocol.getClass()))
- .findAny();
-
- if (!optPair.isPresent()) {
- if (Other.class.isAssignableFrom(ipProtocol.getClass())) {
- return Other.class.cast(ipProtocol).getOtherNodes().getProtocol().byteValue();
- }
-
- throw new IllegalArgumentException(String.format("Unsupported Protocol Type %s", ipProtocol.getClass()));
- }
- return (byte) optPair.get().getIndex();
- }
-
- static AclRule bindIcmpNodes(AclRule rule, VppAce ace) {
- final VppAceNodes vppAceNodes = ace.getVppAceNodes();
- checkArgument(vppAceNodes.getIpProtocol() instanceof Icmp);
- final IcmpNodes icmp = Icmp.class.cast(vppAceNodes.getIpProtocol()).getIcmpNodes();
- final ValueRange typesRange = icmp.getIcmpTypeRange();
- final ValueRange codesRange = icmp.getIcmpCodeRange();
-
- rule.srcportOrIcmptypeFirst = typesRange.getFirst();
- rule.srcportOrIcmptypeLast = typesRange.getLast();
- rule.dstportOrIcmpcodeFirst = codesRange.getFirst();
- rule.dstportOrIcmpcodeLast = codesRange.getLast();
return rule;
}
- static AclRule bindIcmpv6Nodes(AclRule rule, VppAce ace) {
- final VppAceNodes vppAceNodes = ace.getVppAceNodes();
- checkArgument(vppAceNodes.getIpProtocol() instanceof IcmpV6);
- final IcmpV6Nodes icmpV6 = IcmpV6.class.cast(vppAceNodes.getIpProtocol()).getIcmpV6Nodes();
- final ValueRange typesRange = icmpV6.getIcmpTypeRange();
- final ValueRange codesRange = icmpV6.getIcmpCodeRange();
-
- rule.srcportOrIcmptypeFirst = typesRange.getFirst();
- rule.srcportOrIcmptypeLast = typesRange.getLast();
- rule.dstportOrIcmpcodeFirst = codesRange.getFirst();
- rule.dstportOrIcmpcodeLast = codesRange.getLast();
-
- return rule;
- }
-
- static void bindSourcePortRange(@Nonnull final AclRule rule, @Nullable final SourcePortRange sourcePortRange) {
+ static void bindSourcePortRange(@Nonnull final AclRule rule, @Nullable final PortRangeOrOperator sourcePortRange) {
// allow all ports by default:
rule.srcportOrIcmptypeFirst = 0;
rule.srcportOrIcmptypeLast = MAX_PORT_NUMBER;
- if(sourcePortRange != null) {
+ if (sourcePortRange != null) {
// lower port is mandatory
- rule.srcportOrIcmptypeFirst = portNumber(sourcePortRange.getLowerPort());
+ Preconditions.checkArgument(sourcePortRange instanceof Range);
+ Range portRange = (Range) sourcePortRange;
+ Preconditions.checkNotNull(portRange.getLowerPort(), "Lower port is mandatory!");
+ rule.srcportOrIcmptypeFirst = portNumber(portRange.getLowerPort());
- if (sourcePortRange.getUpperPort() != null) {
- rule.srcportOrIcmptypeLast = portNumber(sourcePortRange.getUpperPort());
+ if (portRange.getUpperPort() != null) {
+ rule.srcportOrIcmptypeLast = portNumber(portRange.getUpperPort());
} else {
// if upper port is missing, set lower port value as end of checked range:
rule.srcportOrIcmptypeLast = rule.srcportOrIcmptypeFirst;
@@ -143,17 +91,21 @@ public interface ProtoPreBindRuleProducer {
}
}
- static void bindDestinationPortRange(@Nonnull final AclRule rule, @Nullable final DestinationPortRange destinationPortRange) {
+ static void bindDestinationPortRange(@Nonnull final AclRule rule,
+ @Nullable final PortRangeOrOperator destinationPortRange) {
// allow all ports by default:
rule.dstportOrIcmpcodeFirst = 0;
rule.dstportOrIcmpcodeLast = MAX_PORT_NUMBER;
- if(destinationPortRange != null) {
+ if (destinationPortRange != null) {
// lower port is mandatory
- rule.dstportOrIcmpcodeFirst = portNumber(destinationPortRange.getLowerPort());
+ Preconditions.checkArgument(destinationPortRange instanceof Range);
+ Range portRange = (Range) destinationPortRange;
+ Preconditions.checkNotNull(portRange.getLowerPort(), "Lower port is mandatory!");
+ rule.dstportOrIcmpcodeFirst = portNumber(portRange.getLowerPort());
- if (destinationPortRange.getUpperPort() != null) {
- rule.dstportOrIcmpcodeLast = portNumber(destinationPortRange.getUpperPort());
+ if (portRange.getUpperPort() != null) {
+ rule.dstportOrIcmpcodeLast = portNumber(portRange.getUpperPort());
} else {
// if upper port is missing, set lower port value as end of checked range:
rule.dstportOrIcmpcodeLast = rule.dstportOrIcmpcodeFirst;
@@ -161,30 +113,78 @@ public interface ProtoPreBindRuleProducer {
}
}
- static AclRule bindTcpNodes(AclRule rule, VppAce ace) {
- final VppAceNodes vppAceNodes = ace.getVppAceNodes();
- checkArgument(vppAceNodes.getIpProtocol() instanceof Tcp);
+ static AclRule bindTcpAttributes(AclRule rule, Tcp tcp) {
+ SourcePort srcPort = Preconditions.checkNotNull(tcp.getSourcePort()).getSourcePort();
+ if (srcPort instanceof RangeOrOperator) {
+ bindSourcePortRange(rule, ((RangeOrOperator) srcPort).getPortRangeOrOperator());
+ }
- final TcpNodes tcp = Tcp.class.cast(vppAceNodes.getIpProtocol()).getTcpNodes();
- bindSourcePortRange(rule, tcp.getSourcePortRange());
- bindDestinationPortRange(rule, tcp.getDestinationPortRange());
+ DestinationPort dstPort = Preconditions.checkNotNull(tcp.getDestinationPort()).getDestinationPort();
+ if (dstPort instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperator) {
+ bindDestinationPortRange(rule,
+ ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperator) dstPort)
+ .getPortRangeOrOperator());
+ }
+ AclTcpHeaderFields.Flags flags = tcp.getFlags();
- if(tcp.getTcpFlagsMask() != null) {
- rule.tcpFlagsMask = tcp.getTcpFlagsMask().byteValue();
+ if (flags != null) {
+ rule.tcpFlagsValue = parseTcpFlagsValue(flags);
}
- if(tcp.getTcpFlagsValue() != null) {
- rule.tcpFlagsValue = tcp.getTcpFlagsValue().byteValue();
+
+ VppTcpAceAugmentation vppTcpAceAugmentation = tcp.augmentation(VppTcpAceAugmentation.class);
+ if (vppTcpAceAugmentation != null && vppTcpAceAugmentation.getVppTcpAce() != null &&
+ vppTcpAceAugmentation.getVppTcpAce().getFlagsMask() != null) {
+ rule.tcpFlagsMask = parseTcpFlagsMask(vppTcpAceAugmentation.getVppTcpAce().getFlagsMask());
}
+
return rule;
}
- static AclRule bindUdpNodes(AclRule rule, VppAce ace) {
- final VppAceNodes vppAceNodes = ace.getVppAceNodes();
- checkArgument(vppAceNodes.getIpProtocol() instanceof Udp);
+ static byte parseTcpFlagsValue(AclTcpHeaderFields.Flags flags) {
+ int fin = flags.isFin() ? 1 : 0;
+ int syn = flags.isSyn() ? 1 : 0;
+ int rst = flags.isRst() ? 1 : 0;
+ int psh = flags.isPsh() ? 1 : 0;
+ int ack = flags.isAck() ? 1 : 0;
+ int urg = flags.isUrg() ? 1 : 0;
+ int ece = flags.isEce() ? 1 : 0;
+ int cwr = flags.isCwr() ? 1 : 0;
+ String strFlags = String.format("%d%d%d%d%d%d%d%d", fin, syn, rst, psh, ack, urg, ece, cwr);
+ return Byte.parseByte(strFlags, 2);
+ }
+
+ static byte parseTcpFlagsMask(
+ org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.AclTcpHeaderFields.FlagsMask flags) {
+ int fin = flags.isFin() ? 1 : 0;
+ int syn = flags.isSyn() ? 1 : 0;
+ int rst = flags.isRst() ? 1 : 0;
+ int psh = flags.isPsh() ? 1 : 0;
+ int ack = flags.isAck() ? 1 : 0;
+ int urg = flags.isUrg() ? 1 : 0;
+ int ece = flags.isEce() ? 1 : 0;
+ int cwr = flags.isCwr() ? 1 : 0;
+ String strFlags = String.format("%d%d%d%d%d%d%d%d", fin, syn, rst, psh, ack, urg, ece, cwr);
+ return Byte.parseByte(strFlags, 2);
+ }
+
+ static AclRule bindUdpAttributes(AclRule rule, Udp udp) {
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.source.port.SourcePort
+ srcPort = Preconditions.checkNotNull(udp.getSourcePort()).getSourcePort();
+
+ if (srcPort instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.source.port.source.port.RangeOrOperator) {
+ bindSourcePortRange(rule,
+ ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.source.port.source.port.RangeOrOperator) srcPort)
+ .getPortRangeOrOperator());
+ }
+
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.destination.port.DestinationPort
+ dstPort = Preconditions.checkNotNull(udp.getDestinationPort()).getDestinationPort();
- final UdpNodes udp = Udp.class.cast(vppAceNodes.getIpProtocol()).getUdpNodes();
- bindSourcePortRange(rule, udp.getSourcePortRange());
- bindDestinationPortRange(rule, udp.getDestinationPortRange());
+ if (dstPort instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.destination.port.destination.port.RangeOrOperator) {
+ bindDestinationPortRange(rule,
+ ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.destination.port.destination.port.RangeOrOperator) dstPort)
+ .getPortRangeOrOperator());
+ }
return rule;
}
@@ -208,39 +208,56 @@ public interface ProtoPreBindRuleProducer {
* @param vppAce rule to be processed
* @return AclRule with protocol filled protocol fields
*/
- default AclRule createPreBindRule(@Nonnull final VppAce vppAce) {
+ default AclRule createPreBindRule(@Nonnull final Ace vppAce) {
AclRule rule = new AclRule();
-
- final IpProtocol ipProtocol = vppAce.getVppAceNodes().getIpProtocol();
- if (ipProtocol == null) {
+ L4 l4 = Preconditions.checkNotNull(vppAce.getMatches(), "Matches are not defined for ACE: {}!", vppAce).getL4();
+ if (l4 == null) {
// returns AclRule with rule.proto set to 0 (protocol fields will be ignored by vpp)
return rule;
}
- rule.proto = protocol(ipProtocol);
-
- switch (rule.proto) {
- case ICMP_INDEX: {
- return bindIcmpNodes(rule, vppAce);
- }
-
- case TCP_INDEX: {
- return bindTcpNodes(rule, vppAce);
- }
-
- case UDP_INDEX: {
- return bindUdpNodes(rule, vppAce);
- }
+ if (l4.getImplementedInterface()
+ .equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Icmp.class)) {
+ return getIcmpAclRule(vppAce, rule,
+ (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Icmp) l4);
+ } else if (l4.getImplementedInterface()
+ .equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Tcp.class)) {
+ return getTcpAclRule(rule,
+ (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Tcp) l4);
+ } else if (l4.getImplementedInterface()
+ .equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Udp.class)) {
+ return getUdpAclRule(rule,
+ (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Udp) l4);
+ } else {
+ return bindDefaultNodes(rule);
+ }
+ }
- case ICMPV6_INDEX: {
- return bindIcmpv6Nodes(rule, vppAce);
- }
- default: {
- return bindDefaultNodes(rule);
- }
+ default AclRule getIcmpAclRule(@Nonnull final Ace vppAce, final AclRule rule,
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Icmp l4) {
+ if (vppAce.getMatches().getL3() == null) {
+ rule.proto = ICMP_INDEX;
+ } else {
+ Class<? extends DataContainer> ipVersion = vppAce.getMatches().getL3().getImplementedInterface();
+ rule.proto = (byte) (ipVersion.equals(Ipv6.class) ? ICMPV6_INDEX : ICMP_INDEX);
}
+ Icmp icmp = l4.getIcmp();
+ return icmp != null ? bindIcmpVppFields(rule, icmp) : bindDefaultNodes(rule);
}
+ default AclRule getUdpAclRule(final AclRule rule,
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Udp l4) {
+ rule.proto = UDP_INDEX;
+ Udp udp = l4.getUdp();
+ return udp != null ? bindUdpAttributes(rule, udp) : bindDefaultNodes(rule);
+ }
+
+ default AclRule getTcpAclRule(final AclRule rule,
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Tcp l4) {
+ rule.proto = TCP_INDEX;
+ Tcp tcp = l4.getTcp();
+ return tcp != null ? bindTcpAttributes(rule, tcp) : bindDefaultNodes(rule);
+ }
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclCustomizer.java
index 00cd8a56c..1161c09ef 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclCustomizer.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclCustomizer.java
@@ -19,26 +19,25 @@ package io.fd.hc2vpp.acl.write;
import io.fd.hc2vpp.acl.util.AclContextManager;
import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer;
import io.fd.hc2vpp.acl.util.acl.AclDataExtractor;
-import io.fd.hc2vpp.acl.util.acl.AclWriter;
-import io.fd.honeycomb.translate.MappingContext;
+import io.fd.hc2vpp.acl.write.request.AclAddReplaceRequest;
import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
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.access.lists.Acl;
-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.rev181001.acls.Acl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class VppAclCustomizer extends FutureJVppAclCustomizer
- implements ListWriterCustomizer<Acl, AclKey>, AclDataExtractor, AclWriter {
+public class AclCustomizer extends FutureJVppAclCustomizer
+ implements ListWriterCustomizer<Acl, AclKey>, AclDataExtractor {
private final AclContextManager standardAclContext;
private final AclContextManager macIpAclContext;
- public VppAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade,
- @Nonnull final AclContextManager standardAclContext,
- @Nonnull final AclContextManager macIpAclContext) {
+ public AclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade,
+ @Nonnull final AclContextManager standardAclContext,
+ @Nonnull final AclContextManager macIpAclContext) {
super(jVppAclFacade);
this.standardAclContext = standardAclContext;
this.macIpAclContext = macIpAclContext;
@@ -47,12 +46,11 @@ public class VppAclCustomizer extends FutureJVppAclCustomizer
@Override
public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataAfter,
@Nonnull final WriteContext writeContext) throws WriteFailedException {
- final MappingContext mappingContext = writeContext.getMappingContext();
-
+ AclAddReplaceRequest request = new AclAddReplaceRequest(getjVppAclFacade(), writeContext.getMappingContext());
if (isStandardAcl(dataAfter)) {
- addStandardAcl(getjVppAclFacade(), id, dataAfter, standardAclContext, mappingContext);
+ request.addStandardAcl(id, dataAfter, standardAclContext);
} else if (isMacIpAcl(dataAfter)) {
- addMacIpAcl(getjVppAclFacade(), id, dataAfter, macIpAclContext, mappingContext);
+ request.addMacIpAcl(id, dataAfter, macIpAclContext);
} else {
// double check, first one done by validation
throw new WriteFailedException.CreateFailedException(id, dataAfter,
@@ -64,17 +62,17 @@ public class VppAclCustomizer extends FutureJVppAclCustomizer
public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
@Nonnull final Acl dataAfter, @Nonnull final WriteContext writeContext)
throws WriteFailedException {
- final MappingContext mappingContext = writeContext.getMappingContext();
+ AclAddReplaceRequest request = new AclAddReplaceRequest(getjVppAclFacade(), writeContext.getMappingContext());
if (isStandardAcl(dataAfter)) {
- updateStandardAcl(getjVppAclFacade(), id, dataAfter, standardAclContext, mappingContext);
+ request.updateStandardAcl(id, dataAfter, standardAclContext);
} else if (isMacIpAcl(dataAfter)) {
synchronized (macIpAclContext) {
// there is no direct support for update of mac-ip acl, but only one is allowed per interface
// so it is atomic from vpp standpoint. Enclosed in synchronized block to prevent issues with
// multiple threads managing naming context
- deleteMacIpAcl(getjVppAclFacade(), id, dataBefore, macIpAclContext, mappingContext);
- addMacIpAcl(getjVppAclFacade(), id, dataAfter, macIpAclContext, mappingContext);
+ request.deleteMacIpAcl(id, dataBefore, macIpAclContext);
+ request.addMacIpAcl(id, dataAfter, macIpAclContext);
}
} else {
// double check, first one done by validation
@@ -86,12 +84,12 @@ public class VppAclCustomizer extends FutureJVppAclCustomizer
@Override
public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
@Nonnull final WriteContext writeContext) throws WriteFailedException {
- final MappingContext mappingContext = writeContext.getMappingContext();
+ AclAddReplaceRequest request = new AclAddReplaceRequest(getjVppAclFacade(), writeContext.getMappingContext());
if (isStandardAcl(dataBefore)) {
- deleteStandardAcl(getjVppAclFacade(), id, dataBefore, standardAclContext, mappingContext);
+ request.deleteStandardAcl(id, dataBefore, standardAclContext);
} else if (isMacIpAcl(dataBefore)) {
- deleteMacIpAcl(getjVppAclFacade(), id, dataBefore, macIpAclContext, mappingContext);
+ request.deleteMacIpAcl(id, dataBefore, macIpAclContext);
} else {
// double check, first one done by validation
throw new WriteFailedException.DeleteFailedException(id,
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclValidator.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclValidator.java
new file mode 100644
index 000000000..b7aaebcff
--- /dev/null
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/AclValidator.java
@@ -0,0 +1,233 @@
+/*
+ * 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.write;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import io.fd.hc2vpp.acl.AclIIds;
+import io.fd.hc2vpp.acl.util.acl.AclDataExtractor;
+import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException;
+import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException;
+import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException;
+import io.fd.honeycomb.translate.write.Validator;
+import io.fd.honeycomb.translate.write.WriteContext;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppAcl;
+import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppMacipAcl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.AclBase;
+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.AttachmentPoints;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.Aces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.Matches;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L3;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.Eth;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6;
+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.AclSets;
+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.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4Network;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6Network;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public final class AclValidator implements Validator<Acl>, AclDataExtractor {
+
+ private static final Set<Class<? extends AclBase>> SUPPORTED_ACL_TYPES =
+ ImmutableSet.of(VppAcl.class, VppMacipAcl.class);
+
+ @Override
+ public void validateWrite(final InstanceIdentifier<Acl> id, final Acl dataAfter, final WriteContext ctx)
+ throws CreateValidationFailedException {
+ try {
+ validateAcl(dataAfter);
+ } catch (RuntimeException e) {
+ throw new CreateValidationFailedException(id, dataAfter, e);
+ }
+ }
+
+ @Override
+ public void validateUpdate(final InstanceIdentifier<Acl> id, final Acl dataBefore, final Acl dataAfter,
+ final WriteContext ctx) throws UpdateValidationFailedException {
+ try {
+ validateAcl(dataAfter);
+ } catch (RuntimeException e) {
+ throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e);
+ }
+ }
+
+ @Override
+ public void validateDelete(final InstanceIdentifier<Acl> id, final Acl dataBefore, final WriteContext ctx)
+ throws DeleteValidationFailedException {
+ try {
+ validateAcl(dataBefore);
+ final List<String> references = checkAclReferenced(ctx, dataBefore);
+ // references must be check, to not leave dead references in configuration
+ checkState(references.isEmpty(),
+ "%s cannot be removed, it is referenced in following interfaces %s", dataBefore, references);
+ } catch (RuntimeException e) {
+ throw new DeleteValidationFailedException(id, e);
+ }
+ }
+
+ private static void validateAcl(@Nonnull final Acl acl) {
+ hasAceList(acl);
+ isSupportedAclType(acl);
+ hasConsistentAceTypeForAclType(acl);
+ }
+
+ private static void hasAceList(final Acl acl) {
+ final Aces accessListEntries = acl.getAces();
+ checkArgument(accessListEntries != null, "The access-list-entries container is not defined.");
+ final List<Ace> ace = accessListEntries.getAce();
+ checkArgument(ace != null, "The ace list is not defined.");
+ checkArgument(!ace.isEmpty(), "The ace list is empty.");
+ }
+
+ private static void isSupportedAclType(final Acl acl) {
+ checkArgument(SUPPORTED_ACL_TYPES.contains(acl.getType()),
+ "Unsupported Acl type %s detected for acl %s, allowed types are %s", acl.getType(),
+ acl.getName(), SUPPORTED_ACL_TYPES);
+ }
+
+ private static void hasConsistentAceTypeForAclType(final Acl acl) {
+ Class<? extends AclBase> type = acl.getType();
+ Preconditions.checkNotNull(type, "Cannot resolve Acl type for validation of Acl: {}", acl);
+ Preconditions.checkNotNull(acl.getAces(), "ACEs are missing for validation of Acl: {}", acl);
+ Preconditions.checkNotNull(acl.getAces().getAce(), "List of ACEs is null for validation of Acl: {}", acl);
+ if (type.equals(VppAcl.class)) {
+ Set<Ace> unsupportedVppAcls =
+ acl.getAces().getAce().stream().filter(ace -> !isVppAce(ace)).collect(Collectors.toSet());
+ checkArgument(unsupportedVppAcls.isEmpty(), "Detected unsupported ace types [%s] for ACL %s",
+ unsupportedVppAcls, acl.getName());
+ }
+
+ if (type.equals(VppMacipAcl.class)) {
+ Set<Ace> unsupportedVppMacipAclAcls =
+ acl.getAces().getAce().stream().filter(ace -> !isVppMacipAclAce(ace)).collect(Collectors.toSet());
+ checkArgument(unsupportedVppMacipAclAcls.isEmpty(), "Detected unsupported ace types [%s] for ACL %s",
+ unsupportedVppMacipAclAcls, acl.getName());
+ }
+ }
+
+ private static boolean isVppMacipAclAce(final Ace ace) {
+ Matches matches = Preconditions
+ .checkNotNull(ace.getMatches(), "Cannot validate VppMacipAcl type for Ace: {}, matches are not defined",
+ ace);
+ if (matches.getL2() == null || !(matches.getL2() instanceof Eth)) {
+ return false;
+ }
+
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l2.eth.Eth
+ eth = ((Eth) matches.getL2()).getEth();
+ if (eth == null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static boolean isVppAce(final Ace ace) {
+ Matches matches = Preconditions
+ .checkNotNull(ace.getMatches(), "Cannot validate VppMacipAcl type for Ace: {}, matches are not defined",
+ ace);
+ L3 l3 = matches.getL3();
+ if (l3 == null || (!(l3 instanceof Ipv4)) && (!(l3 instanceof Ipv6))) {
+ return false;
+ }
+
+ if (l3 instanceof Ipv4) {
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4
+ ipv4 = ((Ipv4) l3).getIpv4();
+ if (ipv4 == null || ipv4.getSourceNetwork() == null ||
+ !(ipv4.getSourceNetwork() instanceof SourceIpv4Network)) {
+ return false;
+ }
+ }
+
+ if (l3 instanceof Ipv6) {
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6
+ ipv6 = ((Ipv6) l3).getIpv6();
+ if (ipv6 == null || ipv6.getSourceNetwork() == null ||
+ !(ipv6.getSourceNetwork() instanceof SourceIpv6Network)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @VisibleForTesting
+ static List<String> checkAclReferenced(@Nonnull final WriteContext writeContext, @Nonnull final Acl acl) {
+ Preconditions.checkNotNull(acl.getType(), "Cannot validate acl: {}, type is not set.", acl);
+ if (!acl.getType().equals(VppAcl.class) && !acl.getType().equals(VppMacipAcl.class)) {
+ throw new IllegalArgumentException(String.format("Acl type %s not supported", acl.getType()));
+ }
+
+ Optional<AttachmentPoints> attachmentPointsOpt = writeContext.readAfter(AclIIds.ACLS_AP);
+ if (!attachmentPointsOpt.isPresent() || attachmentPointsOpt.get().getInterface() == null) {
+ return Collections.emptyList();
+ }
+
+ final List<Interface> interfaces = attachmentPointsOpt.get().getInterface();
+ if (interfaces == null) {
+ return Collections.emptyList();
+ }
+ final String aclName = acl.getName();
+
+ HashMap<String, AclSets> sets = getIngressAclSets(interfaces);
+ sets.putAll(getEgressAclSets(interfaces));
+ List<String> referencedIfcs = new ArrayList<>();
+ sets.forEach((ifc, aclSets) -> {
+ if (aclSets.getAclSet() != null) {
+ if (aclSets.getAclSet().stream()
+ .map(AclSet::getName)
+ .filter(Objects::nonNull)
+ .anyMatch(name -> name.equalsIgnoreCase(aclName))) {
+ referencedIfcs.add(ifc);
+ }
+ }
+ });
+ return referencedIfcs.stream().distinct().collect(Collectors.toList());
+ }
+
+ private static HashMap<String, AclSets> getEgressAclSets(final List<Interface> interfaces) {
+ HashMap<String, AclSets> map = new HashMap<>();
+ interfaces.stream().filter(anInterface -> anInterface.getEgress() != null)
+ .forEach(anInterface -> map.put(anInterface.getInterfaceId(), anInterface.getEgress().getAclSets()));
+ return map;
+ }
+
+ private static HashMap<String, AclSets> getIngressAclSets(final List<Interface> interfaces) {
+ HashMap<String, AclSets> map = new HashMap<>();
+ interfaces.stream().filter(anInterface -> anInterface.getIngress() != null)
+ .forEach(anInterface -> map.put(anInterface.getInterfaceId(), anInterface.getIngress().getAclSets()));
+ return map;
+ }
+}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java
index a6ca35af3..622a84d93 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java
@@ -16,82 +16,177 @@
package io.fd.hc2vpp.acl.write;
+import static io.fd.hc2vpp.acl.write.request.MacIpInterfaceAssignmentRequest.deleteExisting;
import static java.util.stream.Collectors.toList;
import io.fd.hc2vpp.acl.util.AclContextManager;
import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer;
-import io.fd.hc2vpp.acl.util.iface.acl.AclInterfaceAssignmentRequest;
+import io.fd.hc2vpp.acl.write.request.AclInterfaceAssignmentRequest;
+import io.fd.hc2vpp.acl.write.request.MacIpInterfaceAssignmentRequest;
import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclsBaseAttributes;
-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.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.AclSets;
+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.yangtools.yang.binding.InstanceIdentifier;
/**
* Handles acl assignments(only standard ones, mac-ip have dedicated customizer)
*/
-public class InterfaceAclCustomizer extends FutureJVppAclCustomizer implements WriterCustomizer<Acl> {
+public class InterfaceAclCustomizer extends FutureJVppAclCustomizer implements WriterCustomizer<Interface> {
private final NamingContext interfaceContext;
private final AclContextManager standardAclContext;
+ private final AclContextManager macIpAclContext;
public InterfaceAclCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade,
@Nonnull final NamingContext interfaceContext,
- @Nonnull final AclContextManager standardAclContext) {
+ @Nonnull final AclContextManager standardAclContext,
+ @Nonnull final AclContextManager macIpAclContext) {
super(jVppAclFacade);
this.interfaceContext = interfaceContext;
this.standardAclContext = standardAclContext;
+ this.macIpAclContext = macIpAclContext;
+ }
+
+ private static List<String> getAclNames(final AclSets acls) {
+ if (acls == null || acls.getAclSet() == null) {
+ return Collections.emptyList();
+ } else {
+ return acls.getAclSet().stream().map(AclSet::getName).collect(toList());
+ }
}
@Override
- public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataAfter,
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id,
+ @Nonnull final Interface dataAfter,
@Nonnull final WriteContext writeContext) throws WriteFailedException {
- AclInterfaceAssignmentRequest.create(writeContext.getMappingContext())
- .standardAclContext(standardAclContext)
- .interfaceContext(interfaceContext)
- .identifier(id)
- .inputAclNames(getAclNames(dataAfter.getIngress()))
- .outputAclNames(getAclNames(dataAfter.getEgress()))
- .executeAsCreate(getjVppAclFacade());
+ AclSets egress = dataAfter.getEgress() != null ? dataAfter.getEgress().getAclSets() : null;
+ AclSets ingress = dataAfter.getIngress() != null ? dataAfter.getIngress().getAclSets() : null;
+ List<String> macIngress = parseMacRules(getAclNames(ingress), writeContext.getMappingContext());
+ List<String> standardIngress = parseStandardRules(getAclNames(ingress), writeContext.getMappingContext());
+ List<String> standardEgress = parseStandardRules(getAclNames(egress), writeContext.getMappingContext());
+
+ // Process standard ACLs
+ if (!standardIngress.isEmpty() || !standardEgress.isEmpty()) {
+ AclInterfaceAssignmentRequest.create(writeContext.getMappingContext())
+ .standardAclContext(standardAclContext)
+ .interfaceContext(interfaceContext)
+ .identifier(id)
+ .inputAclNames(standardIngress)
+ .outputAclNames(standardEgress)
+ .executeAsCreate(getjVppAclFacade());
+ }
+ // Process mac ACLs
+ if (!macIngress.isEmpty()) {
+ addMacAcls(id, writeContext, macIngress);
+ }
}
@Override
- public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
- @Nonnull final Acl dataAfter, @Nonnull final WriteContext writeContext)
+ public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id,
+ @Nonnull final Interface dataBefore,
+ @Nonnull final Interface dataAfter, @Nonnull final WriteContext writeContext)
throws WriteFailedException {
+ AclSets egress = dataAfter.getEgress() != null ? dataAfter.getEgress().getAclSets() : null;
+ AclSets ingress = dataAfter.getIngress() != null ? dataAfter.getIngress().getAclSets() : null;
+ List<String> standardIngress = parseStandardRules(getAclNames(ingress), writeContext.getMappingContext());
+ List<String> standardEgress = parseStandardRules(getAclNames(egress), writeContext.getMappingContext());
+
+ // update standard ACLs
AclInterfaceAssignmentRequest.create(writeContext.getMappingContext())
.standardAclContext(standardAclContext)
.interfaceContext(interfaceContext)
.identifier(id)
- .inputAclNames(getAclNames(dataAfter.getIngress()))
- .outputAclNames(getAclNames(dataAfter.getEgress()))
+ .inputAclNames(standardIngress)
+ .outputAclNames(standardEgress)
.executeAsUpdate(getjVppAclFacade(), dataBefore, dataAfter);
+
+ // Process mac ACLs
+ AclSets ingressBefore = dataBefore.getIngress() != null ? dataBefore.getIngress().getAclSets() : null;
+ List<String> macIngressAfter = parseMacRules(getAclNames(ingress), writeContext.getMappingContext());
+ List<String> macIngressBefore = parseMacRules(getAclNames(ingressBefore), writeContext.getMappingContext());
+ List<String> added =
+ macIngressAfter.stream().filter(acl -> !macIngressBefore.contains(acl)).collect(Collectors.toList());
+ List<String> removed =
+ macIngressBefore.stream().filter(acl -> !macIngressAfter.contains(acl)).collect(Collectors.toList());
+
+ if (!removed.isEmpty()) {
+ deleteMacACLs(id, writeContext, removed);
+ }
+
+ if (!added.isEmpty()) {
+ addMacAcls(id, writeContext, added);
+ }
}
@Override
- public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
- @Nonnull final WriteContext writeContext) throws WriteFailedException {
- AclInterfaceAssignmentRequest.create(writeContext.getMappingContext())
- .standardAclContext(standardAclContext)
- .interfaceContext(interfaceContext)
- .identifier(id)
- .executeAsDelete(getjVppAclFacade());
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id,
+ @Nonnull final Interface dataBefore, @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ AclSets ingress = dataBefore.getIngress() != null ? dataBefore.getIngress().getAclSets() : null;
+ List<String> standardIngress = parseStandardRules(getAclNames(ingress), writeContext.getMappingContext());
+ List<String> macIngress = parseMacRules(getAclNames(ingress), writeContext.getMappingContext());
+
+ //Process standard ACLs
+ if (!standardIngress.isEmpty()) {
+ AclInterfaceAssignmentRequest.create(writeContext.getMappingContext())
+ .standardAclContext(standardAclContext)
+ .interfaceContext(interfaceContext)
+ .identifier(id)
+ .executeAsDelete(getjVppAclFacade());
+ }
+
+ // Process mac ACLs
+ if (!macIngress.isEmpty()) {
+ deleteMacACLs(id, writeContext, macIngress);
+ }
}
- private static List<String> getAclNames(final VppAclsBaseAttributes acls) {
- if (acls == null || acls.getVppAcls() == null) {
- return Collections.emptyList();
- } else {
- return acls.getVppAcls().stream().map(VppAcls::getName).collect(toList());
+ private List<String> parseMacRules(final List<String> ingress, final MappingContext mappingContext) {
+ return ingress.stream()
+ .filter(aclName -> macIpAclContext.containsAcl(aclName, mappingContext)).collect(Collectors.toList());
+ }
+
+ private List<String> parseStandardRules(final List<String> ingress, final MappingContext mappingContext) {
+ return ingress.stream()
+ .filter(aclName -> standardAclContext.containsAcl(aclName, mappingContext))
+ .collect(Collectors.toList());
+ }
+
+
+ private void addMacAcls(@Nonnull final InstanceIdentifier<Interface> id,
+ @Nonnull final WriteContext writeContext, final List<String> added)
+ throws WriteFailedException {
+ for (String macAcl : added) {
+ MacIpInterfaceAssignmentRequest.addNew(writeContext.getMappingContext())
+ .identifier(id)
+ .aclName(macAcl)
+ .macIpAclContext(macIpAclContext)
+ .interfaceContext(interfaceContext)
+ .execute(getjVppAclFacade());
}
}
+ private void deleteMacACLs(@Nonnull final InstanceIdentifier<Interface> id,
+ @Nonnull final WriteContext writeContext, final List<String> macAcls)
+ throws WriteFailedException {
+ for (String macAcl : macAcls) {
+ deleteExisting(writeContext.getMappingContext())
+ .identifier(id)
+ .aclName(macAcl)
+ .macIpAclContext(macIpAclContext)
+ .interfaceContext(interfaceContext)
+ .execute(getjVppAclFacade());
+ }
+ }
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclMacIpCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclMacIpCustomizer.java
deleted file mode 100644
index fc0acd223..000000000
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclMacIpCustomizer.java
+++ /dev/null
@@ -1,69 +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.write;
-
-import static io.fd.hc2vpp.acl.util.iface.macip.MacIpInterfaceAssignmentRequest.addNew;
-import static io.fd.hc2vpp.acl.util.iface.macip.MacIpInterfaceAssignmentRequest.deleteExisting;
-
-import io.fd.hc2vpp.acl.util.AclContextManager;
-import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer;
-import io.fd.hc2vpp.common.translate.util.NamingContext;
-import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
-import io.fd.honeycomb.translate.write.WriteContext;
-import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
-import javax.annotation.Nonnull;
-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;
-
-public class InterfaceAclMacIpCustomizer extends FutureJVppAclCustomizer implements WriterCustomizer<VppMacipAcl> {
-
- private final AclContextManager macIpAclContext;
- private final NamingContext interfaceContext;
-
- public InterfaceAclMacIpCustomizer(@Nonnull final FutureJVppAclFacade jVppAclFacade,
- @Nonnull final AclContextManager macIpAclContext,
- @Nonnull final NamingContext interfaceContext) {
- super(jVppAclFacade);
- this.macIpAclContext = macIpAclContext;
- this.interfaceContext = interfaceContext;
- }
-
- @Override
- public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VppMacipAcl> id,
- @Nonnull final VppMacipAcl dataAfter,
- @Nonnull final WriteContext writeContext) throws WriteFailedException {
- addNew(writeContext.getMappingContext())
- .identifier(id)
- .aclName(dataAfter.getName())
- .macIpAclContext(macIpAclContext)
- .interfaceContext(interfaceContext)
- .execute(getjVppAclFacade());
- }
-
- @Override
- public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VppMacipAcl> id,
- @Nonnull final VppMacipAcl dataBefore,
- @Nonnull final WriteContext writeContext) throws WriteFailedException {
- deleteExisting(writeContext.getMappingContext())
- .identifier(id)
- .aclName(dataBefore.getName())
- .macIpAclContext(macIpAclContext)
- .interfaceContext(interfaceContext)
- .execute(getjVppAclFacade());
- }
-}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclValidator.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclValidator.java
deleted file mode 100644
index 942d3bcb3..000000000
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/VppAclValidator.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * 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.write;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
-import static java.util.Collections.emptyList;
-import static java.util.Optional.ofNullable;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import io.fd.hc2vpp.acl.util.acl.AclDataExtractor;
-import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException;
-import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException;
-import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException;
-import io.fd.honeycomb.translate.write.Validator;
-import io.fd.honeycomb.translate.write.WriteContext;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-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.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.acl.AccessListEntries;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Matches;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.AceType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.InterfaceAclAttributes;
-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.VppAclsBaseAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppMacipAclsBaseAttributes;
-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.VppMacipAcl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public final class VppAclValidator implements Validator<Acl>, AclDataExtractor {
-
- private static final Set<Class<? extends AclBase>> SUPPORTED_ACL_TYPES =
- ImmutableSet.of(VppAcl.class, VppMacipAcl.class);
- private static final Map<Class<? extends AclBase>, Class<? extends AceType>> ACL_ACE_PAIRS =
- ImmutableMap.of(VppAcl.class, VppAce.class, VppMacipAcl.class, VppMacipAce.class);
-
- @Override
- public void validateWrite(final InstanceIdentifier<Acl> id, final Acl dataAfter, final WriteContext ctx)
- throws CreateValidationFailedException {
- try {
- validateAcl(dataAfter);
- } catch (RuntimeException e) {
- throw new CreateValidationFailedException(id, dataAfter, e);
- }
- }
-
- @Override
- public void validateUpdate(final InstanceIdentifier<Acl> id, final Acl dataBefore, final Acl dataAfter,
- final WriteContext ctx) throws UpdateValidationFailedException {
- try {
- validateAcl(dataAfter);
- } catch (RuntimeException e) {
- throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e);
- }
- }
-
- @Override
- public void validateDelete(final InstanceIdentifier<Acl> id, final Acl dataBefore, final WriteContext ctx)
- throws DeleteValidationFailedException {
- try {
- validateAcl(dataBefore);
- final List<Interface> references = checkAclReferenced(ctx, dataBefore);
- // references must be check, to not leave dead references in configuration
- checkState(references.isEmpty(),
- "%s cannot be removed, it is referenced in following interfaces %s", dataBefore, references);
- } catch (RuntimeException e) {
- throw new DeleteValidationFailedException(id, e);
- }
- }
-
- private static void validateAcl(@Nonnull final Acl acl) {
- hasAceList(acl);
- isSupportedAclType(acl);
- hasConsistentAceTypeForAclType(acl);
- }
-
- private static void hasAceList(final Acl acl) {
- final AccessListEntries accessListEntries = acl.getAccessListEntries();
- checkArgument(accessListEntries != null, "The access-list-entries container is not defined.");
- final List<Ace> ace = accessListEntries.getAce();
- checkArgument(ace != null, "The ace list is not defined.");
- checkArgument(!ace.isEmpty(), "The ace list is empty.");
- }
-
- private static void isSupportedAclType(final Acl acl) {
- checkArgument(SUPPORTED_ACL_TYPES.contains(acl.getAclType()),
- "Unsupported Acl type %s detected for acl %s, allowed types are %s", acl.getAclType(),
- acl.getAclName(), SUPPORTED_ACL_TYPES);
- }
-
- private static void hasConsistentAceTypeForAclType(final Acl acl) {
- checkTypesSame(acl.getAccessListEntries().getAce(), acl.getAclName(),
- checkNotNull(ACL_ACE_PAIRS.get(acl.getAclType()), "Unsupported ACL type %s for ACL %s",
- acl.getAclType(), acl.getAclName()));
- }
-
- private static void checkTypesSame(final List<Ace> aces, final String aclName,
- final Class<? extends AceType> aceType) {
- final Set<AceType> unsupportedAceTypes = aces.stream()
- .map(Ace::getMatches)
- .map(Matches::getAceType)
- .filter(aceType::equals)
- .collect(Collectors.toSet());
- checkArgument(unsupportedAceTypes.isEmpty(), "Detected unsupported ace types [%s] for ACL %s, expected %s",
- unsupportedAceTypes, aclName, aceType);
- }
-
- @VisibleForTesting
- static List<Interface> checkAclReferenced(@Nonnull final WriteContext writeContext,
- @Nonnull final Acl acl) {
- final Optional<Interfaces> readAfter = writeContext.readAfter(InstanceIdentifier.create(Interfaces.class));
- if (!readAfter.isPresent() || readAfter.get().getInterface() == null) {
- return Collections.emptyList();
- }
-
- final List<Interface> interfaces = readAfter.get().getInterface();
- final Class<? extends AclBase> aclType = acl.getAclType();
- final String aclName = acl.getAclName();
-
- if (aclType.equals(VppAcl.class)) {
- return interfaces.stream()
- .filter(iface -> ofNullable(iface.augmentation(VppAclInterfaceAugmentation.class))
- .map(InterfaceAclAttributes::getAcl)
- .filter(references ->
- checkVppAcls(references.getIngress(), aclName) ||
- checkVppAcls(references.getEgress(), aclName)).isPresent()
- ).collect(Collectors.toList());
- } else if (aclType.equals(VppMacipAcl.class)) {
- return interfaces.stream()
- .filter(iface -> ofNullable(iface.augmentation(VppAclInterfaceAugmentation.class))
- .map(InterfaceAclAttributes::getAcl)
- .map(aclAttr -> aclAttr.getIngress())
- .map(VppMacipAclsBaseAttributes::getVppMacipAcl)
- .filter(vppMacipAcl -> vppMacipAcl.getName().equals(aclName))
- .isPresent())
- .collect(Collectors.toList());
- } else {
- throw new IllegalArgumentException(format("Acl type %s not supported", aclType));
- }
- }
-
- private static boolean checkVppAcls(@Nullable final VppAclsBaseAttributes attrs, @Nonnull final String name) {
- return ofNullable(attrs).map(VppAclsBaseAttributes::getVppAcls)
- .orElse(emptyList())
- .stream().anyMatch(acl -> acl.getName().equals(name));
- }
-}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AbstractAclWriterFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AbstractAclWriterFactory.java
index 37a8de2d1..8944e5977 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AbstractAclWriterFactory.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AbstractAclWriterFactory.java
@@ -26,10 +26,10 @@ import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
/**
* Created by jsrnicek on 12.12.2016.
*/
-class AbstractAclWriterFactory {
+abstract class AbstractAclWriterFactory {
@Inject
- protected FutureJVppAclFacade futureAclFacade;
+ FutureJVppAclFacade futureAclFacade;
@Inject
@Named(AclModule.STANDARD_ACL_CONTEXT_NAME)
@@ -37,7 +37,7 @@ class AbstractAclWriterFactory {
@Inject
@Named(AclModule.MAC_IP_ACL_CONTEXT_NAME)
- protected AclContextManager macIpAClContext;
+ protected AclContextManager macIpAclContext;
@Inject
@Named("interface-context")
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AclWriterFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AclWriterFactory.java
new file mode 100644
index 000000000..faab3023d
--- /dev/null
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/AclWriterFactory.java
@@ -0,0 +1,39 @@
+/*
+ * 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.write.factory;
+
+import io.fd.hc2vpp.acl.AclIIds;
+import io.fd.hc2vpp.acl.write.AclCustomizer;
+import io.fd.hc2vpp.acl.write.AclValidator;
+import io.fd.honeycomb.translate.impl.write.GenericListWriter;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
+import javax.annotation.Nonnull;
+
+public class AclWriterFactory extends AbstractAclWriterFactory implements WriterFactory {
+
+ @Override
+ public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
+
+ registry.subtreeAddBefore(AclIIds.vppAclChildren(AclIIds.ACL),
+ new GenericListWriter<>(AclIIds.ACLS_ACL,
+ new AclCustomizer(futureAclFacade, standardAclContext, macIpAclContext),
+ new AclValidator()
+ ),
+ AclIIds.aclHandledChildren(AclIIds.IFC_ACL));
+ }
+}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/InterfaceAclWriterFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/InterfaceAclWriterFactory.java
index 12be40a14..c5144b362 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/InterfaceAclWriterFactory.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/InterfaceAclWriterFactory.java
@@ -17,46 +17,27 @@
package io.fd.hc2vpp.acl.write.factory;
import com.google.common.collect.ImmutableSet;
+import io.fd.hc2vpp.acl.AclIIds;
import io.fd.hc2vpp.acl.write.InterfaceAclCustomizer;
-import io.fd.hc2vpp.acl.write.InterfaceAclMacIpCustomizer;
import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import java.util.Set;
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.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._interface.acl.attributes.acl.Egress;
-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.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;
public class InterfaceAclWriterFactory extends AbstractAclWriterFactory implements WriterFactory {
- static final InstanceIdentifier<Acl> ACL_IID =
- InstanceIdentifier.create(Interfaces.class).child(Interface.class)
- .augmentation(VppAclInterfaceAugmentation.class).child(Acl.class);
- private static final InstanceIdentifier<Interface> IFC_ID =
- InstanceIdentifier.create(Interfaces.class).child(Interface.class);
-
-
@Override
public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
- registry.subtreeAddAfter(aclHandledChildren(InstanceIdentifier.create(Acl.class)),
- new GenericWriter<>(ACL_IID,
- new InterfaceAclCustomizer(futureAclFacade, interfaceContext, standardAclContext)), IFC_ID);
-
- registry.addAfter(new GenericWriter<>(ACL_IID.child(Ingress.class).child(VppMacipAcl.class),
- new InterfaceAclMacIpCustomizer(futureAclFacade, macIpAClContext, interfaceContext)), IFC_ID);
+ registry.subtreeAddAfter(AclIIds.aclHandledChildren(AclIIds.IFC_ACL),
+ new GenericWriter<>(AclIIds.ACLS_AP_INT,
+ new InterfaceAclCustomizer(futureAclFacade, interfaceContext, standardAclContext,
+ macIpAclContext)),
+ aclRequiredIids());
}
- static Set<InstanceIdentifier<?>> aclHandledChildren(final InstanceIdentifier<Acl> parentId) {
- return ImmutableSet.of(parentId.child(Ingress.class),
- parentId.child(Ingress.class).child(VppAcls.class),
- parentId.child(Egress.class),
- parentId.child(Egress.class).child(VppAcls.class));
+ static Set<InstanceIdentifier<?>> aclRequiredIids() {
+ return ImmutableSet.of(AclIIds.IFC, AclIIds.IFC_ACL, AclIIds.ACLS_ACL);
}
}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/VppAclWriterFactory.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/VppAclWriterFactory.java
deleted file mode 100644
index 883cf4f1f..000000000
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/factory/VppAclWriterFactory.java
+++ /dev/null
@@ -1,46 +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.write.factory;
-
-import static io.fd.hc2vpp.acl.write.factory.InterfaceAclWriterFactory.ACL_IID;
-import static io.fd.hc2vpp.acl.write.factory.InterfaceAclWriterFactory.aclHandledChildren;
-
-import io.fd.hc2vpp.acl.util.factory.AclFactory;
-import io.fd.hc2vpp.acl.write.VppAclCustomizer;
-import io.fd.hc2vpp.acl.write.VppAclValidator;
-import io.fd.honeycomb.translate.impl.write.GenericListWriter;
-import io.fd.honeycomb.translate.write.WriterFactory;
-import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
-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.access.lists.Acl;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public class VppAclWriterFactory extends AbstractAclWriterFactory implements WriterFactory, AclFactory {
-
- @Override
- public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
- final InstanceIdentifier<AccessLists> rootNode = InstanceIdentifier.create(AccessLists.class);
-
- registry.subtreeAddBefore(vppAclChildren(InstanceIdentifier.create(Acl.class)),
- new GenericListWriter<>(rootNode.child(Acl.class),
- new VppAclCustomizer(futureAclFacade, standardAclContext, macIpAClContext),
- new VppAclValidator()
- ),
- aclHandledChildren(ACL_IID));
- }
-}
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclWriter.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/AclAddReplaceRequest.java
index 32e20ebac..29a7c7489 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclWriter.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/AclAddReplaceRequest.java
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package io.fd.hc2vpp.acl.util.acl;
+package io.fd.hc2vpp.acl.write.request;
import io.fd.hc2vpp.acl.util.AclContextManager;
import io.fd.hc2vpp.acl.util.ace.AceConverter;
+import io.fd.hc2vpp.acl.util.acl.AclDataExtractor;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -30,21 +31,25 @@ import io.fd.vpp.jvpp.acl.dto.MacipAclDel;
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
import java.util.List;
import javax.annotation.Nonnull;
-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.acl.access.list.entries.Ace;
+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.acl.aces.Ace;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-/**
- * Write standard and mac-ip acls
- */
-public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyConsumer {
+public class AclAddReplaceRequest implements AclDataExtractor, AceConverter, JvppReplyConsumer {
int ACL_INDEX_CREATE_NEW = -1;
+ private final FutureJVppAclFacade futureFacade;
+ private final MappingContext mappingContext;
+
+ public AclAddReplaceRequest(@Nonnull final FutureJVppAclFacade futureFacade,
+ @Nonnull final MappingContext mappingContext) {
+ this.futureFacade = futureFacade;
+ this.mappingContext = mappingContext;
+ }
- default void addStandardAcl(@Nonnull final FutureJVppAclFacade futureFacade,
- @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
- @Nonnull final AclContextManager standardAclContext,
- @Nonnull final MappingContext mappingContext) throws WriteFailedException {
+
+ public void addStandardAcl(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
+ @Nonnull final AclContextManager standardAclContext) throws WriteFailedException {
final AclAddReplace request = new AclAddReplace();
@@ -59,38 +64,35 @@ public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyCons
getReplyForWrite(futureFacade.aclAddReplace(request).toCompletableFuture(), id);
// maps new acl to returned index
- standardAclContext.addAcl(reply.aclIndex, acl.getAclName(), aces, mappingContext);
+ standardAclContext.addAcl(reply.aclIndex, acl.getName(), aces, mappingContext);
}
// according to vpp team, this was tested extensively, and should work
- default void updateStandardAcl(@Nonnull final FutureJVppAclFacade futureFacade,
- @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
- @Nonnull final AclContextManager standardAclContext,
- @Nonnull final MappingContext mappingContext) throws WriteFailedException {
+ public void updateStandardAcl(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
+ @Nonnull final AclContextManager standardAclContext) throws WriteFailedException {
final AclAddReplace request = new AclAddReplace();
request.tag = getAclTag(acl);
// by setting existing index, request is resolved as update
- request.aclIndex = standardAclContext.getAclIndex(acl.getAclName(), mappingContext);
+ request.aclIndex = standardAclContext.getAclIndex(acl.getName(), mappingContext);
final List<Ace> aces = getAces(acl);
request.r = toStandardAclRules(aces);
request.count = request.r.length;
- final AclAddReplaceReply reply = getReplyForWrite(futureFacade.aclAddReplace(request).toCompletableFuture(), id);
+ final AclAddReplaceReply reply =
+ getReplyForWrite(futureFacade.aclAddReplace(request).toCompletableFuture(), id);
// overwrites existing acl metadata (aces might have been changed):
- standardAclContext.addAcl(reply.aclIndex, acl.getAclName(), aces, mappingContext);
+ standardAclContext.addAcl(reply.aclIndex, acl.getName(), aces, mappingContext);
}
- default void deleteStandardAcl(@Nonnull final FutureJVppAclFacade futureFacade,
- @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
- @Nonnull final AclContextManager standardAclContext,
- @Nonnull final MappingContext mappingContext) throws WriteFailedException {
+ public void deleteStandardAcl(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
+ @Nonnull final AclContextManager standardAclContext) throws WriteFailedException {
final AclDel request = new AclDel();
- final String aclName = acl.getAclName();
+ final String aclName = acl.getName();
request.aclIndex = standardAclContext.getAclIndex(aclName, mappingContext);
getReplyForDelete(futureFacade.aclDel(request).toCompletableFuture(), id);
@@ -99,10 +101,8 @@ public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyCons
standardAclContext.removeAcl(aclName, mappingContext);
}
- default void addMacIpAcl(@Nonnull final FutureJVppAclFacade futureFacade,
- @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
- @Nonnull final AclContextManager macIpAclContext,
- @Nonnull final MappingContext mappingContext) throws WriteFailedException {
+ public void addMacIpAcl(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
+ @Nonnull final AclContextManager macIpAclContext) throws WriteFailedException {
final MacipAclAdd request = new MacipAclAdd();
request.tag = getAclTag(acl);
@@ -114,15 +114,13 @@ public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyCons
final MacipAclAddReply reply = getReplyForWrite(futureFacade.macipAclAdd(request).toCompletableFuture(), id);
// map mac-ip acl to returned index
- macIpAclContext.addAcl(reply.aclIndex, acl.getAclName(), aces, mappingContext);
+ macIpAclContext.addAcl(reply.aclIndex, acl.getName(), aces, mappingContext);
}
- default void deleteMacIpAcl(@Nonnull final FutureJVppAclFacade futureFacade,
- @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
- @Nonnull final AclContextManager macIpAclContext,
- @Nonnull final MappingContext mappingContext) throws WriteFailedException {
+ public void deleteMacIpAcl(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
+ @Nonnull final AclContextManager macIpAclContext) throws WriteFailedException {
final MacipAclDel request = new MacipAclDel();
- final String aclName = acl.getAclName();
+ final String aclName = acl.getName();
request.aclIndex = macIpAclContext.getAclIndex(aclName, mappingContext);
getReplyForDelete(futureFacade.macipAclDel(request).toCompletableFuture(), id);
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/AclInterfaceAssignmentRequest.java
index bf1f1497e..2d7777e35 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/AclInterfaceAssignmentRequest.java
@@ -15,7 +15,7 @@
*/
-package io.fd.hc2vpp.acl.util.iface.acl;
+package io.fd.hc2vpp.acl.write.request;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -32,8 +32,7 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,7 +45,8 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceAssignmentRequest.class);
private final MappingContext mappingContext;
- private InstanceIdentifier<Acl> identifier;
+ private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface>
+ identifier;
private List<String> inputAclNames = Collections.emptyList();
private List<String> outputAclNames = Collections.emptyList();
private AclContextManager standardAclContext;
@@ -62,7 +62,7 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
}
public AclInterfaceAssignmentRequest identifier(
- @Nonnull final InstanceIdentifier<Acl> identifier) {
+ @Nonnull final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface> identifier) {
this.identifier = identifier;
return this;
}
@@ -97,7 +97,7 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
public void executeAsCreate(@Nonnull final FutureJVppAclFacade api) throws WriteFailedException {
checkValidRequest();
- final String interfaceName = identifier.firstKeyOf(Interface.class).getName();
+ final String interfaceName = identifier.firstKeyOf(Interface.class).getInterfaceId();
// locking on mapping context, to prevent modifying of mappings (for both contexts) during binding/execution of request
synchronized (mappingContext) {
@@ -113,10 +113,12 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
}
}
- public void executeAsUpdate(@Nonnull final FutureJVppAclFacade api, final Acl before, final Acl after)
+ public void executeAsUpdate(@Nonnull final FutureJVppAclFacade api,
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface before,
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface after)
throws WriteFailedException {
checkValidRequest();
- final String interfaceName = identifier.firstKeyOf(Interface.class).getName();
+ final String interfaceName = identifier.firstKeyOf(Interface.class).getInterfaceId();
// locking on mapping context, to prevent modifying of mappings (for both contexts) during binding/execution of request
synchronized (mappingContext) {
@@ -134,7 +136,7 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
public void executeAsDelete(@Nonnull final FutureJVppAclFacade api) throws WriteFailedException {
checkValidRequest();
- final String interfaceName = identifier.firstKeyOf(Interface.class).getName();
+ final String interfaceName = identifier.firstKeyOf(Interface.class).getInterfaceId();
// locking on mapping context, to prevent modifying of mappings (for both contexts) during binding/execution of request
synchronized (mappingContext) {
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequest.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/MacIpInterfaceAssignmentRequest.java
index 882cfd631..b7849991b 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequest.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/request/MacIpInterfaceAssignmentRequest.java
@@ -15,7 +15,7 @@
*/
-package io.fd.hc2vpp.acl.util.iface.macip;
+package io.fd.hc2vpp.acl.write.request;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -28,8 +28,7 @@ import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceAddDel;
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.Interface;
-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.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +39,8 @@ public class MacIpInterfaceAssignmentRequest implements ByteDataTranslator, Jvpp
private final boolean isNew;
private final MappingContext mappingContext;
- private InstanceIdentifier<VppMacipAcl> identifier;
+ private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface>
+ identifier;
private String aclName;
private AclContextManager macIpAclContext;
private NamingContext interfaceContext;
@@ -59,7 +59,8 @@ public class MacIpInterfaceAssignmentRequest implements ByteDataTranslator, Jvpp
return new MacIpInterfaceAssignmentRequest(false, mappingContext);
}
- public MacIpInterfaceAssignmentRequest identifier(@Nonnull final InstanceIdentifier<VppMacipAcl> identifier) {
+ public MacIpInterfaceAssignmentRequest identifier(
+ @Nonnull final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface> identifier) {
this.identifier = identifier;
return this;
}
@@ -93,7 +94,7 @@ public class MacIpInterfaceAssignmentRequest implements ByteDataTranslator, Jvpp
synchronized (mappingContext) {
checkValidRequest();
- final String interfaceName = identifier.firstKeyOf(Interface.class).getName();
+ final String interfaceName = identifier.firstKeyOf(Interface.class).getInterfaceId();
MacipAclInterfaceAddDel request = new MacipAclInterfaceAddDel();
request.isAdd = booleanToByte(isNew);