blob: a58d3af4917b24852953755ad3b1fc9ed2bf7d62 [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
toma1d16b62014-10-02 23:45:11 -070018import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070019import com.google.common.collect.ImmutableSet;
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.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070025
Michele Santuari4a338072014-11-05 18:38:55 +010026import java.util.Collections;
toma1d16b62014-10-02 23:45:11 -070027import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010028import java.util.List;
toma1d16b62014-10-02 23:45:11 -070029
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 single source, multiple destination connectivity intent.
35 */
Ray Milkeybd4f0112015-03-02 17:07:09 -080036public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
tom85258ee2014-10-07 00:10:02 -070038 private final ConnectPoint ingressPoint;
39 private final Set<ConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
41 /**
42 * Creates a new single-to-multi point connectivity intent.
43 *
Michele Santuari4a338072014-11-05 18:38:55 +010044 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080045 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010046 * @param selector traffic selector
47 * @param treatment treatment
48 * @param ingressPoint port on which traffic will ingress
49 * @param egressPoints set of ports on which traffic will egress
50 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070051 * @param priority priority to use for flows generated by this intent
Michele Santuari4a338072014-11-05 18:38:55 +010052 * @throws NullPointerException if {@code ingressPoint} or
53 * {@code egressPoints} is null
54 * @throws IllegalArgumentException if the size of {@code egressPoints} is
55 * not more than 1
56 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 private SinglePointToMultiPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080058 Key key,
Michele Santuari4a338072014-11-05 18:38:55 +010059 TrafficSelector selector, TrafficTreatment treatment,
60 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
Ray Milkeyc24cde32015-03-10 18:20:18 -070061 List<Constraint> constraints,
62 int priority) {
63 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
64 priority);
tom85258ee2014-10-07 00:10:02 -070065 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080066 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070067 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080068 checkArgument(!egressPoints.contains(ingressPoint),
69 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
70
Michele Santuari4a338072014-11-05 18:38:55 +010071 this.ingressPoint = checkNotNull(ingressPoint);
Ray Milkeyebc5d222015-03-18 15:45:36 -070072 this.egressPoints = egressPoints;
73 }
74
75 /**
76 * Returns a new single point to multi point intent builder. The application id,
77 * ingress point and egress points are required fields. If they are
78 * not set by calls to the appropriate methods, an exception will
79 * be thrown.
80 *
81 * @return single point to multi point builder
82 */
83 public static Builder builder() {
84 return new Builder();
85 }
86
87 /**
88 * Builder of a single point to multi point intent.
89 */
90 public static final class Builder extends ConnectivityIntent.Builder {
91 ConnectPoint ingressPoint;
92 Set<ConnectPoint> egressPoints;
93
94 private Builder() {
95 // Hide constructor
96 }
97
98 @Override
99 public Builder appId(ApplicationId appId) {
100 return (Builder) super.appId(appId);
101 }
102
103 @Override
104 public Builder key(Key key) {
105 return (Builder) super.key(key);
106 }
107
108 @Override
109 public Builder selector(TrafficSelector selector) {
110 return (Builder) super.selector(selector);
111 }
112
113 @Override
114 public Builder treatment(TrafficTreatment treatment) {
115 return (Builder) super.treatment(treatment);
116 }
117
118 @Override
119 public Builder constraints(List<Constraint> constraints) {
120 return (Builder) super.constraints(constraints);
121 }
122
123 @Override
124 public Builder priority(int priority) {
125 return (Builder) super.priority(priority);
126 }
127
128 /**
129 * Sets the ingress point of the single point to multi point intent
130 * that will be built.
131 *
132 * @param ingressPoint ingress connect point
133 * @return this builder
134 */
135 public Builder ingressPoint(ConnectPoint ingressPoint) {
136 this.ingressPoint = ingressPoint;
137 return this;
138 }
139
140 /**
141 * Sets the egress points of the single point to multi point intent
142 * that will be built.
143 *
144 * @param egressPoints egress connect points
145 * @return this builder
146 */
147 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
148 this.egressPoints = ImmutableSet.copyOf(egressPoints);
149 return this;
150 }
151
152 /**
153 * Builds a single point to multi point intent from the
154 * accumulated parameters.
155 *
156 * @return point to point intent
157 */
158 public SinglePointToMultiPointIntent build() {
159
160 return new SinglePointToMultiPointIntent(
161 appId,
162 key,
163 selector,
164 treatment,
165 ingressPoint,
166 egressPoints,
167 constraints,
168 priority
169 );
170 }
Brian O'Connorb876bf12014-10-02 14:59:37 -0700171 }
172
173 /**
174 * Constructor for serializer.
175 */
176 protected SinglePointToMultiPointIntent() {
177 super();
tom85258ee2014-10-07 00:10:02 -0700178 this.ingressPoint = null;
179 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700180 }
181
182 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100183 * Returns the port on which the ingress traffic should be connected to the
184 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700185 *
186 * @return ingress port
187 */
tom85258ee2014-10-07 00:10:02 -0700188 public ConnectPoint ingressPoint() {
189 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700190 }
191
192 /**
193 * Returns the set of ports on which the traffic should egress.
194 *
195 * @return set of egress ports
196 */
tom85258ee2014-10-07 00:10:02 -0700197 public Set<ConnectPoint> egressPoints() {
198 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700199 }
200
201 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700202 public String toString() {
203 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700204 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800205 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700206 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700207 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800208 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700209 .add("selector", selector())
210 .add("treatment", treatment())
211 .add("ingress", ingressPoint)
212 .add("egress", egressPoints)
Michele Santuari4a338072014-11-05 18:38:55 +0100213 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700214 .toString();
215 }
216
217}