64f1e8a7c6a5c5b086bf25e7e1912ae248f43830
[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.v3po.translate.impl.write.GenericListWriter;
8 import io.fd.honeycomb.v3po.translate.impl.write.GenericWriter;
9 import io.fd.honeycomb.v3po.translate.v3po.interfaces.AclCustomizer;
10 import io.fd.honeycomb.v3po.translate.v3po.interfaces.EthernetCustomizer;
11 import io.fd.honeycomb.v3po.translate.v3po.interfaces.InterfaceCustomizer;
12 import io.fd.honeycomb.v3po.translate.v3po.interfaces.L2Customizer;
13 import io.fd.honeycomb.v3po.translate.v3po.interfaces.RoutingCustomizer;
14 import io.fd.honeycomb.v3po.translate.v3po.interfaces.TapCustomizer;
15 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VhostUserCustomizer;
16 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanCustomizer;
17 import io.fd.honeycomb.v3po.translate.v3po.interfaces.VxlanGpeCustomizer;
18 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4AddressCustomizer;
19 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4Customizer;
20 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv4NeighbourCustomizer;
21 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.Ipv6Customizer;
22 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
23 import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry;
24 import io.fd.honeycomb.v3po.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 close() throws Exception {
105             // unregister is not supported in ModifiableWriterRegistry (not really needed though)
106         }
107
108         @Override
109         public void init(final ModifiableWriterRegistry registry) {
110             // Interfaces
111             //  Interface =
112             registry.addWriter(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcContext)));
113             //   VppInterfaceAugmentation
114             addVppInterfaceAgmentationWriters(IFC_ID, registry);
115             //   Interface1 (ietf-ip augmentation)
116             addInterface1AugmentationWriters(IFC_ID, registry);
117             //   SubinterfaceAugmentation TODO make dedicated module for subIfc writer factory
118             new SubinterfaceAugmentationWriterFactory(jvpp, ifcContext, bdContext, classifyTableContext).init(registry);
119         }
120
121         private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId,
122                                                       final ModifiableWriterRegistry registry) {
123             final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class);
124             // Ipv6(after interface) TODO unfinished customizer =
125             registry.addWriterAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)),
126                 ifcId);
127             // Ipv4(after interface)
128             final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
129             registry.addWriterAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp, ifcContext)),
130                 ifcId);
131             //  Address(after Ipv4) =
132             final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
133             registry.addWriterAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcContext)),
134                 ipv4Id);
135             //  Neighbor(after ipv4Address)
136             registry.addWriterAfter(
137                 new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, ifcContext)),
138                 ipv4AddressId);
139         }
140
141         private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId,
142                                                        final ModifiableWriterRegistry registry) {
143             // VhostUser(Needs to be executed before Interface customizer) =
144             final InstanceIdentifier<VhostUser> vhostId = VPP_IFC_AUG_ID.child(VhostUser.class);
145             registry.addWriterBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcContext)),
146                 ifcId);
147             // Vxlan(Needs to be executed before Interface customizer) =
148             final InstanceIdentifier<Vxlan> vxlanId = VPP_IFC_AUG_ID.child(Vxlan.class);
149             registry.addWriterBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcContext)),
150                 ifcId);
151             // VxlanGpe(Needs to be executed before Interface customizer) =
152             final InstanceIdentifier<VxlanGpe> vxlanGpeId = VPP_IFC_AUG_ID.child(VxlanGpe.class);
153             registry.addWriterBefore(new GenericWriter<>(vxlanGpeId, new VxlanGpeCustomizer(jvpp, ifcContext)),
154                 ifcId);
155             // Tap(Needs to be executed before Interface customizer) =
156             final InstanceIdentifier<Tap> tapId = VPP_IFC_AUG_ID.child(Tap.class);
157             registry.addWriterBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcContext)),
158                 ifcId);
159
160             final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId);
161
162             // Ethernet(No dependency, customizer not finished TODO) =
163             registry.addWriter(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp)));
164             // Routing(Execute only after specific interface customizers) =
165             registry.addWriterAfter(
166                 new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcContext)),
167                 specificIfcTypes);
168             // Routing(Execute only after specific interface customizers) =
169             registry.addWriterAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcContext, bdContext)),
170                 specificIfcTypes);
171
172             // ACL (execute after classify table and session writers)
173             // also handles L2Acl, Ip4Acl and Ip6Acl:
174             final InstanceIdentifier<Acl> aclId = InstanceIdentifier.create(Acl.class);
175             registry
176                 .addSubtreeWriterAfter(
177                     Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)),
178                     new GenericWriter<>(ACL_ID, new AclCustomizer(jvpp, ifcContext, classifyTableContext)),
179                     Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID)
180                 );
181         }
182
183     }
184
185 }