blob: cc045bcd2d9e4f36d2e6aeb7984b2d8832f585d5 [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.onlab.packet.MacAddress;
Jonathan Hart7baba072015-02-23 14:27:59 -080021import org.onosproject.net.group.GroupKey;
Jonathan Hartf5829202015-02-12 09:37:02 -080022
23import java.util.Objects;
24
25/**
Jonathan Hart7baba072015-02-23 14:27:59 -080026 * Represents a next hop for routing, whose MAC address has already been resolved.
Jonathan Hartf5829202015-02-12 09:37:02 -080027 */
28public class NextHop {
29
30 private final IpAddress ip;
31 private final MacAddress mac;
Jonathan Hart7baba072015-02-23 14:27:59 -080032 private final GroupKey group;
Jonathan Hartf5829202015-02-12 09:37:02 -080033
Jonathan Hart7baba072015-02-23 14:27:59 -080034 /**
35 * Creates a new next hop.
36 *
37 * @param ip next hop's IP address
38 * @param mac next hop's MAC address
39 * @param group next hop's group
40 */
41 public NextHop(IpAddress ip, MacAddress mac, GroupKey group) {
Jonathan Hartf5829202015-02-12 09:37:02 -080042 this.ip = ip;
43 this.mac = mac;
Jonathan Hart7baba072015-02-23 14:27:59 -080044 this.group = group;
Jonathan Hartf5829202015-02-12 09:37:02 -080045 }
46
Jonathan Hart7baba072015-02-23 14:27:59 -080047 /**
48 * Returns the next hop's IP address.
49 *
50 * @return next hop's IP address
51 */
Jonathan Hartf5829202015-02-12 09:37:02 -080052 public IpAddress ip() {
53 return ip;
54 }
55
Jonathan Hart7baba072015-02-23 14:27:59 -080056 /**
57 * Returns the next hop's MAC address.
58 *
59 * @return next hop's MAC address
60 */
Jonathan Hartf5829202015-02-12 09:37:02 -080061 public MacAddress mac() {
62 return mac;
63 }
64
Jonathan Hart7baba072015-02-23 14:27:59 -080065 /**
66 * Returns the next hop group.
67 *
68 * @return group
69 */
70 public GroupKey group() {
71 return group;
72 }
73
Jonathan Hartf5829202015-02-12 09:37:02 -080074 @Override
75 public boolean equals(Object o) {
76 if (!(o instanceof NextHop)) {
77 return false;
78 }
79
80 NextHop that = (NextHop) o;
81
82 return Objects.equals(this.ip, that.ip) &&
Jonathan Hart7baba072015-02-23 14:27:59 -080083 Objects.equals(this.mac, that.mac) &&
84 Objects.equals(this.group, that.group);
Jonathan Hartf5829202015-02-12 09:37:02 -080085 }
86
87 @Override
88 public int hashCode() {
Jonathan Hart7baba072015-02-23 14:27:59 -080089 return Objects.hash(ip, mac, group);
Jonathan Hartf5829202015-02-12 09:37:02 -080090 }
91
92 @Override
93 public String toString() {
94 return MoreObjects.toStringHelper(getClass())
95 .add("ip", ip)
96 .add("mac", mac)
Jonathan Hart7baba072015-02-23 14:27:59 -080097 .add("group", group)
Jonathan Hartf5829202015-02-12 09:37:02 -080098 .toString();
99 }
100}