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.v3po.interfacesstate.ip.v6.subinterface;
19 import com.google.common.base.Optional;
20 import io.fd.hc2vpp.common.translate.util.NamingContext;
21 import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter;
22 import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpNeighbourReader;
23 import io.fd.honeycomb.translate.read.ReadContext;
24 import io.fd.honeycomb.translate.read.ReadFailedException;
25 import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
26 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder;
27 import io.fd.vpp.jvpp.core.dto.IpNeighborDetails;
28 import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump;
29 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6Builder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborKey;
35 import org.opendaylight.yangtools.concepts.Builder;
36 import org.opendaylight.yangtools.yang.binding.DataObject;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import javax.annotation.Nonnull;
40 import java.util.List;
41 import java.util.function.Function;
43 public class SubInterfaceIpv6NeighbourCustomizer extends IpNeighbourReader
44 implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> {
46 public SubInterfaceIpv6NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
47 @Nonnull final NamingContext interfaceContext) {
48 super(interfaceContext, true, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>()
49 .withExecutor(createNeighbourDumpExecutor(futureJVppCore))
50 // cached with parent interface scope
51 .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class))
56 public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) {
57 return new NeighborBuilder();
61 public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx)
62 throws ReadFailedException {
64 final Ipv6AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp();
66 final Optional<IpNeighborDetailsReplyDump> dumpOpt = subInterfaceNeighboursDump(id, ctx);
68 if (dumpOpt.isPresent()) {
69 dumpOpt.get().ipNeighborDetails
71 .filter(ipNeighborDetails -> ip.equals(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)))
73 .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress))
74 .setKey(keyMapper().apply(ipNeighborDetails))
75 .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress)));
80 public List<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context)
81 throws ReadFailedException {
82 return getNeighborKeys(subInterfaceNeighboursDump(id, context), keyMapper());
86 public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) {
87 ((Ipv6Builder) builder).setNeighbor(readData);
90 private Function<IpNeighborDetails, NeighborKey> keyMapper() {
91 return ipNeighborDetails -> new NeighborKey(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress));