blob: 60ba70c29024e3e6c84cab2dd1157749fc83dee4 [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
Brian O'Connorb876bf12014-10-02 14:59:37 -070045 * @throws NullPointerException {@code path} is null
46 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070047 public PathIntent(ApplicationId appId, TrafficSelector selector,
Ray Milkeycaa450b2014-10-29 15:54:24 -070048 TrafficTreatment treatment, Path path, LinkResourceRequest[] resourceRequests) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070049 super(id(PathIntent.class, selector, treatment, path), appId,
50 resources(path.links()), selector, treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070051 this.path = path;
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080052 this.resourceRequests = ImmutableList.copyOf(resourceRequests);
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 }
54
Thomas Vachuskac96058a2014-10-20 23:00:16 -070055 /**
56 * Constructor for serializer.
57 */
Brian O'Connorb876bf12014-10-02 14:59:37 -070058 protected PathIntent() {
59 super();
60 this.path = null;
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080061 this.resourceRequests = ImmutableList.of();
Brian O'Connorb876bf12014-10-02 14:59:37 -070062 }
63
64 /**
65 * Returns the links which the traffic goes along.
66 *
67 * @return traversed links
68 */
tom85258ee2014-10-07 00:10:02 -070069 public Path path() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070070 return path;
71 }
72
73 @Override
Thomas Vachuskac96058a2014-10-20 23:00:16 -070074 public boolean isInstallable() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 return true;
76 }
77
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080078 // TODO: consider changing return type
Ray Milkeycaa450b2014-10-29 15:54:24 -070079 public LinkResourceRequest[] resourceRequests() {
Yuta HIGUCHI909d2262014-11-03 15:22:42 -080080 return resourceRequests.toArray(new LinkResourceRequest[resourceRequests.size()]);
Ray Milkeycaa450b2014-10-29 15:54:24 -070081 }
82
Brian O'Connorb876bf12014-10-02 14:59:37 -070083 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -070084 public String toString() {
85 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070086 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070087 .add("appId", appId())
88 .add("selector", selector())
89 .add("treatment", treatment())
Brian O'Connorb876bf12014-10-02 14:59:37 -070090 .add("path", path)
91 .toString();
92 }
tom95329eb2014-10-06 08:40:06 -070093
Brian O'Connorb876bf12014-10-02 14:59:37 -070094}