375aad0f9efbd2d63a036025bdb559e887182f4e
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.hc2vpp.srv6.write.encap.source;
18
19 import com.google.common.annotations.VisibleForTesting;
20 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
21 import io.fd.hc2vpp.srv6.write.encap.source.request.EncapsulationSourceDeleteRequest;
22 import io.fd.hc2vpp.srv6.write.encap.source.request.EncapsulationSourceWriteRequest;
23 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
24 import io.fd.honeycomb.translate.write.WriteContext;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.Encapsulation;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 public class EncapsulationSourceCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Encapsulation> {
32
33     public EncapsulationSourceCustomizer(@Nonnull FutureJVppCore futureJVppCore) {
34         super(futureJVppCore);
35     }
36
37     @Override
38     public void writeCurrentAttributes(@Nonnull InstanceIdentifier<Encapsulation> instanceIdentifier,
39                                        @Nonnull Encapsulation encapsulation, @Nonnull WriteContext writeContext)
40             throws WriteFailedException {
41         bindEncapsulationSourceWriteRequest(encapsulation).write(instanceIdentifier);
42
43     }
44
45     private EncapsulationSourceWriteRequest bindEncapsulationSourceWriteRequest(Encapsulation encapsulation) {
46         return new EncapsulationSourceWriteRequest(getFutureJVpp()).setBsid(encapsulation.getSourceAddress());
47     }
48
49     @Override
50     public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Encapsulation> instanceIdentifier,
51                                         @Nonnull Encapsulation encapsulation, @Nonnull WriteContext writeContext)
52             throws WriteFailedException {
53         bindEncapsulationSourceDeleteRequest().delete(instanceIdentifier);
54     }
55
56     @VisibleForTesting
57     private EncapsulationSourceDeleteRequest bindEncapsulationSourceDeleteRequest() {
58         return new EncapsulationSourceDeleteRequest(getFutureJVpp());
59     }
60 }