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 com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableList;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
16 import org.opendaylight.protocol.bgp.mode.impl.BestPathStateImpl;
17 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
18 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
19 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
20 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
26 public final boolean selectBest(final long localAs) {
27 final List<AddPathBestPath> newBestPathList = new ArrayList<>();
28 final List<RouteKey> keyList = this.offsets.getRouteKeysList();
30 if (!keyList.isEmpty()) {
31 /* we set the best path first on List for not supported Add path cases*/
32 final AddPathBestPath newBest = selectBest(localAs, keyList);
33 newBestPathList.add(newBest);
34 keyList.remove(newBest.getRouteKey());
35 /*we add the rest of path, regardless in what order they are, since this is all path case */
36 for (final RouteKey key : keyList) {
37 final int offset = this.offsets.offsetOf(key);
38 final ContainerNode attributes = this.offsets.getValue(this.values, offset);
39 Preconditions.checkNotNull(key.getRouteId(), "Router ID may not be null");
40 if (attributes != null) {
41 final BestPathState state = new BestPathStateImpl(attributes);
42 final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset, this.offsets.getValue(this.pathsId, offset));
43 newBestPathList.add(bestPath);
47 return isBestPathNew(ImmutableList.copyOf(newBestPathList));