f24dbf7e048241df93a06612f5038bb3f31e78d0
[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 org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
18
19 import static io.fd.honeycomb.v3po.translate.util.RWUtils.singletonChildWriterList;
20
21 import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
22 import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
23 import io.fd.honeycomb.v3po.translate.util.RWUtils;
24 import io.fd.honeycomb.v3po.translate.util.write.ReflexiveAugmentWriterCustomizer;
25 import io.fd.honeycomb.v3po.translate.util.write.ReflexiveChildWriterCustomizer;
26 import io.fd.honeycomb.v3po.translate.v3po.interfaces.RewriteCustomizer;
27 import io.fd.honeycomb.v3po.translate.v3po.interfaces.SubInterfaceCustomizer;
28 import io.fd.honeycomb.v3po.translate.v3po.interfaces.SubInterfaceL2Customizer;
29 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.SubInterfaceIpv4AddressCustomizer;
30 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
31 import io.fd.honeycomb.v3po.translate.write.ChildWriter;
32 import java.util.ArrayList;
33 import java.util.List;
34 import javax.annotation.Nonnull;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address;
43 import org.opendaylight.yangtools.yang.binding.ChildOf;
44 import org.openvpp.jvpp.future.FutureJVpp;
45
46 final class SubinterfaceAugmentationWriterFactory {
47
48     private SubinterfaceAugmentationWriterFactory() {
49     }
50
51     private static ChildWriter<Ipv4> getIp4Writer(
52         @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext) {
53
54         final ChildWriter<Address> addressWriter = new CompositeListWriter<>(
55             Address.class,
56             new SubInterfaceIpv4AddressCustomizer(futureJvpp, interfaceContext));
57
58         return new CompositeChildWriter<>(
59             Ipv4.class,
60             RWUtils.singletonChildWriterList(addressWriter),
61             new ReflexiveChildWriterCustomizer<>());
62     }
63
64     private static ChildWriter<L2> getL2Writer(
65         @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext,
66         @Nonnull final NamingContext bridgeDomainContext) {
67
68         final ChildWriter<? extends ChildOf<L2>> rewriteWriter =
69             new CompositeChildWriter<>(Rewrite.class, new RewriteCustomizer(futureJvpp, interfaceContext));
70
71         return new CompositeChildWriter<>(
72             L2.class,
73             singletonChildWriterList(rewriteWriter),
74             new SubInterfaceL2Customizer(futureJvpp, interfaceContext, bridgeDomainContext)
75         );
76     }
77
78     static ChildWriter<SubinterfaceAugmentation> createInstance(
79         @Nonnull final FutureJVpp futureJvpp, @Nonnull final NamingContext interfaceContext,
80         @Nonnull final NamingContext bridgeDomainContext) {
81         final List<ChildWriter<? extends ChildOf<SubInterface>>> childWriters = new ArrayList<>();
82
83         // TODO L2 is ChildOf<SubInterfaceBaseAttributes>, but SubInterface extends SubInterfaceBaseAttributes
84         // If we use containers inside groupings, we need to cast and lose static type checking.
85         // Can we get rid of the cast?
86         childWriters.add((ChildWriter) getL2Writer(futureJvpp, interfaceContext, bridgeDomainContext));
87         childWriters.add((ChildWriter) getIp4Writer(futureJvpp, interfaceContext));
88
89         final CompositeListWriter<SubInterface, SubInterfaceKey> subInterfaceWriter = new CompositeListWriter<>(
90             SubInterface.class,
91             childWriters,
92             new SubInterfaceCustomizer(futureJvpp, interfaceContext));
93
94         final ChildWriter<SubInterfaces> subInterfacesWriter = new CompositeChildWriter<>(
95             SubInterfaces.class,
96             singletonChildWriterList(subInterfaceWriter),
97             new ReflexiveChildWriterCustomizer<>());
98
99         return new CompositeChildWriter<>(
100             SubinterfaceAugmentation.class,
101             singletonChildWriterList(subInterfacesWriter),
102             RWUtils.emptyAugWriterList(),
103             new ReflexiveAugmentWriterCustomizer<>());
104     }
105 }