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.initializers;
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;
37 * Initializes ietf-interfaces config data based on operational state
39 public class InterfacesInitializer extends AbstractDataTreeConverter<InterfacesState, Interfaces> {
40 private static final Logger LOG = LoggerFactory.getLogger(InterfacesInitializer.class);
42 public InterfacesInitializer(@Nonnull final DataBroker bindingDataBroker) {
43 super(bindingDataBroker, InstanceIdentifier.create(InterfacesState.class),
44 InstanceIdentifier.create(Interfaces.class));
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();
55 private static final Function<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface, Interface>
57 new Function<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface, Interface>() {
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) {
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();