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.yangtools.yang.data.api.schema.ContainerNode;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 final class BasePathSelector extends AbstractBestPathSelector {
21 private static final Logger LOG = LoggerFactory.getLogger(BasePathSelector.class);
23 private UnsignedInteger bestRouterId = null;
25 BasePathSelector(final Long ourAs) {
29 void processPath(final UnsignedInteger routerId, final ContainerNode attrs) {
30 requireNonNull(routerId, "Router ID may not be null");
32 // Consider only non-null attributes
34 final UnsignedInteger originatorId = replaceOriginator(routerId, attrs);
36 * Store the new details if we have nothing stored or when the selection algorithm indicates new details
39 final BestPathState state = new BestPathStateImpl(attrs);
40 if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
41 LOG.trace("Selecting path from router {}", routerId);
42 this.bestOriginatorId = originatorId;
43 this.bestRouterId = routerId;
44 this.bestState = state;
50 BaseBestPath result() {
51 return this.bestRouterId == null ? null : new BaseBestPath(this.bestRouterId, this.bestState);