Fix missing return under AbstractBestPathSelector
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / impl / add / AddPathSelector.java
1 /*
2  * Copyright (c) 2016 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.add;
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 public final class AddPathSelector extends AbstractBestPathSelector {
22     private static final Logger LOG = LoggerFactory.getLogger(AddPathSelector.class);
23
24     private RouteKey bestRouteKey;
25     private int bestOffsetPosition;
26     private long bestPathId;
27
28     public AddPathSelector(final long ourAs) {
29         super(ourAs);
30     }
31
32     void processPath(final Attributes attrs, final RouteKey key, final int offsetPosition, final long pathId) {
33         requireNonNull(key.getRouteId(), "Router ID may not be null");
34
35         // Consider only non-null attributes
36         if (attrs != null) {
37             final UnsignedInteger originatorId = replaceOriginator(key.getRouteId(), attrs.getOriginatorId());
38
39             /*
40              * Store the new details if we have nothing stored or when the selection algorithm indicates new details
41              * are better.
42              */
43             final BestPathState state = new BestPathStateImpl(attrs);
44             if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
45                 LOG.trace("Selecting path from router {}", RouterIds.createPeerId(key.getRouteId()).getValue());
46                 this.bestOriginatorId = originatorId;
47                 this.bestState = state;
48                 this.bestRouteKey = key;
49                 this.bestOffsetPosition = offsetPosition;
50                 this.bestPathId = pathId;
51             }
52         }
53     }
54
55     public AddPathBestPath result() {
56         return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey,
57                 this.bestOffsetPosition, this.bestPathId);
58     }
59 }