blob: 5f448e0fe188f27be1cb8aecc7a65f081ba04ef2 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
samuel7a5691a2015-05-23 00:36:32 +08002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07003 *
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 Vachuskabf916ea2015-05-20 18:24:34 -070016package org.onosproject.incubator.net.tunnel;
wei wei89ddc322015-03-22 16:29:04 -050017
18import static com.google.common.base.MoreObjects.toStringHelper;
wei wei89ddc322015-03-22 16:29:04 -050019
20import java.util.Objects;
21
jcc4a20a5f2015-04-30 15:43:39 +080022import org.onosproject.core.DefaultGroupId;
wei wei89ddc322015-03-22 16:29:04 -050023import org.onosproject.net.AbstractModel;
24import org.onosproject.net.Annotations;
jcc4a20a5f2015-04-30 15:43:39 +080025import org.onosproject.net.NetworkResource;
samuel7a5691a2015-05-23 00:36:32 +080026import org.onosproject.net.Path;
wei wei89ddc322015-03-22 16:29:04 -050027import org.onosproject.net.provider.ProviderId;
wei wei89ddc322015-03-22 16:29:04 -050028
29/**
jcc4a20a5f2015-04-30 15:43:39 +080030 * 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 wei89ddc322015-03-22 16:29:04 -050032 */
33public final class DefaultTunnel extends AbstractModel implements Tunnel {
jcc4a20a5f2015-04-30 15:43:39 +080034
35 private final TunnelEndPoint src; // a source point of tunnel.
36 private final TunnelEndPoint dst; // a destination point of tunnel.
wei wei89ddc322015-03-22 16:29:04 -050037 private final State state;
jcc4a20a5f2015-04-30 15:43:39 +080038 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
samuel7a5691a2015-05-23 00:36:32 +080045 private final Path path;
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
samuel7a5691a2015-05-23 00:36:32 +080057 * @param path the path of tunnel
wei wei89ddc322015-03-22 16:29:04 -050058 * @param annotations optional key/value annotations
wei wei89ddc322015-03-22 16:29:04 -050059 */
jcc4a20a5f2015-04-30 15:43:39 +080060 public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
61 TunnelEndPoint dst, Type type, DefaultGroupId groupId,
samuel7a5691a2015-05-23 00:36:32 +080062 TunnelId tunnelId, TunnelName tunnelName, Path path,
jcc4a20a5f2015-04-30 15:43:39 +080063 Annotations... annotations) {
64 this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
samuel7a5691a2015-05-23 00:36:32 +080065 tunnelId, tunnelName, path, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080066 }
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
samuel7a5691a2015-05-23 00:36:32 +080079 * @param path the path of tunnel
jcc4a20a5f2015-04-30 15:43:39 +080080 * @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,
samuel7a5691a2015-05-23 00:36:32 +080085 TunnelName tunnelName, Path path, Annotations... annotations) {
jcc4a20a5f2015-04-30 15:43:39 +080086 super(producerName, annotations);
jcc4a20a5f2015-04-30 15:43:39 +080087 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;
samuel7a5691a2015-05-23 00:36:32 +080094 this.path = path;
wei wei89ddc322015-03-22 16:29:04 -050095 }
96
97 @Override
jcc4a20a5f2015-04-30 15:43:39 +080098 public TunnelEndPoint src() {
wei wei89ddc322015-03-22 16:29:04 -050099 return src;
100 }
101
102 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800103 public TunnelEndPoint dst() {
wei wei89ddc322015-03-22 16:29:04 -0500104 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
jcc4a20a5f2015-04-30 15:43:39 +0800118 public NetworkResource resource() {
119 return null;
wei wei89ddc322015-03-22 16:29:04 -0500120 }
121
122 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800123 public TunnelId tunnelId() {
124 return tunnelId;
wei wei89ddc322015-03-22 16:29:04 -0500125 }
126
127 @Override
jcc4a20a5f2015-04-30 15:43:39 +0800128 public DefaultGroupId groupId() {
129 return groupId;
130 }
131
132 @Override
133 public TunnelName tunnelName() {
134 return tunnelName;
wei wei89ddc322015-03-22 16:29:04 -0500135 }
136
samuel7a5691a2015-05-23 00:36:32 +0800137
138 @Override
139 public Path path() {
140 return path;
141 }
142
wei wei89ddc322015-03-22 16:29:04 -0500143 @Override
144 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +0800145 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
samuel7a5691a2015-05-23 00:36:32 +0800146 state, path);
wei wei89ddc322015-03-22 16:29:04 -0500147 }
148
wei wei89ddc322015-03-22 16:29:04 -0500149 @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;
jcc4a20a5f2015-04-30 15:43:39 +0800156 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)
samuel7a5691a2015-05-23 00:36:32 +0800162 && Objects.equals(this.state, other.state)
163 && Objects.equals(this.path, other.path);
wei wei89ddc322015-03-22 16:29:04 -0500164 }
165 return false;
166 }
167
168 @Override
169 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +0800170 return toStringHelper(this).add("src", src).add("dst", dst)
171 .add("type", type).add("state", state).add("groupId", groupId)
172 .add("producerTunnelId", tunnelId)
samuel7a5691a2015-05-23 00:36:32 +0800173 .add("tunnelName", tunnelName)
174 .add("path", path).toString();
wei wei89ddc322015-03-22 16:29:04 -0500175 }
wei wei89ddc322015-03-22 16:29:04 -0500176}