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.add;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.primitives.UnsignedInteger;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
16 import org.opendaylight.protocol.bgp.mode.spi.AbstractBestPath;
17 import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
20 public final class AddPathBestPath extends AbstractBestPath {
21 private final RouteKey routeKey;
22 private final int offsetPosition;
23 private final long pathId;
25 public AddPathBestPath(@Nonnull final BestPathState state, @Nonnull final RouteKey key, final int offsetPosition,
28 this.routeKey = requireNonNull(key);
29 this.offsetPosition = offsetPosition;
33 public RouteKey getRouteKey() {
38 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
39 toStringHelper.add("routeKey", this.routeKey);
40 toStringHelper.add("state", this.state);
41 toStringHelper.add("offsetPosition", this.offsetPosition);
42 toStringHelper.add("pathId", this.pathId);
43 return toStringHelper;
47 public int hashCode() {
50 result = prime * result + this.routeKey.hashCode();
51 result = prime * result + this.state.hashCode();
56 public boolean equals(final Object obj) {
60 if (!(obj instanceof AddPathBestPath)) {
63 final AddPathBestPath other = (AddPathBestPath) obj;
64 if (!this.routeKey.equals(other.routeKey)) {
68 We don't check offset position since it will change as new path is added, and we want to be able
69 to use List comparison between old bestpath list and new best path list.
71 if (!this.state.equals(other.state)) {
75 return this.pathId == other.pathId;
79 public UnsignedInteger getRouterId() {
80 return this.routeKey.getRouteId();
84 public PeerId getPeerId() {
85 return RouterIds.createPeerId(this.routeKey.getRouteId());
89 public long getPathId() {