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 io.fd.honeycomb.translate.impl.write.GenericListWriter;
24 import io.fd.honeycomb.translate.impl.write.GenericWriter;
25 import io.fd.honeycomb.translate.v3po.interfaces.RewriteCustomizer;
26 import io.fd.honeycomb.translate.v3po.interfaces.SubInterfaceAclCustomizer;
27 import io.fd.honeycomb.translate.v3po.interfaces.SubInterfaceCustomizer;
28 import io.fd.honeycomb.translate.v3po.interfaces.SubInterfaceL2Customizer;
29 import io.fd.honeycomb.translate.v3po.interfaces.ip.SubInterfaceIpv4AddressCustomizer;
30 import io.fd.honeycomb.translate.v3po.util.NamingContext;
31 import io.fd.honeycomb.translate.write.WriterFactory;
32 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
33 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
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.vpp.vlan.rev150527.SubinterfaceAugmentation;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTagged;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.openvpp.jvpp.future.FutureJVpp;
53 public final class SubinterfaceAugmentationWriterFactory implements WriterFactory {
55 private final FutureJVpp jvpp;
56 private final NamingContext ifcContext;
57 private final NamingContext bdContext;
58 private final NamingContext classifyTableContext;
60 public static final InstanceIdentifier<SubinterfaceAugmentation> SUB_IFC_AUG_ID =
61 InterfacesWriterFactory.IFC_ID.augmentation(SubinterfaceAugmentation.class);
62 public static final InstanceIdentifier<SubInterface> SUB_IFC_ID =
63 SUB_IFC_AUG_ID.child(SubInterfaces.class).child(SubInterface.class);
64 public static final InstanceIdentifier<L2> L2_ID = SUB_IFC_ID.child(
66 public static final InstanceIdentifier<Acl> SUBIF_ACL_ID = SUB_IFC_ID.child(Acl.class);
68 public SubinterfaceAugmentationWriterFactory(final FutureJVpp jvpp,
69 final NamingContext ifcContext, final NamingContext bdContext, final NamingContext classifyTableContext) {
71 this.ifcContext = ifcContext;
72 this.bdContext = bdContext;
73 this.classifyTableContext = classifyTableContext;
77 public void init(final ModifiableWriterRegistryBuilder registry) {
79 // Subinterface(Handle only after all interface related stuff gets processed) =
80 registry.subtreeAddAfter(
81 // TODO this customizer covers quite a lot of complex child nodes (maybe refactor ?)
83 InstanceIdentifier.create(SubInterface.class).child(Tags.class),
84 InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
85 InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(
87 InstanceIdentifier.create(SubInterface.class).child(Match.class),
88 InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
89 new GenericListWriter<>(SUB_IFC_ID, new SubInterfaceCustomizer(jvpp, ifcContext)),
90 InterfacesWriterFactory.IFC_ID);
92 registry.addAfter(new GenericWriter<>(L2_ID, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)),
94 // Rewrite(also handles pushTags + pushTags/dot1qtag) =
95 final InstanceIdentifier<Rewrite> rewriteId = L2_ID.child(Rewrite.class);
96 registry.subtreeAddAfter(
98 InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
99 InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
100 .child(org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
101 new GenericWriter<>(rewriteId, new RewriteCustomizer(jvpp, ifcContext)),
103 // Ipv4(handled after L2 and L2/rewrite is done) =
104 final InstanceIdentifier<Address> ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class);
105 registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId,
106 new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)),
109 // ACL (execute after classify table and session writers)
110 // also handles L2Acl, Ip4Acl and Ip6Acl:
111 final InstanceIdentifier<Acl> aclId = InstanceIdentifier.create(Acl.class);
114 Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)),
115 new GenericWriter<>(SUBIF_ACL_ID, new SubInterfaceAclCustomizer(jvpp, ifcContext, classifyTableContext)),
116 Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID));