1 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
3 import com.google.common.collect.Sets;
4 import io.fd.honeycomb.v3po.translate.impl.write.GenericListWriter;
5 import io.fd.honeycomb.v3po.translate.impl.write.GenericWriter;
6 import io.fd.honeycomb.v3po.translate.v3po.interfaces.EthernetCustomizer;
7 import io.fd.honeycomb.v3po.translate.v3po.interfaces.InterfaceCustomizer;
8 import io.fd.honeycomb.v3po.translate.v3po.interfaces.L2Customizer;
9 import io.fd.honeycomb.v3po.translate.v3po.interfaces.RoutingCustomizer;
10 import io.fd.honeycomb.v3po.translate.v3po.interfaces.TapCustomizer;
11 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VhostUserCustomizer;
12 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanCustomizer;
13 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanGpeCustomizer;
14 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4AddressCustomizer;
15 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4Customizer;
16 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4NeighbourCustomizer;
17 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv6Customizer;
18 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
19 import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry;
20 import io.fd.honeycomb.v3po.translate.write.WriterFactory;
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.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Routing;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Tap;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUser;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Vxlan;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VxlanGpe;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.openvpp.jvpp.future.FutureJVpp;
40 public class InterfacesHoneycombWriterModule extends
41 org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractInterfacesHoneycombWriterModule {
43 // TODO split configuration and translation code into 2 or more bundles
45 public static final InstanceIdentifier<Interface> IFC_ID =
46 InstanceIdentifier.create(Interfaces.class).child(Interface.class);
47 public static final InstanceIdentifier<VppInterfaceAugmentation> VPP_IFC_AUG_ID =
48 IFC_ID.augmentation(VppInterfaceAugmentation.class);
49 public static final InstanceIdentifier<L2> L2_ID = VPP_IFC_AUG_ID.child(L2.class);
51 public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
52 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
53 super(identifier, dependencyResolver);
56 public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
57 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
58 org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.InterfacesHoneycombWriterModule oldModule,
59 java.lang.AutoCloseable oldInstance) {
60 super(identifier, dependencyResolver, oldModule, oldInstance);
64 public void customValidation() {
65 // add custom validation form module attributes here.
69 public java.lang.AutoCloseable createInstance() {
70 return new InterfacesWriterFactory(getVppJvppIfcDependency(),
71 getBridgeDomainContextDependency(),
72 getInterfaceContextDependency());
76 private static class InterfacesWriterFactory implements WriterFactory, AutoCloseable {
78 private final FutureJVpp jvpp;
79 private final NamingContext bdContext;
80 private final NamingContext ifcContext;
82 InterfacesWriterFactory(final FutureJVpp vppJvppIfcDependency,
83 final NamingContext bridgeDomainContextDependency,
84 final NamingContext interfaceContextDependency) {
85 this.jvpp = vppJvppIfcDependency;
86 this.bdContext = bridgeDomainContextDependency;
87 this.ifcContext = interfaceContextDependency;
91 public void close() throws Exception {
92 // unregister is not supported in ModifiableWriterRegistry (not really needed though)
96 public void init(final ModifiableWriterRegistry registry) {
99 registry.addWriter(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcContext)));
100 // VppInterfaceAugmentation
101 addVppInterfaceAgmentationWriters(IFC_ID, registry);
102 // Interface1 (ietf-ip augmentation)
103 addInterface1AugmentationWriters(IFC_ID, registry);
104 // SubinterfaceAugmentation TODO make dedicated module for subIfc writer factory
105 new SubinterfaceAugmentationWriterFactory(jvpp, ifcContext, bdContext).init(registry);
108 private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId,
109 final ModifiableWriterRegistry registry) {
110 final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class);
111 // Ipv6(after interface) TODO unfinished customizer =
112 registry.addWriterAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)),
114 // Ipv4(after interface)
115 final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
116 registry.addWriterAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)),
118 // Address(after Ipv4) =
119 final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
120 registry.addWriterAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)),
122 // Neighbor(after ipv4Address)
123 registry.addWriterAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)),
127 private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId,
128 final ModifiableWriterRegistry registry) {
129 // VhostUser(Needs to be executed before Interface customizer) =
130 final InstanceIdentifier<VhostUser> vhostId = VPP_IFC_AUG_ID.child(VhostUser.class);
131 registry.addWriterBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)),
133 // Vxlan(Needs to be executed before Interface customizer) =
134 final InstanceIdentifier<Vxlan> vxlanId = VPP_IFC_AUG_ID.child(Vxlan.class);
135 registry.addWriterBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)),
137 // VxlanGpe(Needs to be executed before Interface customizer) =
138 final InstanceIdentifier<VxlanGpe> vxlanGpeId = VPP_IFC_AUG_ID.child(VxlanGpe.class);
139 registry.addWriterBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)),
141 // Tap(Needs to be executed before Interface customizer) =
142 final InstanceIdentifier<Tap> tapId = VPP_IFC_AUG_ID.child(Tap.class);
143 registry.addWriterBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)),
146 final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId);
148 // Ethernet(No dependency, customizer not finished TODO) =
149 registry.addWriter(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp)));
150 // Routing(Execute only after specific interface customizers) =
151 registry.addWriterAfter(
152 new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)),
154 // Routing(Execute only after specific interface customizers) =
155 registry.addWriterAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcContext, bdContext)),