2 * Copyright (c) 2015 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.base;
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 final class BasePathSelector extends AbstractBestPathSelector {
22 private static final Logger LOG = LoggerFactory.getLogger(BasePathSelector.class);
24 private UnsignedInteger bestRouterId = null;
26 BasePathSelector(final Long ourAs) {
30 void processPath(final UnsignedInteger routerId, final Attributes attrs) {
31 requireNonNull(routerId, "Router ID may not be null");
33 // Consider only non-null attributes
35 final UnsignedInteger 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 {}", RouterIds.createPeerId(routerId).getValue());
43 this.bestOriginatorId = originatorId;
44 this.bestRouterId = routerId;
45 this.bestState = state;
51 BaseBestPath result() {
52 return this.bestRouterId == null ? null : new BaseBestPath(this.bestRouterId, this.bestState);