Satish K
Committed by Gerrit Code Review

Tunnel Service extenstion to support to create tunnel from APP and also to carr…

…y Label stack as network resource

Change-Id: Ie69fd2d824bd40a14012406be3eea5b1449b5cf2
1 +/*
2 + * Copyright 2016-present 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 +package org.onosproject.incubator.net.tunnel;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.collect.ImmutableList;
20 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
21 +import java.util.List;
22 +import java.util.Objects;
23 +
24 +/**
25 + * Default implementation of label stack.
26 + */
27 +public class DefaultLabelStack implements LabelStack {
28 +
29 + private final List<LabelResourceId> labelResources;
30 +
31 + /**
32 + * Creates label stack.
33 + *
34 + * @param labelResources contiguous label ids that comprise the path
35 + */
36 + public DefaultLabelStack(List<LabelResourceId> labelResources) {
37 + this.labelResources = ImmutableList.copyOf(labelResources);
38 + }
39 +
40 + @Override
41 + public List<LabelResourceId> labelResources() {
42 + return labelResources;
43 + }
44 +
45 + @Override
46 + public String toString() {
47 + return MoreObjects.toStringHelper(this)
48 + .add("labelResources", labelResources)
49 + .toString();
50 + }
51 +
52 + @Override
53 + public int hashCode() {
54 + return labelResources.hashCode();
55 + }
56 +
57 + @Override
58 + public boolean equals(Object obj) {
59 + if (this == obj) {
60 + return true;
61 + }
62 + if (obj instanceof DefaultLabelStack) {
63 + final DefaultLabelStack other = (DefaultLabelStack) obj;
64 + return Objects.equals(this.labelResources, other.labelResources);
65 + }
66 + return false;
67 + }
68 +}
...@@ -45,6 +45,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel { ...@@ -45,6 +45,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel {
45 // ONOS as primary key 45 // ONOS as primary key
46 private final TunnelName tunnelName; // name of a tunnel 46 private final TunnelName tunnelName; // name of a tunnel
47 private final Path path; 47 private final Path path;
48 + private final NetworkResource networkRes; // network resource to carry label stack
48 49
49 /** 50 /**
50 * Creates an active infrastructure tunnel using the supplied information. 51 * Creates an active infrastructure tunnel using the supplied information.
...@@ -94,6 +95,61 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel { ...@@ -94,6 +95,61 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel {
94 this.tunnelId = tunnelId; 95 this.tunnelId = tunnelId;
95 this.tunnelName = tunnelName; 96 this.tunnelName = tunnelName;
96 this.path = path; 97 this.path = path;
98 + this.networkRes = null;
99 + }
100 +
101 + /**
102 + * Creates an active infrastructure tunnel using the supplied information.
103 + *
104 + * @param producerName provider identity
105 + * @param src tunnel source
106 + * @param dst tunnel destination
107 + * @param type tunnel type
108 + * @param groupId groupId
109 + * @param tunnelId tunnelId
110 + * @param tunnelName tunnel name
111 + * @param path the path of tunnel
112 + * @param networkRes network resource of tunnel
113 + * @param annotations optional key/value annotations
114 + */
115 + public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
116 + TunnelEndPoint dst, Type type, DefaultGroupId groupId,
117 + TunnelId tunnelId, TunnelName tunnelName, Path path,
118 + NetworkResource networkRes, Annotations... annotations) {
119 + this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
120 + tunnelId, tunnelName, path, networkRes, annotations);
121 + }
122 +
123 + /**
124 + * Creates an tunnel using the supplied information.
125 + *
126 + * @param producerName provider identity
127 + * @param src tunnel source
128 + * @param dst tunnel destination
129 + * @param type tunnel type
130 + * @param state tunnel state
131 + * @param groupId groupId
132 + * @param tunnelId tunnelId
133 + * @param tunnelName tunnel name
134 + * @param path the path of tunnel
135 + * @param networkRes network resource of tunnel
136 + * @param annotations optional key/value annotations
137 + */
138 + public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
139 + TunnelEndPoint dst, Type type, State state,
140 + DefaultGroupId groupId, TunnelId tunnelId,
141 + TunnelName tunnelName, Path path, NetworkResource networkRes,
142 + Annotations... annotations) {
143 + super(producerName, annotations);
144 + this.src = src;
145 + this.dst = dst;
146 + this.type = type;
147 + this.state = state;
148 + this.groupId = groupId;
149 + this.tunnelId = tunnelId;
150 + this.tunnelName = tunnelName;
151 + this.path = path;
152 + this.networkRes = networkRes;
97 } 153 }
98 154
99 @Override 155 @Override
...@@ -118,7 +174,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel { ...@@ -118,7 +174,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel {
118 174
119 @Override 175 @Override
120 public NetworkResource resource() { 176 public NetworkResource resource() {
121 - return null; 177 + return networkRes;
122 } 178 }
123 179
124 @Override 180 @Override
...@@ -145,7 +201,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel { ...@@ -145,7 +201,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel {
145 @Override 201 @Override
146 public int hashCode() { 202 public int hashCode() {
147 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName, 203 return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
148 - state, path); 204 + state, path, networkRes);
149 } 205 }
150 206
151 @Override 207 @Override
...@@ -162,7 +218,8 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel { ...@@ -162,7 +218,8 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel {
162 && Objects.equals(this.tunnelId, other.tunnelId) 218 && Objects.equals(this.tunnelId, other.tunnelId)
163 && Objects.equals(this.tunnelName, other.tunnelName) 219 && Objects.equals(this.tunnelName, other.tunnelName)
164 && Objects.equals(this.state, other.state) 220 && Objects.equals(this.state, other.state)
165 - && Objects.equals(this.path, other.path); 221 + && Objects.equals(this.path, other.path)
222 + && Objects.equals(this.networkRes, other.networkRes);
166 } 223 }
167 return false; 224 return false;
168 } 225 }
...@@ -173,6 +230,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel { ...@@ -173,6 +230,7 @@ public final class DefaultTunnel extends AbstractModel implements Tunnel {
173 .add("type", type).add("state", state).add("groupId", groupId) 230 .add("type", type).add("state", state).add("groupId", groupId)
174 .add("producerTunnelId", tunnelId) 231 .add("producerTunnelId", tunnelId)
175 .add("tunnelName", tunnelName) 232 .add("tunnelName", tunnelName)
176 - .add("path", path).toString(); 233 + .add("path", path)
234 + .add("networkResource", networkRes).toString();
177 } 235 }
178 } 236 }
......
...@@ -18,6 +18,7 @@ package org.onosproject.incubator.net.tunnel; ...@@ -18,6 +18,7 @@ package org.onosproject.incubator.net.tunnel;
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 import org.onosproject.core.DefaultGroupId; 19 import org.onosproject.core.DefaultGroupId;
20 import org.onosproject.net.AbstractDescription; 20 import org.onosproject.net.AbstractDescription;
21 +import org.onosproject.net.NetworkResource;
21 import org.onosproject.net.Path; 22 import org.onosproject.net.Path;
22 import org.onosproject.net.SparseAnnotations; 23 import org.onosproject.net.SparseAnnotations;
23 import org.onosproject.net.provider.ProviderId; 24 import org.onosproject.net.provider.ProviderId;
...@@ -41,6 +42,7 @@ public class DefaultTunnelDescription extends AbstractDescription ...@@ -41,6 +42,7 @@ public class DefaultTunnelDescription extends AbstractDescription
41 private final ProviderId producerName; // tunnel producer name 42 private final ProviderId producerName; // tunnel producer name
42 private final TunnelName tunnelName; // name of a tunnel 43 private final TunnelName tunnelName; // name of a tunnel
43 private final Path path; 44 private final Path path;
45 + private final NetworkResource networkRes;
44 46
45 /** 47 /**
46 * Creates a tunnel description using the supplied information. 48 * Creates a tunnel description using the supplied information.
...@@ -71,6 +73,41 @@ public class DefaultTunnelDescription extends AbstractDescription ...@@ -71,6 +73,41 @@ public class DefaultTunnelDescription extends AbstractDescription
71 this.producerName = producerName; 73 this.producerName = producerName;
72 this.tunnelName = tunnelName; 74 this.tunnelName = tunnelName;
73 this.path = path; 75 this.path = path;
76 + this.networkRes = null;
77 + }
78 +
79 + /**
80 + * Creates a tunnel description using the supplied information.
81 + *
82 + * @param id TunnelId
83 + * @param src TunnelPoint source
84 + * @param dst TunnelPoint destination
85 + * @param type tunnel type
86 + * @param groupId groupId
87 + * @param producerName tunnel producer
88 + * @param tunnelName tunnel name
89 + * @param path the path of tunnel
90 + * @param networkRes network resource of tunnel
91 + * @param annotations optional key/value annotations
92 + */
93 + public DefaultTunnelDescription(TunnelId id, TunnelEndPoint src,
94 + TunnelEndPoint dst, Tunnel.Type type,
95 + DefaultGroupId groupId,
96 + ProviderId producerName,
97 + TunnelName tunnelName,
98 + Path path,
99 + NetworkResource networkRes,
100 + SparseAnnotations... annotations) {
101 + super(annotations);
102 + this.tunnelId = id;
103 + this.src = src;
104 + this.dst = dst;
105 + this.type = type;
106 + this.groupId = groupId;
107 + this.producerName = producerName;
108 + this.tunnelName = tunnelName;
109 + this.path = path;
110 + this.networkRes = networkRes;
74 } 111 }
75 112
76 @Override 113 @Override
...@@ -115,6 +152,11 @@ public class DefaultTunnelDescription extends AbstractDescription ...@@ -115,6 +152,11 @@ public class DefaultTunnelDescription extends AbstractDescription
115 } 152 }
116 153
117 @Override 154 @Override
155 + public NetworkResource resource() {
156 + return networkRes;
157 + }
158 +
159 + @Override
118 public String toString() { 160 public String toString() {
119 return MoreObjects.toStringHelper(this) 161 return MoreObjects.toStringHelper(this)
120 .add("tunnelId", id()) 162 .add("tunnelId", id())
...@@ -125,6 +167,7 @@ public class DefaultTunnelDescription extends AbstractDescription ...@@ -125,6 +167,7 @@ public class DefaultTunnelDescription extends AbstractDescription
125 .add("producerName", producerName()) 167 .add("producerName", producerName())
126 .add("groupId", groupId()) 168 .add("groupId", groupId())
127 .add("path", path) 169 .add("path", path)
170 + .add("resource", networkRes)
128 .toString(); 171 .toString();
129 } 172 }
130 } 173 }
......
1 +/*
2 + * Copyright 2016-present 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 +package org.onosproject.incubator.net.tunnel;
17 +
18 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
19 +import org.onosproject.net.NetworkResource;
20 +
21 +import java.util.List;
22 +
23 +/**
24 + * Representation of a label stack in a network which represents the network path.
25 + */
26 +public interface LabelStack extends NetworkResource {
27 +
28 + /**
29 + * Returns sequence of label resources comprising the path.
30 + *
31 + * @return list of links
32 + */
33 + List<LabelResourceId> labelResources();
34 +}
...@@ -20,6 +20,7 @@ import org.onosproject.core.DefaultGroupId; ...@@ -20,6 +20,7 @@ import org.onosproject.core.DefaultGroupId;
20 import org.onosproject.incubator.net.tunnel.Tunnel.Type; 20 import org.onosproject.incubator.net.tunnel.Tunnel.Type;
21 import org.onosproject.net.Annotated; 21 import org.onosproject.net.Annotated;
22 import org.onosproject.net.Description; 22 import org.onosproject.net.Description;
23 +import org.onosproject.net.NetworkResource;
23 import org.onosproject.net.Path; 24 import org.onosproject.net.Path;
24 import org.onosproject.net.provider.ProviderId; 25 import org.onosproject.net.provider.ProviderId;
25 26
...@@ -84,4 +85,11 @@ public interface TunnelDescription extends Description, Annotated { ...@@ -84,4 +85,11 @@ public interface TunnelDescription extends Description, Annotated {
84 * @return the path of the tunnel 85 * @return the path of the tunnel
85 */ 86 */
86 Path path(); 87 Path path();
88 +
89 + /**
90 + * Returns the network resource backing the tunnel, e.g. lambda, VLAN id, MPLS tag, label stack.
91 + *
92 + * @return backing resource
93 + */
94 + NetworkResource resource();
87 } 95 }
......
...@@ -67,6 +67,7 @@ public class TunnelManager ...@@ -67,6 +67,7 @@ public class TunnelManager
67 implements TunnelService, TunnelAdminService, TunnelProviderRegistry { 67 implements TunnelService, TunnelAdminService, TunnelProviderRegistry {
68 68
69 private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null"; 69 private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null";
70 + private static final String TUNNNEL_NULL = "Tunnel cannot be null";
70 71
71 private final Logger log = getLogger(getClass()); 72 private final Logger log = getLogger(getClass());
72 73
...@@ -235,13 +236,35 @@ public class TunnelManager ...@@ -235,13 +236,35 @@ public class TunnelManager
235 236
236 @Override 237 @Override
237 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) { 238 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
238 - // TODO: Insert into store and trigger provider API. 239 + // TODO: producerId to check if really required to consider while setup the tunnel.
239 - return null; 240 + checkNotNull(tunnel, TUNNNEL_NULL);
241 + TunnelId tunnelId = store.createOrUpdateTunnel(tunnel, State.INIT);
242 + if (tunnelId != null) {
243 + Set<ProviderId> ids = getProviders();
244 + for (ProviderId providerId : ids) {
245 + TunnelProvider provider = getProvider(providerId);
246 + provider.setupTunnel(srcElementId, tunnel, path);
247 + }
248 + }
249 + return tunnelId;
240 } 250 }
241 251
242 @Override 252 @Override
243 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) { 253 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
244 - // TODO: Change the tunnel status and trigger provider API. 254 + // TODO: producerId to check if really required to consider while deleting the tunnel.
255 + checkNotNull(tunnelId, TUNNNEL_ID_NULL);
256 + Tunnel tunnel = store.queryTunnel(tunnelId);
257 + if (tunnel != null) {
258 + TunnelId updtTunnelId = store.createOrUpdateTunnel(tunnel, State.INACTIVE);
259 + if (updtTunnelId != null) {
260 + Set<ProviderId> ids = getProviders();
261 + for (ProviderId providerId : ids) {
262 + TunnelProvider provider = getProvider(providerId);
263 + provider.releaseTunnel(tunnel);
264 + }
265 + }
266 + return true;
267 + }
245 return false; 268 return false;
246 } 269 }
247 270
...@@ -324,6 +347,7 @@ public class TunnelManager ...@@ -324,6 +347,7 @@ public class TunnelManager
324 tunnel.id(), 347 tunnel.id(),
325 tunnel.tunnelName(), 348 tunnel.tunnelName(),
326 tunnel.path(), 349 tunnel.path(),
350 + tunnel.resource(),
327 tunnel.annotations()); 351 tunnel.annotations());
328 return store.createOrUpdateTunnel(storedTunnel); 352 return store.createOrUpdateTunnel(storedTunnel);
329 } 353 }
...@@ -338,6 +362,7 @@ public class TunnelManager ...@@ -338,6 +362,7 @@ public class TunnelManager
338 tunnel.id(), 362 tunnel.id(),
339 tunnel.tunnelName(), 363 tunnel.tunnelName(),
340 tunnel.path(), 364 tunnel.path(),
365 + tunnel.resource(),
341 tunnel.annotations()); 366 tunnel.annotations());
342 return store.createOrUpdateTunnel(storedTunnel); 367 return store.createOrUpdateTunnel(storedTunnel);
343 } 368 }
...@@ -351,6 +376,7 @@ public class TunnelManager ...@@ -351,6 +376,7 @@ public class TunnelManager
351 tunnel.id(), 376 tunnel.id(),
352 tunnel.tunnelName(), 377 tunnel.tunnelName(),
353 tunnel.path(), 378 tunnel.path(),
379 + tunnel.resource(),
354 tunnel.annotations()); 380 tunnel.annotations());
355 store.createOrUpdateTunnel(storedTunnel); 381 store.createOrUpdateTunnel(storedTunnel);
356 } 382 }
...@@ -365,6 +391,7 @@ public class TunnelManager ...@@ -365,6 +391,7 @@ public class TunnelManager
365 tunnel.id(), 391 tunnel.id(),
366 tunnel.tunnelName(), 392 tunnel.tunnelName(),
367 tunnel.path(), 393 tunnel.path(),
394 + tunnel.resource(),
368 tunnel.annotations()); 395 tunnel.annotations());
369 store.createOrUpdateTunnel(storedTunnel, state); 396 store.createOrUpdateTunnel(storedTunnel, state);
370 } 397 }
......
...@@ -174,6 +174,7 @@ public class DistributedTunnelStore ...@@ -174,6 +174,7 @@ public class DistributedTunnelStore
174 old.tunnelId(), 174 old.tunnelId(),
175 old.tunnelName(), 175 old.tunnelName(),
176 old.path(), 176 old.path(),
177 + old.resource(),
177 DefaultAnnotations.merge(oldAnno, newAnno)); 178 DefaultAnnotations.merge(oldAnno, newAnno));
178 tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT); 179 tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT);
179 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, 180 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED,
...@@ -189,6 +190,7 @@ public class DistributedTunnelStore ...@@ -189,6 +190,7 @@ public class DistributedTunnelStore
189 tunnelId, 190 tunnelId,
190 tunnel.tunnelName(), 191 tunnel.tunnelName(),
191 tunnel.path(), 192 tunnel.path(),
193 + tunnel.resource(),
192 tunnel.annotations()); 194 tunnel.annotations());
193 tunnelIdAsKeyStore.put(tunnelId, newT); 195 tunnelIdAsKeyStore.put(tunnelId, newT);
194 196
......