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