blob: d6cb4b43a3c5eb21691bdf746b473d935d319fdb [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;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070022import org.onosproject.net.ConnectPoint;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070023
Jonathan Hart6c2e7962016-04-11 13:54:09 -070024import java.util.Objects;
25
Jonathan Hartfd176612016-04-11 10:42:10 -070026import static com.google.common.base.MoreObjects.toStringHelper;
27
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070028/**
29 * Represents a route with the next hop MAC address resolved.
30 */
31public class ResolvedRoute {
32
33 private final IpPrefix prefix;
34 private final IpAddress nextHop;
35 private final MacAddress nextHopMac;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070036 private final ConnectPoint location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070037
38 /**
39 * Creates a new resolved route.
40 *
41 * @param route input route
42 * @param nextHopMac next hop MAC address
Charles Chan8fe9f4c2016-10-24 16:46:25 -070043 * @param location connect point where the next hop connects to
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070044 */
Charles Chan8fe9f4c2016-10-24 16:46:25 -070045 public ResolvedRoute(Route route, MacAddress nextHopMac, ConnectPoint location) {
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070046 this.prefix = route.prefix();
47 this.nextHop = route.nextHop();
48 this.nextHopMac = nextHopMac;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070049 this.location = location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070050 }
51
52 /**
53 * Creates a new resolved route.
54 *
55 * @param prefix route prefix
56 * @param nextHop route next hop IP address
57 * @param nextHopMac next hop MAC address
Charles Chan8fe9f4c2016-10-24 16:46:25 -070058 * @param location connect point where the next hop connects to
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070059 */
Charles Chan8fe9f4c2016-10-24 16:46:25 -070060 public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac,
61 ConnectPoint location) {
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070062 this.prefix = prefix;
63 this.nextHop = nextHop;
64 this.nextHopMac = nextHopMac;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070065 this.location = location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070066 }
67
68 /**
69 * Returns the IP prefix.
70 *
71 * @return IP prefix
72 */
73 public IpPrefix prefix() {
74 return prefix;
75 }
76
77 /**
78 * Returns the next hop IP address.
79 *
80 * @return IP address
81 */
82 public IpAddress nextHop() {
83 return nextHop;
84 }
85
86 /**
87 * Returns the next hop MAC address.
88 *
89 * @return MAC address
90 */
91 public MacAddress nextHopMac() {
92 return nextHopMac;
93 }
Jonathan Hartfd176612016-04-11 10:42:10 -070094
Charles Chan8fe9f4c2016-10-24 16:46:25 -070095 /**
96 * Returns the next hop location.
97 *
98 * @return connect point where the next hop attaches to
99 */
100 public ConnectPoint location() {
101 return location;
102 }
103
Jonathan Hartfd176612016-04-11 10:42:10 -0700104 @Override
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700105 public int hashCode() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700106 return Objects.hash(prefix, nextHop, nextHopMac, location);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700107 }
108
109 @Override
110 public boolean equals(Object other) {
111 if (this == other) {
112 return true;
113 }
114
115 if (!(other instanceof ResolvedRoute)) {
116 return false;
117 }
118
119 ResolvedRoute that = (ResolvedRoute) other;
120
121 return Objects.equals(this.prefix, that.prefix) &&
122 Objects.equals(this.nextHop, that.nextHop) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700123 Objects.equals(this.nextHopMac, that.nextHopMac) &&
124 Objects.equals(this.location, that.location);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700125 }
126
127 @Override
Jonathan Hartfd176612016-04-11 10:42:10 -0700128 public String toString() {
129 return toStringHelper(this)
130 .add("prefix", prefix)
131 .add("nextHop", nextHop)
132 .add("nextHopMac", nextHopMac)
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700133 .add("location", location)
Jonathan Hartfd176612016-04-11 10:42:10 -0700134 .toString();
135 }
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700136}