diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2016-12-06 07:56:27 +0100 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2016-12-07 09:46:42 +0000 |
commit | 304258199c928cd73baced4b6c62614b469c272e (patch) | |
tree | 58d5a72e42e04960e344ec1a97e6d768dc59667a /v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java | |
parent | fb7dd3797b431d2a14c574c712fdf43bb9acb7a3 (diff) |
HONEYCOMB-304: provide separate guice module for ietf-acl implementation
Current IETF-ACL implementation is using vpp-classfier.
In the future, acl implementation based on acl plugin is going to be
supported. Current implementation is going to be deprecated, then removed.
In order to switch between acl implementations, ietf-acl configuration
needs separate guice module.
After fixing nested augmentation support (HONEYCOMB-302), current
implementation can be moved to separate hc2vpp module (HONEYCOMB-308).
Change-Id: I1668c274c03f9a750654cb0f96ec328af09f89f5
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java new file mode 100644 index 000000000..fbf741fba --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.factory; + +import static io.fd.hc2vpp.v3po.factory.VppClassifierHoneycombWriterFactory.CLASSIFY_SESSION_ID; +import static io.fd.hc2vpp.v3po.factory.VppClassifierHoneycombWriterFactory.CLASSIFY_TABLE_ID; + +import com.google.common.collect.Sets; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.hc2vpp.v3po.interfaces.EthernetCustomizer; +import io.fd.hc2vpp.v3po.interfaces.GreCustomizer; +import io.fd.hc2vpp.v3po.interfaces.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.interfaces.L2Customizer; +import io.fd.hc2vpp.v3po.interfaces.LoopbackCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ProxyArpCustomizer; +import io.fd.hc2vpp.v3po.interfaces.RoutingCustomizer; +import io.fd.hc2vpp.v3po.interfaces.TapCustomizer; +import io.fd.hc2vpp.v3po.interfaces.VhostUserCustomizer; +import io.fd.hc2vpp.v3po.interfaces.VxlanCustomizer; +import io.fd.hc2vpp.v3po.interfaces.VxlanGpeCustomizer; +import io.fd.hc2vpp.v3po.interfaces.acl.egress.EgressIetfAclWriter; +import io.fd.hc2vpp.v3po.interfaces.acl.ingress.AclCustomizer; +import io.fd.hc2vpp.v3po.interfaces.acl.ingress.IngressIetfAclWriter; +import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4AddressCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4Customizer; +import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4NeighbourCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ip.Ipv6Customizer; +import io.fd.hc2vpp.v3po.interfaces.pbb.PbbRewriteCustomizer; +import io.fd.hc2vpp.v3po.interfaces.span.MirroredInterfacesCustomizer; +import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.impl.write.GenericWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Set; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Loopback; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ProxyArp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Span; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Tap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.acl.base.attributes.Ip4Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.acl.base.attributes.Ip6Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.acl.base.attributes.L2Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class InterfacesWriterFactory implements WriterFactory { + + public static final InstanceIdentifier<Interface> IFC_ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class); + public static final InstanceIdentifier<VppInterfaceAugmentation> VPP_IFC_AUG_ID = + IFC_ID.augmentation(VppInterfaceAugmentation.class); + public static final InstanceIdentifier<Acl> ACL_ID = VPP_IFC_AUG_ID.child(Acl.class); + public static final InstanceIdentifier<Ingress> INGRESS_ACL_ID = ACL_ID.child(Ingress.class); + public static final InstanceIdentifier<L2> L2_ID = VPP_IFC_AUG_ID.child(L2.class); + + private final FutureJVppCore jvpp; + private final IngressIetfAclWriter ingressAclWriter; + private final EgressIetfAclWriter egressAclWriter; + private final NamingContext bdNamingContext; + private final NamingContext ifcNamingContext; + private final VppClassifierContextManager classifyTableContext; + private final DisabledInterfacesManager ifcDisableContext; + + @Inject + public InterfacesWriterFactory(final FutureJVppCore vppJvppIfcDependency, + final IngressIetfAclWriter ingressAclWriter, + final EgressIetfAclWriter egressAclWriter, + @Named("bridge-domain-context") final NamingContext bridgeDomainContextDependency, + @Named("interface-context") final NamingContext interfaceContextDependency, + @Named("classify-table-context") final VppClassifierContextManager classifyTableContext, + final DisabledInterfacesManager ifcDisableContext) { + this.jvpp = vppJvppIfcDependency; + this.ingressAclWriter = ingressAclWriter; + this.egressAclWriter = egressAclWriter; + this.bdNamingContext = bridgeDomainContextDependency; + this.ifcNamingContext = interfaceContextDependency; + this.ifcDisableContext = ifcDisableContext; + this.classifyTableContext = classifyTableContext; + } + + @Override + public void init(final ModifiableWriterRegistryBuilder registry) { + // Interfaces + // Interface = + registry.add(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcNamingContext))); + // VppInterfaceAugmentation + addVppInterfaceAgmentationWriters(IFC_ID, registry); + // Interface1 (ietf-ip augmentation) + addInterface1AugmentationWriters(IFC_ID, registry); + // SubinterfaceAugmentation + new SubinterfaceAugmentationWriterFactory(jvpp, ifcNamingContext, bdNamingContext, + classifyTableContext).init(registry); + + addPbbAugmentationWriters(IFC_ID, registry); + } + + private void addInterface1AugmentationWriters(final InstanceIdentifier<Interface> ifcId, + final ModifiableWriterRegistryBuilder registry) { + final InstanceIdentifier<Interface1> ifc1AugId = ifcId.augmentation(Interface1.class); + // Ipv6(after interface) = + registry.addAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)), + ifcId); + // Ipv4(after interface) + final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class); + registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp)), + ifcId); + // Address(after Ipv4) = + final InstanceIdentifier<Address> ipv4AddressId = ipv4Id.child(Address.class); + registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcNamingContext)), + ipv4Id); + // Neighbor(after ipv4Address) + registry.addAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, + ifcNamingContext)), + ipv4AddressId); + } + + private void addVppInterfaceAgmentationWriters(final InstanceIdentifier<Interface> ifcId, + final ModifiableWriterRegistryBuilder registry) { + // VhostUser(Needs to be executed before Interface customizer) = + final InstanceIdentifier<VhostUser> vhostId = VPP_IFC_AUG_ID.child(VhostUser.class); + registry.addBefore(new GenericWriter<>(vhostId, new VhostUserCustomizer(jvpp, ifcNamingContext)), + ifcId); + // Vxlan(Needs to be executed before Interface customizer) = + final InstanceIdentifier<Vxlan> vxlanId = VPP_IFC_AUG_ID.child(Vxlan.class); + registry.addBefore(new GenericWriter<>(vxlanId, new VxlanCustomizer(jvpp, ifcNamingContext, ifcDisableContext)), + ifcId); + // VxlanGpe(Needs to be executed before Interface customizer) = + final InstanceIdentifier<VxlanGpe> vxlanGpeId = VPP_IFC_AUG_ID.child(VxlanGpe.class); + registry.addBefore(new GenericWriter<>(vxlanGpeId, + new VxlanGpeCustomizer(jvpp, ifcNamingContext, ifcDisableContext)), ifcId); + // Tap(Needs to be executed before Interface customizer) = + final InstanceIdentifier<Tap> tapId = VPP_IFC_AUG_ID.child(Tap.class); + registry.addBefore(new GenericWriter<>(tapId, new TapCustomizer(jvpp, ifcNamingContext)), + ifcId); + // Loopback(Needs to be executed before Interface customizer) = + final InstanceIdentifier<Loopback> loopbackId = VPP_IFC_AUG_ID.child(Loopback.class); + registry.addBefore(new GenericWriter<>(loopbackId, new LoopbackCustomizer(jvpp, ifcNamingContext)), + ifcId); + + // Gre(Needs to be executed before Interface customizer) = + final InstanceIdentifier<Gre> greId = VPP_IFC_AUG_ID.child(Gre.class); + registry.addBefore(new GenericWriter<>(greId, new GreCustomizer(jvpp, ifcNamingContext)), + ifcId); + + + final Set<InstanceIdentifier<?>> specificIfcTypes = Sets.newHashSet(vhostId, vxlanGpeId, vxlanGpeId, tapId); + + // Ethernet = + registry.add(new GenericWriter<>(VPP_IFC_AUG_ID.child(Ethernet.class), new EthernetCustomizer(jvpp))); + // Routing(Execute only after specific interface customizers) = + registry.addAfter( + new GenericWriter<>(VPP_IFC_AUG_ID.child(Routing.class), new RoutingCustomizer(jvpp, ifcNamingContext)), + specificIfcTypes); + // L2(Execute only after subinterface (and all other ifc types) = + registry.addAfter(new GenericWriter<>(L2_ID, new L2Customizer(jvpp, ifcNamingContext, bdNamingContext)), + SubinterfaceAugmentationWriterFactory.SUB_IFC_ID); + // Proxy Arp (execute after specific interface customizers) + registry.addAfter( + new GenericWriter<>(VPP_IFC_AUG_ID.child(ProxyArp.class), new ProxyArpCustomizer(jvpp)), + specificIfcTypes); + // Ingress (execute after classify table and session writers) + // also handles L2Acl, Ip4Acl and Ip6Acl: + final InstanceIdentifier<Ingress> ingressId = InstanceIdentifier.create(Ingress.class); + registry + .subtreeAddAfter( + Sets.newHashSet(ingressId.child(L2Acl.class), ingressId.child(Ip4Acl.class), + ingressId.child(Ip6Acl.class)), + new GenericWriter<>(INGRESS_ACL_ID, + new AclCustomizer(jvpp, ifcNamingContext, classifyTableContext)), + Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID)); + + // Span writers + // Mirrored interfaces + final InstanceIdentifier<MirroredInterfaces> mirroredIfcsId = VPP_IFC_AUG_ID + .child(Span.class) + .child(MirroredInterfaces.class); + registry.addAfter(new GenericWriter<>(mirroredIfcsId, new MirroredInterfacesCustomizer(jvpp, ifcNamingContext)), + ifcId); + } + + private void addPbbAugmentationWriters(final InstanceIdentifier<Interface> ifcId, + final ModifiableWriterRegistryBuilder registry) { + final InstanceIdentifier<PbbRewrite> pbbRewriteId = + ifcId.augmentation(PbbRewriteInterfaceAugmentation.class).child(PbbRewrite.class); + + registry.add(new GenericWriter<>(pbbRewriteId, new PbbRewriteCustomizer(jvpp, ifcNamingContext))); + } +} |