Fix missing return under AbstractBestPathSelector
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / impl / base / BasePathSelector.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.mode.impl.base;
9
10 import static java.util.Objects.requireNonNull;
11
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;
20
21 final class BasePathSelector extends AbstractBestPathSelector {
22     private static final Logger LOG = LoggerFactory.getLogger(BasePathSelector.class);
23
24     private UnsignedInteger bestRouterId = null;
25
26     BasePathSelector(final Long ourAs) {
27         super(ourAs);
28     }
29
30     void processPath(final UnsignedInteger routerId, final Attributes attrs) {
31         requireNonNull(routerId, "Router ID may not be null");
32
33         // Consider only non-null attributes
34         if (attrs != null) {
35             final UnsignedInteger originatorId = replaceOriginator(routerId, attrs.getOriginatorId());
36             /*
37              * Store the new details if we have nothing stored or when the selection algorithm indicates new details
38              * are better.
39              */
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;
46             }
47         }
48     }
49
50
51     BaseBestPath result() {
52         return this.bestRouterId == null ? null : new BaseBestPath(this.bestRouterId, this.bestState);
53     }
54 }