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.read.ipv4.subinterface;
19 import com.google.common.base.Optional;
20 import io.fd.hc2vpp.common.translate.util.NamingContext;
21 import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter;
22 import io.fd.hc2vpp.l3.utils.ip.read.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 java.util.List;
31 import java.util.function.Function;
32 import javax.annotation.Nonnull;
33 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4Builder;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.Neighbor;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.NeighborBuilder;
36 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.NeighborKey;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
38 import org.opendaylight.yangtools.concepts.Builder;
39 import org.opendaylight.yangtools.yang.binding.DataObject;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 public class SubInterfaceIpv4NeighbourCustomizer extends IpNeighbourReader
43 implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> {
45 public SubInterfaceIpv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
46 @Nonnull final NamingContext interfaceContext) {
47 super(interfaceContext, false, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>()
48 .withExecutor(createNeighbourDumpExecutor(futureJVppCore))
49 // cached with parent interface scope
50 .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class))
55 public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) {
56 return new NeighborBuilder();
60 public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx)
61 throws ReadFailedException {
63 final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp();
65 final Optional<IpNeighborDetailsReplyDump> dumpOpt = subInterfaceNeighboursDump(id, ctx);
67 if (dumpOpt.isPresent()) {
68 dumpOpt.get().ipNeighborDetails
70 .filter(ipNeighborDetails -> ip.equals(arrayToIpv4AddressNoZone(
71 ipNeighborDetails.neighbor.ipAddress.un.getIp4().ip4Address)))
73 .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv4AddressNoZone(
74 ipNeighborDetails.neighbor.ipAddress.un.getIp4().ip4Address))
75 .withKey(keyMapper().apply(ipNeighborDetails))
76 .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.neighbor.macAddress.macaddress)));
81 public List<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context)
82 throws ReadFailedException {
83 return getNeighborKeys(subInterfaceNeighboursDump(id, context), keyMapper());
87 public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) {
88 ((Ipv4Builder) builder).setNeighbor(readData);
91 private Function<IpNeighborDetails, NeighborKey> keyMapper() {
92 return ipNeighborDetails -> new NeighborKey(
93 arrayToIpv4AddressNoZone(ipNeighborDetails.neighbor.ipAddress.un.getIp4().ip4Address));