blob: ac6061c7d99e30801bdfe3d43e5b9b96faee5c5d [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
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
tom85258ee2014-10-07 00:10:02 -070019import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020import com.google.common.collect.ImmutableSet;
tom85258ee2014-10-07 00:10:02 -070021import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070026
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080027import java.util.Collections;
Ray Milkey460f4022014-11-05 15:41:43 -080028import java.util.List;
tom85258ee2014-10-07 00:10:02 -070029import java.util.Set;
30
31import static com.google.common.base.Preconditions.checkArgument;
32import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070033
34/**
35 * Abstraction of multiple source to single destination connectivity intent.
36 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040037@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070038public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
tom85258ee2014-10-07 00:10:02 -070040 private final Set<ConnectPoint> ingressPoints;
41 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070042
43 /**
44 * Creates a new multi-to-single point connectivity intent for the specified
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045 * traffic selector and treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070046 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070047 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080048 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080049 * @param selector traffic selector
50 * @param treatment treatment
51 * @param ingressPoints set of ports from which ingress traffic originates
52 * @param egressPoint port to which traffic will egress
53 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070054 * @param priority priority to use for flows generated by this intent
Ray Milkey460f4022014-11-05 15:41:43 -080055 * @throws NullPointerException if {@code ingressPoints} or
56 * {@code egressPoint} is null.
57 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
58 * not more than 1
59 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070060 private MultiPointToSinglePointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080061 Key key,
Ray Milkey460f4022014-11-05 15:41:43 -080062 TrafficSelector selector,
63 TrafficTreatment treatment,
64 Set<ConnectPoint> ingressPoints,
65 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -070066 List<Constraint> constraints,
67 int priority) {
68 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
69 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080070
71 checkNotNull(ingressPoints);
72 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080073 checkNotNull(egressPoint);
74 checkArgument(!ingressPoints.contains(egressPoint),
75 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080076
77 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080078 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080079 }
80
81 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070082 * Constructor for serializer.
83 */
84 protected MultiPointToSinglePointIntent() {
85 super();
tom85258ee2014-10-07 00:10:02 -070086 this.ingressPoints = null;
87 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070088 }
89
90 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070091 * Returns a new multi point to single point intent builder. The application id,
92 * ingress points and egress point 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 multi point to single point intent.
104 */
105 public static final class Builder extends ConnectivityIntent.Builder {
106 Set<ConnectPoint> ingressPoints;
107 ConnectPoint egressPoint;
108
109 private Builder() {
110 // Hide constructor
111 }
112
113 @Override
114 public Builder appId(ApplicationId appId) {
115 return (Builder) super.appId(appId);
116 }
117
118 @Override
119 public Builder key(Key key) {
120 return (Builder) super.key(key);
121 }
122
123 @Override
124 public Builder selector(TrafficSelector selector) {
125 return (Builder) super.selector(selector);
126 }
127
128 @Override
129 public Builder treatment(TrafficTreatment treatment) {
130 return (Builder) super.treatment(treatment);
131 }
132
133 @Override
134 public Builder constraints(List<Constraint> constraints) {
135 return (Builder) super.constraints(constraints);
136 }
137
138 @Override
139 public Builder priority(int priority) {
140 return (Builder) super.priority(priority);
141 }
142
143 /**
144 * Sets the ingress point of the single point to multi point intent
145 * that will be built.
146 *
147 * @param ingressPoints ingress connect points
148 * @return this builder
149 */
150 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
151 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
152 return this;
153 }
154
155 /**
156 * Sets the egress point of the multi point to single point intent
157 * that will be built.
158 *
159 * @param egressPoint egress connect point
160 * @return this builder
161 */
162 public Builder egressPoint(ConnectPoint egressPoint) {
163 this.egressPoint = egressPoint;
164 return this;
165 }
166
167 /**
168 * Builds a multi point to single point intent from the
169 * accumulated parameters.
170 *
171 * @return point to point intent
172 */
173 public MultiPointToSinglePointIntent build() {
174
175 return new MultiPointToSinglePointIntent(
176 appId,
177 key,
178 selector,
179 treatment,
180 ingressPoints,
181 egressPoint,
182 constraints,
183 priority
184 );
185 }
186 }
187
188
189 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700190 * Returns the set of ports on which ingress traffic should be connected to
191 * the egress port.
192 *
193 * @return set of ingress ports
194 */
tom85258ee2014-10-07 00:10:02 -0700195 public Set<ConnectPoint> ingressPoints() {
196 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700197 }
198
199 /**
200 * Returns the port on which the traffic should egress.
201 *
202 * @return egress port
203 */
tom85258ee2014-10-07 00:10:02 -0700204 public ConnectPoint egressPoint() {
205 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700206 }
207
208 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700209 public String toString() {
210 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700211 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800212 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700213 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700214 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800215 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700216 .add("selector", selector())
217 .add("treatment", treatment())
218 .add("ingress", ingressPoints())
219 .add("egress", egressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800220 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700221 .toString();
222 }
223}