35d0c380a25ace3c0df0d26893bfb772379e6bb0
[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.read;
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.vpp.classifier.context.VppClassifierContextManager;
24 import io.fd.hc2vpp.vpp.classifier.read.acl.AclCustomizer;
25 import io.fd.honeycomb.translate.impl.read.GenericInitReader;
26 import io.fd.honeycomb.translate.read.ReaderFactory;
27 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
28 import io.fd.jvpp.core.future.FutureJVppCore;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclStateAugmentation;
31 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclStateAugmentationBuilder;
32 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip4Acl;
33 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip6Acl;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.L2Acl;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl;
36 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder;
37 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress;
38 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42
43 public class InterfaceAclReaderFactory implements ReaderFactory{
44
45     private static final InstanceIdentifier<Interface> IFC_ID =
46             InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
47     private static final InstanceIdentifier<VppInterfaceAclStateAugmentation> VPP_IFC_AUG_ID =
48             IFC_ID.augmentation(VppInterfaceAclStateAugmentation.class);
49
50     @Inject
51     private FutureJVppCore jvpp;
52
53     @Inject
54     @Named("interface-context")
55     private NamingContext ifcNamingContext;
56
57     @Inject
58     @Named("classify-table-context")
59     private VppClassifierContextManager classifyTableContext;
60
61     @Override
62     public void init(@Nonnull ModifiableReaderRegistryBuilder registry) {
63         //    Acl augmentation(structural)
64         registry.addStructuralReader(VPP_IFC_AUG_ID, VppInterfaceAclStateAugmentationBuilder.class);
65         //    Acl(Structural)
66         final InstanceIdentifier<Acl> aclIid = VPP_IFC_AUG_ID.child(Acl.class);
67         registry.addStructuralReader(aclIid, AclBuilder.class);
68         //    Ingress(Subtree)
69         final InstanceIdentifier<Ingress> ingressIdRelative = InstanceIdentifier.create(Ingress.class);
70         registry.subtreeAdd(
71                 Sets.newHashSet(ingressIdRelative.child(L2Acl.class), ingressIdRelative.child(Ip4Acl.class),
72                         ingressIdRelative.child(Ip6Acl.class)),
73                 new GenericInitReader<Ingress,IngressBuilder>(aclIid.child(Ingress.class),
74                         new AclCustomizer(jvpp, ifcNamingContext, classifyTableContext)));
75     }
76 }