blob: f3b7da7f65aefe40b223fe953cd726ca72074f51 [file] [log] [blame]
Charles Chan8fe9f4c2016-10-24 16:46:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chan8fe9f4c2016-10-24 16:46:25 -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
Ray Milkey69ec8712017-08-08 13:00:43 -070017package org.onosproject.routeservice;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070018
19import org.onlab.packet.MacAddress;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.Host;
22
23import java.util.Objects;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26
27/**
28 * Stores next hop information.
29 */
30public class NextHopData {
31
32 private final MacAddress mac;
33 private final ConnectPoint location;
34
35 /**
36 * Creates a new instance.
37 *
38 * @param mac MAC address
39 * @param location Connect point
40 */
41 public NextHopData(MacAddress mac, ConnectPoint location) {
42 this.mac = mac;
43 this.location = location;
44 }
45
46 /**
47 * Returns the MAC address.
48 *
49 * @return MAC address
50 */
51 public MacAddress mac() {
52 return mac;
53 }
54
55 /**
56 * Returns the location.
57 *
58 * @return Connect point
59 */
60 public ConnectPoint location() {
61 return location;
62 }
63
64 /**
65 * Creates a new instance from a host.
66 *
67 * @param host Host information
68 * @return NextHopData instance
69 */
70 public static NextHopData fromHost(Host host) {
71 return new NextHopData(host.mac(), host.location());
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hash(mac, location);
77 }
78
79 @Override
80 public boolean equals(Object other) {
81 if (this == other) {
82 return true;
83 }
84
85 if (!(other instanceof NextHopData)) {
86 return false;
87 }
88
89 NextHopData that = (NextHopData) other;
90
91 return Objects.equals(this.mac, that.mac) &&
92 Objects.equals(this.location, that.location);
93 }
94
95 @Override
96 public String toString() {
97 return toStringHelper(this)
98 .add("mac", mac)
99 .add("location", location)
100 .toString();
101 }
102}