2a066b41737de88e79c9c291f6f1cc26d8a1c321
[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 static com.google.common.base.Preconditions.checkNotNull;
21
22 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
23 import io.fd.hc2vpp.common.translate.util.NamingContext;
24 import io.fd.hc2vpp.l3.utils.ip.write.IpWriter;
25 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
26 import io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.sub._interface.ip6.attributes.ipv6.Address;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.sub._interface.ip6.attributes.ipv6.AddressKey;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33
34 public class SubInterfaceIpv6AddressCustomizer extends FutureJVppCustomizer
35         implements ListWriterCustomizer<Address, AddressKey>, IpWriter {
36
37     private final NamingContext interfaceContext;
38
39     public SubInterfaceIpv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
40                                              @Nonnull final NamingContext interfaceContext) {
41         super(futureJVppCore);
42         this.interfaceContext = checkNotNull(interfaceContext, "interface context should not be null");
43     }
44
45     @Override
46     public void writeCurrentAttributes(InstanceIdentifier<Address> id, Address dataAfter, WriteContext writeContext)
47             throws WriteFailedException {
48         setAddress(true, id, dataAfter, writeContext);
49     }
50
51     @Override
52     public void deleteCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, WriteContext writeContext)
53             throws WriteFailedException {
54         setAddress(false, id, dataBefore, writeContext);
55     }
56
57     private void setAddress(boolean add,
58                             final InstanceIdentifier<Address> id,
59                             final Address address,
60                             final WriteContext writeContext) throws WriteFailedException {
61
62         addDelAddress(getFutureJVpp(), add, id,
63                 subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()), address.getIp(),
64                 address.getPrefixLength().byteValue());
65     }
66 }