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.v3po.translate.v3po.interfacesstate;
19 import io.fd.honeycomb.v3po.translate.Context;
20 import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
21 import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
22 import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer;
23 import javax.annotation.Nonnull;
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.InterfaceBuilder;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.EthernetBuilder;
31 import org.opendaylight.yangtools.concepts.Builder;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.openvpp.jvpp.dto.SwInterfaceDetails;
35 import org.openvpp.jvpp.future.FutureJVpp;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 public class VppInterfaceStateCustomizer extends FutureJVppCustomizer
41 implements ChildReaderCustomizer<VppInterfaceStateAugmentation, VppInterfaceStateAugmentationBuilder> {
43 private static final Logger LOG = LoggerFactory.getLogger(VppInterfaceStateCustomizer.class);
45 public VppInterfaceStateCustomizer(@Nonnull final FutureJVpp jvpp) {
50 public void merge(@Nonnull Builder<? extends DataObject> parentBuilder,
51 @Nonnull VppInterfaceStateAugmentation readValue) {
52 ((InterfaceBuilder) parentBuilder).addAugmentation(VppInterfaceStateAugmentation.class, readValue);
57 public VppInterfaceStateAugmentationBuilder getBuilder(
58 @Nonnull InstanceIdentifier<VppInterfaceStateAugmentation> id) {
59 return new VppInterfaceStateAugmentationBuilder();
63 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<VppInterfaceStateAugmentation> id,
64 @Nonnull final VppInterfaceStateAugmentationBuilder builder,
65 @Nonnull final Context ctx) throws ReadFailedException {
67 final InterfaceKey key = id.firstKeyOf(Interface.class);
68 final SwInterfaceDetails iface;
70 iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), key);
71 } catch (Exception e) {
72 throw new ReadFailedException(id, e);
75 final EthernetBuilder ethernet = new EthernetBuilder();
76 ethernet.setMtu((int) iface.linkMtu);
77 switch (iface.linkDuplex) {
79 ethernet.setDuplex(Ethernet.Duplex.Half);
82 ethernet.setDuplex(Ethernet.Duplex.Full);
88 builder.setEthernet(ethernet.build());