blob: 9059522dbc67fcbd42157762c7113296b9a265c6 [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
Thomas Vachuskac96058a2014-10-20 23:00:16 -070018import com.google.common.collect.ImmutableSet;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070019import org.onlab.onos.core.ApplicationId;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070020import org.onlab.onos.net.Link;
21import org.onlab.onos.net.NetworkResource;
Brian O'Connorb876bf12014-10-02 14:59:37 -070022import org.onlab.onos.net.flow.TrafficSelector;
23import org.onlab.onos.net.flow.TrafficTreatment;
24
Thomas Vachuskac96058a2014-10-20 23:00:16 -070025import java.util.Collection;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080026import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080027import java.util.List;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070028
toma1d16b62014-10-02 23:45:11 -070029import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
31/**
32 * Abstraction of connectivity intent for traffic matching some criteria.
33 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070034public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070035
36 // TODO: other forms of intents should be considered for this family:
37 // point-to-point with constraints (waypoints/obstacles)
38 // multi-to-single point with constraints (waypoints/obstacles)
39 // single-to-multi point with constraints (waypoints/obstacles)
40 // concrete path (with alternate)
41 // ...
42
43 private final TrafficSelector selector;
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 private final TrafficTreatment treatment;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080045 private final List<Constraint> constraints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070046
47 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070048 * Creates a connectivity intent that matches on the specified selector
49 * and applies the specified treatment.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080050 * <p>
51 * Path will be chosen without any constraints.
52 * </p>
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070054 * @param appId application identifier
55 * @param resources required network resources (optional)
56 * @param selector traffic selector
57 * @param treatment treatment
toma1d16b62014-10-02 23:45:11 -070058 * @throws NullPointerException if the selector or treatement is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070059 */
Brian O'Connor520c0522014-11-23 23:50:47 -080060 protected ConnectivityIntent(ApplicationId appId,
Thomas Vachuskac96058a2014-10-20 23:00:16 -070061 Collection<NetworkResource> resources,
62 TrafficSelector selector,
63 TrafficTreatment treatment) {
Brian O'Connor520c0522014-11-23 23:50:47 -080064 this(appId, resources, selector, treatment, Collections.emptyList());
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080065 }
66
67 /**
68 * Creates a connectivity intent that matches on the specified selector
69 * and applies the specified treatment.
70 * <p>
71 * Path will be optimized based on the first constraint if one is given.
72 * </p>
73 *
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080074 * @param appId application identifier
75 * @param resources required network resources (optional)
76 * @param selector traffic selector
77 * @param treatment treatment
78 * @param constraints optional prioritized list of constraints
79 * @throws NullPointerException if the selector or treatement is null
80 */
Brian O'Connor520c0522014-11-23 23:50:47 -080081 protected ConnectivityIntent(ApplicationId appId,
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080082 Collection<NetworkResource> resources,
83 TrafficSelector selector,
84 TrafficTreatment treatment,
85 List<Constraint> constraints) {
Brian O'Connor520c0522014-11-23 23:50:47 -080086 super(appId, resources);
toma1d16b62014-10-02 23:45:11 -070087 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070088 this.treatment = checkNotNull(treatment);
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080089 this.constraints = checkNotNull(constraints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070090 }
91
92 /**
93 * Constructor for serializer.
94 */
95 protected ConnectivityIntent() {
96 super();
97 this.selector = null;
98 this.treatment = null;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080099 this.constraints = Collections.emptyList();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700100 }
101
102 /**
103 * Returns the match specifying the type of traffic.
104 *
105 * @return traffic match
106 */
tom85258ee2014-10-07 00:10:02 -0700107 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700108 return selector;
109 }
110
111 /**
112 * Returns the action applied to the traffic.
113 *
114 * @return applied action
115 */
tom85258ee2014-10-07 00:10:02 -0700116 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700117 return treatment;
118 }
119
Thomas Vachuskae291c842014-10-21 02:52:38 -0700120 /**
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800121 * Returns the set of connectivity constraints.
122 *
123 * @return list of intent constraints
124 */
125 public List<Constraint> constraints() {
126 return constraints;
127 }
128
129 /**
Thomas Vachuskae291c842014-10-21 02:52:38 -0700130 * Produces a collection of network resources from the given links.
131 *
132 * @param links collection of links
133 * @return collection of link resources
134 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700135 protected static Collection<NetworkResource> resources(Collection<Link> links) {
Sho SHIMIZUf4dbc7262014-11-04 18:49:02 -0800136 return ImmutableSet.copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700137 }
138
139}