blob: ae281e37875e05e551ffe4004a3b98642b55da33 [file] [log] [blame]
Jonathan Hartf5829202015-02-12 09:37:02 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 */
16package org.onosproject.bgprouter;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.group.GroupKey;
21
22import java.util.Objects;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
Jonathan Hart7baba072015-02-23 14:27:59 -080027 * Identifier for a next hop group.
Jonathan Hartf5829202015-02-12 09:37:02 -080028 */
29public class NextHopGroupKey implements GroupKey {
30
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() {
64 return Objects.hash(address);
65 }
66
67 @Override
68 public String toString() {
69 return MoreObjects.toStringHelper(getClass())
70 .add("address", address)
71 .toString();
72 }
73}