diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-01-17 17:57:26 +0100 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-01-18 12:51:19 +0000 |
commit | 90d286c396eee2555b9a98b0af7fce292fce4879 (patch) | |
tree | 9618fbfe800e4c98754c0659ed7401c588810476 /acl/acl-impl/src/main/java/io/fd | |
parent | 75f8aa0f9a1ff45f1be500304fb156a13fb6e6ef (diff) |
HONEYCOMB-330: fix acl tag handling
Acl tag in vpp's acl plugin is an ascii tag, so it should not be handled as hex string.
Change-Id: I801d5b72a4c20f78246288ea63d914b0b9f3564b
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'acl/acl-impl/src/main/java/io/fd')
6 files changed, 35 insertions, 26 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java index e222c2142..5b08074d2 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizer.java @@ -31,7 +31,6 @@ 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.AclDetails; import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; import io.fd.vpp.jvpp.acl.dto.AclDump; import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; @@ -45,7 +44,6 @@ import java.util.stream.IntStream; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; @@ -162,14 +160,8 @@ abstract class AbstractVppAclCustomizer extends FutureJVppAclCustomizer aclDumpManager.getDump(id, ctx.getModificationCache(), aclIndex); if (dumpReply.isPresent() && !dumpReply.get().aclDetails.isEmpty()) { - // TODO(HONEYCOMB-330): (model expects hex string, but tag is written and read as ascii string) - // decide how tag should be handled (model change might be needed). builder.setName(aclName); builder.setType(vppAclsKey.getType()); - final AclDetails aclDetails = dumpReply.get().aclDetails.get(0); - if (aclDetails.tag != null && aclDetails.tag.length > 0) { - builder.setTag(new HexString(printHexBinary(aclDetails.tag))); - } } else { throw new ReadFailedException(id, 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/AclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/AclCustomizer.java index 83fc3186c..e194da1de 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 @@ -40,6 +40,7 @@ import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; 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; @@ -47,6 +48,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.cont 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.rev161214.VppAcl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppAclAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppAclAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -157,8 +160,10 @@ public class AclCustomizer extends FutureJVppAclCustomizer final java.util.Optional<AclDetails> detail = dump.get().aclDetails.stream() .filter(acl -> acl.aclIndex == index).findFirst(); if (detail.isPresent()) { + final AclDetails aclDetails = detail.get(); + setTag(builder, aclDetails.tag); builder.setAccessListEntries(new AccessListEntriesBuilder() - .setAce(toStandardAces(name, detail.get().r, standardAclContext, ctx.getMappingContext())) + .setAce(toStandardAces(name, aclDetails.r, standardAclContext, ctx.getMappingContext())) .build()); } } @@ -170,9 +175,11 @@ public class AclCustomizer extends FutureJVppAclCustomizer if (dump.isPresent() && !dump.get().macipAclDetails.isEmpty()) { final java.util.Optional<MacipAclDetails> detail = dump.get().macipAclDetails.stream().filter(acl -> acl.aclIndex == index).findFirst(); + final MacipAclDetails macipAclDetails = detail.get(); + setTag(builder, macipAclDetails.tag); if (detail.isPresent()) { builder.setAccessListEntries(new AccessListEntriesBuilder() - .setAce(toMacIpAces(name, detail.get().r, macipAclContext, ctx.getMappingContext())) + .setAce(toMacIpAces(name, macipAclDetails.r, macipAclContext, ctx.getMappingContext())) .build()); } } @@ -180,4 +187,15 @@ public class AclCustomizer extends FutureJVppAclCustomizer throw new IllegalArgumentException("Unsupported acl type: " + aclType); } } + + private void setTag(@Nonnull final AclBuilder builder, @Nullable final byte[] tag) { + if (tag != null) { + final String strTag = toString(tag); + if (strTag.length() > 0) { + builder.addAugmentation( + VppAclAugmentation.class, new VppAclAugmentationBuilder().setTag(strTag).build() + ); + } + } + } } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java index 23776fe07..b95acf82d 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java @@ -34,7 +34,6 @@ import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; -import io.fd.vpp.jvpp.acl.dto.MacipAclDetails; import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump; import io.fd.vpp.jvpp.acl.dto.MacipAclDump; import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGet; @@ -42,7 +41,6 @@ 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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder; @@ -128,14 +126,9 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer macIpAclDumpManager.getDump(id, modificationCache, aclIndex); if (macIpDumpReply.isPresent() && !macIpDumpReply.get().macipAclDetails.isEmpty()) { - final MacipAclDetails details = macIpDumpReply.get().macipAclDetails.get(0); - builder.setName(macIpAclContext.getAclName(aclIndex, mappingContext)); builder.setType( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl.class); - if (details.tag != null && details.tag.length > 0) { - builder.setTag(new HexString(printHexBinary(details.tag))); - } } else { // this is invalid state(Interface in VPP will act as "deny-all" for security reasons), but generally // it should not happen 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 8c6cdcfef..45e548ce7 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 @@ -23,6 +23,7 @@ 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.rev161214.VppAclAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.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.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce; @@ -62,11 +63,13 @@ public interface AclDataExtractor { } /** - * Convert {@link Acl} name to byte array as UTF_8 + * Convert {@link Acl} tag to byte array in US_ASCII */ - default byte[] getAclNameAsBytes(@Nonnull final Acl acl) { - return Optional.ofNullable(acl.getAclName()) - .orElseThrow(() -> new IllegalArgumentException("Unable to extract bytes for null")) - .getBytes(StandardCharsets.UTF_8); + default byte[] getAclTag(@Nonnull final Acl acl) { + final VppAclAugmentation augmentation = acl.getAugmentation(VppAclAugmentation.class); + if (augmentation != null && augmentation.getTag() != null) { + return augmentation.getTag().getBytes(StandardCharsets.US_ASCII); + } + return new byte[0]; } } 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/util/acl/AclWriter.java index eae4bab4e..32e20ebac 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/util/acl/AclWriter.java @@ -48,7 +48,7 @@ public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyCons final AclAddReplace request = new AclAddReplace(); - request.tag = getAclNameAsBytes(acl); + request.tag = getAclTag(acl); request.aclIndex = ACL_INDEX_CREATE_NEW; final List<Ace> aces = getAces(acl); @@ -70,7 +70,7 @@ public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyCons final AclAddReplace request = new AclAddReplace(); - request.tag = getAclNameAsBytes(acl); + request.tag = getAclTag(acl); // by setting existing index, request is resolved as update request.aclIndex = standardAclContext.getAclIndex(acl.getAclName(), mappingContext); @@ -105,7 +105,7 @@ public interface AclWriter extends AclDataExtractor, AceConverter, JvppReplyCons @Nonnull final MappingContext mappingContext) throws WriteFailedException { final MacipAclAdd request = new MacipAclAdd(); - request.tag = getAclNameAsBytes(acl); + request.tag = getAclTag(acl); final List<Ace> aces = getAces(acl); request.r = toMacIpAclRules(aces); 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 index 4057d229a..3c9a521c9 100644 --- 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 @@ -25,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.cont 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.rev161214.VppAclAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.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.rev161214.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.rev161214.acl.icmp.header.fields.IcmpCodeRange; @@ -41,7 +42,9 @@ 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.child(AccessListEntries.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), |