2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.v3po.interfacesstate;
19 import static com.google.common.base.Preconditions.checkArgument;
20 import static com.google.common.base.Preconditions.checkNotNull;
21 import static io.fd.honeycomb.translate.vpp.util.SubInterfaceUtils.getSubInterfaceName;
23 import io.fd.honeycomb.translate.read.ReadContext;
24 import io.fd.honeycomb.translate.read.ReadFailedException;
25 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
26 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
27 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
28 import io.fd.honeycomb.translate.vpp.util.NamingContext;
29 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
30 import javax.annotation.Nonnull;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder;
38 import org.opendaylight.yangtools.concepts.Builder;
39 import org.opendaylight.yangtools.yang.binding.DataObject;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import io.fd.vpp.jvpp.VppBaseCallException;
42 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface;
43 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
44 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Customizer for reading ACLs enabled on given sub-interface.
51 public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
52 implements ReaderCustomizer<Acl, AclBuilder>, AclReader, JvppReplyConsumer {
54 private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceAclCustomizer.class);
55 private final NamingContext interfaceContext;
56 private final VppClassifierContextManager classifyTableContext;
58 public SubInterfaceAclCustomizer(@Nonnull final FutureJVppCore jvpp, @Nonnull final NamingContext interfaceContext,
59 @Nonnull final VppClassifierContextManager classifyTableContext) {
61 this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
62 this.classifyTableContext = checkNotNull(classifyTableContext, "classifyTableContext should not be null");
66 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Acl readValue) {
67 ((SubInterfaceBuilder) parentBuilder).setAcl(readValue);
72 public AclBuilder getBuilder(@Nonnull final InstanceIdentifier<Acl> id) {
73 return new AclBuilder();
77 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final AclBuilder builder,
78 @Nonnull final ReadContext ctx) throws ReadFailedException {
79 LOG.debug("Reading attributes for sub-interface ACL: {}", id);
80 final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class);
81 checkArgument(parentInterfacekey != null, "No parent interface key found");
82 final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
83 checkArgument(subInterfacekey != null, "No sub-interface key found");
84 final String subInterfaceName =
85 getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
87 final ClassifyTableByInterface request = new ClassifyTableByInterface();
88 request.swIfIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
90 final ClassifyTableByInterfaceReply reply =
91 getReplyForRead(getFutureJVpp().classifyTableByInterface(request).toCompletableFuture(), id);
93 builder.setL2Acl(readL2Acl(reply.l2TableId, classifyTableContext, ctx.getMappingContext()));
94 builder.setIp4Acl(readIp4Acl(reply.ip4TableId, classifyTableContext, ctx.getMappingContext()));
95 builder.setIp6Acl(readIp6Acl(reply.ip6TableId, classifyTableContext, ctx.getMappingContext()));
97 if (LOG.isTraceEnabled()) {
98 LOG.trace("Attributes for ACL {} successfully read: {}", id, builder.build());
100 } catch (VppBaseCallException e) {
101 throw new ReadFailedException(id, e);