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 static io.fd.honeycomb.translate.v3po.VppClassifierHoneycombWriterFactory.CLASSIFY_SESSION_ID;
20 import static io.fd.honeycomb.translate.v3po.VppClassifierHoneycombWriterFactory.CLASSIFY_TABLE_ID;
22 import com.google.common.collect.Sets;
23 import com.google.inject.Inject;
24 import com.google.inject.name.Named;
25 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
26 import io.fd.honeycomb.translate.impl.write.GenericWriter;
27 import io.fd.honeycomb.translate.v3po.interfaces.EthernetCustomizer;
28 import io.fd.honeycomb.translate.v3po.interfaces.GreCustomizer;
29 import io.fd.honeycomb.translate.v3po.interfaces.InterfaceCustomizer;
30 import io.fd.honeycomb.translate.v3po.interfaces.L2Customizer;
31 import io.fd.honeycomb.translate.v3po.interfaces.LoopbackCustomizer;
32 import io.fd.honeycomb.translate.v3po.interfaces.ProxyArpCustomizer;
33 import io.fd.honeycomb.translate.v3po.interfaces.RoutingCustomizer;
34 import io.fd.honeycomb.translate.v3po.interfaces.TapCustomizer;
35 import io.fd.honeycomb.translate.v3po.interfaces.VhostUserCustomizer;
36 import io.fd.honeycomb.translate.v3po.interfaces.VxlanCustomizer;
37 import io.fd.honeycomb.translate.v3po.interfaces.VxlanGpeCustomizer;
38 import io.fd.honeycomb.translate.v3po.interfaces.acl.egress.EgressIetfAclWriter;
39 import io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.AclCustomizer;
40 import io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.IetfAclCustomizer;
41 import io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.IngressIetfAclWriter;
42 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4AddressCustomizer;
43 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4Customizer;
44 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4NeighbourCustomizer;
45 import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv6Customizer;
46 import io.fd.honeycomb.translate.v3po.interfaces.pbb.PbbRewriteCustomizer;
47 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
48 import io.fd.honeycomb.translate.vpp.util.NamingContext;
49 import io.fd.honeycomb.translate.write.WriterFactory;
50 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
51 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Acl;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Ethernet;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Gre;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.IetfAcl;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Loopback;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ProxyArp;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Routing;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Tap;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.VhostUser;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Vxlan;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.VxlanGpe;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.acl.Ingress;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip4Acl;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip6Acl;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.L2Acl;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.AccessLists;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite;
80 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
82 public final class InterfacesWriterFactory implements WriterFactory {
84 public static final InstanceIdentifier<Interface> IFC_ID =
85 InstanceIdentifier.create(Interfaces.class).child(Interface.class);
86 public static final InstanceIdentifier<VppInterfaceAugmentation> VPP_IFC_AUG_ID =
87 IFC_ID.augmentation(VppInterfaceAugmentation.class);
88 public static final InstanceIdentifier<Acl> ACL_ID = VPP_IFC_AUG_ID.child(Acl.class);
89 public static final InstanceIdentifier<Ingress> INGRESS_ACL_ID = ACL_ID.child(Ingress.class);
90 public static final InstanceIdentifier<L2> L2_ID = VPP_IFC_AUG_ID.child(L2.class);
91 public static final InstanceIdentifier<IetfAcl> IETF_ACL_ID = VPP_IFC_AUG_ID.child(IetfAcl.class);
92 public static final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ietf.acl.Ingress>
93 INGRESS_IETF_ACL_ID = IETF_ACL_ID.child(
94 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ietf.acl.Ingress.class);
95 public static final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ietf.acl.Egress>
96 EGRESS_IETF_ACL_ID = IETF_ACL_ID.child(
97 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ietf.acl.Egress.class);
99 private final FutureJVppCore jvpp;
100 private final IngressIetfAclWriter ingressAclWriter;
101 private final EgressIetfAclWriter egressAclWriter;
102 private final NamingContext bdNamingContext;
103 private final NamingContext ifcNamingContext;
104 private final VppClassifierContextManager classifyTableContext;
105 private final DisabledInterfacesManager ifcDisableContext;
108 public InterfacesWriterFactory(final FutureJVppCore vppJvppIfcDependency,
109 final IngressIetfAclWriter ingressAclWriter,
110 final EgressIetfAclWriter egressAclWriter,
111 @Named("bridge-domain-context") final NamingContext bridgeDomainContextDependency,
112 @Named("interface-context") final NamingContext interfaceContextDependency,
113 @Named("classify-table-context") final VppClassifierContextManager classifyTableContext,
114 final DisabledInterfacesManager ifcDisableContext) {
115 this.jvpp = vppJvppIfcDependency;
116 this.ingressAclWriter = ingressAclWriter;
117 this.egressAclWriter = egressAclWriter;
118 this.bdNamingContext = bridgeDomainContextDependency;
119 this.ifcNamingContext = interfaceContextDependency;
120 this.ifcDisableContext = ifcDisableContext;
121 this.classifyTableContext = classifyTableContext;
125 public void init(final ModifiableWriterRegistryBuilder registry) {
128 registry.add(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcNamingContext)));
129 // VppInterfaceAugmentation
130 addVppInterfaceAgmentationWriters(IFC_ID, registry);
131 // Interface1 (ietf-ip augmentation)
132 addInterface1AugmentationWriters(IFC_ID, registry);
133 // SubinterfaceAugmentation
134 new SubinterfaceAugmentationWriterFactory(jvpp, ingressAclWriter, egressAclWriter, ifcNamingContext, bdNamingContext,
135 classifyTableContext).init(registry);
137 addPbbAugmentationWriters(IFC_ID, registry);
140 private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId,
141 final ModifiableWriterRegistryBuilder registry) {
142 final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class);
143 // Ipv6(after interface) =
144 registry.addAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)),
146 // Ipv4(after interface)
147 final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class);
148 registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp)),
150 // Address(after Ipv4) =
151 final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class);
152 registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcNamingContext)),
154 // Neighbor(after ipv4Address)
155 registry.addAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp,
160 private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId,
161 final ModifiableWriterRegistryBuilder registry) {
162 // VhostUser(Needs to be executed before Interface customizer) =
163 final InstanceIdentifier<VhostUser> vhostId = VPP_IFC_AUG_ID.child(VhostUser.class);
164 registry.addBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcNamingContext)),
166 // Vxlan(Needs to be executed before Interface customizer) =
167 final InstanceIdentifier<Vxlan> vxlanId = VPP_IFC_AUG_ID.child(Vxlan.class);
168 registry.addBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcNamingContext, ifcDisableContext)),
170 // VxlanGpe(Needs to be executed before Interface customizer) =
171 final InstanceIdentifier<VxlanGpe> vxlanGpeId = VPP_IFC_AUG_ID.child(VxlanGpe.class);
172 registry.addBefore(new GenericWriter<>(vxlanGpeId,
173 new VxlanGpeCustomizer(jvpp, ifcNamingContext, ifcDisableContext)), ifcId);
174 // Tap(Needs to be executed before Interface customizer) =
175 final InstanceIdentifier<Tap> tapId = VPP_IFC_AUG_ID.child(Tap.class);
176 registry.addBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcNamingContext)),
178 // Loopback(Needs to be executed before Interface customizer) =
179 final InstanceIdentifier<Loopback> loopbackId = VPP_IFC_AUG_ID.child(Loopback.class);
180 registry.addBefore(new GenericWriter<>(loopbackId, new LoopbackCustomizer(jvpp, ifcNamingContext)),
183 // Gre(Needs to be executed before Interface customizer) =
184 final InstanceIdentifier<Gre> greId = VPP_IFC_AUG_ID.child(Gre.class);
185 registry.addBefore(new GenericWriter<>(greId, new GreCustomizer(jvpp, ifcNamingContext)),
189 final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId);
192 registry.add(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp)));
193 // Routing(Execute only after specific interface customizers) =
195 new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcNamingContext)),
197 // L2(Execute only after subinterface (and all other ifc types) =
198 registry.addAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcNamingContext, bdNamingContext)),
199 SubinterfaceAugmentationWriterFactory.SUB_IFC_ID);
200 // Proxy Arp (execute after specific interface customizers)
202 new GenericWriter<>(VPP_IFC_AUG_ID.child(ProxyArp.class), new ProxyArpCustomizer(jvpp)),
204 // Ingress (execute after classify table and session writers)
205 // also handles L2Acl, Ip4Acl and Ip6Acl:
206 final InstanceIdentifier<Ingress> ingressId = InstanceIdentifier.create(Ingress.class);
209 Sets.newHashSet(ingressId.child(L2Acl.class), ingressId.child(Ip4Acl.class),
210 ingressId.child(Ip6Acl.class)),
211 new GenericWriter<>(INGRESS_ACL_ID,
212 new AclCustomizer(jvpp, ifcNamingContext, classifyTableContext)),
213 Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID));
215 // Ingress IETF-ACL, also handles AccessLists and Acl:
216 final InstanceIdentifier<AccessLists> accessListsIdIngress = InstanceIdentifier.create(
217 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ietf.acl.Ingress.class)
218 .child(AccessLists.class);
219 final InstanceIdentifier<?> aclIdIngress = accessListsIdIngress.child(
220 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.access.lists.Acl.class);
222 Sets.newHashSet(accessListsIdIngress, aclIdIngress),
223 new GenericWriter<>(INGRESS_IETF_ACL_ID, new IetfAclCustomizer(ingressAclWriter, ifcNamingContext)));
225 // Ingress IETF-ACL, also handles AccessLists and Acl:
226 final InstanceIdentifier<AccessLists> accessListsIdEgress = InstanceIdentifier.create(
227 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ietf.acl.Egress.class)
228 .child(AccessLists.class);
229 final InstanceIdentifier<?> aclIdEgress = accessListsIdEgress.child(
230 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.access.lists.Acl.class);
232 Sets.newHashSet(accessListsIdEgress, aclIdEgress),
233 new GenericWriter<>(EGRESS_IETF_ACL_ID,
234 new io.fd.honeycomb.translate.v3po.interfaces.acl.egress.IetfAclCustomizer(egressAclWriter,
238 private void addPbbAugmentationWriters(final InstanceIdentifier<Interface> ifcId,
239 final ModifiableWriterRegistryBuilder registry) {
240 final InstanceIdentifier<PbbRewrite> pbbRewriteId =
241 ifcId.augmentation(PbbRewriteInterfaceAugmentation.class).child(PbbRewrite.class);
243 registry.add(new GenericWriter<>(pbbRewriteId, new PbbRewriteCustomizer(jvpp, ifcNamingContext)));