2 * Copyright (c) 2017 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.hc2vpp.l3.write.ipv6.subinterface;
20 import static com.google.common.base.Preconditions.checkNotNull;
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.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.Address;
31 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.AddressKey;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 public class SubInterfaceIpv6AddressCustomizer extends FutureJVppCustomizer
35 implements ListWriterCustomizer<Address, AddressKey>, IpWriter {
37 private final NamingContext interfaceContext;
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");
46 public void writeCurrentAttributes(InstanceIdentifier<Address> id, Address dataAfter, WriteContext writeContext)
47 throws WriteFailedException {
48 setAddress(true, id, dataAfter, writeContext);
52 public void deleteCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, WriteContext writeContext)
53 throws WriteFailedException {
54 setAddress(false, id, dataBefore, writeContext);
57 private void setAddress(boolean add,
58 final InstanceIdentifier<Address> id,
59 final Address address,
60 final WriteContext writeContext) throws WriteFailedException {
62 addDelAddress(getFutureJVpp(), add, id,
63 subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()), address.getIp(),
64 address.getPrefixLength().byteValue());