HONEYCOMB-117: add support for jvpp plugins
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / vppstate / VppStateTestUtils.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.vppstate;
18
19 import io.fd.honeycomb.translate.impl.read.GenericListReader;
20 import io.fd.honeycomb.translate.impl.read.GenericReader;
21 import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
22 import io.fd.honeycomb.translate.util.read.registry.CompositeReaderRegistryBuilder;
23 import io.fd.honeycomb.translate.v3po.util.NamingContext;
24 import javax.annotation.Nonnull;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.openvpp.jvpp.core.future.FutureJVppCore;
35
36 final class VppStateTestUtils {
37
38     private static InstanceIdentifier<BridgeDomains> bridgeDomainsId;
39
40     public VppStateTestUtils() {
41     }
42
43     /**
44      * Create root VppState reader with all its children wired.
45      */
46     static ReaderRegistry getVppStateReader(@Nonnull final FutureJVppCore jVpp,
47                                             @Nonnull final NamingContext bdContext) {
48         final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder();
49
50         // VppState(Structural)
51         final InstanceIdentifier<VppState> vppStateId = InstanceIdentifier.create(VppState.class);
52         registry.addStructuralReader(vppStateId, VppStateBuilder.class);
53         //  Version
54         // Wrap with keepalive reader to detect connection issues
55         // TODO keepalive reader wrapper relies on VersionReaderCustomizer (to perform timeout on reads)
56         // Once readers+customizers are asynchronous, pull the timeout to keepalive executor so that keepalive wrapper
57         // is truly generic
58         registry.add(new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp)));
59         //  BridgeDomains(Structural)
60         bridgeDomainsId = vppStateId.child(BridgeDomains.class);
61         registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class);
62         //   BridgeDomain
63         registry.add(getBridgeDomainReader(jVpp, bdContext));
64         return registry.build();
65     }
66
67     static GenericListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> getBridgeDomainReader(
68             final @Nonnull FutureJVppCore jVpp, final @Nonnull NamingContext bdContext) {
69         final InstanceIdentifier<BridgeDomain> bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class);
70         return new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdContext));
71     }
72 }