HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / write / VrfSubtableCustomizer.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 io.fd.honeycomb.lisp.translate.write.trait.SubtableWriter;
20 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
21 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
22 import io.fd.honeycomb.translate.write.WriteContext;
23 import io.fd.honeycomb.translate.write.WriteFailedException;
24 import java.util.concurrent.TimeoutException;
25 import javax.annotation.Nonnull;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import io.fd.vpp.jvpp.VppBaseCallException;
29 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class VrfSubtableCustomizer extends FutureJVppCustomizer
34         implements WriterCustomizer<VrfSubtable>, SubtableWriter {
35
36     private static final Logger LOG = LoggerFactory.getLogger(VrfSubtableCustomizer.class);
37
38     public VrfSubtableCustomizer(@Nonnull final FutureJVppCore futureJvpp) {
39         super(futureJvpp);
40     }
41
42     @Override
43     public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id,
44                                        @Nonnull final VrfSubtable dataAfter, @Nonnull final WriteContext writeContext)
45             throws WriteFailedException {
46
47         LOG.debug("Writing Id[{}]/Data[{}]", id, dataAfter);
48
49         try {
50             addDelSubtableMapping(getFutureJVpp(), true, extractVni(id), dataAfter.getTableId().intValue(), false, LOG);
51         } catch (TimeoutException | VppBaseCallException e) {
52             throw new WriteFailedException.CreateFailedException(id, dataAfter, e);
53         }
54
55         LOG.debug("{} successfully written", id);
56     }
57
58     @Override
59     public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id,
60                                         @Nonnull final VrfSubtable dataBefore, @Nonnull final VrfSubtable dataAfter,
61                                         @Nonnull final WriteContext writeContext) throws WriteFailedException {
62         throw new UnsupportedOperationException("Operation not supported");
63     }
64
65     @Override
66     public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id,
67                                         @Nonnull final VrfSubtable dataBefore, @Nonnull final WriteContext writeContext)
68             throws WriteFailedException {
69
70         LOG.debug("Removing Id[{}]/Data[{}]", id, dataBefore);
71
72         try {
73             addDelSubtableMapping(getFutureJVpp(), false, extractVni(id), dataBefore.getTableId().intValue(), false,
74                     LOG);
75         } catch (TimeoutException | VppBaseCallException e) {
76             throw new WriteFailedException.CreateFailedException(id, dataBefore, e);
77         }
78
79         LOG.debug("{} successfully removed", id);
80     }
81
82 }