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 java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
14 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
15 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 abstract class AbstractNPathsRouteEntry extends AddPathAbstractRouteEntry {
20 private final long nBestPaths;
22 AbstractNPathsRouteEntry(final Long nBestPaths) {
23 this.nBestPaths = nBestPaths;
27 public final boolean selectBest(final long localAs) {
28 final List<AddPathBestPath> newBestPathList = new ArrayList<>();
29 final List<RouteKey> keyList = this.offsets.getRouteKeysList();
30 final long maxSearch = this.nBestPaths < this.offsets.size() && this.nBestPaths != 0 ? this.nBestPaths : 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(newBestPathList);