Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 18 | import java.util.List; |
| 19 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 20 | import com.google.common.base.MoreObjects; |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableList; |
| 22 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 23 | import org.onlab.onos.core.ApplicationId; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 24 | import org.onlab.onos.net.Path; |
| 25 | import org.onlab.onos.net.flow.TrafficSelector; |
| 26 | import org.onlab.onos.net.flow.TrafficTreatment; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 27 | import org.onlab.onos.net.resource.LinkResourceRequest; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 28 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Abstraction of explicitly path specified connectivity intent. |
| 31 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 32 | public class PathIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 33 | |
| 34 | private final Path path; |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 35 | private final List<LinkResourceRequest> resourceRequests; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 39 | * ports and using the specified explicit path. |
| 40 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 41 | * @param appId application identifier |
| 42 | * @param selector traffic selector |
| 43 | * @param treatment treatment |
| 44 | * @param path traversed links |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame^] | 45 | * @param resourceRequests link resource request |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 46 | * @throws NullPointerException {@code path} is null |
| 47 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 48 | public PathIntent(ApplicationId appId, TrafficSelector selector, |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 49 | TrafficTreatment treatment, Path path, LinkResourceRequest[] resourceRequests) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 50 | super(id(PathIntent.class, selector, treatment, path), appId, |
| 51 | resources(path.links()), selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 52 | this.path = path; |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 53 | this.resourceRequests = ImmutableList.copyOf(resourceRequests); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Constructor for serializer. |
| 58 | */ |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 59 | protected PathIntent() { |
| 60 | super(); |
| 61 | this.path = null; |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 62 | this.resourceRequests = ImmutableList.of(); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the links which the traffic goes along. |
| 67 | * |
| 68 | * @return traversed links |
| 69 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 70 | public Path path() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 71 | return path; |
| 72 | } |
| 73 | |
| 74 | @Override |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 75 | public boolean isInstallable() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 79 | // TODO: consider changing return type |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 80 | public LinkResourceRequest[] resourceRequests() { |
Yuta HIGUCHI | 909d226 | 2014-11-03 15:22:42 -0800 | [diff] [blame] | 81 | return resourceRequests.toArray(new LinkResourceRequest[resourceRequests.size()]); |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 84 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 85 | public String toString() { |
| 86 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 87 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 88 | .add("appId", appId()) |
| 89 | .add("selector", selector()) |
| 90 | .add("treatment", treatment()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 91 | .add("path", path) |
| 92 | .toString(); |
| 93 | } |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 94 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 95 | } |