657769aadf5868e73df7bf6dd481577d9c7ab3b9
[hc2vpp.git] /
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 org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.v3po2vpp.rev160406;
18
19 import com.google.common.collect.Sets;
20 import io.fd.honeycomb.v3po.translate.impl.write.GenericListWriter;
21 import io.fd.honeycomb.v3po.translate.impl.write.GenericWriter;
22 import io.fd.honeycomb.v3po.translate.v3po.interfaces.RewriteCustomizer;
23 import io.fd.honeycomb.v3po.translate.v3po.interfaces.SubInterfaceCustomizer;
24 import io.fd.honeycomb.v3po.translate.v3po.interfaces.SubInterfaceL2Customizer;
25 import io.fd.honeycomb.v3po.translate.v3po.interfaces.ip.SubInterfaceIpv4AddressCustomizer;
26 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
27 import io.fd.honeycomb.v3po.translate.write.ModifiableWriterRegistry;
28 import io.fd.honeycomb.v3po.translate.write.WriterFactory;
29 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTagged;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.openvpp.jvpp.future.FutureJVpp;
44
45 final class SubinterfaceAugmentationWriterFactory implements WriterFactory {
46
47     private final FutureJVpp jvpp;
48     private final NamingContext ifcContext;
49     private final NamingContext bdContext;
50     public static final InstanceIdentifier<SubinterfaceAugmentation> SUB_IFC_AUG_ID =
51             InterfacesHoneycombWriterModule.IFC_ID.augmentation(SubinterfaceAugmentation.class);
52     public static final InstanceIdentifier<SubInterface> SUB_IFC_ID =
53             SUB_IFC_AUG_ID.child(SubInterfaces.class).child(SubInterface.class);
54     public static final InstanceIdentifier<L2> L2_ID = SUB_IFC_ID.child(
55             L2.class);
56
57     public SubinterfaceAugmentationWriterFactory(final FutureJVpp jvpp,
58             final NamingContext ifcContext, final NamingContext bdContext) {
59         this.jvpp = jvpp;
60         this.ifcContext = ifcContext;
61         this.bdContext = bdContext;
62     }
63
64     @Override
65     public void init(final ModifiableWriterRegistry registry) {
66         // Subinterfaces
67         //  Subinterface(Handle only after all interface related stuff gets processed) =
68         registry.addSubtreeWriterAfter(
69                 // TODO this customizer covers quite a lot of complex child nodes (maybe refactor ?)
70                 Sets.newHashSet(
71                         InstanceIdentifier.create(SubInterface.class).child(Tags.class),
72                         InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class),
73                         InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(
74                                 Dot1qTag.class),
75                         InstanceIdentifier.create(SubInterface.class).child(Match.class),
76                         InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)),
77                 new GenericListWriter<>(SUB_IFC_ID, new SubInterfaceCustomizer(jvpp, ifcContext)),
78                 InterfacesHoneycombWriterModule.IFC_ID);
79         //   L2 =
80         registry.addWriterAfter(new GenericWriter<>(L2_ID, new SubInterfaceL2Customizer(jvpp, ifcContext, bdContext)),
81                 SUB_IFC_ID);
82         //    Rewrite(also handles pushTags + pushTags/dot1qtag) =
83         final InstanceIdentifier<Rewrite> rewriteId = L2_ID.child(Rewrite.class);
84         registry.addSubtreeWriterAfter(
85                 Sets.newHashSet(
86                         InstanceIdentifier.create(Rewrite.class).child(PushTags.class),
87                         InstanceIdentifier.create(Rewrite.class).child(PushTags.class)
88                                 .child(org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)),
89                 new GenericWriter<>(rewriteId, new RewriteCustomizer(jvpp, ifcContext)),
90                 L2_ID);
91         //   Ipv4(handled after L2 and L2/rewrite is done) =
92         final InstanceIdentifier<Address> ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class);
93         registry.addWriterAfter(new GenericListWriter<>(ipv4SubifcAddressId,
94                 new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)),
95                 rewriteId);
96
97     }
98 }