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.acl.IetfAClWriter;
30 import io.fd.honeycomb.translate.v3po.interfaces.acl.SubInterfaceIetfAclCustomizer;
31 import io.fd.honeycomb.translate.v3po.interfaces.ip.SubInterfaceIpv4AddressCustomizer;
32 import io.fd.honeycomb.translate.v3po.util.NamingContext;
33 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
34 import io.fd.honeycomb.translate.write.WriterFactory;
35 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
36 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.AccessLists;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTagged;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.IetfAcl;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags;
55 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
56 import org.openvpp.jvpp.core.future.FutureJVppCore;
58 public final class SubinterfaceAugmentationWriterFactory implements WriterFactory {
60 private final FutureJVppCore jvpp;
61 private final IetfAClWriter aclWriter;
62 private final NamingContext ifcContext;
63 private final NamingContext bdContext;
64 private final VppClassifierContextManager classifyTableContext;
66 public static final InstanceIdentifier<SubinterfaceAugmentation> SUB_IFC_AUG_ID =
67 InterfacesWriterFactory.IFC_ID.augmentation(SubinterfaceAugmentation.class);
68 public static final InstanceIdentifier<SubInterface> SUB_IFC_ID =
69 SUB_IFC_AUG_ID.child(SubInterfaces.class).child(SubInterface.class);
70 public static final InstanceIdentifier<L2> L2_ID = SUB_IFC_ID.child(
72 public static final InstanceIdentifier<Acl> SUBIF_ACL_ID = SUB_IFC_ID.child(Acl.class);
73 public static final InstanceIdentifier<IetfAcl> SUBIF_IETF_ACL_ID = SUB_IFC_ID.child(IetfAcl.class);
75 public SubinterfaceAugmentationWriterFactory(final FutureJVppCore jvpp,
76 final IetfAClWriter aclWriter,
77 final NamingContext ifcContext, final NamingContext bdContext, final VppClassifierContextManager classifyTableContext) {
79 this.aclWriter = aclWriter;
80 this.ifcContext = ifcContext;
81 this.bdContext = bdContext;
82 this.classifyTableContext = classifyTableContext;
86 public void init(final ModifiableWriterRegistryBuilder registry) {
88 // Subinterface(Handle only after all interface related stuff gets processed) =
89 registry.subtreeAddAfter(
90 // TODO HONEYCOMB-188 this customizer covers quite a lot of complex child nodes (maybe refactor ?)
92 InstanceIdentifier.create(SubInterface.class).child(Tags.class),
93 InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
94 InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(
96 InstanceIdentifier.create(SubInterface.class).child(Match.class),
97 InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
98 new GenericListWriter<>(SUB_IFC_ID, new SubInterfaceCustomizer(jvpp, ifcContext)),
99 InterfacesWriterFactory.IFC_ID);
101 registry.addAfter(new GenericWriter<>(L2_ID, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)),
103 // Rewrite(also handles pushTags + pushTags/dot1qtag) =
104 final InstanceIdentifier<Rewrite> rewriteId = L2_ID.child(Rewrite.class);
105 registry.subtreeAddAfter(
107 InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
108 InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
109 .child(org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
110 new GenericWriter<>(rewriteId, new RewriteCustomizer(jvpp, ifcContext)),
112 // Ipv4(handled after L2 and L2/rewrite is done) =
113 final InstanceIdentifier<Address> ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class);
114 registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId,
115 new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)),
118 // ACL (execute after classify table and session writers)
119 // also handles L2Acl, Ip4Acl and Ip6Acl:
120 final InstanceIdentifier<Acl> aclId = InstanceIdentifier.create(Acl.class);
123 Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)),
124 new GenericWriter<>(SUBIF_ACL_ID, new SubInterfaceAclCustomizer(jvpp, ifcContext, classifyTableContext)),
125 Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID));
127 // IETF-ACL, also handles IetfAcl, AccessLists and Acl:
128 final InstanceIdentifier<AccessLists> accessListsID = InstanceIdentifier.create(IetfAcl.class)
129 .child(AccessLists.class);
130 final InstanceIdentifier<?> aclListId = accessListsID.child(
131 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.Acl.class);
133 Sets.newHashSet(accessListsID, aclListId),
134 new GenericWriter<>(SUBIF_IETF_ACL_ID, new SubInterfaceIetfAclCustomizer(aclWriter, ifcContext)));