blob: 024174255ea3c63665293a83e4b65b27908096d6 [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;
Charles Chanc78a0982016-11-09 16:52:11 -080021import org.onosproject.net.ConnectPoint;
Jonathan Hartfd176612016-04-11 10:42:10 -070022
23import java.util.Objects;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26
27/**
28 * Describes a routing next hop.
29 */
30public class NextHop {
31
32 private final IpAddress ip;
Charles Chanc78a0982016-11-09 16:52:11 -080033 private final NextHopData nextHopData;
Jonathan Hartfd176612016-04-11 10:42:10 -070034
35 /**
36 * Creates a new next hop.
37 *
38 * @param ip IP address
Charles Chanc78a0982016-11-09 16:52:11 -080039 * @param nextHopData Next hop data
Jonathan Hartfd176612016-04-11 10:42:10 -070040 */
Charles Chanc78a0982016-11-09 16:52:11 -080041 public NextHop(IpAddress ip, NextHopData nextHopData) {
Jonathan Hartfd176612016-04-11 10:42:10 -070042 this.ip = ip;
Charles Chanc78a0982016-11-09 16:52:11 -080043 this.nextHopData = nextHopData;
Jonathan Hartfd176612016-04-11 10:42:10 -070044 }
45
46 /**
47 * Returns the IP address of the next hop.
48 *
49 * @return IP address
50 */
51 public IpAddress ip() {
52 return ip;
53 }
54
55 /**
56 * Returns the MAC address of the next hop.
57 *
58 * @return MAC address
59 */
60 public MacAddress mac() {
Charles Chanc78a0982016-11-09 16:52:11 -080061 return nextHopData.mac();
62 }
63
64 /**
65 * Returns the location of the next hop.
66 *
67 * @return Connect point
68 */
69 public ConnectPoint location() {
70 return nextHopData.location();
Jonathan Hartfd176612016-04-11 10:42:10 -070071 }
72
73 @Override
74 public int hashCode() {
Charles Chanc78a0982016-11-09 16:52:11 -080075 return Objects.hash(ip, nextHopData);
Jonathan Hartfd176612016-04-11 10:42:10 -070076 }
77
78 @Override
79 public boolean equals(Object other) {
80 if (this == other) {
81 return true;
82 }
83
84 if (!(other instanceof NextHop)) {
85 return false;
86 }
87
88 NextHop that = (NextHop) other;
89
HIGUCHI Yuta0a011be2016-05-03 14:52:03 -070090 return Objects.equals(this.ip, that.ip) &&
Charles Chanc78a0982016-11-09 16:52:11 -080091 Objects.equals(this.nextHopData, that.nextHopData);
Jonathan Hartfd176612016-04-11 10:42:10 -070092 }
93
94 @Override
95 public String toString() {
96 return toStringHelper(this)
97 .add("ip", ip)
Charles Chanc78a0982016-11-09 16:52:11 -080098 .add("nextHopData", nextHopData)
Jonathan Hartfd176612016-04-11 10:42:10 -070099 .toString();
100 }
101}