blob: 23e6c02c8871ff4fc4984f7b0e50ed41e72f8b69 [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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Thomas Vachuskac96058a2014-10-20 23:00:16 -070018import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.core.ApplicationId;
20import org.onosproject.net.Link;
21import org.onosproject.net.NetworkResource;
22import org.onosproject.net.flow.TrafficSelector;
23import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070024
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
Ray Milkeye1dfb502015-01-13 16:35:46 -080058 * @throws NullPointerException if the selector or treatment 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) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070064 this(appId, null, resources, selector, treatment, Collections.emptyList(),
65 DEFAULT_INTENT_PRIORITY);
Ray Milkey5b3717e2015-02-05 11:44:08 -080066 }
67
68 /**
69 * Creates a connectivity intent that matches on the specified selector
70 * and applies the specified treatment.
71 * <p>
72 * Path will be chosen without any constraints.
73 * </p>
74 *
75 * @param appId application identifier
76 * @param key intent key
77 * @param resources required network resources (optional)
78 * @param selector traffic selector
79 * @param treatment treatment
80 * @throws NullPointerException if the selector or treatment is null
81 */
82 protected ConnectivityIntent(ApplicationId appId,
83 Key key,
84 Collection<NetworkResource> resources,
85 TrafficSelector selector,
86 TrafficTreatment treatment) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070087 this(appId, key, resources, selector, treatment, Collections.emptyList(),
88 DEFAULT_INTENT_PRIORITY);
Ray Milkey5b3717e2015-02-05 11:44:08 -080089 }
90
91 /**
92 * Creates a connectivity intent that matches on the specified selector
93 * and applies the specified treatment.
94 * <p>
95 * Path will be optimized based on the first constraint if one is given.
96 * </p>
97 *
98 * @param appId application identifier
99 * @param key explicit key to use for intent
100 * @param resources required network resources (optional)
101 * @param selector traffic selector
102 * @param treatment treatment
103 * @param constraints optional prioritized list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700104 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -0800105 * @throws NullPointerException if the selector or treatment is null
106 */
107
108 protected ConnectivityIntent(ApplicationId appId,
109 Key key,
110 Collection<NetworkResource> resources,
111 TrafficSelector selector,
112 TrafficTreatment treatment,
Ray Milkeyc24cde32015-03-10 18:20:18 -0700113 List<Constraint> constraints,
114 int priority) {
115 super(appId, key, resources, priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800116 this.selector = checkNotNull(selector);
117 this.treatment = checkNotNull(treatment);
118 this.constraints = checkNotNull(constraints);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800119 }
120
121 /**
122 * Creates a connectivity intent that matches on the specified selector
123 * and applies the specified treatment.
124 * <p>
125 * Path will be optimized based on the first constraint if one is given.
126 * </p>
127 *
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800128 * @param appId application identifier
129 * @param resources required network resources (optional)
130 * @param selector traffic selector
131 * @param treatment treatment
132 * @param constraints optional prioritized list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700133 * @param priority priority to use for flows generated by this intent
Ray Milkeye1dfb502015-01-13 16:35:46 -0800134 * @throws NullPointerException if the selector or treatment is null
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800135 */
Ray Milkey5b3717e2015-02-05 11:44:08 -0800136
Brian O'Connor520c0522014-11-23 23:50:47 -0800137 protected ConnectivityIntent(ApplicationId appId,
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800138 Collection<NetworkResource> resources,
139 TrafficSelector selector,
140 TrafficTreatment treatment,
Ray Milkeyc24cde32015-03-10 18:20:18 -0700141 List<Constraint> constraints,
142 int priority) {
143 super(appId, null, resources, priority);
toma1d16b62014-10-02 23:45:11 -0700144 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700145 this.treatment = checkNotNull(treatment);
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -0800146 this.constraints = checkNotNull(constraints);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700147 }
148
149 /**
150 * Constructor for serializer.
151 */
152 protected ConnectivityIntent() {
153 super();
154 this.selector = null;
155 this.treatment = null;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -0800156 this.constraints = Collections.emptyList();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700157 }
158
159 /**
160 * Returns the match specifying the type of traffic.
161 *
162 * @return traffic match
163 */
tom85258ee2014-10-07 00:10:02 -0700164 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700165 return selector;
166 }
167
168 /**
169 * Returns the action applied to the traffic.
170 *
171 * @return applied action
172 */
tom85258ee2014-10-07 00:10:02 -0700173 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700174 return treatment;
175 }
176
Thomas Vachuskae291c842014-10-21 02:52:38 -0700177 /**
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800178 * Returns the set of connectivity constraints.
179 *
180 * @return list of intent constraints
181 */
182 public List<Constraint> constraints() {
183 return constraints;
184 }
185
186 /**
Thomas Vachuskae291c842014-10-21 02:52:38 -0700187 * Produces a collection of network resources from the given links.
188 *
189 * @param links collection of links
190 * @return collection of link resources
191 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700192 protected static Collection<NetworkResource> resources(Collection<Link> links) {
Sho SHIMIZUf4dbc7262014-11-04 18:49:02 -0800193 return ImmutableSet.copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700194 }
195
196}