5eb54669a2263580fb1874066046b1410c268e86
[honeycomb.git] / nsh / impl / src / main / java / io / fd / honeycomb / vppnsh / impl / oper / VppNshReaderFactory.java
1 /*
2  * Copyright (c) 2016 Intel 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.honeycomb.vppnsh.impl.oper;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.translate.impl.read.GenericInitListReader;
22 import io.fd.honeycomb.translate.read.ReaderFactory;
23 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
24 import io.fd.honeycomb.translate.vpp.util.NamingContext;
25 import io.fd.vpp.jvpp.nsh.future.FutureJVppNsh;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.VppNshState;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.VppNshStateBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.state.NshEntries;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.state.NshEntriesBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.state.NshMaps;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.state.NshMapsBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.state.nsh.entries.NshEntry;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.state.nsh.maps.NshMap;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36
37 public class VppNshReaderFactory implements ReaderFactory {
38
39     private final FutureJVppNsh jvppNsh;
40     private final NamingContext nshEntryContext;
41     private final NamingContext nshMapContext;
42     private final NamingContext interfaceContext;
43
44     @Inject
45     public VppNshReaderFactory(final FutureJVppNsh jvppNsh,
46                                @Named("nsh-entry-context") final NamingContext nshEntryContext,
47                                @Named("nsh-map-context") final NamingContext nshMapContext,
48                                @Named("interface-context") @Nonnull final NamingContext interfaceContext) {
49         this.jvppNsh = jvppNsh;
50         this.nshEntryContext = nshEntryContext;
51         this.nshMapContext = nshMapContext;
52         this.interfaceContext = interfaceContext;
53     }
54     @Override
55     public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
56         // ReaderFactory is intended for registering Readers into HC framework
57         // Readers provide ONLY operational (config "false") data straight from underlying device/layer
58         // they are triggered when RESTCONF GET on operational is invoked or when NETCONF get operation is executed
59
60         // VppNshState(Structural)
61         final InstanceIdentifier<VppNshState> vppNshStateId = InstanceIdentifier.create(VppNshState.class);
62         registry.addStructuralReader(vppNshStateId, VppNshStateBuilder.class);
63
64         //  NshENtries(Structural)
65         final InstanceIdentifier<NshEntries> nshEntriesId = vppNshStateId.child(NshEntries.class);
66         registry.addStructuralReader(nshEntriesId, NshEntriesBuilder.class);
67         //  NshENtry
68         final InstanceIdentifier<NshEntry> nshEntryId = nshEntriesId.child(NshEntry.class);
69         registry.add(new GenericInitListReader<>(nshEntryId, new NshEntryReaderCustomizer(jvppNsh, nshEntryContext)));
70
71         //  NshMaps(Structural)
72         final InstanceIdentifier<NshMaps> nshMapsId = vppNshStateId.child(NshMaps.class);
73         registry.addStructuralReader(nshMapsId, NshMapsBuilder.class);
74         //  NshMap
75         final InstanceIdentifier<NshMap> nshMapId = nshMapsId.child(NshMap.class);
76         registry.add(new GenericInitListReader<>(nshMapId, new NshMapReaderCustomizer(jvppNsh, nshMapContext, interfaceContext)));
77     }
78 }