2538904d58910e7b619b0046b2ac1868ee6d9819
[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 static io.fd.hc2vpp.vpp.classifier.factory.write.VppClassifierHoneycombWriterFactory.CLASSIFY_SESSION_ID;
20 import static io.fd.hc2vpp.vpp.classifier.factory.write.VppClassifierHoneycombWriterFactory.CLASSIFY_TABLE_ID;
21
22 import com.google.common.collect.Sets;
23 import com.google.inject.Inject;
24 import com.google.inject.name.Named;
25 import io.fd.hc2vpp.common.translate.util.NamingContext;
26 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
27 import io.fd.hc2vpp.vpp.classifier.write.acl.ingress.AclCustomizer;
28 import io.fd.hc2vpp.vpp.classifier.write.acl.ingress.AclValidator;
29 import io.fd.honeycomb.translate.impl.write.GenericWriter;
30 import io.fd.honeycomb.translate.write.WriterFactory;
31 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
32 import io.fd.jvpp.core.future.FutureJVppCore;
33 import javax.annotation.Nonnull;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclAugmentation;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip4Acl;
36 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip6Acl;
37 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.L2Acl;
38 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl;
39 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43
44 public class InterfaceAclWriterFactory implements WriterFactory {
45
46     private static final InstanceIdentifier<Interface> IFC_ID =
47             InstanceIdentifier.create(Interfaces.class).child(Interface.class);
48     private static final InstanceIdentifier<VppInterfaceAclAugmentation> VPP_IFC_ACL_ID =
49             IFC_ID.augmentation(VppInterfaceAclAugmentation.class);
50     static final InstanceIdentifier<Acl> ACL_ID = VPP_IFC_ACL_ID.child(Acl.class);
51     private static final InstanceIdentifier<Ingress> INGRESS_ACL_ID = ACL_ID.child(Ingress.class);
52
53     @Inject
54     private FutureJVppCore jvpp;
55
56     @Inject
57     @Named("interface-context")
58     private NamingContext ifcNamingContext;
59
60     @Inject
61     @Named("classify-table-context")
62     private VppClassifierContextManager classifyTableContext;
63
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> ingressId = InstanceIdentifier.create(Ingress.class);
70         registry
71                 .subtreeAddAfter(
72                         Sets.newHashSet(ingressId.child(L2Acl.class), ingressId.child(Ip4Acl.class),
73                                 ingressId.child(Ip6Acl.class)),
74                         new GenericWriter<>(INGRESS_ACL_ID,
75                                 new AclCustomizer(jvpp, ifcNamingContext, classifyTableContext),
76                                 new AclValidator(ifcNamingContext, classifyTableContext)),
77                         Sets.newHashSet(CLASSIFY_TABLE_ID, CLASSIFY_SESSION_ID));
78     }
79 }