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 com.google.common.base.Preconditions;
11 import com.google.common.primitives.UnsignedInteger;
12 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
13 import org.opendaylight.protocol.bgp.mode.impl.BestPathStateImpl;
14 import org.opendaylight.protocol.bgp.mode.spi.AbstractBestPathSelector;
15 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
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 int bestOffsetPosition;
24 private Long bestPathId;
26 public AddPathSelector(final Long ourAs) {
30 public void processPath(final ContainerNode attrs, final RouteKey key, final int offsetPosition, final Long pathId) {
31 Preconditions.checkNotNull(key.getRouteId(), "Router ID may not be null");
33 // Consider only non-null attributes
35 final UnsignedInteger originatorId = replaceOriginator(key.getRouteId(), attrs);
38 * Store the new details if we have nothing stored or when the selection algorithm indicates new details
41 final BestPathState state = new BestPathStateImpl(attrs);
42 if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
43 LOG.trace("Selecting path from router {}", key);
44 this.bestOriginatorId = originatorId;
45 this.bestState = state;
46 this.bestRouteKey = key;
47 this.bestOffsetPosition = offsetPosition;
48 this.bestPathId = pathId;
53 public AddPathBestPath result() {
54 return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey, this.bestOffsetPosition, this.bestPathId);