Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.incubator.net.tunnel; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 18 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 21 | |
| 22 | import java.util.Objects; |
| 23 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 24 | import org.onosproject.core.DefaultGroupId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 25 | import org.onosproject.net.AbstractModel; |
| 26 | import org.onosproject.net.Annotations; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 27 | import org.onosproject.net.NetworkResource; |
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 | */ |
| 34 | public final class DefaultTunnel extends AbstractModel implements Tunnel { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 35 | |
| 36 | private final TunnelEndPoint src; // a source point of tunnel. |
| 37 | private final TunnelEndPoint dst; // a destination point of tunnel. |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 38 | private final State state; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 39 | private final Type type; // tunnel type |
| 40 | private final DefaultGroupId groupId; // represent for a group flow table |
| 41 | // which a tunnel match up |
| 42 | // tunnel producer |
| 43 | private final TunnelId tunnelId; // tunnel identify generated by |
| 44 | // ONOS as primary key |
| 45 | private final TunnelName tunnelName; // name of a tunnel |
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 |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 57 | * @param annotations optional key/value annotations |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 58 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 59 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
| 60 | TunnelEndPoint dst, Type type, DefaultGroupId groupId, |
| 61 | TunnelId tunnelId, TunnelName tunnelName, |
| 62 | Annotations... annotations) { |
| 63 | this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId, |
| 64 | tunnelId, tunnelName, annotations); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates an tunnel using the supplied information. |
| 69 | * |
| 70 | * @param producerName provider identity |
| 71 | * @param src tunnel source |
| 72 | * @param dst tunnel destination |
| 73 | * @param type tunnel type |
| 74 | * @param state tunnel state |
| 75 | * @param groupId groupId |
| 76 | * @param tunnelId tunnelId |
| 77 | * @param tunnelName tunnel name |
| 78 | * @param annotations optional key/value annotations |
| 79 | */ |
| 80 | public DefaultTunnel(ProviderId producerName, TunnelEndPoint src, |
| 81 | TunnelEndPoint dst, Type type, State state, |
| 82 | DefaultGroupId groupId, TunnelId tunnelId, |
| 83 | TunnelName tunnelName, Annotations... annotations) { |
| 84 | super(producerName, annotations); |
| 85 | checkNotNull(producerName, "producerName cannot be null"); |
| 86 | checkNotNull(src, "src cannot be null"); |
| 87 | checkNotNull(dst, "dst cannot be null"); |
| 88 | checkNotNull(type, "type cannot be null"); |
| 89 | checkNotNull(state, "state cannot be null"); |
| 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; |
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 | |
| 139 | @Override |
| 140 | public int hashCode() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 141 | return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName, |
| 142 | state); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 143 | } |
| 144 | |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 145 | @Override |
| 146 | public boolean equals(Object obj) { |
| 147 | if (this == obj) { |
| 148 | return true; |
| 149 | } |
| 150 | if (obj instanceof DefaultTunnel) { |
| 151 | final DefaultTunnel other = (DefaultTunnel) obj; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 152 | return Objects.equals(this.src, other.src) |
| 153 | && Objects.equals(this.dst, other.dst) |
| 154 | && Objects.equals(this.type, other.type) |
| 155 | && Objects.equals(this.groupId, other.groupId) |
| 156 | && Objects.equals(this.tunnelId, other.tunnelId) |
| 157 | && Objects.equals(this.tunnelName, other.tunnelName) |
| 158 | && Objects.equals(this.state, other.state); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 159 | } |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public String toString() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 165 | return toStringHelper(this).add("src", src).add("dst", dst) |
| 166 | .add("type", type).add("state", state).add("groupId", groupId) |
| 167 | .add("producerTunnelId", tunnelId) |
| 168 | .add("tunnelName", tunnelName).toString(); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | } |