blob: 4b17c660848a7cbc003fc03f671d3d740425137f [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;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
toma1d16b62014-10-02 23:45:11 -070019import com.google.common.base.MoreObjects;
Pier Ventre27d42572016-08-29 17:37:08 -070020import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableMap;
Ray Milkeyebc5d222015-03-18 15:45:36 -070022import com.google.common.collect.ImmutableSet;
Michele Santuari4a338072014-11-05 18:38:55 +010023
Pier Ventre27d42572016-08-29 17:37:08 -070024import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.core.ApplicationId;
26import org.onosproject.net.ConnectPoint;
Pier Ventre27d42572016-08-29 17:37:08 -070027import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
Pier Ventre27d42572016-08-29 17:37:08 -070031import java.util.Map;
toma1d16b62014-10-02 23:45:11 -070032import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010033import java.util.List;
toma1d16b62014-10-02 23:45:11 -070034
35import static com.google.common.base.Preconditions.checkArgument;
36import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
38/**
39 * Abstraction of single source, multiple destination connectivity intent.
40 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040041@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080042public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070043
tom85258ee2014-10-07 00:10:02 -070044 private final ConnectPoint ingressPoint;
45 private final Set<ConnectPoint> egressPoints;
Pier Ventre27d42572016-08-29 17:37:08 -070046 /**
47 * To manage multiple treatments use case.
48 */
49 private final Map<ConnectPoint, TrafficTreatment> egressTreatments;
Brian O'Connorb876bf12014-10-02 14:59:37 -070050
51 /**
52 * Creates a new single-to-multi point connectivity intent.
53 *
Michele Santuari4a338072014-11-05 18:38:55 +010054 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080055 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010056 * @param selector traffic selector
57 * @param treatment treatment
58 * @param ingressPoint port on which traffic will ingress
59 * @param egressPoints set of ports on which traffic will egress
60 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070061 * @param priority priority to use for flows generated by this intent
Pier Ventre27d42572016-08-29 17:37:08 -070062 * @param egressTreatments map to store the association egress to treatment
Michele Santuari4a338072014-11-05 18:38:55 +010063 * @throws NullPointerException if {@code ingressPoint} or
64 * {@code egressPoints} is null
65 * @throws IllegalArgumentException if the size of {@code egressPoints} is
66 * not more than 1
67 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070068 private SinglePointToMultiPointIntent(ApplicationId appId,
Pier Ventre27d42572016-08-29 17:37:08 -070069 Key key,
70 TrafficSelector selector,
71 TrafficTreatment treatment,
72 ConnectPoint ingressPoint,
73 Set<ConnectPoint> egressPoints,
74 List<Constraint> constraints,
75 int priority,
76 Map<ConnectPoint, TrafficTreatment> egressTreatments) {
77 super(appId, key, ImmutableList.of(), selector, treatment, constraints,
78 priority);
tom85258ee2014-10-07 00:10:02 -070079 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080080 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070081 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080082 checkArgument(!egressPoints.contains(ingressPoint),
83 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
84
Pier Ventre27d42572016-08-29 17:37:08 -070085 this.ingressPoint = ingressPoint;
86 this.egressPoints = Sets.newHashSet(egressPoints);
87 this.egressTreatments = egressTreatments;
Ray Milkeyebc5d222015-03-18 15:45:36 -070088 }
89
90 /**
91 * Returns a new single point to multi point intent builder. The application id,
92 * ingress point and egress points are required fields. If they are
93 * not set by calls to the appropriate methods, an exception will
94 * be thrown.
95 *
96 * @return single point to multi point builder
97 */
98 public static Builder builder() {
99 return new Builder();
100 }
101
102 /**
103 * Builder of a single point to multi point intent.
104 */
105 public static final class Builder extends ConnectivityIntent.Builder {
106 ConnectPoint ingressPoint;
107 Set<ConnectPoint> egressPoints;
Pier Ventre27d42572016-08-29 17:37:08 -0700108 Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of();
Ray Milkeyebc5d222015-03-18 15:45:36 -0700109
110 private Builder() {
111 // Hide constructor
112 }
113
114 @Override
115 public Builder appId(ApplicationId appId) {
116 return (Builder) super.appId(appId);
117 }
118
119 @Override
120 public Builder key(Key key) {
121 return (Builder) super.key(key);
122 }
123
124 @Override
125 public Builder selector(TrafficSelector selector) {
126 return (Builder) super.selector(selector);
127 }
128
129 @Override
130 public Builder treatment(TrafficTreatment treatment) {
131 return (Builder) super.treatment(treatment);
132 }
133
134 @Override
135 public Builder constraints(List<Constraint> constraints) {
136 return (Builder) super.constraints(constraints);
137 }
138
139 @Override
140 public Builder priority(int priority) {
141 return (Builder) super.priority(priority);
142 }
143
144 /**
145 * Sets the ingress point of the single point to multi point intent
146 * that will be built.
147 *
148 * @param ingressPoint ingress connect point
149 * @return this builder
150 */
151 public Builder ingressPoint(ConnectPoint ingressPoint) {
152 this.ingressPoint = ingressPoint;
153 return this;
154 }
155
156 /**
157 * Sets the egress points of the single point to multi point intent
158 * that will be built.
159 *
160 * @param egressPoints egress connect points
161 * @return this builder
162 */
163 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
164 this.egressPoints = ImmutableSet.copyOf(egressPoints);
165 return this;
166 }
167
168 /**
Pier Ventre27d42572016-08-29 17:37:08 -0700169 * Sets the treatments of the single point to multi point intent
170 * that will be built.
171 *
172 * @param egressTreatments the multiple treatments
173 * @return this builder
174 */
175 public Builder treatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) {
176 this.egressTreatments = ImmutableMap.copyOf(egressTreatments);
177 return this;
178 }
179
180 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700181 * Builds a single point to multi point intent from the
182 * accumulated parameters.
183 *
184 * @return point to point intent
185 */
186 public SinglePointToMultiPointIntent build() {
187
Pier Ventre27d42572016-08-29 17:37:08 -0700188 if (treatment != null && !treatment.allInstructions().isEmpty() &&
189 !treatment.equals(DefaultTrafficTreatment.emptyTreatment()) &&
190 egressTreatments != null && !egressTreatments.isEmpty()) {
191 throw new IllegalArgumentException("Treatment and Multiple Treatments are both set");
192 }
193
Ray Milkeyebc5d222015-03-18 15:45:36 -0700194 return new SinglePointToMultiPointIntent(
195 appId,
196 key,
197 selector,
198 treatment,
199 ingressPoint,
200 egressPoints,
201 constraints,
Pier Ventre27d42572016-08-29 17:37:08 -0700202 priority,
203 egressTreatments
Ray Milkeyebc5d222015-03-18 15:45:36 -0700204 );
205 }
Brian O'Connorb876bf12014-10-02 14:59:37 -0700206 }
207
208 /**
209 * Constructor for serializer.
210 */
211 protected SinglePointToMultiPointIntent() {
212 super();
tom85258ee2014-10-07 00:10:02 -0700213 this.ingressPoint = null;
214 this.egressPoints = null;
Pier Ventre27d42572016-08-29 17:37:08 -0700215 this.egressTreatments = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700216 }
217
218 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100219 * Returns the port on which the ingress traffic should be connected to the
220 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700221 *
222 * @return ingress port
223 */
tom85258ee2014-10-07 00:10:02 -0700224 public ConnectPoint ingressPoint() {
225 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700226 }
227
228 /**
229 * Returns the set of ports on which the traffic should egress.
230 *
231 * @return set of egress ports
232 */
tom85258ee2014-10-07 00:10:02 -0700233 public Set<ConnectPoint> egressPoints() {
234 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700235 }
236
Pier Ventre27d42572016-08-29 17:37:08 -0700237 /**
238 * Returns the multiple treatments jointly with their connection points.
239 * @return multiple treatments
240 */
241 public Map<ConnectPoint, TrafficTreatment> egressTreatments() {
242 return egressTreatments;
243 }
244
Brian O'Connorb876bf12014-10-02 14:59:37 -0700245 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700246 public String toString() {
247 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700248 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800249 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700250 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700251 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800252 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700253 .add("selector", selector())
254 .add("treatment", treatment())
255 .add("ingress", ingressPoint)
256 .add("egress", egressPoints)
Pier Ventre27d42572016-08-29 17:37:08 -0700257 .add("treatments", egressTreatments)
Michele Santuari4a338072014-11-05 18:38:55 +0100258 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700259 .toString();
260 }
261
262}