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 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 20 | import com.google.common.collect.Sets; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 25 | |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 26 | import java.util.Collections; |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 27 | import java.util.List; |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 28 | import java.util.Set; |
| 29 | |
| 30 | import static com.google.common.base.Preconditions.checkArgument; |
| 31 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Abstraction of multiple source to single destination connectivity intent. |
| 35 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 36 | public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 38 | private final Set<ConnectPoint> ingressPoints; |
| 39 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Creates a new multi-to-single point connectivity intent for the specified |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 43 | * traffic selector and treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 44 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 45 | * @param appId application identifier |
Jonathan Hart | d0ba217 | 2015-02-11 13:54:33 -0800 | [diff] [blame] | 46 | * @param key intent key |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 47 | * @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 Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 52 | * @param priority priority to use for flows generated by this intent |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 53 | * @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 Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 58 | private MultiPointToSinglePointIntent(ApplicationId appId, |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 59 | Key key, |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 60 | TrafficSelector selector, |
| 61 | TrafficTreatment treatment, |
| 62 | Set<ConnectPoint> ingressPoints, |
| 63 | ConnectPoint egressPoint, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 64 | List<Constraint> constraints, |
| 65 | int priority) { |
| 66 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
| 67 | priority); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 68 | |
| 69 | checkNotNull(ingressPoints); |
| 70 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 71 | checkNotNull(egressPoint); |
| 72 | checkArgument(!ingressPoints.contains(egressPoint), |
| 73 | "Set of ingresses should not contain egress (egress: %s)", egressPoint); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 74 | |
| 75 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 76 | this.egressPoint = egressPoint; |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 80 | * Constructor for serializer. |
| 81 | */ |
| 82 | protected MultiPointToSinglePointIntent() { |
| 83 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 84 | this.ingressPoints = null; |
| 85 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 89 | * 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'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 188 | * 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 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 193 | public Set<ConnectPoint> ingressPoints() { |
| 194 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Returns the port on which the traffic should egress. |
| 199 | * |
| 200 | * @return egress port |
| 201 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 202 | public ConnectPoint egressPoint() { |
| 203 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 207 | public String toString() { |
| 208 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 209 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 210 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 211 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 212 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 213 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 214 | .add("selector", selector()) |
| 215 | .add("treatment", treatment()) |
| 216 | .add("ingress", ingressPoints()) |
| 217 | .add("egress", egressPoint()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 218 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 219 | .toString(); |
| 220 | } |
| 221 | } |