blob: c92898e92a43ee335af65f049f324de5f1c5bf78 [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;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
tom85258ee2014-10-07 00:10:02 -070018import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070019import com.google.common.collect.ImmutableSet;
tom85258ee2014-10-07 00:10:02 -070020import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070025
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080026import java.util.Collections;
Ray Milkey460f4022014-11-05 15:41:43 -080027import java.util.List;
tom85258ee2014-10-07 00:10:02 -070028import java.util.Set;
29
30import static com.google.common.base.Preconditions.checkArgument;
31import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070032
33/**
34 * Abstraction of multiple source to single destination connectivity intent.
35 */
Ray Milkeye6684082014-10-16 16:59:47 -070036public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
tom85258ee2014-10-07 00:10:02 -070038 private final Set<ConnectPoint> ingressPoints;
39 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
41 /**
42 * Creates a new multi-to-single point connectivity intent for the specified
Thomas Vachuskac96058a2014-10-20 23:00:16 -070043 * traffic selector and treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080046 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080047 * @param selector traffic selector
48 * @param treatment treatment
49 * @param ingressPoints set of ports from which ingress traffic originates
50 * @param egressPoint port to which traffic will egress
51 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070052 * @param priority priority to use for flows generated by this intent
Ray Milkey460f4022014-11-05 15:41:43 -080053 * @throws NullPointerException if {@code ingressPoints} or
54 * {@code egressPoint} is null.
55 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
56 * not more than 1
57 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070058 private MultiPointToSinglePointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080059 Key key,
Ray Milkey460f4022014-11-05 15:41:43 -080060 TrafficSelector selector,
61 TrafficTreatment treatment,
62 Set<ConnectPoint> ingressPoints,
63 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -070064 List<Constraint> constraints,
65 int priority) {
66 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
67 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080068
69 checkNotNull(ingressPoints);
70 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080071 checkNotNull(egressPoint);
72 checkArgument(!ingressPoints.contains(egressPoint),
73 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080074
75 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080076 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080077 }
78
79 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070080 * Constructor for serializer.
81 */
82 protected MultiPointToSinglePointIntent() {
83 super();
tom85258ee2014-10-07 00:10:02 -070084 this.ingressPoints = null;
85 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070086 }
87
88 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070089 * Returns a new multi point to single point intent builder. The application id,
90 * ingress points and egress point are required fields. If they are
91 * not set by calls to the appropriate methods, an exception will
92 * be thrown.
93 *
94 * @return single point to multi point builder
95 */
96 public static Builder builder() {
97 return new Builder();
98 }
99
100 /**
101 * Builder of a multi point to single point intent.
102 */
103 public static final class Builder extends ConnectivityIntent.Builder {
104 Set<ConnectPoint> ingressPoints;
105 ConnectPoint egressPoint;
106
107 private Builder() {
108 // Hide constructor
109 }
110
111 @Override
112 public Builder appId(ApplicationId appId) {
113 return (Builder) super.appId(appId);
114 }
115
116 @Override
117 public Builder key(Key key) {
118 return (Builder) super.key(key);
119 }
120
121 @Override
122 public Builder selector(TrafficSelector selector) {
123 return (Builder) super.selector(selector);
124 }
125
126 @Override
127 public Builder treatment(TrafficTreatment treatment) {
128 return (Builder) super.treatment(treatment);
129 }
130
131 @Override
132 public Builder constraints(List<Constraint> constraints) {
133 return (Builder) super.constraints(constraints);
134 }
135
136 @Override
137 public Builder priority(int priority) {
138 return (Builder) super.priority(priority);
139 }
140
141 /**
142 * Sets the ingress point of the single point to multi point intent
143 * that will be built.
144 *
145 * @param ingressPoints ingress connect points
146 * @return this builder
147 */
148 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
149 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
150 return this;
151 }
152
153 /**
154 * Sets the egress point of the multi point to single point intent
155 * that will be built.
156 *
157 * @param egressPoint egress connect point
158 * @return this builder
159 */
160 public Builder egressPoint(ConnectPoint egressPoint) {
161 this.egressPoint = egressPoint;
162 return this;
163 }
164
165 /**
166 * Builds a multi point to single point intent from the
167 * accumulated parameters.
168 *
169 * @return point to point intent
170 */
171 public MultiPointToSinglePointIntent build() {
172
173 return new MultiPointToSinglePointIntent(
174 appId,
175 key,
176 selector,
177 treatment,
178 ingressPoints,
179 egressPoint,
180 constraints,
181 priority
182 );
183 }
184 }
185
186
187 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700188 * Returns the set of ports on which ingress traffic should be connected to
189 * the egress port.
190 *
191 * @return set of ingress ports
192 */
tom85258ee2014-10-07 00:10:02 -0700193 public Set<ConnectPoint> ingressPoints() {
194 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700195 }
196
197 /**
198 * Returns the port on which the traffic should egress.
199 *
200 * @return egress port
201 */
tom85258ee2014-10-07 00:10:02 -0700202 public ConnectPoint egressPoint() {
203 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700204 }
205
206 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700207 public String toString() {
208 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700209 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800210 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700211 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700212 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800213 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700214 .add("selector", selector())
215 .add("treatment", treatment())
216 .add("ingress", ingressPoints())
217 .add("egress", egressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800218 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700219 .toString();
220 }
221}