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.interfaces;
19 import static com.google.common.base.Preconditions.checkNotNull;
21 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
22 import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
23 import io.fd.honeycomb.translate.v3po.util.NamingContext;
24 import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils;
25 import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException;
26 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
27 import io.fd.honeycomb.translate.write.WriteContext;
28 import io.fd.honeycomb.translate.write.WriteFailedException;
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.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.openvpp.jvpp.VppBaseCallException;
37 import org.openvpp.jvpp.core.future.FutureJVppCore;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Customizer for enabling/disabling ACLs on given sub-interface.
44 public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
45 implements WriterCustomizer<Acl>, AclWriter {
47 private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceAclCustomizer.class);
48 private final NamingContext interfaceContext;
49 private final VppClassifierContextManager classifyTableContext;
51 public SubInterfaceAclCustomizer(@Nonnull final FutureJVppCore vppApi,
52 @Nonnull final NamingContext interfaceContext,
53 @Nonnull final VppClassifierContextManager classifyTableContext) {
55 this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
56 this.classifyTableContext = checkNotNull(classifyTableContext, "classifyTableContext should not be null");
60 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataAfter,
61 @Nonnull final WriteContext writeContext) throws WriteFailedException {
63 setAcl(true, id, dataAfter, writeContext);
64 } catch (VppBaseCallException e) {
65 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
70 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
71 @Nonnull final Acl dataAfter, @Nonnull final WriteContext writeContext)
72 throws WriteFailedException {
73 throw new UnsupportedOperationException("Acl update is not supported. Please delete Acl container first.");
77 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
78 @Nonnull final WriteContext writeContext) throws WriteFailedException {
80 setAcl(false, id, dataBefore, writeContext);
81 } catch (VppBaseCallException e) {
82 throw new WriteFailedException.DeleteFailedException(id, e);
86 private void setAcl(final boolean isAdd, @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
87 @Nonnull final WriteContext writeContext)
88 throws VppBaseCallException, WriteTimeoutException {
89 final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class);
90 final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
91 final String subInterfaceName = SubInterfaceUtils
92 .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
93 final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext());
95 LOG.debug("Setting ACL(isAdd={}) on sub-interface={}(id={}): {}",
96 isAdd, subInterfaceName, subInterfaceIndex, acl);
97 inputAclSetInterface(getFutureJVpp(), isAdd, id, acl, subInterfaceIndex, classifyTableContext,
98 writeContext.getMappingContext());
99 LOG.debug("Successfully set ACL(isAdd={}) on sub-interface={}(id={}): {}",
100 isAdd, subInterfaceName, subInterfaceIndex, acl);