2 * Copyright (c) 2017 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.hc2vpp.vpp.classifier.write.acl.ingress;
19 import static com.google.common.base.Preconditions.checkNotNull;
21 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
22 import io.fd.hc2vpp.common.translate.util.NamingContext;
23 import io.fd.hc2vpp.v3po.util.SubInterfaceUtils;
24 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
25 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
26 import io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterfaceKey;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Customizer for enabling/disabling ingress ACLs on given sub-interface.
42 public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
43 implements WriterCustomizer<Ingress>, AclWriter {
45 private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceAclCustomizer.class);
46 private final NamingContext interfaceContext;
47 private final VppClassifierContextManager classifyTableContext;
49 public SubInterfaceAclCustomizer(@Nonnull final FutureJVppCore vppApi,
50 @Nonnull final NamingContext interfaceContext,
51 @Nonnull final VppClassifierContextManager classifyTableContext) {
53 this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
54 this.classifyTableContext = checkNotNull(classifyTableContext, "classifyTableContext should not be null");
58 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id, @Nonnull final Ingress dataAfter,
59 @Nonnull final WriteContext writeContext) throws WriteFailedException {
60 setAcl(true, id, dataAfter, writeContext);
64 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id,
65 @Nonnull final Ingress dataBefore,
66 @Nonnull final Ingress dataAfter, @Nonnull final WriteContext writeContext)
67 throws WriteFailedException {
68 throw new UnsupportedOperationException("Acl update is not supported. Please delete Acl container first.");
72 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id,
73 @Nonnull final Ingress dataBefore,
74 @Nonnull final WriteContext writeContext) throws WriteFailedException {
75 setAcl(false, id, dataBefore, writeContext);
78 private void setAcl(final boolean isAdd, @Nonnull final InstanceIdentifier<Ingress> id, @Nonnull final Ingress acl,
79 @Nonnull final WriteContext writeContext) throws WriteFailedException {
80 final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class);
81 final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
82 final String subInterfaceName = SubInterfaceUtils
83 .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
84 final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext());
86 LOG.debug("Setting ACL(isAdd={}) on sub-interface={}(id={}): {}",
87 isAdd, subInterfaceName, subInterfaceIndex, acl);
88 inputAclSetInterface(getFutureJVpp(), isAdd, id, acl, subInterfaceIndex, classifyTableContext,
89 writeContext.getMappingContext());
90 LOG.debug("Successfully set ACL(isAdd={}) on sub-interface={}(id={}): {}",
91 isAdd, subInterfaceName, subInterfaceIndex, acl);