Move interface acls to separate yang module
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / SubinterfaceStateAugmentationReaderFactory.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 com.google.common.collect.Sets;
20 import io.fd.honeycomb.translate.impl.read.GenericListReader;
21 import io.fd.honeycomb.translate.impl.read.GenericReader;
22 import io.fd.honeycomb.translate.read.ReaderFactory;
23 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
24 import io.fd.honeycomb.translate.v3po.interfacesstate.RewriteCustomizer;
25 import io.fd.honeycomb.translate.v3po.interfacesstate.SubInterfaceCustomizer;
26 import io.fd.honeycomb.translate.v3po.interfacesstate.acl.ingress.SubInterfaceAclCustomizer;
27 import io.fd.honeycomb.translate.v3po.interfacesstate.SubInterfaceL2Customizer;
28 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.SubInterfaceIpv4AddressCustomizer;
29 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
30 import io.fd.honeycomb.translate.vpp.util.NamingContext;
31 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
32 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip4Acl;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip6Acl;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.L2Acl;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentationBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfacesBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.match.attributes.match.type.vlan.tagged.VlanTagged;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Acl;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.AclBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Match;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Tags;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.Ingress;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.l2.Rewrite;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.tags.Tag;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.tag.rewrite.PushTags;
54 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55
56 final class SubinterfaceStateAugmentationReaderFactory implements ReaderFactory {
57
58     private final FutureJVppCore jvpp;
59     private final NamingContext ifcCtx;
60     private final NamingContext bdCtx;
61     private final VppClassifierContextManager classifyCtx;
62
63     SubinterfaceStateAugmentationReaderFactory(final FutureJVppCore jvpp, final NamingContext ifcCtx,
64                                                final NamingContext bdCtx,
65                                                final VppClassifierContextManager classifyCtx) {
66         this.jvpp = jvpp;
67         this.ifcCtx = ifcCtx;
68         this.bdCtx = bdCtx;
69         this.classifyCtx = classifyCtx;
70     }
71
72     @Override
73     public void init(final ModifiableReaderRegistryBuilder registry) {
74         // SubinterfaceStateAugmentation(Structural)
75         final InstanceIdentifier<SubinterfaceStateAugmentation> subIfcAugId =
76             InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class);
77         registry.addStructuralReader(subIfcAugId, SubinterfaceStateAugmentationBuilder.class);
78         //  SubInterfaces(Structural)
79         final InstanceIdentifier<SubInterfaces> subIfcsId = subIfcAugId.child(SubInterfaces.class);
80         registry.addStructuralReader(subIfcsId, SubInterfacesBuilder.class);
81         //   SubInterface(Subtree)
82         final InstanceIdentifier<SubInterface> subIfcId = subIfcsId.child(SubInterface.class);
83         registry.subtreeAdd(Sets.newHashSet(
84             InstanceIdentifier.create(SubInterface.class).child(Tags.class),
85             InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
86             InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(Dot1qTag.class),
87             InstanceIdentifier.create(SubInterface.class).child(Match.class),
88             InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
89             new GenericListReader<>(subIfcId, new SubInterfaceCustomizer(jvpp, ifcCtx)));
90         //    L2
91         final InstanceIdentifier<L2> l2Id = subIfcId.child(L2.class);
92         registry.add(new GenericReader<>(l2Id, new SubInterfaceL2Customizer(jvpp, ifcCtx, bdCtx)));
93         //     Rewrite(Subtree)
94         registry.subtreeAdd(Sets.newHashSet(
95             InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
96             InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
97                 .child(
98                     org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
99             new GenericReader<>(l2Id.child(Rewrite.class), new RewriteCustomizer(jvpp, ifcCtx)));
100         //    Ipv4(Structural)
101         final InstanceIdentifier<Ipv4> ipv4Id = subIfcId.child(Ipv4.class);
102         registry.addStructuralReader(ipv4Id, Ipv4Builder.class);
103         //     Address
104         registry.add(
105             new GenericListReader<>(ipv4Id.child(Address.class), new SubInterfaceIpv4AddressCustomizer(jvpp, ifcCtx)));
106         //    Acl(Structural)
107         final InstanceIdentifier<Acl> aclIid = subIfcId.child(Acl.class);
108         registry.addStructuralReader(aclIid, AclBuilder.class);
109         //    Ingress(Subtree)
110         final InstanceIdentifier<Ingress> ingressIdRelative = InstanceIdentifier.create(Ingress.class);
111         registry.subtreeAdd(
112             Sets.newHashSet(ingressIdRelative.child(L2Acl.class), ingressIdRelative.child(Ip4Acl.class),
113                 ingressIdRelative.child(Ip6Acl.class)),
114             new GenericReader<>(aclIid.child(Ingress.class),
115                 new SubInterfaceAclCustomizer(jvpp, ifcCtx, classifyCtx)));
116     }
117 }