blob: 12d993b30020ec83a8863ec5bc1f7beb46a9375f [file] [log] [blame]
Jonathan Hartf5829202015-02-12 09:37:02 -08001/*
Jonathan Hartf4bd0482017-01-27 15:11:18 -08002 * Copyright 2017-present Open Networking Laboratory
Jonathan Hartf5829202015-02-12 09:37:02 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jonathan Hartf5829202015-02-12 09:37:02 -080016
Jonathan Hartf4bd0482017-01-27 15:11:18 -080017package org.onosproject.routing;
Jonathan Hartc22e8472015-11-17 18:25:45 -080018
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.IpAddress;
Jonathan Hartf5829202015-02-12 09:37:02 -080021
22import java.util.Objects;
23
Jonathan Hartc22e8472015-11-17 18:25:45 -080024import static com.google.common.base.Preconditions.checkNotNull;
Jonathan Hartf5829202015-02-12 09:37:02 -080025
26/**
Jonathan Hart7baba072015-02-23 14:27:59 -080027 * Identifier for a next hop group.
Jonathan Hartf5829202015-02-12 09:37:02 -080028 */
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070029public class NextHopGroupKey {
Jonathan Hartf5829202015-02-12 09:37:02 -080030
31 private final IpAddress address;
32
Jonathan Hart7baba072015-02-23 14:27:59 -080033 /**
34 * Creates a new next hop group key.
35 *
36 * @param address next hop's IP address
37 */
Jonathan Hartf5829202015-02-12 09:37:02 -080038 public NextHopGroupKey(IpAddress address) {
39 this.address = checkNotNull(address);
40 }
41
Jonathan Hart7baba072015-02-23 14:27:59 -080042 /**
43 * Returns the next hop's IP address.
44 *
45 * @return next hop's IP address
46 */
Jonathan Hartf5829202015-02-12 09:37:02 -080047 public IpAddress address() {
48 return address;
49 }
50
51 @Override
52 public boolean equals(Object o) {
53 if (!(o instanceof NextHopGroupKey)) {
54 return false;
55 }
56
57 NextHopGroupKey that = (NextHopGroupKey) o;
58
59 return Objects.equals(this.address, that.address);
60 }
61
62 @Override
63 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070064 return address.hashCode();
Jonathan Hartf5829202015-02-12 09:37:02 -080065 }
66
67 @Override
68 public String toString() {
69 return MoreObjects.toStringHelper(getClass())
70 .add("address", address)
71 .toString();
72 }
73}