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.egress;
19 import static com.google.common.base.Preconditions.checkArgument;
20 import static com.google.common.base.Preconditions.checkNotNull;
22 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
23 import io.fd.honeycomb.translate.v3po.interfaces.acl.common.IetfAclWriter;
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 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.rev161214.interfaces._interface.ietf.acl.Egress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.AccessLists;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class IetfAclCustomizer implements WriterCustomizer<Egress> {
37 private static final Logger LOG = LoggerFactory.getLogger(IetfAclCustomizer.class);
38 private final IetfAclWriter aclWriter;
39 private final NamingContext interfaceContext;
41 public IetfAclCustomizer(final IetfAclWriter aclWriter, final NamingContext interfaceContext) {
42 this.aclWriter = checkNotNull(aclWriter, "aclWriter should not be null");
43 this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
47 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Egress> id, @Nonnull final Egress dataAfter,
48 @Nonnull final WriteContext writeContext) throws WriteFailedException {
49 final String ifName = id.firstKeyOf(Interface.class).getName();
50 final int ifIndex = interfaceContext.getIndex(ifName, writeContext.getMappingContext());
51 LOG.debug("Adding egress ACLs for interface={}(id={}): {}", ifName, ifIndex, dataAfter);
53 final AccessLists accessLists = dataAfter.getAccessLists();
54 checkArgument(accessLists != null && accessLists.getAcl() != null,
55 "ietf-acl container does not define acl list");
57 if (!InterfaceMode.L2.equals(accessLists.getMode())) {
58 LOG.debug("Writing egress Acls is supported only in L2 mode. Ignoring config: {}", dataAfter);
62 aclWriter.write(id, ifIndex, accessLists.getAcl(), accessLists.getDefaultAction(), accessLists.getMode(),
63 writeContext, writeContext.getMappingContext());
67 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Egress> id, @Nonnull final Egress dataBefore,
68 @Nonnull final Egress dataAfter, @Nonnull final WriteContext writeContext)
69 throws WriteFailedException {
70 LOG.debug("ACLs update: removing previously configured ACLs");
71 deleteCurrentAttributes(id, dataBefore, writeContext);
72 LOG.debug("ACLs update: adding updated ACLs");
73 writeCurrentAttributes(id, dataAfter, writeContext);
74 LOG.debug("ACLs update was successful");
78 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Egress> id, @Nonnull final Egress dataBefore,
79 @Nonnull final WriteContext writeContext) throws WriteFailedException {
80 final String ifName = id.firstKeyOf(Interface.class).getName();
81 final int ifIndex = interfaceContext.getIndex(ifName, writeContext.getMappingContext());
82 LOG.debug("Removing ACLs for interface={}(id={}): {}", ifName, ifIndex, dataBefore);
83 aclWriter.deleteAcl(id, ifIndex, writeContext.getMappingContext());