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