blob: 8cea253f8a2e3182fdfbe3222abe21a8ea194fa9 [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;
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'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.Link;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070026
Ray Milkeyebc5d222015-03-18 15:45:36 -070027import com.google.common.base.MoreObjects;
28import com.google.common.collect.ImmutableSet;
Ray Milkey0742ec92014-10-13 08:39:55 -070029
30/**
31 * Abstraction of a connectivity intent that is implemented by a set of path
32 * segments.
33 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070034public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070035
36 private final Set<Link> links;
37
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080038 private final Set<ConnectPoint> ingressPoints;
Michele Santuari4a338072014-11-05 18:38:55 +010039 private final Set<ConnectPoint> egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070040
Ray Milkey0742ec92014-10-13 08:39:55 -070041 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080042 * Creates a new actionable intent capable of funneling the selected
43 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080044 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080045 *
46 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070047 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080048 * @param selector traffic match
49 * @param treatment action
50 * @param links traversed links
Ray Milkeyebc5d222015-03-18 15:45:36 -070051 * @param ingressPoints ingress points
52 * @param egressPoints egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080053 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070054 * @param priority priority to use for the flows generated by this intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080055 * @throws NullPointerException {@code path} is null
56 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 private LinkCollectionIntent(ApplicationId appId,
58 Key key,
Michele Santuari4a338072014-11-05 18:38:55 +010059 TrafficSelector selector,
60 TrafficTreatment treatment,
61 Set<Link> links,
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080062 Set<ConnectPoint> ingressPoints,
Michele Santuari4a338072014-11-05 18:38:55 +010063 Set<ConnectPoint> egressPoints,
Ray Milkeyc24cde32015-03-10 18:20:18 -070064 List<Constraint> constraints,
65 int priority) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070066 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010067 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070068 this.ingressPoints = ingressPoints;
69 this.egressPoints = egressPoints;
Ray Milkey0742ec92014-10-13 08:39:55 -070070 }
71
Thomas Vachuskac96058a2014-10-20 23:00:16 -070072 /**
73 * Constructor for serializer.
74 */
Ray Milkey0742ec92014-10-13 08:39:55 -070075 protected LinkCollectionIntent() {
76 super();
77 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080078 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +010079 this.egressPoints = null;
Ray Milkey0742ec92014-10-13 08:39:55 -070080 }
81
Ray Milkeye6684082014-10-16 16:59:47 -070082 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070083 * Returns a new link collection intent builder. The application id,
84 * ingress point and egress points are required fields. If they are
85 * not set by calls to the appropriate methods, an exception will
86 * be thrown.
87 *
88 * @return single point to multi point builder
89 */
90 public static Builder builder() {
91 return new Builder();
92 }
93
94 /**
95 * Builder of a single point to multi point intent.
96 */
97 public static final class Builder extends ConnectivityIntent.Builder {
98 Set<Link> links;
99 Set<ConnectPoint> ingressPoints;
100 Set<ConnectPoint> egressPoints;
101
102 private Builder() {
103 // Hide constructor
104 }
105
106 @Override
107 public Builder appId(ApplicationId appId) {
108 return (Builder) super.appId(appId);
109 }
110
111 @Override
112 public Builder key(Key key) {
113 return (Builder) super.key(key);
114 }
115
116 @Override
117 public Builder selector(TrafficSelector selector) {
118 return (Builder) super.selector(selector);
119 }
120
121 @Override
122 public Builder treatment(TrafficTreatment treatment) {
123 return (Builder) super.treatment(treatment);
124 }
125
126 @Override
127 public Builder constraints(List<Constraint> constraints) {
128 return (Builder) super.constraints(constraints);
129 }
130
131 @Override
132 public Builder priority(int priority) {
133 return (Builder) super.priority(priority);
134 }
135
136 /**
137 * Sets the ingress point of the single point to multi point intent
138 * that will be built.
139 *
140 * @param ingressPoints ingress connect points
141 * @return this builder
142 */
143 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
144 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
145 return this;
146 }
147
148 /**
149 * Sets the egress points of the single point to multi point intent
150 * that will be built.
151 *
152 * @param egressPoints egress connect points
153 * @return this builder
154 */
155 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
156 this.egressPoints = ImmutableSet.copyOf(egressPoints);
157 return this;
158 }
159
160 /**
161 * Sets the links of the link collection intent
162 * that will be built.
163 *
164 * @param links links for the intent
165 * @return this builder
166 */
167 public Builder links(Set<Link> links) {
168 this.links = ImmutableSet.copyOf(links);
169 return this;
170 }
171
172
173 /**
174 * Builds a single point to multi point intent from the
175 * accumulated parameters.
176 *
177 * @return point to point intent
178 */
179 public LinkCollectionIntent build() {
180
181 return new LinkCollectionIntent(
182 appId,
183 key,
184 selector,
185 treatment,
186 links,
187 ingressPoints,
188 egressPoints,
189 constraints,
190 priority
191 );
192 }
193 }
194
195
196 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700197 * Returns the set of links that represent the network connections needed
198 * by this intent.
199 *
200 * @return Set of links for the network hops needed by this intent
201 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700202 public Set<Link> links() {
203 return links;
204 }
205
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700206 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800207 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700208 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800209 * @return the ingress points
210 */
211 public Set<ConnectPoint> ingressPoints() {
212 return ingressPoints;
213 }
214
215 /**
216 * Returns the egress points of the intent.
217 *
218 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700219 */
Michele Santuari4a338072014-11-05 18:38:55 +0100220 public Set<ConnectPoint> egressPoints() {
221 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700222 }
223
Ray Milkey0742ec92014-10-13 08:39:55 -0700224 @Override
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700225 public boolean isInstallable() {
226 return true;
Ray Milkey0742ec92014-10-13 08:39:55 -0700227 }
228
229 @Override
230 public String toString() {
231 return MoreObjects.toStringHelper(getClass())
232 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800233 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700234 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700235 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800236 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700237 .add("selector", selector())
238 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700239 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800240 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100241 .add("egress", egressPoints())
Ray Milkey0742ec92014-10-13 08:39:55 -0700242 .toString();
243 }
244}