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.yangtools.yang.data.api.schema.ContainerNode;
23 abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
25 public final boolean selectBest(final long localAs) {
26 final List<AddPathBestPath> newBestPathList = new ArrayList<>();
27 final List<RouteKey> keyList = this.offsets.getRouteKeysList();
29 if (!keyList.isEmpty()) {
30 /* we set the best path first on List for not supported Add path cases*/
31 final AddPathBestPath newBest = selectBest(localAs, keyList);
32 newBestPathList.add(newBest);
33 keyList.remove(newBest.getRouteKey());
34 /*we add the rest of path, regardless in what order they are, since this is all path case */
35 for (final RouteKey key : keyList) {
36 final int offset = this.offsets.offsetOf(key);
37 final ContainerNode attributes = this.offsets.getValue(this.values, offset);
38 requireNonNull(key.getRouteId(), "Router ID may not be null");
39 if (attributes != null) {
40 final BestPathState state = new BestPathStateImpl(attributes);
41 final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset,
42 this.offsets.getValue(this.pathsId, offset));
43 newBestPathList.add(bestPath);
47 return isBestPathNew(ImmutableList.copyOf(newBestPathList));