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