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 org.opendaylight.protocol.bgp.mode.api.BestPathState;
11 import org.opendaylight.protocol.bgp.mode.impl.BestPathStateImpl;
12 import org.opendaylight.protocol.bgp.mode.spi.AbstractBestPathSelector;
13 import org.opendaylight.protocol.bgp.rib.spi.RouterId;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public final class AddPathSelector extends AbstractBestPathSelector {
20 private static final Logger LOG = LoggerFactory.getLogger(AddPathSelector.class);
22 private RouteKey bestRouteKey;
23 private Uint32 bestPathId;
24 private int bestOffset;
26 public AddPathSelector(final long ourAs) {
30 void processPath(final Attributes attrs, final RouteKey key, final int offsetPosition, final Uint32 pathId) {
31 // Consider only non-null attributes
33 final RouterId routerId = key.getRouterId();
34 final RouterId originatorId = replaceOriginator(routerId, attrs.getOriginatorId());
37 * Store the new details if we have nothing stored or when the selection algorithm indicates new details
40 final BestPathState state = new BestPathStateImpl(attrs);
41 if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
42 LOG.trace("Selecting path from router {}", routerId);
43 this.bestOriginatorId = originatorId;
44 this.bestState = state;
45 this.bestRouteKey = key;
46 this.bestOffset = offsetPosition;
47 this.bestPathId = pathId;
52 public AddPathBestPath result() {
53 return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey,
54 this.bestPathId, this.bestOffset);