0b5cef4d81dec0d89648306840dca2e04c1eed91
[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.initializers;
18
19 import com.google.common.base.Function;
20 import com.google.common.collect.Lists;
21 import io.fd.honeycomb.v3po.vpp.data.init.AbstractDataTreeConverter;
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Initializes ietf-interfaces config data based on operational state
38  */
39 public class InterfacesInitializer extends AbstractDataTreeConverter<InterfacesState, Interfaces> {
40     private static final Logger LOG = LoggerFactory.getLogger(InterfacesInitializer.class);
41
42     public InterfacesInitializer(@Nonnull final DataBroker bindingDataBroker) {
43         super(bindingDataBroker, InstanceIdentifier.create(InterfacesState.class),
44                 InstanceIdentifier.create(Interfaces.class));
45     }
46
47     @Override
48     protected Interfaces convert(final InterfacesState operationalData) {
49         LOG.debug("InterfacesInitializer.convert()");
50         InterfacesBuilder interfacesBuilder = new InterfacesBuilder();
51         interfacesBuilder.setInterface(Lists.transform(operationalData.getInterface(), CONVERT_INTERFACE));
52         return interfacesBuilder.build();
53     }
54
55     private static final Function<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface, Interface>
56             CONVERT_INTERFACE =
57             new Function<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface, Interface>() {
58                 @Nullable
59                 @Override
60                 public Interface apply(
61                         @Nullable final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface input) {
62
63                     InterfaceBuilder builder = new InterfaceBuilder();
64                     builder.setKey(new InterfaceKey(input.getKey().getName()));
65                     builder.setName(input.getName());
66                     // builder.setDescription(); not present in interfaces-state
67                     builder.setType(input.getType());
68                     builder.setEnabled(AdminStatus.Up.equals(input.getAdminStatus()));
69                     // builder.setLinkUpDownTrapEnable(); not present in interfaces-state
70                     return builder.build();
71                 }
72             };
73 }