blob: 51dfcb8eedf9f0155268abaaebc33c0e42730ede [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;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020import com.google.common.collect.ImmutableSet;
Michele Santuari4a338072014-11-05 18:38:55 +010021
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
Michele Santuari4a338072014-11-05 18:38:55 +010027import java.util.Collections;
toma1d16b62014-10-02 23:45:11 -070028import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010029import java.util.List;
toma1d16b62014-10-02 23:45:11 -070030
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 single source, multiple destination connectivity intent.
36 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040037@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080038public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
tom85258ee2014-10-07 00:10:02 -070040 private final ConnectPoint ingressPoint;
41 private final Set<ConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070042
43 /**
44 * Creates a new single-to-multi point connectivity intent.
45 *
Michele Santuari4a338072014-11-05 18:38:55 +010046 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080047 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010048 * @param selector traffic selector
49 * @param treatment treatment
50 * @param ingressPoint port on which traffic will ingress
51 * @param egressPoints set of ports on which traffic will egress
52 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070053 * @param priority priority to use for flows generated by this intent
Michele Santuari4a338072014-11-05 18:38:55 +010054 * @throws NullPointerException if {@code ingressPoint} or
55 * {@code egressPoints} is null
56 * @throws IllegalArgumentException if the size of {@code egressPoints} is
57 * not more than 1
58 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070059 private SinglePointToMultiPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080060 Key key,
Michele Santuari4a338072014-11-05 18:38:55 +010061 TrafficSelector selector, TrafficTreatment treatment,
62 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
Ray Milkeyc24cde32015-03-10 18:20:18 -070063 List<Constraint> constraints,
64 int priority) {
65 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
66 priority);
tom85258ee2014-10-07 00:10:02 -070067 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080068 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070069 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080070 checkArgument(!egressPoints.contains(ingressPoint),
71 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
72
Michele Santuari4a338072014-11-05 18:38:55 +010073 this.ingressPoint = checkNotNull(ingressPoint);
Ray Milkeyebc5d222015-03-18 15:45:36 -070074 this.egressPoints = egressPoints;
75 }
76
77 /**
78 * Returns a new single point to multi point intent builder. The application id,
79 * ingress point and egress points are required fields. If they are
80 * not set by calls to the appropriate methods, an exception will
81 * be thrown.
82 *
83 * @return single point to multi point builder
84 */
85 public static Builder builder() {
86 return new Builder();
87 }
88
89 /**
90 * Builder of a single point to multi point intent.
91 */
92 public static final class Builder extends ConnectivityIntent.Builder {
93 ConnectPoint ingressPoint;
94 Set<ConnectPoint> egressPoints;
95
96 private Builder() {
97 // Hide constructor
98 }
99
100 @Override
101 public Builder appId(ApplicationId appId) {
102 return (Builder) super.appId(appId);
103 }
104
105 @Override
106 public Builder key(Key key) {
107 return (Builder) super.key(key);
108 }
109
110 @Override
111 public Builder selector(TrafficSelector selector) {
112 return (Builder) super.selector(selector);
113 }
114
115 @Override
116 public Builder treatment(TrafficTreatment treatment) {
117 return (Builder) super.treatment(treatment);
118 }
119
120 @Override
121 public Builder constraints(List<Constraint> constraints) {
122 return (Builder) super.constraints(constraints);
123 }
124
125 @Override
126 public Builder priority(int priority) {
127 return (Builder) super.priority(priority);
128 }
129
130 /**
131 * Sets the ingress point of the single point to multi point intent
132 * that will be built.
133 *
134 * @param ingressPoint ingress connect point
135 * @return this builder
136 */
137 public Builder ingressPoint(ConnectPoint ingressPoint) {
138 this.ingressPoint = ingressPoint;
139 return this;
140 }
141
142 /**
143 * Sets the egress points of the single point to multi point intent
144 * that will be built.
145 *
146 * @param egressPoints egress connect points
147 * @return this builder
148 */
149 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
150 this.egressPoints = ImmutableSet.copyOf(egressPoints);
151 return this;
152 }
153
154 /**
155 * Builds a single point to multi point intent from the
156 * accumulated parameters.
157 *
158 * @return point to point intent
159 */
160 public SinglePointToMultiPointIntent build() {
161
162 return new SinglePointToMultiPointIntent(
163 appId,
164 key,
165 selector,
166 treatment,
167 ingressPoint,
168 egressPoints,
169 constraints,
170 priority
171 );
172 }
Brian O'Connorb876bf12014-10-02 14:59:37 -0700173 }
174
175 /**
176 * Constructor for serializer.
177 */
178 protected SinglePointToMultiPointIntent() {
179 super();
tom85258ee2014-10-07 00:10:02 -0700180 this.ingressPoint = null;
181 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700182 }
183
184 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100185 * Returns the port on which the ingress traffic should be connected to the
186 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700187 *
188 * @return ingress port
189 */
tom85258ee2014-10-07 00:10:02 -0700190 public ConnectPoint ingressPoint() {
191 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700192 }
193
194 /**
195 * Returns the set of ports on which the traffic should egress.
196 *
197 * @return set of egress ports
198 */
tom85258ee2014-10-07 00:10:02 -0700199 public Set<ConnectPoint> egressPoints() {
200 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700201 }
202
203 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700204 public String toString() {
205 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700206 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800207 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700208 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700209 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800210 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700211 .add("selector", selector())
212 .add("treatment", treatment())
213 .add("ingress", ingressPoint)
214 .add("egress", egressPoints)
Michele Santuari4a338072014-11-05 18:38:55 +0100215 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700216 .toString();
217 }
218
219}