blob: d777a624e7f1a9b9597e317edb6d2842b1a4cddb [file] [log] [blame]
Jonathan Hartf5829202015-02-12 09:37:02 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
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 Hartc22e8472015-11-17 18:25:45 -080016
Jonathan Hartf4bd0482017-01-27 15:11:18 -080017package org.onosproject.routing;
Jonathan Hartf5829202015-02-12 09:37:02 -080018
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070019import java.util.Objects;
20
Jonathan Hartf5829202015-02-12 09:37:02 -080021import org.onlab.packet.IpAddress;
22import org.onlab.packet.MacAddress;
23
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070024import com.google.common.base.MoreObjects;
Jonathan Hartf5829202015-02-12 09:37:02 -080025
26/**
Jonathan Hart7baba072015-02-23 14:27:59 -080027 * Represents a next hop for routing, whose MAC address has already been resolved.
Jonathan Hartf5829202015-02-12 09:37:02 -080028 */
29public class NextHop {
30
31 private final IpAddress ip;
32 private final MacAddress mac;
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070033 private final NextHopGroupKey group;
Jonathan Hartf5829202015-02-12 09:37:02 -080034
Jonathan Hart7baba072015-02-23 14:27:59 -080035 /**
36 * Creates a new next hop.
37 *
38 * @param ip next hop's IP address
39 * @param mac next hop's MAC address
40 * @param group next hop's group
41 */
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070042 public NextHop(IpAddress ip, MacAddress mac, NextHopGroupKey group) {
Jonathan Hartf5829202015-02-12 09:37:02 -080043 this.ip = ip;
44 this.mac = mac;
Jonathan Hart7baba072015-02-23 14:27:59 -080045 this.group = group;
Jonathan Hartf5829202015-02-12 09:37:02 -080046 }
47
Jonathan Hart7baba072015-02-23 14:27:59 -080048 /**
49 * Returns the next hop's IP address.
50 *
51 * @return next hop's IP address
52 */
Jonathan Hartf5829202015-02-12 09:37:02 -080053 public IpAddress ip() {
54 return ip;
55 }
56
Jonathan Hart7baba072015-02-23 14:27:59 -080057 /**
58 * Returns the next hop's MAC address.
59 *
60 * @return next hop's MAC address
61 */
Jonathan Hartf5829202015-02-12 09:37:02 -080062 public MacAddress mac() {
63 return mac;
64 }
65
Jonathan Hart7baba072015-02-23 14:27:59 -080066 /**
67 * Returns the next hop group.
68 *
69 * @return group
70 */
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070071 public NextHopGroupKey group() {
Jonathan Hart7baba072015-02-23 14:27:59 -080072 return group;
73 }
74
Jonathan Hartf5829202015-02-12 09:37:02 -080075 @Override
76 public boolean equals(Object o) {
77 if (!(o instanceof NextHop)) {
78 return false;
79 }
80
81 NextHop that = (NextHop) o;
82
83 return Objects.equals(this.ip, that.ip) &&
Jonathan Hart7baba072015-02-23 14:27:59 -080084 Objects.equals(this.mac, that.mac) &&
85 Objects.equals(this.group, that.group);
Jonathan Hartf5829202015-02-12 09:37:02 -080086 }
87
88 @Override
89 public int hashCode() {
Jonathan Hart7baba072015-02-23 14:27:59 -080090 return Objects.hash(ip, mac, group);
Jonathan Hartf5829202015-02-12 09:37:02 -080091 }
92
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(getClass())
96 .add("ip", ip)
97 .add("mac", mac)
Jonathan Hart7baba072015-02-23 14:27:59 -080098 .add("group", group)
Jonathan Hartf5829202015-02-12 09:37:02 -080099 .toString();
100 }
101}