Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 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 | */ |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 16 | |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 17 | package org.onosproject.routing; |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import org.onlab.packet.IpAddress; |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 21 | |
| 22 | import java.util.Objects; |
| 23 | |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 27 | * Identifier for a next hop group. |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 28 | */ |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 29 | public class NextHopGroupKey { |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 30 | |
| 31 | private final IpAddress address; |
| 32 | |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 33 | /** |
| 34 | * Creates a new next hop group key. |
| 35 | * |
| 36 | * @param address next hop's IP address |
| 37 | */ |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 38 | public NextHopGroupKey(IpAddress address) { |
| 39 | this.address = checkNotNull(address); |
| 40 | } |
| 41 | |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Returns the next hop's IP address. |
| 44 | * |
| 45 | * @return next hop's IP address |
| 46 | */ |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 47 | 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 Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 64 | return address.hashCode(); |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public String toString() { |
| 69 | return MoreObjects.toStringHelper(getClass()) |
| 70 | .add("address", address) |
| 71 | .toString(); |
| 72 | } |
| 73 | } |