e906167fd718baf52bbb4f9ad41ab6dea8b7caa2
[hc2vpp.git] /
1 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
2
3 import com.google.common.collect.Lists;
4 import io.fd.honeycomb.v3po.translate.impl.TraversalType;
5 import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
6 import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
7 import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
8 import io.fd.honeycomb.v3po.translate.util.RWUtils;
9 import io.fd.honeycomb.v3po.translate.util.write.CloseableWriter;
10 import io.fd.honeycomb.v3po.translate.util.write.NoopWriterCustomizer;
11 import io.fd.honeycomb.v3po.translate.util.write.ReflexiveAugmentWriterCustomizer;
12 import io.fd.honeycomb.v3po.translate.v3po.interfaces.EthernetCustomizer;
13 import io.fd.honeycomb.v3po.translate.v3po.interfaces.InterfaceCustomizer;
14 import io.fd.honeycomb.v3po.translate.v3po.interfaces.L2Customizer;
15 import io.fd.honeycomb.v3po.translate.v3po.interfaces.RoutingCustomizer;
16 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanCustomizer;
17 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4Customizer;
18 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv6Customizer;
19 import io.fd.honeycomb.v3po.translate.write.ChildWriter;
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Routing;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Vxlan;
32 import org.opendaylight.yangtools.yang.binding.Augmentation;
33 import org.opendaylight.yangtools.yang.binding.ChildOf;
34
35 public class InterfacesHoneycombWriterModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractInterfacesHoneycombWriterModule {
36     public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
37         super(identifier, dependencyResolver);
38     }
39
40     public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.InterfacesHoneycombWriterModule oldModule, java.lang.AutoCloseable oldInstance) {
41         super(identifier, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     public void customValidation() {
46         // add custom validation form module attributes here.
47     }
48
49     @Override
50     public java.lang.AutoCloseable createInstance() {
51
52         final List<ChildWriter<? extends Augmentation<Interface>>> ifcAugmentations = Lists.newArrayList();
53         ifcAugmentations.add(getVppIfcAugmentationWriter());
54         ifcAugmentations.add(getInterface1AugmentationWriter());
55
56         final ChildWriter<Interface> interfaceWriter = new CompositeListWriter<>(Interface.class,
57             RWUtils.<Interface>emptyChildWriterList(),
58             ifcAugmentations,
59             new InterfaceCustomizer(getVppJapiIfcDependency()),
60             // It's important that this customizer is handled in a postorder way, because you first have to handle child nodes
61             // e.g. Vxlan before setting other interface or vppInterfaceAugmentation leaves
62             TraversalType.POSTORDER);
63
64         final List<ChildWriter<? extends ChildOf<Interfaces>>> childWriters = new ArrayList<>();
65         childWriters.add(interfaceWriter);
66
67         // FIXME if we just return the root writer and cfg subsystem takes care to set it into reader registry,
68         // we loose the ordering information for root writers
69         // Or can we rely to the order in which readers are configured ?
70         return new CloseableWriter<>(new CompositeRootWriter<>(Interfaces.class,
71             childWriters, new NoopWriterCustomizer<Interfaces>()));
72     }
73
74     private ChildWriter<? extends Augmentation<Interface>> getInterface1AugmentationWriter() {
75         final ChildWriter<Ipv4> ipv4Writer = new CompositeChildWriter<>(Ipv4.class,
76             new Ipv4Customizer(getVppJapiIfcDependency()));
77         final ChildWriter<Ipv6> ipv6Writer = new CompositeChildWriter<>(Ipv6.class,
78             new Ipv6Customizer(getVppJapiIfcDependency()));
79
80         final List<ChildWriter<? extends ChildOf<Interface1>>> interface1ChildWriters = Lists.newArrayList();
81         interface1ChildWriters.add(ipv4Writer);
82         interface1ChildWriters.add(ipv6Writer);
83
84         return new CompositeChildWriter<>(Interface1.class,
85             interface1ChildWriters, new ReflexiveAugmentWriterCustomizer<Interface1>());
86     }
87
88     private ChildWriter<VppInterfaceAugmentation> getVppIfcAugmentationWriter() {
89
90         final ChildWriter<Ethernet> ethernetWriter = new CompositeChildWriter<>(Ethernet.class,
91             new EthernetCustomizer(getVppJapiIfcDependency()));
92
93         final ChildWriter<Routing> routingWriter = new CompositeChildWriter<>(Routing.class,
94             new RoutingCustomizer(getVppJapiIfcDependency()));
95
96         final ChildWriter<Vxlan> vxlanWriter = new CompositeChildWriter<>(Vxlan.class,
97             new VxlanCustomizer(getVppJapiIfcDependency()));
98
99         final ChildWriter<L2> l2Writer = new CompositeChildWriter<>(L2.class,
100             new L2Customizer(getVppJapiIfcDependency()));
101
102         final List<ChildWriter<? extends ChildOf<VppInterfaceAugmentation>>> vppIfcChildWriters = Lists.newArrayList();
103         // TODO what's the order here ?
104         vppIfcChildWriters.add(vxlanWriter);
105         vppIfcChildWriters.add(ethernetWriter);
106         vppIfcChildWriters.add(l2Writer);
107         vppIfcChildWriters.add(routingWriter);
108
109         return new CompositeChildWriter<>(VppInterfaceAugmentation.class,
110             vppIfcChildWriters,
111             RWUtils.<VppInterfaceAugmentation>emptyAugWriterList(),
112             new ReflexiveAugmentWriterCustomizer<VppInterfaceAugmentation>());
113     }
114 }