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.all.paths;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.collect.ImmutableList;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
17 import org.opendaylight.protocol.bgp.mode.impl.BestPathStateImpl;
18 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
19 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
20 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
21 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
24 abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
25 AbstractAllPathsRouteEntry(final BGPPeerTracker peerTracker) {
30 public final boolean selectBest(final long localAs) {
31 final List<AddPathBestPath> newBestPathList = new ArrayList<>();
32 final List<RouteKey> keyList = this.offsets.getRouteKeysList();
34 if (!keyList.isEmpty()) {
35 /* we set the best path first on List for not supported Add path cases*/
36 final AddPathBestPath newBest = selectBest(localAs, keyList);
37 newBestPathList.add(newBest);
38 keyList.remove(newBest.getRouteKey());
39 /*we add the rest of path, regardless in what order they are, since this is all path case */
40 for (final RouteKey key : keyList) {
41 final int offset = this.offsets.offsetOf(key);
42 final Attributes attributes = this.offsets.getValue(this.values, offset);
43 requireNonNull(key.getRouteId(), "Router ID may not be null");
44 if (attributes != null) {
45 final BestPathState state = new BestPathStateImpl(attributes);
46 final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset,
47 this.offsets.getValue(this.pathsId, offset));
48 newBestPathList.add(bestPath);
52 return isBestPathNew(ImmutableList.copyOf(newBestPathList));