Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 1 | /* |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
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; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 23 | import org.onosproject.core.DefaultGroupId; |
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 |
| 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 |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 47 | private final Path path; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 48 | |
| 49 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 50 | * Creates an active infrastructure tunnel using the supplied information. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 51 | * |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 52 | * @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 |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 59 | * @param path the path of tunnel |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 60 | * @param annotations optional key/value annotations |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 61 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 62 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
| 63 | TunnelEndPoint dst, Type type, DefaultGroupId groupId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 64 | TunnelId tunnelId, TunnelName tunnelName, Path path, |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 65 | Annotations... annotations) { |
| 66 | this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 67 | tunnelId, tunnelName, path, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 68 | } |
| 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 |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 81 | * @param path the path of tunnel |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 82 | * @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, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 87 | TunnelName tunnelName, Path path, Annotations... annotations) { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 88 | super(producerName, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 89 | 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; |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 96 | this.path = path; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 100 | public TunnelEndPoint src() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 101 | return src; |
| 102 | } |
| 103 | |
| 104 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 105 | public TunnelEndPoint dst() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 106 | 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 |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 120 | public NetworkResource resource() { |
| 121 | return null; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 125 | public TunnelId tunnelId() { |
| 126 | return tunnelId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 130 | public DefaultGroupId groupId() { |
| 131 | return groupId; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public TunnelName tunnelName() { |
| 136 | return tunnelName; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 137 | } |
| 138 | |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 139 | |
| 140 | @Override |
| 141 | public Path path() { |
| 142 | return path; |
| 143 | } |
| 144 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 145 | @Override |
| 146 | public int hashCode() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 147 | return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 148 | state, path); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 149 | } |
| 150 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 151 | @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; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 158 | 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) |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 164 | && Objects.equals(this.state, other.state) |
| 165 | && Objects.equals(this.path, other.path); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public String toString() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 172 | return toStringHelper(this).add("src", src).add("dst", dst) |
| 173 | .add("type", type).add("state", state).add("groupId", groupId) |
| 174 | .add("producerTunnelId", tunnelId) |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 175 | .add("tunnelName", tunnelName) |
| 176 | .add("path", path).toString(); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 177 | } |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 178 | } |