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.protocol.bgp.rib.spi.RouterIds;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public final class AddPathSelector extends AbstractBestPathSelector {
22 private static final Logger LOG = LoggerFactory.getLogger(AddPathSelector.class);
24 private RouteKey bestRouteKey;
25 private int bestOffsetPosition;
26 private long bestPathId;
28 public AddPathSelector(final long ourAs) {
32 void processPath(final Attributes attrs, final RouteKey key, final int offsetPosition, final long pathId) {
33 requireNonNull(key.getRouteId(), "Router ID may not be null");
35 // Consider only non-null attributes
37 final UnsignedInteger originatorId = replaceOriginator(key.getRouteId(), attrs.getOriginatorId());
40 * Store the new details if we have nothing stored or when the selection algorithm indicates new details
43 final BestPathState state = new BestPathStateImpl(attrs);
44 if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
45 LOG.trace("Selecting path from router {}", RouterIds.createPeerId(key.getRouteId()).getValue());
46 this.bestOriginatorId = originatorId;
47 this.bestState = state;
48 this.bestRouteKey = key;
49 this.bestOffsetPosition = offsetPosition;
50 this.bestPathId = pathId;
55 public AddPathBestPath result() {
56 return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey,
57 this.bestOffsetPosition, this.bestPathId);