8173b67ba2397fe2a47074783d8159afcfb885b1
[hc2vpp.git] /
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.v3po.translate.v3po.interfacesstate;
18
19 import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceCustomizer.getCachedInterfaceDump;
20
21 import io.fd.honeycomb.v3po.translate.read.ReadContext;
22 import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
23 import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
24 import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer;
25 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.EthernetBuilder;
32 import org.opendaylight.yangtools.concepts.Builder;
33 import org.opendaylight.yangtools.yang.binding.DataObject;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.openvpp.jvpp.dto.SwInterfaceDetails;
36 import org.openvpp.jvpp.future.FutureJVpp;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41 public class EthernetCustomizer extends FutureJVppCustomizer
42         implements ChildReaderCustomizer<Ethernet, EthernetBuilder> {
43
44     private static final Logger LOG = LoggerFactory.getLogger(EthernetCustomizer.class);
45     private NamingContext interfaceContext;
46
47     public EthernetCustomizer(@Nonnull final FutureJVpp jvpp,
48                               final NamingContext interfaceContext) {
49         super(jvpp);
50         this.interfaceContext = interfaceContext;
51     }
52
53     @Override
54     public void merge(@Nonnull Builder<? extends DataObject> parentBuilder,
55                       @Nonnull Ethernet readValue) {
56         ((VppInterfaceStateAugmentationBuilder) parentBuilder).setEthernet(readValue);
57     }
58
59     @Nonnull
60     @Override
61     public EthernetBuilder getBuilder(
62             @Nonnull InstanceIdentifier<Ethernet> id) {
63         return new EthernetBuilder();
64     }
65
66     @Override
67     public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Ethernet> id,
68                                       @Nonnull final EthernetBuilder builder,
69                                       @Nonnull final ReadContext ctx) throws ReadFailedException {
70
71         final InterfaceKey key = id.firstKeyOf(Interface.class);
72         final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), key,
73                 interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache());
74
75         builder.setMtu((int) iface.linkMtu);
76         switch (iface.linkDuplex) {
77             case 1:
78                 builder.setDuplex(Ethernet.Duplex.Half);
79                 break;
80             case 2:
81                 builder.setDuplex(Ethernet.Duplex.Full);
82                 break;
83             default:
84                 break;
85         }
86     }
87 }