2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.mode.impl.add.n.paths;
11 import com.google.common.collect.ImmutableList;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
15 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
16 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
18 abstract class AbstractNPathsRouteEntry extends AddPathAbstractRouteEntry {
19 private final long npaths;
21 AbstractNPathsRouteEntry(final Long npaths) {
26 public final boolean selectBest(final long localAs) {
27 final List<AddPathBestPath> newBestPathList = new ArrayList<>();
28 final List<RouteKey> keyList = this.offsets.getRouteKeysList();
29 final long maxSearch = this.npaths < this.offsets.size()
30 && this.npaths != 0 ? this.npaths : this.offsets.size();
31 for (long i = 0; i < maxSearch; ++i) {
32 final AddPathBestPath newBest = selectBest(localAs, keyList);
33 newBestPathList.add(newBest);
34 keyList.remove(newBest.getRouteKey());
36 return isBestPathNew(ImmutableList.copyOf(newBestPathList));