ef020e971a994d6bad395a430ef7cbbd1ba07f5b
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / InterfacesStateReaderFactory.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.v3po;
18
19 import com.google.common.collect.Sets;
20 import com.google.inject.Inject;
21 import com.google.inject.name.Named;
22 import io.fd.honeycomb.translate.impl.read.GenericListReader;
23 import io.fd.honeycomb.translate.impl.read.GenericReader;
24 import io.fd.honeycomb.translate.read.ReaderFactory;
25 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
26 import io.fd.honeycomb.translate.v3po.interfacesstate.AclCustomizer;
27 import io.fd.honeycomb.translate.v3po.interfacesstate.EthernetCustomizer;
28 import io.fd.honeycomb.translate.v3po.interfacesstate.GreCustomizer;
29 import io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceCustomizer;
30 import io.fd.honeycomb.translate.v3po.interfacesstate.L2Customizer;
31 import io.fd.honeycomb.translate.v3po.interfacesstate.ProxyArpCustomizer;
32 import io.fd.honeycomb.translate.v3po.interfacesstate.TapCustomizer;
33 import io.fd.honeycomb.translate.v3po.interfacesstate.VhostUserCustomizer;
34 import io.fd.honeycomb.translate.v3po.interfacesstate.VxlanCustomizer;
35 import io.fd.honeycomb.translate.v3po.interfacesstate.VxlanGpeCustomizer;
36 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4AddressCustomizer;
37 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4Customizer;
38 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4NeighbourCustomizer;
39 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv6Customizer;
40 import io.fd.honeycomb.translate.v3po.util.NamingContext;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Gre;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.ProxyArp;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Tap;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VhostUser;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Vxlan;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpe;
64 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
65 import org.openvpp.jvpp.core.future.FutureJVppCore;
66
67 public final class InterfacesStateReaderFactory implements ReaderFactory {
68
69     private final NamingContext ifcNamingCtx;
70     private final NamingContext bdNamingCtx;
71     private final NamingContext classifyNamingCtx;
72     private final DisabledInterfacesManager ifcDisableContext;
73     private final FutureJVppCore jvpp;
74
75     static final InstanceIdentifier<InterfacesState> IFC_STATE_ID =
76             InstanceIdentifier.create(InterfacesState.class);
77     static final InstanceIdentifier<Interface> IFC_ID = IFC_STATE_ID.child(Interface.class);
78
79     @Inject
80     public InterfacesStateReaderFactory(final FutureJVppCore jvpp,
81                                         @Named("interface-context") final NamingContext ifcNamingCtx,
82                                         @Named("bridge-domain-context") final NamingContext bdNamingCtx,
83                                         @Named("classify-table-context") final NamingContext classifyNamingCtx,
84                                         final DisabledInterfacesManager ifcDisableContext) {
85         this.jvpp = jvpp;
86         this.ifcNamingCtx = ifcNamingCtx;
87         this.bdNamingCtx = bdNamingCtx;
88         this.classifyNamingCtx = classifyNamingCtx;
89         this.ifcDisableContext = ifcDisableContext;
90     }
91
92     @Override
93     public void init(final ModifiableReaderRegistryBuilder registry) {
94         // InterfacesState(Structural)
95         registry.addStructuralReader(IFC_STATE_ID, InterfacesStateBuilder.class);
96         //  Interface
97         registry.add(new GenericListReader<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcNamingCtx, ifcDisableContext)));
98
99         // v3po.yang
100         initVppIfcAugmentationReaders(registry, IFC_ID);
101         // ietf-ip.yang
102         initInterface2AugmentationReaders(registry, IFC_ID);
103         // vpp-vlan.yang
104         new SubinterfaceStateAugmentationReaderFactory(jvpp, ifcNamingCtx, bdNamingCtx, classifyNamingCtx).init(registry);
105     }
106
107     private void initInterface2AugmentationReaders(final ModifiableReaderRegistryBuilder registry,
108                                                    final InstanceIdentifier<Interface> ifcId) {
109         //   Interface2Augmentation(Structural)
110         final InstanceIdentifier<Interface2> ifc2AugId = ifcId.augmentation(Interface2.class);
111         registry.addStructuralReader(ifc2AugId, Interface2Builder.class);
112         //    Ipv4
113         final InstanceIdentifier<Ipv4> ipv4Id = ifc2AugId.child(Ipv4.class);
114         registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp)));
115         //     Address
116         final InstanceIdentifier<Address> ipv4AddrId = ipv4Id.child(Address.class);
117         registry.add(new GenericListReader<>(ipv4AddrId, new Ipv4AddressCustomizer(jvpp, ifcNamingCtx)));
118         //     Neighbor
119         final InstanceIdentifier<Neighbor> neighborId = ipv4Id.child(Neighbor.class);
120         registry.add(new GenericListReader<>(neighborId, new Ipv4NeighbourCustomizer(jvpp)));
121         //    Ipv6
122         final InstanceIdentifier<Ipv6> ipv6Id = ifc2AugId.child(Ipv6.class);
123         registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp, ifcNamingCtx)));
124     }
125
126     private void initVppIfcAugmentationReaders(final ModifiableReaderRegistryBuilder registry,
127                                                final InstanceIdentifier<Interface> ifcId) {
128         //   VppInterfaceStateAugmentation
129         final InstanceIdentifier<VppInterfaceStateAugmentation> vppIfcAugId = ifcId.augmentation(VppInterfaceStateAugmentation.class);
130         registry.addStructuralReader(vppIfcAugId, VppInterfaceStateAugmentationBuilder.class);
131         //    Ethernet
132         registry.add(new GenericReader<>(vppIfcAugId.child(Ethernet.class), new EthernetCustomizer(jvpp, ifcNamingCtx)));
133         //    Tap
134         registry.add(new GenericReader<>(vppIfcAugId.child(Tap.class), new TapCustomizer(jvpp, ifcNamingCtx)));
135         //    VhostUser
136         registry.add(new GenericReader<>(vppIfcAugId.child(VhostUser.class), new VhostUserCustomizer(jvpp, ifcNamingCtx)));
137         //    Vxlan
138         registry.add(new GenericReader<>(vppIfcAugId.child(Vxlan.class), new VxlanCustomizer(jvpp, ifcNamingCtx)));
139         //    VxlanGpe
140         registry.add(new GenericReader<>(vppIfcAugId.child(VxlanGpe.class), new VxlanGpeCustomizer(jvpp, ifcNamingCtx)));
141         //    Gre
142         registry.add(new GenericReader<>(vppIfcAugId.child(Gre.class), new GreCustomizer(jvpp, ifcNamingCtx)));
143         //    L2
144         registry.add(new GenericReader<>(vppIfcAugId.child(L2.class), new L2Customizer(jvpp, ifcNamingCtx, bdNamingCtx)));
145         //    Acl(Subtree)
146         final InstanceIdentifier<Acl> aclIdRelative = InstanceIdentifier.create(Acl.class);
147         registry.subtreeAdd(
148                 Sets.newHashSet(aclIdRelative.child(L2Acl.class), aclIdRelative.child(Ip4Acl.class), aclIdRelative.child(Ip6Acl.class)),
149                 new GenericReader<>(vppIfcAugId.child(Acl.class), new AclCustomizer(jvpp, ifcNamingCtx,
150                         classifyNamingCtx)));
151         //   Proxy ARP
152         registry.add(new GenericReader<>(vppIfcAugId.child(ProxyArp.class), new ProxyArpCustomizer(jvpp,
153                 ifcNamingCtx)));
154     }
155 }