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;
19 import static com.google.common.base.Preconditions.checkNotNull;
21 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
22 import io.fd.honeycomb.translate.vpp.util.AddressTranslator;
23 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
24 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
25 import io.fd.honeycomb.translate.write.WriteContext;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
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.map.resolvers.grouping.map.resolvers.MapResolver;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolverKey;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.openvpp.jvpp.VppBaseCallException;
33 import org.openvpp.jvpp.core.dto.LispAddDelMapResolver;
34 import org.openvpp.jvpp.core.future.FutureJVppCore;
38 * Handles updates of {@link MapResolver} list
40 public class MapResolverCustomizer extends FutureJVppCustomizer
41 implements ListWriterCustomizer<MapResolver, MapResolverKey>, AddressTranslator,
44 public MapResolverCustomizer(final FutureJVppCore vppApi) {
49 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id,
50 @Nonnull final MapResolver dataAfter, @Nonnull final WriteContext writeContext)
51 throws WriteFailedException {
53 checkNotNull(dataAfter, "Data is null");
54 checkNotNull(dataAfter.getIpAddress(), "Address is null");
57 addDelMapResolverAndReply(true, dataAfter);
58 } catch (VppBaseCallException | TimeoutException e) {
59 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
64 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id,
65 @Nonnull final MapResolver dataBefore, @Nonnull final MapResolver dataAfter,
66 @Nonnull final WriteContext writeContext) throws WriteFailedException {
67 throw new UnsupportedOperationException("Operation not supported");
71 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id,
72 @Nonnull final MapResolver dataBefore, @Nonnull final WriteContext writeContext)
73 throws WriteFailedException {
75 checkNotNull(dataBefore, "Data is null");
76 checkNotNull(dataBefore.getIpAddress(), "Address is null");
79 addDelMapResolverAndReply(false, dataBefore);
80 } catch (VppBaseCallException | TimeoutException e) {
81 throw new WriteFailedException.CreateFailedException(id, dataBefore, e);
85 private void addDelMapResolverAndReply(boolean add, MapResolver data) throws VppBaseCallException,
88 LispAddDelMapResolver request = new LispAddDelMapResolver();
89 request.isAdd = booleanToByte(add);
92 boolean ipv6 = isIpv6(data.getIpAddress());
94 request.isIpv6 = booleanToByte(ipv6);
95 request.ipAddress = ipAddressToArray(ipv6, data.getIpAddress());
97 getReply(getFutureJVpp().lispAddDelMapResolver(request).toCompletableFuture());