blob: c740fa886fab4dd1af676aeba798d75ef812b608 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskabf916ea2015-05-20 18:24:34 -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 */
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070016package org.onosproject.incubator.net.tunnel;
wei wei89ddc322015-03-22 16:29:04 -050017
18import static com.google.common.base.MoreObjects.toStringHelper;
wei wei89ddc322015-03-22 16:29:04 -050019
20import java.util.Objects;
21
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040022import com.google.common.annotations.Beta;
Yi Tsengfa394de2017-02-01 11:26:40 -080023import org.onosproject.core.GroupId;
wei wei89ddc322015-03-22 16:29:04 -050024import org.onosproject.net.AbstractModel;
25import org.onosproject.net.Annotations;
jcc4a20a5f2015-04-30 15:43:39 +080026import org.onosproject.net.NetworkResource;
samuel7a5691a2015-05-23 00:36:32 +080027import org.onosproject.net.Path;
wei wei89ddc322015-03-22 16:29:04 -050028import org.onosproject.net.provider.ProviderId;
wei wei89ddc322015-03-22 16:29:04 -050029
30/**
jcc4a20a5f2015-04-30 15:43:39 +080031 * The default implementation of an network tunnel. supports for creating a
32 * tunnel by connect point ,IP address, MAC address, device and so on.
wei wei89ddc322015-03-22 16:29:04 -050033 */
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040034@Beta
wei wei89ddc322015-03-22 16:29:04 -050035public final class DefaultTunnel extends AbstractModel implements Tunnel {
jcc4a20a5f2015-04-30 15:43:39 +080036
37 private final TunnelEndPoint src; // a source point of tunnel.
38 private final TunnelEndPoint dst; // a destination point of tunnel.
wei wei89ddc322015-03-22 16:29:04 -050039 private final State state;
jcc4a20a5f2015-04-30 15:43:39 +080040 private final Type type; // tunnel type
Yi Tsengfa394de2017-02-01 11:26:40 -080041 private final GroupId groupId; // represent for a group flow table
jcc4a20a5f2015-04-30 15:43:39 +080042 // which a tunnel match up
43 // tunnel producer
44 private final TunnelId tunnelId; // tunnel identify generated by
45 // ONOS as primary key
46 private final TunnelName tunnelName; // name of a tunnel
samuel7a5691a2015-05-23 00:36:32 +080047 private final Path path;
Satish Kd70e9572016-04-28 13:58:51 +053048 private final NetworkResource networkRes; // network resource to carry label stack
wei wei89ddc322015-03-22 16:29:04 -050049
50 /**
jcc4a20a5f2015-04-30 15:43:39 +080051 * Creates an active infrastructure tunnel using the supplied information.
wei wei89ddc322015-03-22 16:29:04 -050052 *
jcc4a20a5f2015-04-30 15:43:39 +080053 * @param producerName provider identity
54 * @param src tunnel source
55 * @param dst tunnel destination
56 * @param type tunnel type
57 * @param groupId groupId
58 * @param tunnelId tunnelId
59 * @param tunnelName tunnel name
samuel7a5691a2015-05-23 00:36:32 +080060 * @param path the path of tunnel
wei wei89ddc322015-03-22 16:29:04 -050061 * @param annotations optional key/value annotations
wei wei89ddc322015-03-22 16:29:04 -050062 */
jcc4a20a5f2015-04-30 15:43:39 +080063 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
Yi Tsengfa394de2017-02-01 11:26:40 -080064 TunnelEndPoint dst, Type type, GroupId groupId,
samuel7a5691a2015-05-23 00:36:32 +080065 TunnelId tunnelId, TunnelName tunnelName, Path path,
jcc4a20a5f2015-04-30 15:43:39 +080066 Annotations... annotations) {
67 this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
samuel7a5691a2015-05-23 00:36:32 +080068 tunnelId, tunnelName, path, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080069 }
70
71 /**
72 * Creates an tunnel using the supplied information.
73 *
74 * @param producerName provider identity
75 * @param src tunnel source
76 * @param dst tunnel destination
77 * @param type tunnel type
78 * @param state tunnel state
79 * @param groupId groupId
80 * @param tunnelId tunnelId
81 * @param tunnelName tunnel name
samuel7a5691a2015-05-23 00:36:32 +080082 * @param path the path of tunnel
jcc4a20a5f2015-04-30 15:43:39 +080083 * @param annotations optional key/value annotations
84 */
85 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
86 TunnelEndPoint dst, Type type, State state,
Yi Tsengfa394de2017-02-01 11:26:40 -080087 GroupId groupId, TunnelId tunnelId,
samuel7a5691a2015-05-23 00:36:32 +080088 TunnelName tunnelName, Path path, Annotations... annotations) {
jcc4a20a5f2015-04-30 15:43:39 +080089 super(producerName, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080090 this.src = src;
91 this.dst = dst;
92 this.type = type;
93 this.state = state;
94 this.groupId = groupId;
95 this.tunnelId = tunnelId;
96 this.tunnelName = tunnelName;
samuel7a5691a2015-05-23 00:36:32 +080097 this.path = path;
Satish Kd70e9572016-04-28 13:58:51 +053098 this.networkRes = null;
99 }
100
101 /**
102 * Creates an active infrastructure tunnel using the supplied information.
103 *
104 * @param producerName provider identity
105 * @param src tunnel source
106 * @param dst tunnel destination
107 * @param type tunnel type
108 * @param groupId groupId
109 * @param tunnelId tunnelId
110 * @param tunnelName tunnel name
111 * @param path the path of tunnel
112 * @param networkRes network resource of tunnel
113 * @param annotations optional key/value annotations
114 */
115 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
Yi Tsengfa394de2017-02-01 11:26:40 -0800116 TunnelEndPoint dst, Type type, GroupId groupId,
Satish Kd70e9572016-04-28 13:58:51 +0530117 TunnelId tunnelId, TunnelName tunnelName, Path path,
118 NetworkResource networkRes, Annotations... annotations) {
119 this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
120 tunnelId, tunnelName, path, networkRes, annotations);
121 }
122
123 /**
124 * Creates an tunnel using the supplied information.
125 *
126 * @param producerName provider identity
127 * @param src tunnel source
128 * @param dst tunnel destination
129 * @param type tunnel type
130 * @param state tunnel state
131 * @param groupId groupId
132 * @param tunnelId tunnelId
133 * @param tunnelName tunnel name
134 * @param path the path of tunnel
135 * @param networkRes network resource of tunnel
136 * @param annotations optional key/value annotations
137 */
138 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
139 TunnelEndPoint dst, Type type, State state,
Yi Tsengfa394de2017-02-01 11:26:40 -0800140 GroupId groupId, TunnelId tunnelId,
Satish Kd70e9572016-04-28 13:58:51 +0530141 TunnelName tunnelName, Path path, NetworkResource networkRes,
142 Annotations... annotations) {
143 super(producerName, annotations);
144 this.src = src;
145 this.dst = dst;
146 this.type = type;
147 this.state = state;
148 this.groupId = groupId;
149 this.tunnelId = tunnelId;
150 this.tunnelName = tunnelName;
151 this.path = path;
152 this.networkRes = networkRes;
wei wei89ddc322015-03-22 16:29:04 -0500153 }
154
155 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800156 public TunnelEndPoint src() {
wei wei89ddc322015-03-22 16:29:04 -0500157 return src;
158 }
159
160 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800161 public TunnelEndPoint dst() {
wei wei89ddc322015-03-22 16:29:04 -0500162 return dst;
163 }
164
165 @Override
166 public Type type() {
167 return type;
168 }
169
170 @Override
171 public State state() {
172 return state;
173 }
174
175 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800176 public NetworkResource resource() {
Satish Kd70e9572016-04-28 13:58:51 +0530177 return networkRes;
wei wei89ddc322015-03-22 16:29:04 -0500178 }
179
180 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800181 public TunnelId tunnelId() {
182 return tunnelId;
wei wei89ddc322015-03-22 16:29:04 -0500183 }
184
185 @Override
Yi Tsengfa394de2017-02-01 11:26:40 -0800186 public GroupId groupId() {
jcc4a20a5f2015-04-30 15:43:39 +0800187 return groupId;
188 }
189
190 @Override
191 public TunnelName tunnelName() {
192 return tunnelName;
wei wei89ddc322015-03-22 16:29:04 -0500193 }
194
samuel7a5691a2015-05-23 00:36:32 +0800195
196 @Override
197 public Path path() {
198 return path;
199 }
200
wei wei89ddc322015-03-22 16:29:04 -0500201 @Override
202 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +0800203 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
Satish Kd70e9572016-04-28 13:58:51 +0530204 state, path, networkRes);
wei wei89ddc322015-03-22 16:29:04 -0500205 }
206
wei wei89ddc322015-03-22 16:29:04 -0500207 @Override
208 public boolean equals(Object obj) {
209 if (this == obj) {
210 return true;
211 }
212 if (obj instanceof DefaultTunnel) {
213 final DefaultTunnel other = (DefaultTunnel) obj;
jcc4a20a5f2015-04-30 15:43:39 +0800214 return Objects.equals(this.src, other.src)
215 && Objects.equals(this.dst, other.dst)
216 && Objects.equals(this.type, other.type)
217 && Objects.equals(this.groupId, other.groupId)
218 && Objects.equals(this.tunnelId, other.tunnelId)
219 && Objects.equals(this.tunnelName, other.tunnelName)
samuel7a5691a2015-05-23 00:36:32 +0800220 && Objects.equals(this.state, other.state)
Satish Kd70e9572016-04-28 13:58:51 +0530221 && Objects.equals(this.path, other.path)
222 && Objects.equals(this.networkRes, other.networkRes);
wei wei89ddc322015-03-22 16:29:04 -0500223 }
224 return false;
225 }
226
227 @Override
228 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +0800229 return toStringHelper(this).add("src", src).add("dst", dst)
230 .add("type", type).add("state", state).add("groupId", groupId)
231 .add("producerTunnelId", tunnelId)
samuel7a5691a2015-05-23 00:36:32 +0800232 .add("tunnelName", tunnelName)
Satish Kd70e9572016-04-28 13:58:51 +0530233 .add("path", path)
234 .add("networkResource", networkRes).toString();
wei wei89ddc322015-03-22 16:29:04 -0500235 }
wei wei89ddc322015-03-22 16:29:04 -0500236}