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
8 package org.opendaylight.protocol.bgp.mode.impl.add;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.primitives.UnsignedInteger;
13 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
14 import org.opendaylight.protocol.bgp.mode.impl.BestPathStateImpl;
15 import org.opendaylight.protocol.bgp.mode.spi.AbstractBestPathSelector;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public final class AddPathSelector extends AbstractBestPathSelector {
21 private static final Logger LOG = LoggerFactory.getLogger(AddPathSelector.class);
23 private RouteKey bestRouteKey;
24 private int bestOffsetPosition;
25 private Long bestPathId;
27 public AddPathSelector(final Long ourAs) {
31 void processPath(final ContainerNode attrs, final RouteKey key, final int offsetPosition, final Long pathId) {
32 requireNonNull(key.getRouteId(), "Router ID may not be null");
34 // Consider only non-null attributes
36 final UnsignedInteger originatorId = replaceOriginator(key.getRouteId(), attrs);
39 * Store the new details if we have nothing stored or when the selection algorithm indicates new details
42 final BestPathState state = new BestPathStateImpl(attrs);
43 if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
44 LOG.trace("Selecting path from router {}", key);
45 this.bestOriginatorId = originatorId;
46 this.bestState = state;
47 this.bestRouteKey = key;
48 this.bestOffsetPosition = offsetPosition;
49 this.bestPathId = pathId;
54 public AddPathBestPath result() {
55 return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey,
56 this.bestOffsetPosition, this.bestPathId);