2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.lisp.translate.write;
19 import com.google.common.base.Preconditions;
20 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
21 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
22 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
23 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
24 import io.fd.honeycomb.translate.write.WriteContext;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import java.util.concurrent.CompletionStage;
27 import java.util.concurrent.TimeoutException;
28 import javax.annotation.Nonnull;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import io.fd.vpp.jvpp.VppBaseCallException;
32 import io.fd.vpp.jvpp.core.dto.LispEnableDisable;
33 import io.fd.vpp.jvpp.core.dto.LispEnableDisableReply;
34 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
38 * Handles updates of {@link Lisp} node. Takes care of LISP enable/disable
40 public class LispCustomizer extends FutureJVppCustomizer
41 implements WriterCustomizer<Lisp>, ByteDataTranslator, JvppReplyConsumer {
43 public LispCustomizer(final FutureJVppCore vppApi) {
48 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Lisp> id, @Nonnull final Lisp dataAfter,
49 @Nonnull final WriteContext writeContext) throws WriteFailedException {
50 Preconditions.checkNotNull(dataAfter, "Lisp is null");
53 enableDisableLisp(dataAfter.isEnable());
54 } catch (VppBaseCallException | TimeoutException e) {
55 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
60 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Lisp> id, @Nonnull final Lisp dataBefore,
61 @Nonnull final Lisp dataAfter, @Nonnull final WriteContext writeContext)
62 throws WriteFailedException {
63 Preconditions.checkNotNull(dataAfter, "Lisp is null");
66 enableDisableLisp(dataAfter.isEnable());
67 } catch (VppBaseCallException | TimeoutException e) {
68 throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e);
73 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Lisp> id, @Nonnull final Lisp dataBefore,
74 @Nonnull final WriteContext writeContext) throws WriteFailedException {
75 Preconditions.checkNotNull(dataBefore, "Lisp is null");
78 enableDisableLisp(false);
79 } catch (VppBaseCallException | TimeoutException e) {
80 throw new WriteFailedException.DeleteFailedException(id, e);
86 private void enableDisableLisp(final boolean enable) throws VppBaseCallException, TimeoutException {
87 final CompletionStage<LispEnableDisableReply> lispEnableDisableReplyCompletionStage =
88 getFutureJVpp().lispEnableDisable(getRequest(enable));
89 getReply(lispEnableDisableReplyCompletionStage.toCompletableFuture());
92 private LispEnableDisable getRequest(final boolean enable) {
93 final LispEnableDisable lispEnableDisable = new LispEnableDisable();
94 lispEnableDisable.isEn = booleanToByte(enable);
95 return lispEnableDisable;