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 org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
15 import org.opendaylight.protocol.bgp.mode.spi.AbstractBestPath;
16 import org.opendaylight.protocol.bgp.rib.spi.RouterId;
17 import org.opendaylight.yangtools.yang.common.Uint32;
19 public final class AddPathBestPath extends AbstractBestPath {
20 private final @NonNull RouteKey routeKey;
21 private final @NonNull Uint32 pathId;
22 private final int offset;
24 AddPathBestPath(final @NonNull BestPathState state, final @NonNull RouteKey key, final @NonNull Uint32 pathId,
27 this.routeKey = requireNonNull(key);
28 this.pathId = requireNonNull(pathId);
32 RouteKey getRouteKey() {
36 public int getOffset() {
41 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
42 return super.addToStringAttributes(toStringHelper.add("routeKey", this.routeKey)
43 .add("pathId", this.pathId)
44 .add("offset", offset));
48 public int hashCode() {
51 result = prime * result + this.routeKey.hashCode();
52 result = prime * result + this.state.hashCode();
57 public boolean equals(final Object obj) {
61 if (!(obj instanceof AddPathBestPath)) {
64 final AddPathBestPath other = (AddPathBestPath) obj;
65 if (!this.routeKey.equals(other.routeKey)) {
69 We don't check offset position since it will change as new path is added, and we want to be able
70 to use List comparison between old bestpath list and new best path list.
72 if (!this.state.equals(other.state)) {
76 return this.pathId.equals(other.pathId);
80 public RouterId getRouterId() {
81 return this.routeKey.getRouterId();
85 public long getPathId() {
86 // FIXME: this should return int bits...
87 return this.pathId.longValue();
91 * Return the boxed value equivalent of {@link #getPathId()}. This class uses boxed instances internally, hence
92 * this method exposes it.
94 * @return Path Id as a {@link Long}
96 @NonNull Uint32 getPathIdLong() {