76caf16c0ab4a72714875d1cdc34ff95fc025b8f
[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 package io.fd.honeycomb.v3po.translate.v3po.initializers;
17
18 import com.google.common.collect.Lists;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubInterfaceStatus;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentationBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface;
27
28 /**
29  * Utility class for sub interface initialization
30  */
31 final class SubInterfaceInitializationUtils {
32
33     private SubInterfaceInitializationUtils() {
34         throw new UnsupportedOperationException("Utility class cannot be instantiated");
35     }
36
37     static void initializeSubinterfaceStateAugmentation(
38             final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface input,
39             final InterfaceBuilder builder) {
40         final SubinterfaceStateAugmentation subIfcAugmentation =
41                 input.getAugmentation(SubinterfaceStateAugmentation.class);
42         if (subIfcAugmentation != null) {
43             final SubinterfaceAugmentationBuilder augmentBuilder = new SubinterfaceAugmentationBuilder();
44
45             final SubInterfaces subInterfaces = subIfcAugmentation.getSubInterfaces();
46             if (subInterfaces != null) {
47                 setSubInterfaces(augmentBuilder, subInterfaces);
48             }
49
50             builder.addAugmentation(SubinterfaceAugmentation.class, augmentBuilder.build());
51         }
52     }
53
54     private static void setSubInterfaces(final SubinterfaceAugmentationBuilder augmentBuilder,
55                                          final SubInterfaces operationalData) {
56
57         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfacesBuilder
58                 subInterfacesCfgBuilder =
59                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfacesBuilder();
60         subInterfacesCfgBuilder.setSubInterface(Lists.transform(operationalData.getSubInterface(),
61                 SubInterfaceInitializationUtils::convertSubInterface));
62         augmentBuilder.setSubInterfaces(subInterfacesCfgBuilder.build());
63     }
64
65     private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface convertSubInterface(
66             final SubInterface operationalData) {
67         org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceBuilder subInterfaceCfgBuilder =
68                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceBuilder();
69
70         subInterfaceCfgBuilder.setEnabled(SubInterfaceStatus.Up.equals(operationalData.getAdminStatus()));
71         subInterfaceCfgBuilder.setIdentifier(operationalData.getIdentifier());
72         subInterfaceCfgBuilder.setKey(new SubInterfaceKey(operationalData.getIdentifier()));
73         subInterfaceCfgBuilder.setL2(operationalData.getL2());
74         subInterfaceCfgBuilder.setMatch(operationalData.getMatch());
75         subInterfaceCfgBuilder.setTags(operationalData.getTags());
76         subInterfaceCfgBuilder.setVlanType(operationalData.getVlanType());
77
78         return subInterfaceCfgBuilder.build();
79     }
80
81 }