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.acl.ingress;
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.vppclassifier.VppClassifierContextManager;
23 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
24 import io.fd.honeycomb.translate.vpp.util.NamingContext;
25 import io.fd.honeycomb.translate.write.WriteContext;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
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.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.acl.Ingress;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Customizer for enabling/disabling ingress ACLs on given interface based on low lever classfier model.
38 public class AclCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Ingress>, AclWriter {
40 private static final Logger LOG = LoggerFactory.getLogger(AclCustomizer.class);
41 private final NamingContext interfaceContext;
42 private final VppClassifierContextManager classifyTableContext;
44 public AclCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext,
45 @Nonnull final VppClassifierContextManager classifyTableContext) {
47 this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
48 this.classifyTableContext = checkNotNull(classifyTableContext, "classifyTableContext should not be null");
52 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id, @Nonnull final Ingress dataAfter,
53 @Nonnull final WriteContext writeContext) throws WriteFailedException {
54 setAcl(true, id, dataAfter, writeContext);
58 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id,
59 @Nonnull final Ingress dataBefore,
60 @Nonnull final Ingress dataAfter, @Nonnull final WriteContext writeContext)
61 throws WriteFailedException {
62 throw new UnsupportedOperationException("Acl update is not supported. Please delete Acl container first.");
66 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id,
67 @Nonnull final Ingress dataBefore,
68 @Nonnull final WriteContext writeContext) throws WriteFailedException {
69 setAcl(false, id, dataBefore, writeContext);
72 private void setAcl(final boolean isAdd, @Nonnull final InstanceIdentifier<Ingress> id, @Nonnull final Ingress acl,
73 @Nonnull final WriteContext writeContext) throws WriteFailedException {
74 final String ifName = id.firstKeyOf(Interface.class).getName();
75 final int ifIndex = interfaceContext.getIndex(ifName, writeContext.getMappingContext());
77 LOG.debug("Setting ACL(isAdd={}) on interface={}(id={}): {}", isAdd, ifName, ifIndex, acl);
79 inputAclSetInterface(getFutureJVpp(), isAdd, id, acl, ifIndex, classifyTableContext,
80 writeContext.getMappingContext());
81 LOG.debug("Successfully set ACL(isAdd={}) on interface={}(id={}): {}", isAdd, ifName, ifIndex, acl);