Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 3 | * |
| 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 Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 16 | package org.onosproject.incubator.net.tunnel; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
Brian O'Connor | 2bed5ce | 2015-06-25 15:10:28 -0400 | [diff] [blame] | 22 | import com.google.common.annotations.Beta; |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 23 | import org.onosproject.core.GroupId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 24 | import org.onosproject.net.AbstractModel; |
| 25 | import org.onosproject.net.Annotations; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 26 | import org.onosproject.net.NetworkResource; |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 27 | import org.onosproject.net.Path; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 28 | import org.onosproject.net.provider.ProviderId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 29 | |
| 30 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 31 | * 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 wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 33 | */ |
Brian O'Connor | 2bed5ce | 2015-06-25 15:10:28 -0400 | [diff] [blame] | 34 | @Beta |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 35 | public final class DefaultTunnel extends AbstractModel implements Tunnel { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 36 | |
| 37 | private final TunnelEndPoint src; // a source point of tunnel. |
| 38 | private final TunnelEndPoint dst; // a destination point of tunnel. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 39 | private final State state; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 40 | private final Type type; // tunnel type |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 41 | private final GroupId groupId; // represent for a group flow table |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 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 |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 47 | private final Path path; |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 48 | private final NetworkResource networkRes; // network resource to carry label stack |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 49 | |
| 50 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 51 | * Creates an active infrastructure tunnel using the supplied information. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 52 | * |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 53 | * @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 |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 60 | * @param path the path of tunnel |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 61 | * @param annotations optional key/value annotations |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 62 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 63 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 64 | TunnelEndPoint dst, Type type, GroupId groupId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 65 | TunnelId tunnelId, TunnelName tunnelName, Path path, |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 66 | Annotations... annotations) { |
| 67 | this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 68 | tunnelId, tunnelName, path, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 69 | } |
| 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 |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 82 | * @param path the path of tunnel |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 83 | * @param annotations optional key/value annotations |
| 84 | */ |
| 85 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
| 86 | TunnelEndPoint dst, Type type, State state, |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 87 | GroupId groupId, TunnelId tunnelId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 88 | TunnelName tunnelName, Path path, Annotations... annotations) { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 89 | super(producerName, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 90 | 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; |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 97 | this.path = path; |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 98 | 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 Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 116 | TunnelEndPoint dst, Type type, GroupId groupId, |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 117 | 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 Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 140 | GroupId groupId, TunnelId tunnelId, |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 141 | 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 wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 156 | public TunnelEndPoint src() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 157 | return src; |
| 158 | } |
| 159 | |
| 160 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 161 | public TunnelEndPoint dst() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 162 | 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 |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 176 | public NetworkResource resource() { |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 177 | return networkRes; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 181 | public TunnelId tunnelId() { |
| 182 | return tunnelId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | @Override |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 186 | public GroupId groupId() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 187 | return groupId; |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public TunnelName tunnelName() { |
| 192 | return tunnelName; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 193 | } |
| 194 | |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 195 | |
| 196 | @Override |
| 197 | public Path path() { |
| 198 | return path; |
| 199 | } |
| 200 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 201 | @Override |
| 202 | public int hashCode() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 203 | return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName, |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 204 | state, path, networkRes); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 205 | } |
| 206 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 207 | @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; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 214 | 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) |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 220 | && Objects.equals(this.state, other.state) |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 221 | && Objects.equals(this.path, other.path) |
| 222 | && Objects.equals(this.networkRes, other.networkRes); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 223 | } |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public String toString() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 229 | return toStringHelper(this).add("src", src).add("dst", dst) |
| 230 | .add("type", type).add("state", state).add("groupId", groupId) |
| 231 | .add("producerTunnelId", tunnelId) |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 232 | .add("tunnelName", tunnelName) |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 233 | .add("path", path) |
| 234 | .add("networkResource", networkRes).toString(); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 235 | } |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 236 | } |