diff options
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/egress/EgressIetfAclWriter.java')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/egress/EgressIetfAclWriter.java | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/egress/EgressIetfAclWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/egress/EgressIetfAclWriter.java index eee8f68eb..bfd58cf4a 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/egress/EgressIetfAclWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/egress/EgressIetfAclWriter.java @@ -17,8 +17,13 @@ package io.fd.honeycomb.translate.v3po.interfaces.acl.egress; 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 com.google.common.base.Optional; +import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.v3po.interfaces.acl.common.AbstractIetfAclWriter; +import io.fd.honeycomb.translate.v3po.interfaces.acl.common.AclTableContextManager; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.ClassifySetInterfaceL2Tables; @@ -32,26 +37,31 @@ 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.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.ace.type.AceEth; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.AccessLists; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.access.lists.Acl; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class EgressIetfAclWriter extends AbstractIetfAclWriter { - private static final int NOT_DEFINED = -1; + private final AclTableContextManager aclCtx; - public EgressIetfAclWriter(@Nonnull final FutureJVppCore futureJVppCore) { + public EgressIetfAclWriter(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull AclTableContextManager aclCtx) { super(futureJVppCore); + this.aclCtx = checkNotNull(aclCtx, "aclCtx should not be null"); } @Override - public void deleteAcl(@Nonnull final InstanceIdentifier<?> id, final int swIfIndex) + public void deleteAcl(@Nonnull final InstanceIdentifier<?> id, final int swIfIndex, + @Nonnull final MappingContext mappingContext) throws WriteFailedException { - // We unassign and remove all ACL-related classify tables for given interface (we assume we are the only - // classify table manager) + Optional<MappingEntry> optional = aclCtx.getEntry(swIfIndex, mappingContext); + checkState(optional.isPresent(), "Removing ACL id=%s, but acl mapping entry is not present", id); + final MappingEntry entry = optional.get(); unassignClassifyTables(id, swIfIndex); - - // TODO(HONEYCOMB-264): remove classify tables from vpp (we need to cache interface/acl mapping) + removeClassifyTables(id, entry); + aclCtx.removeEntry(swIfIndex, mappingContext); } private void unassignClassifyTables(@Nonnull final InstanceIdentifier<?> id, final int swIfIndex) @@ -68,8 +78,9 @@ public final class EgressIetfAclWriter extends AbstractIetfAclWriter { @Override public void write(@Nonnull final InstanceIdentifier<?> id, int swIfIndex, @Nonnull final List<Acl> acls, - final AccessLists.DefaultAction defaultAction, @Nullable InterfaceMode mode, - @Nonnull final WriteContext writeContext, @Nonnegative final int numberOfTags) + @Nonnull final AccessLists.DefaultAction defaultAction, @Nullable InterfaceMode mode, + @Nonnull final WriteContext writeContext, @Nonnegative final int numberOfTags, + @Nonnull final MappingContext mappingContext) throws WriteFailedException { checkArgument(numberOfTags >= 0 && numberOfTags <= 2, "Number of vlan tags %s is not in [0,2] range"); checkArgument(InterfaceMode.L2.equals(mode), "Writing egress Acls is supported only in L2 mode"); @@ -86,8 +97,19 @@ public final class EgressIetfAclWriter extends AbstractIetfAclWriter { final List<Ace> aces = getACEs(acls, writeContext, EgressIetfAclWriter::isNotIpRule); request.otherTableIndex = writeAces(id, aces, defaultAction, mode, numberOfTags); - final CompletionStage<ClassifySetInterfaceL2TablesReply> cs = jvpp.classifySetInterfaceL2Tables(request); - getReplyForWrite(cs.toCompletableFuture(), id); + final MappingEntry entry = new MappingEntryBuilder().setIndex(swIfIndex) + .setIp4TableId(request.ip4TableIndex) + .setIp6TableId(request.ip6TableIndex) + .setL2TableId(request.otherTableIndex) + .build(); + aclCtx.addEntry(entry, mappingContext); + + try { + getReplyForWrite(jvpp.classifySetInterfaceL2Tables(request).toCompletableFuture(), id); + } catch (WriteFailedException e) { + removeClassifyTables(id, entry); + throw e; + } } private static boolean isNotIpRule(final Ace ace) { |