blob: fa911fc2ba4a8ba1356bd894da33649f76939ae7 [file] [log] [blame]
wei wei89ddc322015-03-22 16:29:04 -05001package org.onosproject.net.tunnel;
2
jcc4a20a5f2015-04-30 15:43:39 +08003import static com.google.common.base.Preconditions.checkNotNull;
wei wei89ddc322015-03-22 16:29:04 -05004import static com.google.common.base.MoreObjects.toStringHelper;
wei wei89ddc322015-03-22 16:29:04 -05005
6import java.util.Objects;
7
jcc4a20a5f2015-04-30 15:43:39 +08008import org.onosproject.core.DefaultGroupId;
wei wei89ddc322015-03-22 16:29:04 -05009import org.onosproject.net.AbstractModel;
10import org.onosproject.net.Annotations;
jcc4a20a5f2015-04-30 15:43:39 +080011import org.onosproject.net.NetworkResource;
wei wei89ddc322015-03-22 16:29:04 -050012import org.onosproject.net.provider.ProviderId;
wei wei89ddc322015-03-22 16:29:04 -050013
14/**
jcc4a20a5f2015-04-30 15:43:39 +080015 * 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 wei89ddc322015-03-22 16:29:04 -050017 */
18public final class DefaultTunnel extends AbstractModel implements Tunnel {
jcc4a20a5f2015-04-30 15:43:39 +080019
20 private final TunnelEndPoint src; // a source point of tunnel.
21 private final TunnelEndPoint dst; // a destination point of tunnel.
wei wei89ddc322015-03-22 16:29:04 -050022 private final State state;
jcc4a20a5f2015-04-30 15:43:39 +080023 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 wei89ddc322015-03-22 16:29:04 -050030
31 /**
jcc4a20a5f2015-04-30 15:43:39 +080032 * Creates an active infrastructure tunnel using the supplied information.
wei wei89ddc322015-03-22 16:29:04 -050033 *
jcc4a20a5f2015-04-30 15:43:39 +080034 * @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 wei89ddc322015-03-22 16:29:04 -050041 * @param annotations optional key/value annotations
wei wei89ddc322015-03-22 16:29:04 -050042 */
jcc4a20a5f2015-04-30 15:43:39 +080043 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 wei89ddc322015-03-22 16:29:04 -050081 }
82
83 @Override
jcc4a20a5f2015-04-30 15:43:39 +080084 public TunnelEndPoint src() {
wei wei89ddc322015-03-22 16:29:04 -050085 return src;
86 }
87
88 @Override
jcc4a20a5f2015-04-30 15:43:39 +080089 public TunnelEndPoint dst() {
wei wei89ddc322015-03-22 16:29:04 -050090 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
jcc4a20a5f2015-04-30 15:43:39 +0800104 public NetworkResource resource() {
105 return null;
wei wei89ddc322015-03-22 16:29:04 -0500106 }
107
108 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800109 public TunnelId tunnelId() {
110 return tunnelId;
wei wei89ddc322015-03-22 16:29:04 -0500111 }
112
113 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800114 public DefaultGroupId groupId() {
115 return groupId;
116 }
117
118 @Override
119 public TunnelName tunnelName() {
120 return tunnelName;
wei wei89ddc322015-03-22 16:29:04 -0500121 }
122
123 @Override
124 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +0800125 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
126 state);
wei wei89ddc322015-03-22 16:29:04 -0500127 }
128
wei wei89ddc322015-03-22 16:29:04 -0500129 @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;
jcc4a20a5f2015-04-30 15:43:39 +0800136 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 wei89ddc322015-03-22 16:29:04 -0500143 }
144 return false;
145 }
146
147 @Override
148 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +0800149 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 wei89ddc322015-03-22 16:29:04 -0500153 }
154
155}