c3e56ef80f1620c18430c132d5824a3ede58b08c
[honeycomb.git] / v3po / v3po2vpp / src / main / java / org / opendaylight / yang / gen / v1 / urn / honeycomb / params / xml / ns / yang / v3po2vpp / rev160406 / InterfacesHoneycombWriterModule.java
1 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
2
3 import static org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.VppClassifierHoneycombWriterModule.CLASSIFY_SESSION_ID;
4 import static org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.VppClassifierHoneycombWriterModule.CLASSIFY_TABLE_ID;
5
6 import com.google.common.collect.Sets;
7 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
8 import io.fd.honeycomb.translate.impl.write.GenericWriter;
9 import io.fd.honeycomb.translate.v3po.interfaces.AclCustomizer;
10 import io.fd.honeycomb.translate.v3po.interfaces.EthernetCustomizer;
11 import io.fd.honeycomb.translate.v3po.interfaces.InterfaceCustomizer;
12 import io.fd.honeycomb.translate.v3po.interfaces.L2Customizer;
13 import io.fd.honeycomb.translate.v3po.interfaces.RoutingCustomizer;
14 import io.fd.honeycomb.translate.v3po.interfaces.TapCustomizer;
15 import io.fd.honeycomb.translate.v3po.interfaces.VhostUserCustomizer;
16 import io.fd.honeycomb.translate.v3po.interfaces.VxlanCustomizer;
17 import io.fd.honeycomb.translate.v3po.interfaces.VxlanGpeCustomizer;
18 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4AddressCustomizer;
19 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4Customizer;
20 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4NeighbourCustomizer;
21 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv6Customizer;
22 import io.fd.honeycomb.translate.v3po.util.NamingContext;
23 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
24 import io.fd.honeycomb.translate.write.WriterFactory;
25 import java.util.Set;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Acl;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Routing;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Tap;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUser;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Vxlan;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VxlanGpe;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.openvpp.jvpp.future.FutureJVpp;
47
48 public class InterfacesHoneycombWriterModule extends
49     org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.AbstractInterfacesHoneycombWriterModule {
50
51     // TODO split configuration and translation code into 2 or more bundles
52
53     public static final InstanceIdentifier<Interface> IFC_ID =
54         InstanceIdentifier.create(Interfaces.class).child(Interface.class);
55     public static final InstanceIdentifier<VppInterfaceAugmentation> VPP_IFC_AUG_ID =
56         IFC_ID.augmentation(VppInterfaceAugmentation.class);
57     public static final InstanceIdentifier<L2> L2_ID = VPP_IFC_AUG_ID.child(L2.class);
58     public static final InstanceIdentifier<Acl> ACL_ID = VPP_IFC_AUG_ID.child(Acl.class);
59
60     public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
61                                            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
62         super(identifier, dependencyResolver);
63     }
64
65     public InterfacesHoneycombWriterModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
66                                            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
67                                            org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406.InterfacesHoneycombWriterModule oldModule,
68                                            java.lang.AutoCloseable oldInstance) {
69         super(identifier, dependencyResolver, oldModule, oldInstance);
70     }
71
72     @Override
73     public void customValidation() {
74         // add custom validation form module attributes here.
75     }
76
77     @Override
78     public java.lang.AutoCloseable createInstance() {
79         return new InterfacesWriterFactory(getVppJvppIfcDependency(),
80             getBridgeDomainContextDependency(),
81             getInterfaceContextDependency(),
82             getClassifyTableContextDependency());
83     }
84
85
86     private static class InterfacesWriterFactory implements WriterFactory, AutoCloseable {
87
88         private final FutureJVpp jvpp;
89         private final NamingContext bdContext;
90         private final NamingContext ifcContext;
91         private final NamingContext classifyTableContext;
92
93         InterfacesWriterFactory(final FutureJVpp vppJvppIfcDependency,
94                                 final NamingContext bridgeDomainContextDependency,
95                                 final NamingContext interfaceContextDependency,
96                                 final NamingContext classifyTableContextDependency) {
97             this.jvpp = vppJvppIfcDependency;
98             this.bdContext = bridgeDomainContextDependency;
99             this.ifcContext = interfaceContextDependency;
100             this.classifyTableContext = classifyTableContextDependency;
101         }
102
103         @Override
104         public void init(final ModifiableWriterRegistryBuilder registry) {
105             // Interfaces
106             //  Interface =
107             registry.add(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcContext)));
108             //   VppInterfaceAugmentation
109             addVppInterfaceAgmentationWriters(IFC_ID, registry);
110             //   Interface1 (ietf-ip augmentation)
111             addInterface1AugmentationWriters(IFC_ID, registry);
112             //   SubinterfaceAugmentation TODO make dedicated module for subIfc writer factory
113             new SubinterfaceAugmentationWriterFactory(jvpp, ifcContext, bdContext, classifyTableContext).init(registry);
114         }
115
116         private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId,
117                                                       final ModifiableWriterRegistryBuilder registry) {
118             final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class);
119             // Ipv6(after interface) TODO unfinished customizer =
120             registry.addAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)),
121                     ifcId);
122             // Ipv4(after interface)
123             final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
124             registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)),
125                     ifcId);
126             //  Address(after Ipv4) =
127             final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
128             registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)),
129                     ipv4Id);
130             //  Neighbor(after ipv4Address)
131             registry.addAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)),
132                     ipv4AddressId);
133         }
134
135         private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId,
136                                                        final ModifiableWriterRegistryBuilder registry) {
137             // VhostUser(Needs to be executed before Interface customizer) =
138             final InstanceIdentifier<VhostUser> vhostId = VPP_IFC_AUG_ID.child(VhostUser.class);
139             registry.addBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)),
140                     ifcId);
141             // Vxlan(Needs to be executed before Interface customizer) =
142             final InstanceIdentifier<Vxlan> vxlanId = VPP_IFC_AUG_ID.child(Vxlan.class);
143             registry.addBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)),
144                     ifcId);
145             // VxlanGpe(Needs to be executed before Interface customizer) =
146             final InstanceIdentifier<VxlanGpe> vxlanGpeId = VPP_IFC_AUG_ID.child(VxlanGpe.class);
147             registry.addBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)),
148                     ifcId);
149             // Tap(Needs to be executed before Interface customizer) =
150             final InstanceIdentifier<Tap> tapId = VPP_IFC_AUG_ID.child(Tap.class);
151             registry.addBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)),
152                     ifcId);
153
154             final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId);
155
156             // Ethernet(No dependency, customizer not finished TODO) =
157             registry.add(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp)));
158             // Routing(Execute only after specific interface customizers) =
159             registry.addAfter(
160                     new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)),
161                     specificIfcTypes);
162             // Routing(Execute only after specific interface customizers) =
163             registry.addAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcContext, bdContext)),
164                     specificIfcTypes);
165
166             // ACL (execute after classify table and session writers)
167             // also handles L2Acl, Ip4Acl and Ip6Acl:
168             final InstanceIdentifier<Acl> aclId = InstanceIdentifier.create(Acl.class);
169             registry
170                 .subtreeAddAfter(
171                     Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)),
172                     new GenericWriter<>(ACL_ID, new AclCustomizer(jvpp, ifcContext, classifyTableContext)),
173                     Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID));
174         }
175
176     }
177
178 }