blob: 02d4e95e22c1abfdd8182ffd75ce4ed30f9efbff [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 Chan92ca94d2017-03-17 18:05:22 -070022import org.onlab.packet.VlanId;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070023import org.onosproject.net.ConnectPoint;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070024
Jonathan Hart6c2e7962016-04-11 13:54:09 -070025import java.util.Objects;
26
Jonathan Hartfd176612016-04-11 10:42:10 -070027import static com.google.common.base.MoreObjects.toStringHelper;
28
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070029/**
30 * Represents a route with the next hop MAC address resolved.
31 */
32public class ResolvedRoute {
33
34 private final IpPrefix prefix;
35 private final IpAddress nextHop;
36 private final MacAddress nextHopMac;
Charles Chan92ca94d2017-03-17 18:05:22 -070037 private final VlanId nextHopVlan;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070038 private final ConnectPoint location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070039
40 /**
41 * Creates a new resolved route.
42 *
43 * @param route input route
44 * @param nextHopMac next hop MAC address
Charles Chan8fe9f4c2016-10-24 16:46:25 -070045 * @param location connect point where the next hop connects to
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070046 */
Charles Chan8fe9f4c2016-10-24 16:46:25 -070047 public ResolvedRoute(Route route, MacAddress nextHopMac, ConnectPoint location) {
Charles Chan92ca94d2017-03-17 18:05:22 -070048 this(route, nextHopMac, VlanId.NONE, location);
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070049 }
50
51 /**
52 * Creates a new resolved route.
53 *
54 * @param prefix route prefix
55 * @param nextHop route next hop IP address
56 * @param nextHopMac next hop MAC address
Charles Chan8fe9f4c2016-10-24 16:46:25 -070057 * @param location connect point where the next hop connects to
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070058 */
Charles Chan8fe9f4c2016-10-24 16:46:25 -070059 public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac,
60 ConnectPoint location) {
Charles Chan92ca94d2017-03-17 18:05:22 -070061 this(prefix, nextHop, nextHopMac, VlanId.NONE, location);
62 }
63
64 /**
65 * Creates a new resolved route.
66 *
67 * @param route input route
68 * @param nextHopMac next hop MAC address
69 * @param nextHopVlan next hop VLAN ID
70 * @param location connect point where the next hop connects to
71 */
72 public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan,
73 ConnectPoint location) {
74 this.prefix = route.prefix();
75 this.nextHop = route.nextHop();
76 this.nextHopMac = nextHopMac;
77 this.nextHopVlan = nextHopVlan;
78 this.location = location;
79 }
80
81 /**
82 * Creates a new resolved route.
83 *
84 * @param prefix route prefix
85 * @param nextHop route next hop IP address
86 * @param nextHopMac next hop MAC address
87 * @param nextHopVlan next hop VLAN address
88 * @param location connect point where the next hop connects to
89 */
90 public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac,
91 VlanId nextHopVlan, ConnectPoint location) {
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070092 this.prefix = prefix;
93 this.nextHop = nextHop;
94 this.nextHopMac = nextHopMac;
Charles Chan92ca94d2017-03-17 18:05:22 -070095 this.nextHopVlan = nextHopVlan;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070096 this.location = location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070097 }
98
99 /**
100 * Returns the IP prefix.
101 *
102 * @return IP prefix
103 */
104 public IpPrefix prefix() {
105 return prefix;
106 }
107
108 /**
109 * Returns the next hop IP address.
110 *
111 * @return IP address
112 */
113 public IpAddress nextHop() {
114 return nextHop;
115 }
116
117 /**
118 * Returns the next hop MAC address.
119 *
120 * @return MAC address
121 */
122 public MacAddress nextHopMac() {
123 return nextHopMac;
124 }
Jonathan Hartfd176612016-04-11 10:42:10 -0700125
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700126 /**
Charles Chan92ca94d2017-03-17 18:05:22 -0700127 * Returns the next hop VLAN ID.
128 *
129 * @return VLAN ID
130 */
131 public VlanId nextHopVlan() {
132 return nextHopVlan;
133 }
134
135 /**
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700136 * Returns the next hop location.
137 *
138 * @return connect point where the next hop attaches to
139 */
140 public ConnectPoint location() {
141 return location;
142 }
143
Jonathan Hartfd176612016-04-11 10:42:10 -0700144 @Override
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700145 public int hashCode() {
Charles Chan92ca94d2017-03-17 18:05:22 -0700146 return Objects.hash(prefix, nextHop, nextHopMac, nextHopVlan, location);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700147 }
148
149 @Override
150 public boolean equals(Object other) {
151 if (this == other) {
152 return true;
153 }
154
155 if (!(other instanceof ResolvedRoute)) {
156 return false;
157 }
158
159 ResolvedRoute that = (ResolvedRoute) other;
160
161 return Objects.equals(this.prefix, that.prefix) &&
162 Objects.equals(this.nextHop, that.nextHop) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700163 Objects.equals(this.nextHopMac, that.nextHopMac) &&
Charles Chan92ca94d2017-03-17 18:05:22 -0700164 Objects.equals(this.nextHopVlan, that.nextHopVlan) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700165 Objects.equals(this.location, that.location);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700166 }
167
168 @Override
Jonathan Hartfd176612016-04-11 10:42:10 -0700169 public String toString() {
170 return toStringHelper(this)
171 .add("prefix", prefix)
172 .add("nextHop", nextHop)
173 .add("nextHopMac", nextHopMac)
Charles Chan92ca94d2017-03-17 18:05:22 -0700174 .add("nextHopVlan", nextHopVlan)
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700175 .add("location", location)
Jonathan Hartfd176612016-04-11 10:42:10 -0700176 .toString();
177 }
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700178}