blob: f7ca15cd0b06aea73802783cc9b575934219e33e [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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;
Ray Milkey0742ec92014-10-13 08:39:55 -070017
Ray Milkeyebc5d222015-03-18 15:45:36 -070018import java.util.List;
19import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010020
Brian O'Connor9476fa12015-06-25 15:17:17 -040021import com.google.common.annotations.Beta;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.Link;
25import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070027
Ray Milkeyebc5d222015-03-18 15:45:36 -070028import com.google.common.base.MoreObjects;
29import com.google.common.collect.ImmutableSet;
Ray Milkey0742ec92014-10-13 08:39:55 -070030
31/**
32 * Abstraction of a connectivity intent that is implemented by a set of path
33 * segments.
34 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040035@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070036public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070037
38 private final Set<Link> links;
39
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080040 private final Set<ConnectPoint> ingressPoints;
Michele Santuari4a338072014-11-05 18:38:55 +010041 private final Set<ConnectPoint> egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070042
Ray Milkey0742ec92014-10-13 08:39:55 -070043 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080044 * Creates a new actionable intent capable of funneling the selected
45 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080046 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080047 *
48 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070049 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080050 * @param selector traffic match
51 * @param treatment action
52 * @param links traversed links
Ray Milkeyebc5d222015-03-18 15:45:36 -070053 * @param ingressPoints ingress points
54 * @param egressPoints egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080055 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070056 * @param priority priority to use for the flows generated by this intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080057 * @throws NullPointerException {@code path} is null
58 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070059 private LinkCollectionIntent(ApplicationId appId,
60 Key key,
Michele Santuari4a338072014-11-05 18:38:55 +010061 TrafficSelector selector,
62 TrafficTreatment treatment,
63 Set<Link> links,
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080064 Set<ConnectPoint> ingressPoints,
Michele Santuari4a338072014-11-05 18:38:55 +010065 Set<ConnectPoint> egressPoints,
Ray Milkeyc24cde32015-03-10 18:20:18 -070066 List<Constraint> constraints,
67 int priority) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070068 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010069 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070070 this.ingressPoints = ingressPoints;
71 this.egressPoints = egressPoints;
Ray Milkey0742ec92014-10-13 08:39:55 -070072 }
73
Thomas Vachuskac96058a2014-10-20 23:00:16 -070074 /**
75 * Constructor for serializer.
76 */
Ray Milkey0742ec92014-10-13 08:39:55 -070077 protected LinkCollectionIntent() {
78 super();
79 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080080 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +010081 this.egressPoints = null;
Ray Milkey0742ec92014-10-13 08:39:55 -070082 }
83
Ray Milkeye6684082014-10-16 16:59:47 -070084 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070085 * Returns a new link collection intent builder. The application id,
86 * ingress point and egress points are required fields. If they are
87 * not set by calls to the appropriate methods, an exception will
88 * be thrown.
89 *
90 * @return single point to multi point builder
91 */
92 public static Builder builder() {
93 return new Builder();
94 }
95
96 /**
97 * Builder of a single point to multi point intent.
98 */
99 public static final class Builder extends ConnectivityIntent.Builder {
100 Set<Link> links;
101 Set<ConnectPoint> ingressPoints;
102 Set<ConnectPoint> egressPoints;
103
104 private Builder() {
105 // Hide constructor
106 }
107
108 @Override
109 public Builder appId(ApplicationId appId) {
110 return (Builder) super.appId(appId);
111 }
112
113 @Override
114 public Builder key(Key key) {
115 return (Builder) super.key(key);
116 }
117
118 @Override
119 public Builder selector(TrafficSelector selector) {
120 return (Builder) super.selector(selector);
121 }
122
123 @Override
124 public Builder treatment(TrafficTreatment treatment) {
125 return (Builder) super.treatment(treatment);
126 }
127
128 @Override
129 public Builder constraints(List<Constraint> constraints) {
130 return (Builder) super.constraints(constraints);
131 }
132
133 @Override
134 public Builder priority(int priority) {
135 return (Builder) super.priority(priority);
136 }
137
138 /**
139 * Sets the ingress point of the single point to multi point intent
140 * that will be built.
141 *
142 * @param ingressPoints ingress connect points
143 * @return this builder
144 */
145 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
146 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
147 return this;
148 }
149
150 /**
151 * Sets the egress points of the single point to multi point intent
152 * that will be built.
153 *
154 * @param egressPoints egress connect points
155 * @return this builder
156 */
157 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
158 this.egressPoints = ImmutableSet.copyOf(egressPoints);
159 return this;
160 }
161
162 /**
163 * Sets the links of the link collection intent
164 * that will be built.
165 *
166 * @param links links for the intent
167 * @return this builder
168 */
169 public Builder links(Set<Link> links) {
170 this.links = ImmutableSet.copyOf(links);
171 return this;
172 }
173
174
175 /**
176 * Builds a single point to multi point intent from the
177 * accumulated parameters.
178 *
179 * @return point to point intent
180 */
181 public LinkCollectionIntent build() {
182
183 return new LinkCollectionIntent(
184 appId,
185 key,
186 selector,
187 treatment,
188 links,
189 ingressPoints,
190 egressPoints,
191 constraints,
192 priority
193 );
194 }
195 }
196
197
198 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700199 * Returns the set of links that represent the network connections needed
200 * by this intent.
201 *
202 * @return Set of links for the network hops needed by this intent
203 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700204 public Set<Link> links() {
205 return links;
206 }
207
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700208 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800209 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700210 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800211 * @return the ingress points
212 */
213 public Set<ConnectPoint> ingressPoints() {
214 return ingressPoints;
215 }
216
217 /**
218 * Returns the egress points of the intent.
219 *
220 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700221 */
Michele Santuari4a338072014-11-05 18:38:55 +0100222 public Set<ConnectPoint> egressPoints() {
223 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700224 }
225
Ray Milkey0742ec92014-10-13 08:39:55 -0700226 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700227 public String toString() {
228 return MoreObjects.toStringHelper(getClass())
229 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800230 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700231 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700232 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800233 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700234 .add("selector", selector())
235 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700236 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800237 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100238 .add("egress", egressPoints())
Ray Milkey0742ec92014-10-13 08:39:55 -0700239 .toString();
240 }
241}