4d8bbede0ed1cd04906d65988586987391d5e9d2
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / PitrCfgCustomizer.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;
18
19
20 import io.fd.honeycomb.translate.read.ReadContext;
21 import io.fd.honeycomb.translate.read.ReadFailedException;
22 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
23 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
24 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
25 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
26 import java.util.concurrent.TimeoutException;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder;
30 import org.opendaylight.yangtools.concepts.Builder;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import io.fd.vpp.jvpp.VppBaseCallException;
34 import io.fd.vpp.jvpp.core.dto.ShowLispPitr;
35 import io.fd.vpp.jvpp.core.dto.ShowLispPitrReply;
36 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41 /**
42  * Customizer for reading {@link PitrCfg}<br> Currently unsupported in jvpp
43  */
44 public class PitrCfgCustomizer extends FutureJVppCustomizer
45         implements ReaderCustomizer<PitrCfg, PitrCfgBuilder>, ByteDataTranslator, JvppReplyConsumer {
46
47     private static final Logger LOG = LoggerFactory.getLogger(PitrCfgCustomizer.class);
48
49     public PitrCfgCustomizer(FutureJVppCore futureJvpp) {
50         super(futureJvpp);
51     }
52
53     @Override
54     public PitrCfgBuilder getBuilder(InstanceIdentifier<PitrCfg> id) {
55         return new PitrCfgBuilder();
56     }
57
58     @Override
59     public void readCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfgBuilder builder, ReadContext ctx)
60             throws ReadFailedException {
61         LOG.debug("Reading status for Lisp Pitr node {}", id);
62
63         ShowLispPitrReply reply;
64
65         try {
66             reply = getPitrStatus();
67         } catch (TimeoutException | VppBaseCallException e) {
68             throw new ReadFailedException(id, e);
69         }
70
71         builder.setLocatorSet(toString(reply.locatorSetName));
72         LOG.debug("Reading status for Lisp Pitr node {} successfull", id);
73     }
74
75     @Override
76     public void merge(Builder<? extends DataObject> parentBuilder, PitrCfg readValue) {
77         ((LispFeatureDataBuilder) parentBuilder).setPitrCfg(readValue);
78     }
79
80     public ShowLispPitrReply getPitrStatus() throws TimeoutException, VppBaseCallException {
81         return getReply(getFutureJVpp().showLispPitr(new ShowLispPitr()).toCompletableFuture());
82     }
83 }