4f47f494f832f97f5d3ae02780ffd92e438bd3dc
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / SubinterfaceAugmentationWriterFactory.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.translate.v3po;
18
19 import static io.fd.honeycomb.translate.v3po.VppClassifierHoneycombWriterFactory.CLASSIFY_SESSION_ID;
20 import static io.fd.honeycomb.translate.v3po.VppClassifierHoneycombWriterFactory.CLASSIFY_TABLE_ID;
21
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.write.WriterFactory;
34 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
35 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.AccessLists;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTagged;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.IetfAcl;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags;
54 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55 import org.openvpp.jvpp.core.future.FutureJVppCore;
56
57 public final class SubinterfaceAugmentationWriterFactory implements WriterFactory {
58
59     private final FutureJVppCore jvpp;
60     private final IetfAClWriter aclWriter;
61     private final NamingContext ifcContext;
62     private final NamingContext bdContext;
63     private final NamingContext classifyTableContext;
64
65     public static final InstanceIdentifier<SubinterfaceAugmentation> SUB_IFC_AUG_ID =
66             InterfacesWriterFactory.IFC_ID.augmentation(SubinterfaceAugmentation.class);
67     public static final InstanceIdentifier<SubInterface> SUB_IFC_ID =
68             SUB_IFC_AUG_ID.child(SubInterfaces.class).child(SubInterface.class);
69     public static final InstanceIdentifier<L2> L2_ID = SUB_IFC_ID.child(
70             L2.class);
71     public static final InstanceIdentifier<Acl> SUBIF_ACL_ID = SUB_IFC_ID.child(Acl.class);
72     public static final InstanceIdentifier<IetfAcl> SUBIF_IETF_ACL_ID = SUB_IFC_ID.child(IetfAcl.class);
73
74     public SubinterfaceAugmentationWriterFactory(final FutureJVppCore jvpp,
75                                                  final IetfAClWriter aclWriter,
76             final NamingContext ifcContext, final NamingContext bdContext, final NamingContext classifyTableContext) {
77         this.jvpp = jvpp;
78         this.aclWriter = aclWriter;
79         this.ifcContext = ifcContext;
80         this.bdContext = bdContext;
81         this.classifyTableContext = classifyTableContext;
82     }
83
84     @Override
85     public void init(final ModifiableWriterRegistryBuilder registry) {
86         // Subinterfaces
87         //  Subinterface(Handle only after all interface related stuff gets processed) =
88         registry.subtreeAddAfter(
89                 // TODO HONEYCOMB-188 this customizer covers quite a lot of complex child nodes (maybe refactor ?)
90                 Sets.newHashSet(
91                         InstanceIdentifier.create(SubInterface.class).child(Tags.class),
92                         InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
93                         InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(
94                                 Dot1qTag.class),
95                         InstanceIdentifier.create(SubInterface.class).child(Match.class),
96                         InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
97                 new GenericListWriter<>(SUB_IFC_ID, new SubInterfaceCustomizer(jvpp, ifcContext)),
98                 InterfacesWriterFactory.IFC_ID);
99         //   L2 =
100         registry.addAfter(new GenericWriter<>(L2_ID, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)),
101                 SUB_IFC_ID);
102         //    Rewrite(also handles pushTags + pushTags/dot1qtag) =
103         final InstanceIdentifier<Rewrite> rewriteId = L2_ID.child(Rewrite.class);
104         registry.subtreeAddAfter(
105                 Sets.newHashSet(
106                         InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
107                         InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
108                                 .child(org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
109                 new GenericWriter<>(rewriteId, new RewriteCustomizer(jvpp, ifcContext)),
110                 L2_ID);
111         //   Ipv4(handled after L2 and L2/rewrite is done) =
112         final InstanceIdentifier<Address> ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class);
113         registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId,
114                 new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)),
115                 rewriteId);
116
117         // ACL (execute after classify table and session writers)
118         // also handles L2Acl, Ip4Acl and Ip6Acl:
119         final InstanceIdentifier<Acl> aclId = InstanceIdentifier.create(Acl.class);
120         registry
121             .subtreeAddAfter(
122                 Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)),
123                 new GenericWriter<>(SUBIF_ACL_ID, new SubInterfaceAclCustomizer(jvpp, ifcContext, classifyTableContext)),
124                 Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID));
125
126         // IETF-ACL, also handles IetfAcl, AccessLists and Acl:
127         final InstanceIdentifier<AccessLists> accessListsID = InstanceIdentifier.create(IetfAcl.class)
128             .child(AccessLists.class);
129         final InstanceIdentifier<?> aclListId = accessListsID.child(
130             org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.Acl.class);
131         registry.subtreeAdd(
132             Sets.newHashSet(accessListsID, aclListId),
133             new GenericWriter<>(SUBIF_IETF_ACL_ID, new SubInterfaceIetfAclCustomizer(aclWriter, ifcContext)));
134     }
135 }