Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 21 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.flow.TrafficSelector; |
| 25 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 26 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 27 | import java.util.Collections; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 28 | import java.util.Set; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 29 | import java.util.List; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 30 | |
| 31 | import static com.google.common.base.Preconditions.checkArgument; |
| 32 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Abstraction of single source, multiple destination connectivity intent. |
| 36 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 37 | @Beta |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 38 | public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 39 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 40 | private final ConnectPoint ingressPoint; |
| 41 | private final Set<ConnectPoint> egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Creates a new single-to-multi point connectivity intent. |
| 45 | * |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 46 | * @param appId application identifier |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 47 | * @param key intent key |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 48 | * @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 Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 53 | * @param priority priority to use for flows generated by this intent |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 54 | * @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 Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 59 | private SinglePointToMultiPointIntent(ApplicationId appId, |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 60 | Key key, |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 61 | TrafficSelector selector, TrafficTreatment treatment, |
| 62 | ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 63 | List<Constraint> constraints, |
| 64 | int priority) { |
| 65 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
| 66 | priority); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 67 | checkNotNull(egressPoints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 68 | checkNotNull(ingressPoint); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 69 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 70 | checkArgument(!egressPoints.contains(ingressPoint), |
| 71 | "Set of egresses should not contain ingress (ingress: %s)", ingressPoint); |
| 72 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 73 | this.ingressPoint = checkNotNull(ingressPoint); |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 74 | 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'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Constructor for serializer. |
| 177 | */ |
| 178 | protected SinglePointToMultiPointIntent() { |
| 179 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 180 | this.ingressPoint = null; |
| 181 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 185 | * Returns the port on which the ingress traffic should be connected to the |
| 186 | * egress. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 187 | * |
| 188 | * @return ingress port |
| 189 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 190 | public ConnectPoint ingressPoint() { |
| 191 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Returns the set of ports on which the traffic should egress. |
| 196 | * |
| 197 | * @return set of egress ports |
| 198 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 199 | public Set<ConnectPoint> egressPoints() { |
| 200 | return egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 204 | public String toString() { |
| 205 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 206 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 207 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 208 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 209 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 210 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 211 | .add("selector", selector()) |
| 212 | .add("treatment", treatment()) |
| 213 | .add("ingress", ingressPoint) |
| 214 | .add("egress", egressPoints) |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 215 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 216 | .toString(); |
| 217 | } |
| 218 | |
| 219 | } |