blob: 62a5dcb3dcc0ed6c51ca39f559a495fc20fd1a76 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
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
17package org.onosproject.incubator.net.tunnel;
wei wei89ddc322015-03-22 16:29:04 -050018
jcc4a20a5f2015-04-30 15:43:39 +080019import static com.google.common.base.Preconditions.checkNotNull;
wei wei89ddc322015-03-22 16:29:04 -050020import static com.google.common.base.MoreObjects.toStringHelper;
wei wei89ddc322015-03-22 16:29:04 -050021
22import java.util.Objects;
23
jcc4a20a5f2015-04-30 15:43:39 +080024import org.onosproject.core.DefaultGroupId;
wei wei89ddc322015-03-22 16:29:04 -050025import org.onosproject.net.AbstractModel;
26import org.onosproject.net.Annotations;
jcc4a20a5f2015-04-30 15:43:39 +080027import org.onosproject.net.NetworkResource;
wei wei89ddc322015-03-22 16:29:04 -050028import org.onosproject.net.provider.ProviderId;
wei wei89ddc322015-03-22 16:29:04 -050029
30/**
jcc4a20a5f2015-04-30 15:43:39 +080031 * 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 wei89ddc322015-03-22 16:29:04 -050033 */
34public final class DefaultTunnel extends AbstractModel implements Tunnel {
jcc4a20a5f2015-04-30 15:43:39 +080035
36 private final TunnelEndPoint src; // a source point of tunnel.
37 private final TunnelEndPoint dst; // a destination point of tunnel.
wei wei89ddc322015-03-22 16:29:04 -050038 private final State state;
jcc4a20a5f2015-04-30 15:43:39 +080039 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 wei89ddc322015-03-22 16:29:04 -050046
47 /**
jcc4a20a5f2015-04-30 15:43:39 +080048 * Creates an active infrastructure tunnel using the supplied information.
wei wei89ddc322015-03-22 16:29:04 -050049 *
jcc4a20a5f2015-04-30 15:43:39 +080050 * @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 wei89ddc322015-03-22 16:29:04 -050057 * @param annotations optional key/value annotations
wei wei89ddc322015-03-22 16:29:04 -050058 */
jcc4a20a5f2015-04-30 15:43:39 +080059 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 wei89ddc322015-03-22 16:29:04 -050097 }
98
99 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800100 public TunnelEndPoint src() {
wei wei89ddc322015-03-22 16:29:04 -0500101 return src;
102 }
103
104 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800105 public TunnelEndPoint dst() {
wei wei89ddc322015-03-22 16:29:04 -0500106 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
jcc4a20a5f2015-04-30 15:43:39 +0800120 public NetworkResource resource() {
121 return null;
wei wei89ddc322015-03-22 16:29:04 -0500122 }
123
124 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800125 public TunnelId tunnelId() {
126 return tunnelId;
wei wei89ddc322015-03-22 16:29:04 -0500127 }
128
129 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800130 public DefaultGroupId groupId() {
131 return groupId;
132 }
133
134 @Override
135 public TunnelName tunnelName() {
136 return tunnelName;
wei wei89ddc322015-03-22 16:29:04 -0500137 }
138
139 @Override
140 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +0800141 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
142 state);
wei wei89ddc322015-03-22 16:29:04 -0500143 }
144
wei wei89ddc322015-03-22 16:29:04 -0500145 @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;
jcc4a20a5f2015-04-30 15:43:39 +0800152 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 wei89ddc322015-03-22 16:29:04 -0500159 }
160 return false;
161 }
162
163 @Override
164 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +0800165 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 wei89ddc322015-03-22 16:29:04 -0500169 }
170
171}