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