2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.translate.v3po;
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.vpp.util.NamingContext;
41 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Gre;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.ProxyArp;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Tap;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VhostUser;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Vxlan;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpe;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
66 import org.openvpp.jvpp.core.future.FutureJVppCore;
68 public final class InterfacesStateReaderFactory implements ReaderFactory {
70 private final NamingContext ifcNamingCtx;
71 private final NamingContext bdNamingCtx;
72 private final VppClassifierContextManager classifyContext;
73 private final DisabledInterfacesManager ifcDisableContext;
74 private final FutureJVppCore jvpp;
76 static final InstanceIdentifier<InterfacesState> IFC_STATE_ID =
77 InstanceIdentifier.create(InterfacesState.class);
78 static final InstanceIdentifier<Interface> IFC_ID = IFC_STATE_ID.child(Interface.class);
81 public InterfacesStateReaderFactory(final FutureJVppCore jvpp,
82 @Named("interface-context") final NamingContext ifcNamingCtx,
83 @Named("bridge-domain-context") final NamingContext bdNamingCtx,
84 @Named("classify-table-context") final VppClassifierContextManager classifyContext,
85 final DisabledInterfacesManager ifcDisableContext) {
87 this.ifcNamingCtx = ifcNamingCtx;
88 this.bdNamingCtx = bdNamingCtx;
89 this.classifyContext = classifyContext;
90 this.ifcDisableContext = ifcDisableContext;
94 public void init(final ModifiableReaderRegistryBuilder registry) {
95 // InterfacesState(Structural)
96 registry.addStructuralReader(IFC_STATE_ID, InterfacesStateBuilder.class);
98 registry.add(new GenericListReader<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcNamingCtx, ifcDisableContext)));
101 initVppIfcAugmentationReaders(registry, IFC_ID);
103 initInterface2AugmentationReaders(registry, IFC_ID);
105 new SubinterfaceStateAugmentationReaderFactory(jvpp, ifcNamingCtx, bdNamingCtx, classifyContext).init(registry);
108 private void initInterface2AugmentationReaders(final ModifiableReaderRegistryBuilder registry,
109 final InstanceIdentifier<Interface> ifcId) {
110 // Interface2Augmentation(Structural)
111 final InstanceIdentifier<Interface2> ifc2AugId = ifcId.augmentation(Interface2.class);
112 registry.addStructuralReader(ifc2AugId, Interface2Builder.class);
114 final InstanceIdentifier<Ipv4> ipv4Id = ifc2AugId.child(Ipv4.class);
115 registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp)));
117 final InstanceIdentifier<Address> ipv4AddrId = ipv4Id.child(Address.class);
118 registry.add(new GenericListReader<>(ipv4AddrId, new Ipv4AddressCustomizer(jvpp, ifcNamingCtx)));
120 final InstanceIdentifier<Neighbor> neighborId = ipv4Id.child(Neighbor.class);
121 registry.add(new GenericListReader<>(neighborId, new Ipv4NeighbourCustomizer(jvpp)));
123 final InstanceIdentifier<Ipv6> ipv6Id = ifc2AugId.child(Ipv6.class);
124 registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp, ifcNamingCtx)));
127 private void initVppIfcAugmentationReaders(final ModifiableReaderRegistryBuilder registry,
128 final InstanceIdentifier<Interface> ifcId) {
129 // VppInterfaceStateAugmentation
130 final InstanceIdentifier<VppInterfaceStateAugmentation> vppIfcAugId = ifcId.augmentation(VppInterfaceStateAugmentation.class);
131 registry.addStructuralReader(vppIfcAugId, VppInterfaceStateAugmentationBuilder.class);
133 registry.add(new GenericReader<>(vppIfcAugId.child(Ethernet.class), new EthernetCustomizer(jvpp, ifcNamingCtx)));
135 registry.add(new GenericReader<>(vppIfcAugId.child(Tap.class), new TapCustomizer(jvpp, ifcNamingCtx)));
137 registry.add(new GenericReader<>(vppIfcAugId.child(VhostUser.class), new VhostUserCustomizer(jvpp, ifcNamingCtx)));
139 registry.add(new GenericReader<>(vppIfcAugId.child(Vxlan.class), new VxlanCustomizer(jvpp, ifcNamingCtx)));
141 registry.add(new GenericReader<>(vppIfcAugId.child(VxlanGpe.class), new VxlanGpeCustomizer(jvpp, ifcNamingCtx)));
143 registry.add(new GenericReader<>(vppIfcAugId.child(Gre.class), new GreCustomizer(jvpp, ifcNamingCtx)));
145 registry.add(new GenericReader<>(vppIfcAugId.child(L2.class), new L2Customizer(jvpp, ifcNamingCtx, bdNamingCtx)));
147 final InstanceIdentifier<Acl> aclIdRelative = InstanceIdentifier.create(Acl.class);
149 Sets.newHashSet(aclIdRelative.child(L2Acl.class), aclIdRelative.child(Ip4Acl.class), aclIdRelative.child(Ip6Acl.class)),
150 new GenericReader<>(vppIfcAugId.child(Acl.class), new AclCustomizer(jvpp, ifcNamingCtx,
153 registry.add(new GenericReader<>(vppIfcAugId.child(ProxyArp.class), new ProxyArpCustomizer(jvpp,