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 static final Logger LOG = LoggerFactory.getLogger(AbstractNPathsRouteEntry.class);
22 private final long nBestPaths;
24 AbstractNPathsRouteEntry(final Long nBestPaths) {
25 this.nBestPaths = nBestPaths;
29 public final boolean selectBest(final long localAs) {
30 final List<AddPathBestPath> newBestPathList = new ArrayList<>();
31 final List<RouteKey> keyList = this.offsets.getRouteKeysList();
32 final long maxSearch = this.nBestPaths < this.offsets.size() && this.nBestPaths != 0 ? this.nBestPaths : this.offsets.size();
33 for (long i = 0; i < maxSearch; ++i) {
34 final AddPathBestPath newBest = selectBest(localAs, keyList);
35 newBestPathList.add(newBest);
36 keyList.remove(newBest.getRouteKey());
39 if(this.bestPath != null) {
40 this.bestPathRemoved = new ArrayList<>(this.bestPath);
42 if (!newBestPathList.equals(this.bestPath) ||
43 this.bestPathRemoved != null && this.bestPathRemoved.removeAll(newBestPathList) && !this.bestPathRemoved.isEmpty()) {
44 this.bestPath = newBestPathList;
45 LOG.trace("Actual Best {}, removed best {}", this.bestPath, this.bestPathRemoved);