a4a6e21ab1afe127009f367845cf95192dee8c37
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / trait / SubtableReader.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.lisp.translate.read.trait;
18
19
20 import static com.google.common.base.Preconditions.checkNotNull;
21 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L2;
22 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L3;
23 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.SubtableDumpParamsBuilder;
24
25 import com.google.common.base.Optional;
26 import io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams;
27 import io.fd.honeycomb.translate.ModificationCache;
28 import io.fd.honeycomb.translate.read.ReadFailedException;
29 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
30 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
31 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
32 import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump;
33 import io.fd.vpp.jvpp.core.dto.LispEidTableMapDump;
34 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
35 import javax.annotation.Nonnull;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
38 import org.opendaylight.yangtools.yang.binding.ChildOf;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40
41 /**
42  * Provides common logic for reading Eid subtables
43  */
44 public interface SubtableReader extends JvppReplyConsumer {
45
46     SubtableDumpParams L2_PARAMS = new SubtableDumpParamsBuilder().setL2(L2).build();
47     SubtableDumpParams L3_PARAMS = new SubtableDumpParamsBuilder().setL2(L3).build();
48
49     default EntityDumpExecutor<LispEidTableMapDetailsReplyDump, SubtableDumpParams> createExecutor(
50             @Nonnull final FutureJVppCore vppApi) {
51         return (identifier, params) -> {
52             final LispEidTableMapDump request = new LispEidTableMapDump();
53             request.isL2 = checkNotNull(params, "Cannot bind null params").isL2();
54             return getReplyForRead(vppApi.lispEidTableMapDump(request).toCompletableFuture(), identifier);
55         };
56     }
57 }