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.v3po.util.FutureJVppCustomizer;
22 import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException;
23 import io.fd.honeycomb.translate.write.WriteContext;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
26 import io.fd.honeycomb.translate.v3po.util.NamingContext;
27 import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils;
28 import javax.annotation.Nonnull;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.openvpp.jvpp.VppBaseCallException;
36 import org.openvpp.jvpp.core.future.FutureJVppCore;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * Customizer for enabling/disabling ACLs on given sub-interface.
43 public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
44 implements WriterCustomizer<Acl>, AclWriter {
46 private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceAclCustomizer.class);
47 private final NamingContext interfaceContext;
48 private final NamingContext classifyTableContext;
50 public SubInterfaceAclCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext,
51 @Nonnull final NamingContext 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<Acl> id, @Nonnull final Acl dataAfter,
59 @Nonnull final WriteContext writeContext) throws WriteFailedException {
61 setAcl(true, id, dataAfter, writeContext);
62 } catch (VppBaseCallException e) {
63 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
68 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
69 @Nonnull final Acl dataAfter, @Nonnull final WriteContext writeContext)
70 throws WriteFailedException {
71 throw new UnsupportedOperationException("Acl update is not supported. Please delete Acl container first.");
75 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
76 @Nonnull final WriteContext writeContext) throws WriteFailedException {
78 setAcl(false, id, dataBefore, writeContext);
79 } catch (VppBaseCallException e) {
80 throw new WriteFailedException.DeleteFailedException(id, e);
84 private void setAcl(final boolean isAdd, @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
85 @Nonnull final WriteContext writeContext)
86 throws VppBaseCallException, WriteTimeoutException {
87 final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class);
88 final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
89 final String subInterfaceName = SubInterfaceUtils
90 .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
91 final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext());
93 LOG.debug("Setting ACL(isAdd={}) on sub-interface={}(id={}): {}",
94 isAdd, subInterfaceName, subInterfaceIndex, acl);
95 inputAclSetInterface(getFutureJVpp(), isAdd, id, acl, subInterfaceIndex, classifyTableContext,
96 writeContext.getMappingContext());
97 LOG.debug("Successfully set ACL(isAdd={}) on sub-interface={}(id={}): {}",
98 isAdd, subInterfaceName, subInterfaceIndex, acl);