blob: d69e85b9e178b412a11d1e7863af44782b9443c7 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070080 * Constructor for serializer.
81 */
82 protected ConnectivityIntent() {
83 super();
84 this.selector = null;
85 this.treatment = null;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080086 this.constraints = Collections.emptyList();
Brian O'Connorb876bf12014-10-02 14:59:37 -070087 }
88
89 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070090 * Abstract builder for connectivity intents.
91 */
92 public abstract static class Builder extends Intent.Builder {
93 protected TrafficSelector selector = DefaultTrafficSelector.emptySelector();
94 protected TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
95 protected List<Constraint> constraints = ImmutableList.of();
96
97 @Override
98 public Builder appId(ApplicationId appId) {
99 return (Builder) super.appId(appId);
100 }
101
102 @Override
103 public Builder key(Key key) {
104 return (Builder) super.key(key);
105 }
106
107 @Override
108 public Builder priority(int priority) {
109 return (Builder) super.priority(priority);
110 }
111
112
113 /**
114 * Sets the traffic selector for the intent that will be built.
115 *
116 * @param selector selector to use for built intent
117 * @return this builder
118 */
119 public Builder selector(TrafficSelector selector) {
120 this.selector = selector;
121 return this;
122 }
123
124 /**
125 * Sets the traffic treatment for the intent that will be built.
126 *
127 * @param treatment treatment to use for built intent
128 * @return this builder
129 */
130 public Builder treatment(TrafficTreatment treatment) {
131 this.treatment = treatment;
132 return this;
133 }
134
135 /**
136 * Sets the constraints for the intent that will be built.
137 *
138 * @param constraints constraints to use for built intent
139 * @return this builder
140 */
141 public Builder constraints(List<Constraint> constraints) {
142 this.constraints = ImmutableList.copyOf(constraints);
143 return this;
144 }
145 }
146
147
148 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700149 * Returns the match specifying the type of traffic.
150 *
151 * @return traffic match
152 */
tom85258ee2014-10-07 00:10:02 -0700153 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700154 return selector;
155 }
156
157 /**
158 * Returns the action applied to the traffic.
159 *
160 * @return applied action
161 */
tom85258ee2014-10-07 00:10:02 -0700162 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700163 return treatment;
164 }
165
Thomas Vachuskae291c842014-10-21 02:52:38 -0700166 /**
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800167 * Returns the set of connectivity constraints.
168 *
169 * @return list of intent constraints
170 */
171 public List<Constraint> constraints() {
172 return constraints;
173 }
174
175 /**
Thomas Vachuskae291c842014-10-21 02:52:38 -0700176 * Produces a collection of network resources from the given links.
177 *
178 * @param links collection of links
179 * @return collection of link resources
180 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700181 protected static Collection<NetworkResource> resources(Collection<Link> links) {
Sho SHIMIZUf4dbc7262014-11-04 18:49:02 -0800182 return ImmutableSet.copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700183 }
184
185}