0ecf13108523573fc7cbac283247d434c0a31b02
[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.request;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import io.fd.hc2vpp.srv6.util.JVppRequest;
22 import io.fd.hc2vpp.srv6.write.WriteRequest;
23 import io.fd.honeycomb.translate.write.WriteFailedException;
24 import io.fd.vpp.jvpp.core.dto.SrSetEncapSource;
25 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 public class EncapsulationSourceWriteRequest extends JVppRequest implements WriteRequest {
30
31     private Ipv6Address bsid;
32
33     public EncapsulationSourceWriteRequest(final FutureJVppCore api) {
34         super(api);
35     }
36
37     @Override
38     public void checkValid() {
39         checkNotNull(bsid, "Binding SID must be set");
40     }
41
42     public Ipv6Address getBsid() {
43         return bsid;
44     }
45
46     public EncapsulationSourceWriteRequest setBsid(final Ipv6Address bsid) {
47         this.bsid = bsid;
48         return this;
49     }
50
51     @Override
52     public void write(final InstanceIdentifier<?> identifier) throws WriteFailedException {
53         checkValid();
54         final SrSetEncapSource request = new SrSetEncapSource();
55         request.encapsSource = ipv6AddressNoZoneToArray(bsid);
56         getReplyForWrite(getApi().srSetEncapSource(request).toCompletableFuture(), identifier);
57     }
58 }