ad7eabcd768eca5b6ec0d6c3c5e35d87ca6d84e8
[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.SubInterfaceAclCustomizer;
26 import io.fd.honeycomb.translate.v3po.interfacesstate.SubInterfaceCustomizer;
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.util.NamingContext;
30 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentationBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfacesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTagged;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4Builder;
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.core.future.FutureJVppCore;
52
53 final class SubinterfaceStateAugmentationReaderFactory implements ReaderFactory {
54
55     private final FutureJVppCore jvpp;
56     private final NamingContext ifcCtx;
57     private final NamingContext bdCtx;
58     private final NamingContext classifyCtx;
59
60     SubinterfaceStateAugmentationReaderFactory(final FutureJVppCore jvpp, final NamingContext ifcCtx,
61                                                final NamingContext bdCtx, final NamingContext classifyCtx) {
62         this.jvpp = jvpp;
63         this.ifcCtx = ifcCtx;
64         this.bdCtx = bdCtx;
65         this.classifyCtx = classifyCtx;
66     }
67
68     @Override
69     public void init(final ModifiableReaderRegistryBuilder registry) {
70         // SubinterfaceStateAugmentation(Structural)
71         final InstanceIdentifier<SubinterfaceStateAugmentation> subIfcAugId =
72                 InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class);
73         registry.addStructuralReader(subIfcAugId, SubinterfaceStateAugmentationBuilder.class);
74         //  SubInterfaces(Structural)
75         final InstanceIdentifier<SubInterfaces> subIfcsId = subIfcAugId.child(SubInterfaces.class);
76         registry.addStructuralReader(subIfcsId, SubInterfacesBuilder.class);
77         //   SubInterface(Subtree)
78         final InstanceIdentifier<SubInterface> subIfcId = subIfcsId.child(SubInterface.class);
79         registry.subtreeAdd(Sets.newHashSet(
80                 InstanceIdentifier.create(SubInterface.class).child(Tags.class),
81                 InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
82                 InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(Dot1qTag.class),
83                 InstanceIdentifier.create(SubInterface.class).child(Match.class),
84                 InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
85                 new GenericListReader<>(subIfcId, new SubInterfaceCustomizer(jvpp, ifcCtx)));
86         //    L2
87         final InstanceIdentifier<L2> l2Id = subIfcId.child(L2.class);
88         registry.add(new GenericReader<>(l2Id, new SubInterfaceL2Customizer(jvpp, ifcCtx, bdCtx)));
89         //     Rewrite(Subtree)
90         registry.subtreeAdd(Sets.newHashSet(
91                 InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
92                 InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
93                         .child(org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
94                 new GenericReader<>(l2Id.child(Rewrite.class), new RewriteCustomizer(jvpp, ifcCtx)));
95         //    Ipv4(Structural)
96         final InstanceIdentifier<Ipv4> ipv4Id = subIfcId.child(Ipv4.class);
97         registry.addStructuralReader(ipv4Id, Ipv4Builder.class);
98         //     Address
99         registry.add(new GenericListReader<>(ipv4Id.child(Address.class), new SubInterfaceIpv4AddressCustomizer(jvpp, ifcCtx)));
100         //    Acl(Subtree)
101         final InstanceIdentifier<Acl> aclIdRelative = InstanceIdentifier.create(Acl.class);
102         registry.subtreeAdd(
103                 Sets.newHashSet(aclIdRelative.child(L2Acl.class), aclIdRelative.child(Ip4Acl.class), aclIdRelative.child(Ip6Acl.class)),
104                 new GenericReader<>(subIfcId.child(Acl.class), new SubInterfaceAclCustomizer(jvpp, ifcCtx, classifyCtx)));
105     }
106 }