blob: 86a790f4db99ab87593baa9f1e6841b3fa6e7b05 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
samuel7a5691a2015-05-23 00:36:32 +08002 * Copyright 2014-2015 Open Networking Laboratory
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;
jcc4a20a5f2015-04-30 15:43:39 +080023import org.onosproject.core.DefaultGroupId;
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
41 private final DefaultGroupId groupId; // represent for a group flow table
42 // 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;
wei wei89ddc322015-03-22 16:29:04 -050048
49 /**
jcc4a20a5f2015-04-30 15:43:39 +080050 * Creates an active infrastructure tunnel using the supplied information.
wei wei89ddc322015-03-22 16:29:04 -050051 *
jcc4a20a5f2015-04-30 15:43:39 +080052 * @param producerName provider identity
53 * @param src tunnel source
54 * @param dst tunnel destination
55 * @param type tunnel type
56 * @param groupId groupId
57 * @param tunnelId tunnelId
58 * @param tunnelName tunnel name
samuel7a5691a2015-05-23 00:36:32 +080059 * @param path the path of tunnel
wei wei89ddc322015-03-22 16:29:04 -050060 * @param annotations optional key/value annotations
wei wei89ddc322015-03-22 16:29:04 -050061 */
jcc4a20a5f2015-04-30 15:43:39 +080062 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
63 TunnelEndPoint dst, Type type, DefaultGroupId groupId,
samuel7a5691a2015-05-23 00:36:32 +080064 TunnelId tunnelId, TunnelName tunnelName, Path path,
jcc4a20a5f2015-04-30 15:43:39 +080065 Annotations... annotations) {
66 this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
samuel7a5691a2015-05-23 00:36:32 +080067 tunnelId, tunnelName, path, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080068 }
69
70 /**
71 * Creates an tunnel using the supplied information.
72 *
73 * @param producerName provider identity
74 * @param src tunnel source
75 * @param dst tunnel destination
76 * @param type tunnel type
77 * @param state tunnel state
78 * @param groupId groupId
79 * @param tunnelId tunnelId
80 * @param tunnelName tunnel name
samuel7a5691a2015-05-23 00:36:32 +080081 * @param path the path of tunnel
jcc4a20a5f2015-04-30 15:43:39 +080082 * @param annotations optional key/value annotations
83 */
84 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
85 TunnelEndPoint dst, Type type, State state,
86 DefaultGroupId groupId, TunnelId tunnelId,
samuel7a5691a2015-05-23 00:36:32 +080087 TunnelName tunnelName, Path path, Annotations... annotations) {
jcc4a20a5f2015-04-30 15:43:39 +080088 super(producerName, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080089 this.src = src;
90 this.dst = dst;
91 this.type = type;
92 this.state = state;
93 this.groupId = groupId;
94 this.tunnelId = tunnelId;
95 this.tunnelName = tunnelName;
samuel7a5691a2015-05-23 00:36:32 +080096 this.path = path;
wei wei89ddc322015-03-22 16:29:04 -050097 }
98
99 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800100 public TunnelEndPoint src() {
wei wei89ddc322015-03-22 16:29:04 -0500101 return src;
102 }
103
104 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800105 public TunnelEndPoint dst() {
wei wei89ddc322015-03-22 16:29:04 -0500106 return dst;
107 }
108
109 @Override
110 public Type type() {
111 return type;
112 }
113
114 @Override
115 public State state() {
116 return state;
117 }
118
119 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800120 public NetworkResource resource() {
121 return null;
wei wei89ddc322015-03-22 16:29:04 -0500122 }
123
124 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800125 public TunnelId tunnelId() {
126 return tunnelId;
wei wei89ddc322015-03-22 16:29:04 -0500127 }
128
129 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800130 public DefaultGroupId groupId() {
131 return groupId;
132 }
133
134 @Override
135 public TunnelName tunnelName() {
136 return tunnelName;
wei wei89ddc322015-03-22 16:29:04 -0500137 }
138
samuel7a5691a2015-05-23 00:36:32 +0800139
140 @Override
141 public Path path() {
142 return path;
143 }
144
wei wei89ddc322015-03-22 16:29:04 -0500145 @Override
146 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +0800147 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
samuel7a5691a2015-05-23 00:36:32 +0800148 state, path);
wei wei89ddc322015-03-22 16:29:04 -0500149 }
150
wei wei89ddc322015-03-22 16:29:04 -0500151 @Override
152 public boolean equals(Object obj) {
153 if (this == obj) {
154 return true;
155 }
156 if (obj instanceof DefaultTunnel) {
157 final DefaultTunnel other = (DefaultTunnel) obj;
jcc4a20a5f2015-04-30 15:43:39 +0800158 return Objects.equals(this.src, other.src)
159 && Objects.equals(this.dst, other.dst)
160 && Objects.equals(this.type, other.type)
161 && Objects.equals(this.groupId, other.groupId)
162 && Objects.equals(this.tunnelId, other.tunnelId)
163 && Objects.equals(this.tunnelName, other.tunnelName)
samuel7a5691a2015-05-23 00:36:32 +0800164 && Objects.equals(this.state, other.state)
165 && Objects.equals(this.path, other.path);
wei wei89ddc322015-03-22 16:29:04 -0500166 }
167 return false;
168 }
169
170 @Override
171 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +0800172 return toStringHelper(this).add("src", src).add("dst", dst)
173 .add("type", type).add("state", state).add("groupId", groupId)
174 .add("producerTunnelId", tunnelId)
samuel7a5691a2015-05-23 00:36:32 +0800175 .add("tunnelName", tunnelName)
176 .add("path", path).toString();
wei wei89ddc322015-03-22 16:29:04 -0500177 }
wei wei89ddc322015-03-22 16:29:04 -0500178}