blob: 313b537ccdfedb07723c2881140a20ad80d6f090 [file] [log] [blame]
Jonathan Hartfd176612016-04-11 10:42:10 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hartfd176612016-04-11 10:42:10 -07003 *
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 */
16
17package org.onosproject.incubator.net.routing;
18
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21
22import java.util.Objects;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Describes a routing next hop.
28 */
29public class NextHop {
30
31 private final IpAddress ip;
32 private final MacAddress mac;
33
34 /**
35 * Creates a new next hop.
36 *
37 * @param ip IP address
38 * @param mac MAC address
39 */
40 public NextHop(IpAddress ip, MacAddress mac) {
41 this.ip = ip;
42 this.mac = mac;
43 }
44
45 /**
46 * Returns the IP address of the next hop.
47 *
48 * @return IP address
49 */
50 public IpAddress ip() {
51 return ip;
52 }
53
54 /**
55 * Returns the MAC address of the next hop.
56 *
57 * @return MAC address
58 */
59 public MacAddress mac() {
60 return mac;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(ip, mac);
66 }
67
68 @Override
69 public boolean equals(Object other) {
70 if (this == other) {
71 return true;
72 }
73
74 if (!(other instanceof NextHop)) {
75 return false;
76 }
77
78 NextHop that = (NextHop) other;
79
HIGUCHI Yuta0a011be2016-05-03 14:52:03 -070080 return Objects.equals(this.ip, that.ip) &&
81 Objects.equals(this.mac, that.mac);
Jonathan Hartfd176612016-04-11 10:42:10 -070082 }
83
84 @Override
85 public String toString() {
86 return toStringHelper(this)
87 .add("ip", ip)
88 .add("mac", mac)
89 .toString();
90 }
91}