54fef659e5b6a3569054bb7adc4bf8e4aae5f034
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / trait / LocatorReader.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 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams;
22 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
23 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
24 import io.fd.vpp.jvpp.core.dto.LispLocatorDetailsReplyDump;
25 import io.fd.vpp.jvpp.core.dto.LispLocatorDump;
26 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
27 import javax.annotation.Nonnull;
28
29 /**
30  * Provides common logic for reading of locators
31  */
32 public interface LocatorReader extends JvppReplyConsumer {
33
34     default EntityDumpExecutor<LispLocatorDetailsReplyDump, LocatorDumpParams> createLocatorDumpExecutor(
35             @Nonnull final FutureJVppCore vppApi) {
36         return (identifier, params) -> {
37             checkNotNull(params, "Params for dump request not present");
38             final LispLocatorDump request = new LispLocatorDump();
39             request.lsIndex = params.getLocatorSetIndex();
40             //flag that lsIndex is set
41             request.isIndexSet = (byte) 1;
42
43             return getReplyForRead(vppApi.lispLocatorDump(request).toCompletableFuture(), identifier);
44         };
45     }
46 }