2 * Copyright (c) 2015 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;
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.nio.charset.StandardCharsets;
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.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import io.fd.vpp.jvpp.VppBaseCallException;
32 import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocs;
33 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
35 public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer implements
36 WriterCustomizer<ItrRemoteLocatorSet>, ByteDataTranslator, JvppReplyConsumer {
38 public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
39 super(futureJVppCore);
43 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id,
44 @Nonnull final ItrRemoteLocatorSet dataAfter,
45 @Nonnull final WriteContext writeContext) throws WriteFailedException {
47 addDelItrRemoteLocatorSet(true, dataAfter);
48 } catch (TimeoutException | VppBaseCallException e) {
49 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
54 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id,
55 @Nonnull final ItrRemoteLocatorSet dataBefore,
56 @Nonnull final ItrRemoteLocatorSet dataAfter,
57 @Nonnull final WriteContext writeContext) throws WriteFailedException {
58 throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter,
59 new UnsupportedOperationException("Operation not supported"));
63 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id,
64 @Nonnull final ItrRemoteLocatorSet dataBefore,
65 @Nonnull final WriteContext writeContext) throws WriteFailedException {
67 addDelItrRemoteLocatorSet(false, dataBefore);
68 } catch (TimeoutException | VppBaseCallException e) {
69 throw new WriteFailedException.DeleteFailedException(id, e);
73 private void addDelItrRemoteLocatorSet(final boolean add, @Nonnull final ItrRemoteLocatorSet data)
74 throws TimeoutException, VppBaseCallException {
76 LispAddDelMapRequestItrRlocs request = new LispAddDelMapRequestItrRlocs();
77 request.isAdd = booleanToByte(add);
78 request.locatorSetName = data.getRemoteLocatorSetName().getBytes(StandardCharsets.UTF_8);
80 getReply(getFutureJVpp().lispAddDelMapRequestItrRlocs(request).toCompletableFuture());