4e18c9804b68d3e694b42f3341b454087b23f222
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / interfacesstate / 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.interfacesstate;
18
19 import io.fd.honeycomb.translate.read.ReadContext;
20 import io.fd.honeycomb.translate.read.ReadFailedException;
21 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
22 import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
23 import io.fd.honeycomb.translate.v3po.util.NamingContext;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2Builder;
29 import org.opendaylight.yangtools.concepts.Builder;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.openvpp.jvpp.future.FutureJVpp;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 import javax.annotation.Nonnull;
37
38 import static com.google.common.base.Preconditions.checkState;
39
40 /**
41  * Customizer for reading ietf-interfaces:interfaces-state/interface/iface_name/v3po:l2
42  */
43 public class L2Customizer extends FutureJVppCustomizer implements ReaderCustomizer<L2, L2Builder> {
44
45     private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class);
46     private final InterconnectionReadUtils icReadUtils;
47
48     public L2Customizer(@Nonnull final FutureJVpp futureJvpp,
49                         @Nonnull final NamingContext interfaceContext,
50                         @Nonnull final NamingContext bridgeDomainContext) {
51         super(futureJvpp);
52         this.icReadUtils = new InterconnectionReadUtils(futureJvpp, interfaceContext, bridgeDomainContext);
53     }
54
55     @Override
56     public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final L2 readValue) {
57         ((VppInterfaceStateAugmentationBuilder) parentBuilder).setL2(readValue);
58     }
59
60     @Nonnull
61     @Override
62     public L2Builder getBuilder(@Nonnull final InstanceIdentifier<L2> id) {
63         return new L2Builder();
64     }
65
66     @Override
67     public void readCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2Builder builder,
68                                       @Nonnull final ReadContext ctx) throws ReadFailedException {
69
70         LOG.debug("Reading attributes for L2: {}", id);
71         final InterfaceKey key = id.firstKeyOf(Interface.class);
72         final String ifaceName = key.getName();
73         builder.setInterconnection(icReadUtils.readInterconnection(id, ifaceName, ctx));
74     }
75 }