HONEYCOMB-206: change package name to match groupId
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / write / PitrCfgCustomizer.java
1 /*
2  * Copyright (c) 2015 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.write;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20 import static java.nio.charset.StandardCharsets.UTF_8;
21
22 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
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 io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
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;
34
35
36 /**
37  * Customizer for {@code PitrCfg}
38  */
39 public class PitrCfgCustomizer extends FutureJVppCustomizer
40         implements WriterCustomizer<PitrCfg>, JvppReplyConsumer, ByteDataTranslator {
41
42     public PitrCfgCustomizer(FutureJVppCore futureJvpp) {
43         super(futureJvpp);
44     }
45
46     @Override
47     public void writeCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataAfter, WriteContext writeContext)
48             throws WriteFailedException {
49         checkNotNull(dataAfter, "PitrCfg is null");
50         checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null");
51
52         try {
53             addDelPitrSetLocatorSetAndReply(true, dataAfter);
54         } catch (VppBaseCallException | TimeoutException e) {
55             throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
56         }
57     }
58
59     @Override
60     public void updateCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, PitrCfg dataAfter,
61                                         WriteContext writeContext) throws WriteFailedException {
62         checkNotNull(dataAfter, "PitrCfg is null");
63         checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null");
64
65         try {
66             addDelPitrSetLocatorSetAndReply(true, dataAfter);
67         } catch (VppBaseCallException | TimeoutException e) {
68             throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
69         }
70     }
71
72     @Override
73     public void deleteCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, WriteContext writeContext)
74             throws WriteFailedException {
75         checkNotNull(dataBefore, "PitrCfg is null");
76         checkNotNull(dataBefore.getLocatorSet(), "Locator set name is null");
77
78         try {
79             addDelPitrSetLocatorSetAndReply(false, dataBefore);
80         } catch (VppBaseCallException | TimeoutException e) {
81             throw new WriteFailedException.CreateFailedException(id, dataBefore, e);
82         }
83     }
84
85     private void addDelPitrSetLocatorSetAndReply(boolean add, PitrCfg data)
86             throws VppBaseCallException, TimeoutException {
87
88         LispPitrSetLocatorSet request = new LispPitrSetLocatorSet();
89         request.isAdd = booleanToByte(add);
90         request.lsName = data.getLocatorSet().getBytes(UTF_8);
91
92         getReply(getFutureJVpp().lispPitrSetLocatorSet(request).toCompletableFuture());
93     }
94
95 }