blob: 9d0a22861368fc52fa5656bcf560d0a24f8d6cb9 [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
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070018import com.google.common.collect.ImmutableList;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070019import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.Link;
22import org.onosproject.net.NetworkResource;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070023import org.onosproject.net.flow.DefaultTrafficSelector;
24import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070027
Thomas Vachuskac96058a2014-10-20 23:00:16 -070028import java.util.Collection;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080029import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080030import java.util.List;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070031
toma1d16b62014-10-02 23:45:11 -070032import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070033
34/**
35 * Abstraction of connectivity intent for traffic matching some criteria.
36 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070037public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070038
39 // TODO: other forms of intents should be considered for this family:
40 // point-to-point with constraints (waypoints/obstacles)
41 // multi-to-single point with constraints (waypoints/obstacles)
42 // single-to-multi point with constraints (waypoints/obstacles)
43 // concrete path (with alternate)
44 // ...
45
46 private final TrafficSelector selector;
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 private final TrafficTreatment treatment;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080048 private final List<Constraint> constraints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070049
50 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070051 * Creates a connectivity intent that matches on the specified selector
52 * and applies the specified treatment.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080053 * <p>
Ray Milkey5b3717e2015-02-05 11:44:08 -080054 * Path will be optimized based on the first constraint if one is given.
55 * </p>
56 *
57 * @param appId application identifier
58 * @param key explicit key to use for intent
59 * @param resources required network resources (optional)
60 * @param selector traffic selector
61 * @param treatment treatment
62 * @param constraints optional prioritized list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070063 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -080064 * @throws NullPointerException if the selector or treatment is null
65 */
Ray Milkey5b3717e2015-02-05 11:44:08 -080066 protected ConnectivityIntent(ApplicationId appId,
67 Key key,
68 Collection<NetworkResource> resources,
69 TrafficSelector selector,
70 TrafficTreatment treatment,
Ray Milkeyc24cde32015-03-10 18:20:18 -070071 List<Constraint> constraints,
72 int priority) {
73 super(appId, key, resources, priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -080074 this.selector = checkNotNull(selector);
75 this.treatment = checkNotNull(treatment);
76 this.constraints = checkNotNull(constraints);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080077 }
78
79 /**
80 * Creates a connectivity intent that matches on the specified selector
81 * and applies the specified treatment.
82 * <p>
83 * Path will be optimized based on the first constraint if one is given.
84 * </p>
85 *
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080086 * @param appId application identifier
87 * @param resources required network resources (optional)
88 * @param selector traffic selector
89 * @param treatment treatment
90 * @param constraints optional prioritized list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070091 * @param priority priority to use for flows generated by this intent
Ray Milkeye1dfb502015-01-13 16:35:46 -080092 * @throws NullPointerException if the selector or treatment is null
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080093 */
Ray Milkey5b3717e2015-02-05 11:44:08 -080094
Brian O'Connor520c0522014-11-23 23:50:47 -080095 protected ConnectivityIntent(ApplicationId appId,
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080096 Collection<NetworkResource> resources,
97 TrafficSelector selector,
98 TrafficTreatment treatment,
Ray Milkeyc24cde32015-03-10 18:20:18 -070099 List<Constraint> constraints,
100 int priority) {
101 super(appId, null, resources, priority);
toma1d16b62014-10-02 23:45:11 -0700102 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700103 this.treatment = checkNotNull(treatment);
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -0800104 this.constraints = checkNotNull(constraints);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700105 }
106
107 /**
108 * Constructor for serializer.
109 */
110 protected ConnectivityIntent() {
111 super();
112 this.selector = null;
113 this.treatment = null;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -0800114 this.constraints = Collections.emptyList();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700115 }
116
117 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700118 * Abstract builder for connectivity intents.
119 */
120 public abstract static class Builder extends Intent.Builder {
121 protected TrafficSelector selector = DefaultTrafficSelector.emptySelector();
122 protected TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
123 protected List<Constraint> constraints = ImmutableList.of();
124
125 @Override
126 public Builder appId(ApplicationId appId) {
127 return (Builder) super.appId(appId);
128 }
129
130 @Override
131 public Builder key(Key key) {
132 return (Builder) super.key(key);
133 }
134
135 @Override
136 public Builder priority(int priority) {
137 return (Builder) super.priority(priority);
138 }
139
140
141 /**
142 * Sets the traffic selector for the intent that will be built.
143 *
144 * @param selector selector to use for built intent
145 * @return this builder
146 */
147 public Builder selector(TrafficSelector selector) {
148 this.selector = selector;
149 return this;
150 }
151
152 /**
153 * Sets the traffic treatment for the intent that will be built.
154 *
155 * @param treatment treatment to use for built intent
156 * @return this builder
157 */
158 public Builder treatment(TrafficTreatment treatment) {
159 this.treatment = treatment;
160 return this;
161 }
162
163 /**
164 * Sets the constraints for the intent that will be built.
165 *
166 * @param constraints constraints to use for built intent
167 * @return this builder
168 */
169 public Builder constraints(List<Constraint> constraints) {
170 this.constraints = ImmutableList.copyOf(constraints);
171 return this;
172 }
173 }
174
175
176 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700177 * Returns the match specifying the type of traffic.
178 *
179 * @return traffic match
180 */
tom85258ee2014-10-07 00:10:02 -0700181 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700182 return selector;
183 }
184
185 /**
186 * Returns the action applied to the traffic.
187 *
188 * @return applied action
189 */
tom85258ee2014-10-07 00:10:02 -0700190 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700191 return treatment;
192 }
193
Thomas Vachuskae291c842014-10-21 02:52:38 -0700194 /**
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800195 * Returns the set of connectivity constraints.
196 *
197 * @return list of intent constraints
198 */
199 public List<Constraint> constraints() {
200 return constraints;
201 }
202
203 /**
Thomas Vachuskae291c842014-10-21 02:52:38 -0700204 * Produces a collection of network resources from the given links.
205 *
206 * @param links collection of links
207 * @return collection of link resources
208 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700209 protected static Collection<NetworkResource> resources(Collection<Link> links) {
Sho SHIMIZUf4dbc7262014-11-04 18:49:02 -0800210 return ImmutableSet.copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700211 }
212
213}