blob: 68f2feb42985e6866a521bb6b97f37a8779c224c [file] [log] [blame]
Jonathan Hart7d7e2f52016-03-29 16:22:49 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hart7d7e2f52016-03-29 16:22:49 -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.IpPrefix;
21import org.onlab.packet.MacAddress;
22
Jonathan Hart6c2e7962016-04-11 13:54:09 -070023import java.util.Objects;
24
Jonathan Hartfd176612016-04-11 10:42:10 -070025import static com.google.common.base.MoreObjects.toStringHelper;
26
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070027/**
28 * Represents a route with the next hop MAC address resolved.
29 */
30public class ResolvedRoute {
31
32 private final IpPrefix prefix;
33 private final IpAddress nextHop;
34 private final MacAddress nextHopMac;
35
36 /**
37 * Creates a new resolved route.
38 *
39 * @param route input route
40 * @param nextHopMac next hop MAC address
41 */
42 public ResolvedRoute(Route route, MacAddress nextHopMac) {
43 this.prefix = route.prefix();
44 this.nextHop = route.nextHop();
45 this.nextHopMac = nextHopMac;
46 }
47
48 /**
49 * Creates a new resolved route.
50 *
51 * @param prefix route prefix
52 * @param nextHop route next hop IP address
53 * @param nextHopMac next hop MAC address
54 */
55 public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac) {
56 this.prefix = prefix;
57 this.nextHop = nextHop;
58 this.nextHopMac = nextHopMac;
59 }
60
61 /**
62 * Returns the IP prefix.
63 *
64 * @return IP prefix
65 */
66 public IpPrefix prefix() {
67 return prefix;
68 }
69
70 /**
71 * Returns the next hop IP address.
72 *
73 * @return IP address
74 */
75 public IpAddress nextHop() {
76 return nextHop;
77 }
78
79 /**
80 * Returns the next hop MAC address.
81 *
82 * @return MAC address
83 */
84 public MacAddress nextHopMac() {
85 return nextHopMac;
86 }
Jonathan Hartfd176612016-04-11 10:42:10 -070087
88 @Override
Jonathan Hart6c2e7962016-04-11 13:54:09 -070089 public int hashCode() {
90 return Objects.hash(prefix, nextHop, nextHopMac);
91 }
92
93 @Override
94 public boolean equals(Object other) {
95 if (this == other) {
96 return true;
97 }
98
99 if (!(other instanceof ResolvedRoute)) {
100 return false;
101 }
102
103 ResolvedRoute that = (ResolvedRoute) other;
104
105 return Objects.equals(this.prefix, that.prefix) &&
106 Objects.equals(this.nextHop, that.nextHop) &&
107 Objects.equals(this.nextHopMac, that.nextHopMac);
108 }
109
110 @Override
Jonathan Hartfd176612016-04-11 10:42:10 -0700111 public String toString() {
112 return toStringHelper(this)
113 .add("prefix", prefix)
114 .add("nextHop", nextHop)
115 .add("nextHopMac", nextHopMac)
116 .toString();
117 }
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700118}