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 {
42 public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
43 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
44 super(identifier, dependencyResolver);
47 public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
48 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
49 org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.InterfacesHoneycombWriterModule oldModule,
50 java.lang.AutoCloseable oldInstance) {
51 super(identifier, dependencyResolver, oldModule, oldInstance);
55 public void customValidation() {
56 // add custom validation form module attributes here.
60 public java.lang.AutoCloseable createInstance() {
61 return new InterfacesWriterFactory(getVppJvppIfcDependency(),
62 getBridgeDomainContextDependency(),
63 getInterfaceContextDependency());
67 private static class InterfacesWriterFactory implements WriterFactory, AutoCloseable {
69 private final FutureJVpp jvpp;
70 private final NamingContext bdContext;
71 private final NamingContext ifcContext;
73 InterfacesWriterFactory(final FutureJVpp vppJvppIfcDependency,
74 final NamingContext bridgeDomainContextDependency,
75 final NamingContext interfaceContextDependency) {
76 this.jvpp = vppJvppIfcDependency;
77 this.bdContext = bridgeDomainContextDependency;
78 this.ifcContext = interfaceContextDependency;
82 public void close() throws Exception {
83 // unregister is not supported in ModifiableWriterRegistry (not really needed though)
87 public void init(final ModifiableWriterRegistry registry) {
90 final InstanceIdentifier<Interface> ifcId = InstanceIdentifier.create(Interfaces.class).child(Interface.class);
91 registry.addWriter(new GenericListWriter<>(ifcId, new InterfaceCustomizer(jvpp, ifcContext)));
92 // VppInterfaceAugmentation
93 addVppInterfaceAgmentationWriters(ifcId, registry);
94 // Interface1 (ietf-ip augmentation)
95 addInterface1AugmentationWriters(ifcId, registry);
96 // SubinterfaceAugmentation TODO make dedicated module for subIfc writer factory
97 new SubinterfaceAugmentationWriterFactory(ifcId, jvpp, ifcContext, bdContext).init(registry);
100 private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId,
101 final ModifiableWriterRegistry registry) {
102 final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class);
103 // Ipv6(after interface) TODO unfinished customizer =
104 registry.addWriterAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)),
106 // Ipv4(after interface)
107 final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
108 registry.addWriterAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)),
110 // Address(after Ipv4) =
111 final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
112 registry.addWriterAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)),
114 // Neighbor(after ipv4Address)
115 registry.addWriterAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)),
119 private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId,
120 final ModifiableWriterRegistry registry) {
121 final InstanceIdentifier<VppInterfaceAugmentation> vppIfcAugId = ifcId.augmentation(VppInterfaceAugmentation.class);
122 // VhostUser(Needs to be executed before Interface customizer) =
123 final InstanceIdentifier<VhostUser> vhostId = vppIfcAugId.child(VhostUser.class);
124 registry.addWriterBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)),
126 // Vxlan(Needs to be executed before Interface customizer) =
127 final InstanceIdentifier<Vxlan> vxlanId = vppIfcAugId.child(Vxlan.class);
128 registry.addWriterBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)),
130 // VxlanGpe(Needs to be executed before Interface customizer) =
131 final InstanceIdentifier<VxlanGpe> vxlanGpeId = vppIfcAugId.child(VxlanGpe.class);
132 registry.addWriterBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)),
134 // Tap(Needs to be executed before Interface customizer) =
135 final InstanceIdentifier<Tap> tapId = vppIfcAugId.child(Tap.class);
136 registry.addWriterBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)),
139 final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId);
141 // Ethernet(No dependency, customizer not finished TODO) =
142 registry.addWriter(new GenericWriter<>(vppIfcAugId.child(Ethernet.class), new EthernetCustomizer(jvpp)));
143 // Routing(Execute only after specific interface customizers) =
144 registry.addWriterAfter(
145 new GenericWriter<>(vppIfcAugId.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)),
147 // Routing(Execute only after specific interface customizers) =
148 registry.addWriterAfter(
149 new GenericWriter<>(vppIfcAugId.child(L2.class), new L2Customizer(jvpp, ifcContext, bdContext)),