8348c8a2562ee73af4c86fabfe7b2a81caca88d6
[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.v3po.interfaces.ip.v6.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.v3po.interfaces.ip.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.rev161214.sub._interface.ip6.attributes.ipv6.Address;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.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 updateCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, Address dataAfter,
53                                         WriteContext writeContext) throws WriteFailedException {
54         throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter,
55                 new UnsupportedOperationException("Operation not supported"));
56     }
57
58     @Override
59     public void deleteCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, WriteContext writeContext)
60             throws WriteFailedException {
61         setAddress(false, id, dataBefore, writeContext);
62     }
63
64     private void setAddress(boolean add,
65                             final InstanceIdentifier<Address> id,
66                             final Address address,
67                             final WriteContext writeContext) throws WriteFailedException {
68
69         addDelAddress(getFutureJVpp(), add, id,
70                 subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()), address.getIp(),
71                 address.getPrefixLength().byteValue());
72     }
73 }