8ea8ced9889e7627c9b9ba6226d1f250073c104d
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2017 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.hc2vpp.l3.write.ipv6.subinterface;
18
19
20 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
21 import io.fd.hc2vpp.common.translate.util.NamingContext;
22 import io.fd.hc2vpp.l3.utils.ip.write.IpWriter;
23 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
24 import io.fd.honeycomb.translate.write.WriteContext;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.jvpp.core.future.FutureJVppCore;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.Address;
29 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.AddressKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 public class SubInterfaceIpv6AddressCustomizer extends FutureJVppCustomizer
33         implements ListWriterCustomizer<Address, AddressKey>, IpWriter {
34
35     private final NamingContext interfaceContext;
36
37     public SubInterfaceIpv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
38                                              @Nonnull final NamingContext interfaceContext) {
39         super(futureJVppCore);
40         this.interfaceContext = interfaceContext;
41     }
42
43     @Override
44     public void writeCurrentAttributes(InstanceIdentifier<Address> id, Address dataAfter, WriteContext writeContext)
45             throws WriteFailedException {
46         setAddress(true, id, dataAfter, writeContext);
47     }
48
49     @Override
50     public void deleteCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, WriteContext writeContext)
51             throws WriteFailedException {
52         setAddress(false, id, dataBefore, writeContext);
53     }
54
55     private void setAddress(boolean add,
56                             final InstanceIdentifier<Address> id,
57                             final Address address,
58                             final WriteContext writeContext) throws WriteFailedException {
59
60         addDelAddress(getFutureJVpp(), add, id,
61                 subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()), address.getIp(),
62                 address.getPrefixLength().byteValue());
63     }
64 }