HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / interfaces / acl / ingress / SubInterfaceAclCustomizer.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.translate.v3po.interfaces.acl.ingress;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
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.vpp.util.SubInterfaceUtils;
26 import io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
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.rev161214.interfaces._interface.sub.interfaces.SubInterface;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.Ingress;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * Customizer for enabling/disabling ingress ACLs on given sub-interface.
41  */
42 public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
43         implements WriterCustomizer<Ingress>, AclWriter {
44
45     private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceAclCustomizer.class);
46     private final NamingContext interfaceContext;
47     private final VppClassifierContextManager classifyTableContext;
48
49     public SubInterfaceAclCustomizer(@Nonnull final FutureJVppCore vppApi,
50                                      @Nonnull final NamingContext interfaceContext,
51                                      @Nonnull final VppClassifierContextManager classifyTableContext) {
52         super(vppApi);
53         this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
54         this.classifyTableContext = checkNotNull(classifyTableContext, "classifyTableContext should not be null");
55     }
56
57     @Override
58     public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id, @Nonnull final Ingress dataAfter,
59                                        @Nonnull final WriteContext writeContext) throws WriteFailedException {
60         setAcl(true, id, dataAfter, writeContext);
61     }
62
63     @Override
64     public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id,
65                                         @Nonnull final Ingress dataBefore,
66                                         @Nonnull final Ingress dataAfter, @Nonnull final WriteContext writeContext)
67             throws WriteFailedException {
68         throw new UnsupportedOperationException("Acl update is not supported. Please delete Acl container first.");
69     }
70
71     @Override
72     public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ingress> id,
73                                         @Nonnull final Ingress dataBefore,
74                                         @Nonnull final WriteContext writeContext) throws WriteFailedException {
75         setAcl(false, id, dataBefore, writeContext);
76     }
77
78     private void setAcl(final boolean isAdd, @Nonnull final InstanceIdentifier<Ingress> id, @Nonnull final Ingress acl,
79                         @Nonnull final WriteContext writeContext) throws WriteFailedException {
80         final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class);
81         final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
82         final String subInterfaceName = SubInterfaceUtils
83                 .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
84         final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext());
85
86         LOG.debug("Setting ACL(isAdd={}) on sub-interface={}(id={}): {}",
87                 isAdd, subInterfaceName, subInterfaceIndex, acl);
88         inputAclSetInterface(getFutureJVpp(), isAdd, id, acl, subInterfaceIndex, classifyTableContext,
89                 writeContext.getMappingContext());
90         LOG.debug("Successfully set ACL(isAdd={}) on sub-interface={}(id={}): {}",
91                 isAdd, subInterfaceName, subInterfaceIndex, acl);
92     }
93 }