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.WriteTimeoutException;
25 import io.fd.honeycomb.translate.write.WriteContext;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Acl;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.openvpp.jvpp.VppBaseCallException;
32 import org.openvpp.jvpp.core.future.FutureJVppCore;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Customizer for enabling/disabling ACLs on given interface.
39 public class AclCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Acl>, AclWriter {
41 private static final Logger LOG = LoggerFactory.getLogger(AclCustomizer.class);
42 private final NamingContext interfaceContext;
43 private final NamingContext classifyTableContext;
45 public AclCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext,
46 @Nonnull final NamingContext classifyTableContext) {
48 this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
49 this.classifyTableContext = checkNotNull(classifyTableContext, "classifyTableContext should not be null");
53 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataAfter,
54 @Nonnull final WriteContext writeContext) throws WriteFailedException {
56 setAcl(true, id, dataAfter, writeContext);
57 } catch (VppBaseCallException e) {
58 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
63 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
64 @Nonnull final Acl dataAfter, @Nonnull final WriteContext writeContext)
65 throws WriteFailedException {
66 throw new UnsupportedOperationException("Acl update is not supported. Please delete Acl container first.");
70 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl dataBefore,
71 @Nonnull final WriteContext writeContext) throws WriteFailedException {
73 setAcl(false, id, dataBefore, writeContext);
74 } catch (VppBaseCallException e) {
75 throw new WriteFailedException.DeleteFailedException(id, e);
79 private void setAcl(final boolean isAdd, @Nonnull final InstanceIdentifier<Acl> id, @Nonnull final Acl acl,
80 @Nonnull final WriteContext writeContext)
81 throws VppBaseCallException, WriteTimeoutException {
82 final String ifName = id.firstKeyOf(Interface.class).getName();
83 final int ifIndex = interfaceContext.getIndex(ifName, writeContext.getMappingContext());
85 LOG.debug("Setting ACL(isAdd={}) on interface={}(id={}): {}", isAdd, ifName, ifIndex, acl);
87 inputAclSetInterface(getFutureJVpp(), isAdd, id, acl, ifIndex, classifyTableContext,
88 writeContext.getMappingContext());
89 LOG.debug("Successfully set ACL(isAdd={}) on interface={}(id={}): {}", isAdd, ifName, ifIndex, acl);