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;
20 import static java.nio.charset.StandardCharsets.UTF_8;
22 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
23 import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
24 import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
25 import io.fd.honeycomb.translate.write.WriteContext;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import java.nio.charset.StandardCharsets;
28 import java.util.concurrent.TimeoutException;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.openvpp.jvpp.VppBaseCallException;
32 import org.openvpp.jvpp.core.dto.LispPitrSetLocatorSet;
33 import org.openvpp.jvpp.core.future.FutureJVppCore;
37 * Customizer for {@code PitrCfg}
39 public class PitrCfgCustomizer extends FutureJVppCustomizer implements WriterCustomizer<PitrCfg> {
41 public PitrCfgCustomizer(FutureJVppCore futureJvpp) {
46 public void writeCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataAfter, WriteContext writeContext)
47 throws WriteFailedException {
48 checkNotNull(dataAfter, "PitrCfg is null");
49 checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null");
52 addDelPitrSetLocatorSetAndReply(true, dataAfter);
53 } catch (VppBaseCallException | TimeoutException e) {
54 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
59 public void updateCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, PitrCfg dataAfter,
60 WriteContext writeContext) throws WriteFailedException {
61 checkNotNull(dataAfter, "PitrCfg is null");
62 checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null");
65 addDelPitrSetLocatorSetAndReply(true, dataAfter);
66 } catch (VppBaseCallException | TimeoutException e) {
67 throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
72 public void deleteCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, WriteContext writeContext)
73 throws WriteFailedException {
74 checkNotNull(dataBefore, "PitrCfg is null");
75 checkNotNull(dataBefore.getLocatorSet(), "Locator set name is null");
78 addDelPitrSetLocatorSetAndReply(false, dataBefore);
79 } catch (VppBaseCallException | TimeoutException e) {
80 throw new WriteFailedException.CreateFailedException(id, dataBefore, e);
84 private void addDelPitrSetLocatorSetAndReply(boolean add, PitrCfg data)
85 throws VppBaseCallException, TimeoutException {
87 LispPitrSetLocatorSet request = new LispPitrSetLocatorSet();
88 request.isAdd = TranslateUtils.booleanToByte(add);
89 request.lsName = data.getLocatorSet().getBytes(UTF_8);
91 TranslateUtils.getReply(getFutureJVpp().lispPitrSetLocatorSet(request).toCompletableFuture());