6d22c1d23c1cf3efc15b32d83a6565344a7ec4c3
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / VppStateHoneycombReaderFactory.java
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.honeycomb.translate.v3po;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.translate.impl.read.GenericListReader;
22 import io.fd.honeycomb.translate.impl.read.GenericReader;
23 import io.fd.honeycomb.translate.read.ReaderFactory;
24 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
25 import io.fd.honeycomb.translate.util.read.KeepaliveReaderWrapper;
26 import io.fd.honeycomb.translate.vpp.util.NamingContext;
27 import io.fd.honeycomb.translate.vpp.util.ReadTimeoutException;
28 import io.fd.honeycomb.translate.vpp.util.VppStatusListener;
29 import io.fd.honeycomb.translate.v3po.vppstate.BridgeDomainCustomizer;
30 import io.fd.honeycomb.translate.v3po.vppstate.L2FibEntryCustomizer;
31 import io.fd.honeycomb.translate.v3po.vppstate.VersionCustomizer;
32 import java.util.concurrent.ScheduledExecutorService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
44
45 public final class VppStateHoneycombReaderFactory implements ReaderFactory {
46
47     private final FutureJVppCore jVpp;
48     private final NamingContext ifcCtx;
49     private final NamingContext bdCtx;
50     private final ScheduledExecutorService keepaliveExecutor;
51     private final VppStatusListener vppStatusListener;
52
53     @Inject
54     public VppStateHoneycombReaderFactory(final FutureJVppCore jVpp,
55                                           @Named("interface-context") final NamingContext ifcCtx,
56                                           @Named("bridge-domain-context") final NamingContext bdCtx,
57                                           final ScheduledExecutorService keepaliveExecutorDependency,
58                                           final VppStatusListener vppStatusListener) {
59         this.jVpp = jVpp;
60         this.ifcCtx = ifcCtx;
61         this.bdCtx = bdCtx;
62         this.keepaliveExecutor = keepaliveExecutorDependency;
63         this.vppStatusListener = vppStatusListener;
64     }
65
66     @Override
67     public void init(final ModifiableReaderRegistryBuilder registry) {
68         // VppState(Structural)
69         final InstanceIdentifier<VppState> vppStateId = InstanceIdentifier.create(VppState.class);
70         registry.addStructuralReader(vppStateId, VppStateBuilder.class);
71         //  Version
72         // Wrap with keepalive reader to detect connection issues
73         // Relying on VersionCustomizer to provide a "timing out read"
74         registry.add(new KeepaliveReaderWrapper<>(
75                 new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp)),
76                 keepaliveExecutor, ReadTimeoutException.class, 30, vppStatusListener));
77         //  BridgeDomains(Structural)
78         final InstanceIdentifier<BridgeDomains> bridgeDomainsId = vppStateId.child(BridgeDomains.class);
79         registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class);
80         //   BridgeDomain
81         final InstanceIdentifier<BridgeDomain> bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class);
82         registry.add(new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdCtx)));
83         //    L2FibTable(Structural)
84         final InstanceIdentifier<L2FibTable> l2FibTableId = bridgeDomainId.child(L2FibTable.class);
85         registry.addStructuralReader(l2FibTableId, L2FibTableBuilder.class);
86         //     L2FibEntry
87         registry.add(new GenericListReader<>(l2FibTableId.child(L2FibEntry.class),
88                 new L2FibEntryCustomizer(jVpp, bdCtx, ifcCtx)));
89     }
90 }