5748f081b9348cc9c10b42e7c152eca4a9210799
[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 io.fd.hc2vpp.v3po.factory;
18
19 import com.google.common.collect.Sets;
20 import com.google.inject.Inject;
21 import com.google.inject.name.Named;
22 import io.fd.hc2vpp.common.translate.util.NamingContext;
23 import io.fd.hc2vpp.v3po.interfaces.acl.egress.EgressIetfAclWriter;
24 import io.fd.hc2vpp.v3po.interfaces.acl.ingress.IngressIetfAclWriter;
25 import io.fd.hc2vpp.v3po.interfaces.acl.ingress.SubInterfaceIetfAclCustomizer;
26 import io.fd.honeycomb.translate.impl.write.GenericWriter;
27 import io.fd.honeycomb.translate.write.WriterFactory;
28 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.ietf.acl.base.attributes.AccessLists;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.ietf.acl.base.attributes.access.lists.Acl;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.IetfAcl;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.Egress;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.Ingress;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38
39 public final class SubInterfacesClassifierIetfAclWriterFactory implements WriterFactory {
40
41     public static final InstanceIdentifier<SubinterfaceAugmentation> SUB_IFC_AUG_ID =
42         InterfacesWriterFactory.IFC_ID.augmentation(SubinterfaceAugmentation.class);
43     public static final InstanceIdentifier<SubInterface> SUB_IFC_ID =
44         SUB_IFC_AUG_ID.child(SubInterfaces.class).child(SubInterface.class);
45     public static final InstanceIdentifier<IetfAcl> SUBIF_IETF_ACL_ID = SUB_IFC_ID.child(IetfAcl.class);
46     public static final InstanceIdentifier<Ingress> SUBIF_INGRESS_IETF_ACL_ID = SUBIF_IETF_ACL_ID.child(Ingress.class);
47     public static final InstanceIdentifier<Egress> SUBIF_EGRESS_IETF_ACL_ID = SUBIF_IETF_ACL_ID.child(Egress.class);
48
49     private final IngressIetfAclWriter ingressAclWriter;
50     private final EgressIetfAclWriter egressAclWriter;
51     private final NamingContext ifcContext;
52
53     @Inject
54     public SubInterfacesClassifierIetfAclWriterFactory(final IngressIetfAclWriter ingressAclWriter,
55                                                        final EgressIetfAclWriter egressAclWriter,
56                                                        @Named("interface-context") final NamingContext ifcContext) {
57         this.ingressAclWriter = ingressAclWriter;
58         this.egressAclWriter = egressAclWriter;
59         this.ifcContext = ifcContext;
60     }
61
62     @Override
63     public void init(final ModifiableWriterRegistryBuilder registry) {
64         // Ingress IETF-ACL, also handles AccessLists and Acl:
65         final InstanceIdentifier<AccessLists> accessListsIdIngress =
66             InstanceIdentifier.create(Ingress.class).child(AccessLists.class);
67         final InstanceIdentifier<?> aclIdIngress = accessListsIdIngress.child(Acl.class);
68         registry.subtreeAdd(
69             Sets.newHashSet(accessListsIdIngress, aclIdIngress),
70             new GenericWriter<>(SUBIF_INGRESS_IETF_ACL_ID,
71                 new SubInterfaceIetfAclCustomizer(ingressAclWriter, ifcContext)));
72
73         // Egress IETF-ACL, also handles AccessLists and Acl:
74         final InstanceIdentifier<AccessLists> accessListsIdEgress =
75             InstanceIdentifier.create(Egress.class).child(AccessLists.class);
76         final InstanceIdentifier<?> aclIdEgress = accessListsIdEgress.child(Acl.class);
77         registry.subtreeAdd(
78             Sets.newHashSet(accessListsIdEgress, aclIdEgress),
79             new GenericWriter<>(SUBIF_EGRESS_IETF_ACL_ID,
80                 new io.fd.hc2vpp.v3po.interfaces.acl.egress.SubInterfaceIetfAclCustomizer(
81                     egressAclWriter, ifcContext)));
82     }
83 }