blob: 0e9fa6d3977d528c5e383a4ce7b8e9174c815aa3 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorb876bf12014-10-02 14:59:37 -070016package org.onlab.onos.net.intent;
17
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080018import java.util.List;
19
tom95329eb2014-10-06 08:40:06 -070020import com.google.common.base.MoreObjects;
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080021import com.google.common.collect.ImmutableList;
22
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070023import org.onlab.onos.core.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -070024import org.onlab.onos.net.Path;
25import org.onlab.onos.net.flow.TrafficSelector;
26import org.onlab.onos.net.flow.TrafficTreatment;
Ray Milkeycaa450b2014-10-29 15:54:24 -070027import org.onlab.onos.net.resource.LinkResourceRequest;
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
Brian O'Connorb876bf12014-10-02 14:59:37 -070029/**
30 * Abstraction of explicitly path specified connectivity intent.
31 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070032public class PathIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070033
34 private final Path path;
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080035 private final List<LinkResourceRequest> resourceRequests;
Brian O'Connorb876bf12014-10-02 14:59:37 -070036
37 /**
38 * Creates a new point-to-point intent with the supplied ingress/egress
39 * ports and using the specified explicit path.
40 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070041 * @param appId application identifier
42 * @param selector traffic selector
43 * @param treatment treatment
44 * @param path traversed links
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080045 * @param resourceRequests link resource request
Brian O'Connorb876bf12014-10-02 14:59:37 -070046 * @throws NullPointerException {@code path} is null
47 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070048 public PathIntent(ApplicationId appId, TrafficSelector selector,
Ray Milkeycaa450b2014-10-29 15:54:24 -070049 TrafficTreatment treatment, Path path, LinkResourceRequest[] resourceRequests) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070050 super(id(PathIntent.class, selector, treatment, path), appId,
51 resources(path.links()), selector, treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 this.path = path;
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080053 this.resourceRequests = ImmutableList.copyOf(resourceRequests);
Brian O'Connorb876bf12014-10-02 14:59:37 -070054 }
55
Thomas Vachuskac96058a2014-10-20 23:00:16 -070056 /**
57 * Constructor for serializer.
58 */
Brian O'Connorb876bf12014-10-02 14:59:37 -070059 protected PathIntent() {
60 super();
61 this.path = null;
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080062 this.resourceRequests = ImmutableList.of();
Brian O'Connorb876bf12014-10-02 14:59:37 -070063 }
64
65 /**
66 * Returns the links which the traffic goes along.
67 *
68 * @return traversed links
69 */
tom85258ee2014-10-07 00:10:02 -070070 public Path path() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070071 return path;
72 }
73
74 @Override
Thomas Vachuskac96058a2014-10-20 23:00:16 -070075 public boolean isInstallable() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070076 return true;
77 }
78
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080079 // TODO: consider changing return type
Ray Milkeycaa450b2014-10-29 15:54:24 -070080 public LinkResourceRequest[] resourceRequests() {
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080081 return resourceRequests.toArray(new LinkResourceRequest[resourceRequests.size()]);
Ray Milkeycaa450b2014-10-29 15:54:24 -070082 }
83
Brian O'Connorb876bf12014-10-02 14:59:37 -070084 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -070085 public String toString() {
86 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070087 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070088 .add("appId", appId())
89 .add("selector", selector())
90 .add("treatment", treatment())
Brian O'Connorb876bf12014-10-02 14:59:37 -070091 .add("path", path)
92 .toString();
93 }
tom95329eb2014-10-06 08:40:06 -070094
Brian O'Connorb876bf12014-10-02 14:59:37 -070095}