2d1b63e426e58baa576959a7e5b3f69823ac6558
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2017 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.vpp.classifier.factory.write;
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.factory.InterfacesWriterFactory;
24 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
25 import io.fd.hc2vpp.vpp.classifier.write.acl.ingress.SubInterfaceAclCustomizer;
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 io.fd.vpp.jvpp.core.future.FutureJVppCore;
30 import javax.annotation.Nonnull;
31 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip4Acl;
32 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip6Acl;
33 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.L2Acl;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress;
36 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclAugmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev180319.SubinterfaceAugmentation;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41
42 public class SubInterfaceAclWriterFactory implements WriterFactory {
43
44     public static final InstanceIdentifier<SubinterfaceAugmentation> SUB_IFC_AUG_ID =
45             InterfacesWriterFactory.IFC_ID.augmentation(SubinterfaceAugmentation.class);
46     public static final InstanceIdentifier<SubInterface> SUB_IFC_ID =
47             SUB_IFC_AUG_ID.child(SubInterfaces.class).child(SubInterface.class);
48     public static final InstanceIdentifier<VppSubinterfaceAclAugmentation> SUB_IF_ACL_AUG_ID =
49             SUB_IFC_ID.augmentation(VppSubinterfaceAclAugmentation.class);
50
51     public static final InstanceIdentifier<Acl> SUBIF_ACL_ID = SUB_IF_ACL_AUG_ID.child(Acl.class);
52     public static final InstanceIdentifier<Ingress> SUBIF_INGRESS_ACL_ID = SUBIF_ACL_ID.child(Ingress.class);
53
54     @Inject
55     private FutureJVppCore jvpp;
56
57     @Inject
58     @Named("interface-context")
59     private NamingContext ifcNamingContext;
60
61     @Inject
62     @Named("classify-table-context")
63     private VppClassifierContextManager classifyTableContext;
64
65     @Override
66     public void init(@Nonnull ModifiableWriterRegistryBuilder registry) {
67         // Ingress (execute after classify table and session writers)
68         // also handles L2Acl, Ip4Acl and Ip6Acl:
69         final InstanceIdentifier<Ingress> aclId = InstanceIdentifier.create(Ingress.class);
70         registry
71                 .subtreeAddAfter(
72                         Sets.newHashSet(aclId.child(L2Acl.class), aclId.child(Ip4Acl.class), aclId.child(Ip6Acl.class)),
73                         new GenericWriter<>(SUBIF_INGRESS_ACL_ID,
74                                 new SubInterfaceAclCustomizer(jvpp, ifcNamingContext, classifyTableContext)),
75                         Sets.newHashSet(VppClassifierHoneycombWriterFactory.CLASSIFY_TABLE_ID,
76                                 VppClassifierHoneycombWriterFactory.CLASSIFY_SESSION_ID));
77     }
78 }