HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / interfaces / L2Customizer.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;
18
19 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
20 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
21 import io.fd.honeycomb.translate.vpp.util.NamingContext;
22 import io.fd.honeycomb.translate.write.WriteContext;
23 import io.fd.honeycomb.translate.write.WriteFailedException;
24 import javax.annotation.Nonnull;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class L2Customizer extends FutureJVppCustomizer implements WriterCustomizer<L2> {
33
34     private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class);
35     private final NamingContext interfaceContext;
36     private final InterconnectionWriteUtils icWriteUtils;
37
38     public L2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext,
39                         final NamingContext bridgeDomainContext) {
40         super(vppApi);
41         this.interfaceContext = interfaceContext;
42         this.icWriteUtils = new InterconnectionWriteUtils(vppApi, interfaceContext, bridgeDomainContext);
43     }
44
45     @Override
46     public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataAfter,
47                                        @Nonnull final WriteContext writeContext)
48         throws WriteFailedException {
49
50         final String ifcName = id.firstKeyOf(Interface.class).getName();
51         final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext());
52         setL2(id, swIfc, ifcName, dataAfter, writeContext);
53     }
54
55     @Override
56     public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore,
57                                         @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext)
58         throws WriteFailedException {
59
60         final String ifcName = id.firstKeyOf(Interface.class).getName();
61         final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext());
62         // No update, again calling set
63         setL2(id, swIfc, ifcName, dataAfter, writeContext);
64     }
65
66     @Override
67     public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore,
68                                         @Nonnull final WriteContext writeContext) throws WriteFailedException {
69         final String ifcName = id.firstKeyOf(Interface.class).getName();
70         final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext());
71         deleteL2(id, swIfc, ifcName, dataBefore, writeContext);
72     }
73
74     private void setL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 l2,
75                        final WriteContext writeContext)
76         throws WriteFailedException {
77         LOG.debug("Setting L2 for interface: {}", ifcName);
78         // Nothing besides interconnection here
79         icWriteUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext);
80     }
81
82     private void deleteL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 l2Before,
83                        final WriteContext writeContext)
84         throws WriteFailedException {
85         LOG.debug("Deleting L2 for interface: {}", ifcName);
86         // Nothing besides interconnection here
87         icWriteUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext);
88     }
89 }