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 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 22 | import org.onosproject.core.DefaultGroupId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 23 | import org.onosproject.net.AbstractModel; |
| 24 | import org.onosproject.net.Annotations; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 25 | import org.onosproject.net.NetworkResource; |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 26 | import org.onosproject.net.Path; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 27 | import org.onosproject.net.provider.ProviderId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 28 | |
| 29 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 30 | * The default implementation of an network tunnel. supports for creating a |
| 31 | * tunnel by connect point ,IP address, MAC address, device and so on. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 32 | */ |
| 33 | public final class DefaultTunnel extends AbstractModel implements Tunnel { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 34 | |
| 35 | private final TunnelEndPoint src; // a source point of tunnel. |
| 36 | private final TunnelEndPoint dst; // a destination point of tunnel. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 37 | private final State state; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 38 | private final Type type; // tunnel type |
| 39 | private final DefaultGroupId groupId; // represent for a group flow table |
| 40 | // which a tunnel match up |
| 41 | // tunnel producer |
| 42 | private final TunnelId tunnelId; // tunnel identify generated by |
| 43 | // ONOS as primary key |
| 44 | private final TunnelName tunnelName; // name of a tunnel |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 45 | private final Path path; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 46 | |
| 47 | /** |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 48 | * Creates an active infrastructure tunnel using the supplied information. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 49 | * |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 50 | * @param producerName provider identity |
| 51 | * @param src tunnel source |
| 52 | * @param dst tunnel destination |
| 53 | * @param type tunnel type |
| 54 | * @param groupId groupId |
| 55 | * @param tunnelId tunnelId |
| 56 | * @param tunnelName tunnel name |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 57 | * @param path the path of tunnel |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 58 | * @param annotations optional key/value annotations |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 59 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 60 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
| 61 | TunnelEndPoint dst, Type type, DefaultGroupId groupId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 62 | TunnelId tunnelId, TunnelName tunnelName, Path path, |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 63 | Annotations... annotations) { |
| 64 | this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 65 | tunnelId, tunnelName, path, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Creates an tunnel using the supplied information. |
| 70 | * |
| 71 | * @param producerName provider identity |
| 72 | * @param src tunnel source |
| 73 | * @param dst tunnel destination |
| 74 | * @param type tunnel type |
| 75 | * @param state tunnel state |
| 76 | * @param groupId groupId |
| 77 | * @param tunnelId tunnelId |
| 78 | * @param tunnelName tunnel name |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 79 | * @param path the path of tunnel |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 80 | * @param annotations optional key/value annotations |
| 81 | */ |
| 82 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
| 83 | TunnelEndPoint dst, Type type, State state, |
| 84 | DefaultGroupId groupId, TunnelId tunnelId, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 85 | TunnelName tunnelName, Path path, Annotations... annotations) { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 86 | super(producerName, annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 87 | this.src = src; |
| 88 | this.dst = dst; |
| 89 | this.type = type; |
| 90 | this.state = state; |
| 91 | this.groupId = groupId; |
| 92 | this.tunnelId = tunnelId; |
| 93 | this.tunnelName = tunnelName; |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 94 | this.path = path; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 98 | public TunnelEndPoint src() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 99 | return src; |
| 100 | } |
| 101 | |
| 102 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 103 | public TunnelEndPoint dst() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 104 | return dst; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Type type() { |
| 109 | return type; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public State state() { |
| 114 | return state; |
| 115 | } |
| 116 | |
| 117 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 118 | public NetworkResource resource() { |
| 119 | return null; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 123 | public TunnelId tunnelId() { |
| 124 | return tunnelId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 128 | public DefaultGroupId groupId() { |
| 129 | return groupId; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public TunnelName tunnelName() { |
| 134 | return tunnelName; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 135 | } |
| 136 | |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 137 | |
| 138 | @Override |
| 139 | public Path path() { |
| 140 | return path; |
| 141 | } |
| 142 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 143 | @Override |
| 144 | public int hashCode() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 145 | return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName, |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 146 | state, path); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 147 | } |
| 148 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 149 | @Override |
| 150 | public boolean equals(Object obj) { |
| 151 | if (this == obj) { |
| 152 | return true; |
| 153 | } |
| 154 | if (obj instanceof DefaultTunnel) { |
| 155 | final DefaultTunnel other = (DefaultTunnel) obj; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 156 | return Objects.equals(this.src, other.src) |
| 157 | && Objects.equals(this.dst, other.dst) |
| 158 | && Objects.equals(this.type, other.type) |
| 159 | && Objects.equals(this.groupId, other.groupId) |
| 160 | && Objects.equals(this.tunnelId, other.tunnelId) |
| 161 | && Objects.equals(this.tunnelName, other.tunnelName) |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 162 | && Objects.equals(this.state, other.state) |
| 163 | && Objects.equals(this.path, other.path); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public String toString() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 170 | return toStringHelper(this).add("src", src).add("dst", dst) |
| 171 | .add("type", type).add("state", state).add("groupId", groupId) |
| 172 | .add("producerTunnelId", tunnelId) |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame^] | 173 | .add("tunnelName", tunnelName) |
| 174 | .add("path", path).toString(); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 175 | } |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 176 | } |