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; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 17 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 18 | import java.util.List; |
| 19 | import java.util.Set; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 20 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 21 | import com.google.common.annotations.Beta; |
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.Link; |
| 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 27 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 28 | import com.google.common.base.MoreObjects; |
| 29 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Abstraction of a connectivity intent that is implemented by a set of path |
| 33 | * segments. |
| 34 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 35 | @Beta |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 36 | public final class LinkCollectionIntent extends ConnectivityIntent { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 37 | |
| 38 | private final Set<Link> links; |
| 39 | |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 40 | private final Set<ConnectPoint> ingressPoints; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 41 | private final Set<ConnectPoint> egressPoints; |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 42 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 43 | /** |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 44 | * Creates a new actionable intent capable of funneling the selected |
| 45 | * traffic along the specified convergent tree and out the given egress |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 46 | * point satisfying the specified constraints. |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 47 | * |
| 48 | * @param appId application identifier |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 49 | * @param key key to use for the intent |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 50 | * @param selector traffic match |
| 51 | * @param treatment action |
| 52 | * @param links traversed links |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 53 | * @param ingressPoints ingress points |
| 54 | * @param egressPoints egress points |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 55 | * @param constraints optional list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 56 | * @param priority priority to use for the flows generated by this intent |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 57 | * @throws NullPointerException {@code path} is null |
| 58 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 59 | private LinkCollectionIntent(ApplicationId appId, |
| 60 | Key key, |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 61 | TrafficSelector selector, |
| 62 | TrafficTreatment treatment, |
| 63 | Set<Link> links, |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 64 | Set<ConnectPoint> ingressPoints, |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 65 | Set<ConnectPoint> egressPoints, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 66 | List<Constraint> constraints, |
| 67 | int priority) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 68 | super(appId, key, resources(links), selector, treatment, constraints, priority); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 69 | this.links = links; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 70 | this.ingressPoints = ingressPoints; |
| 71 | this.egressPoints = egressPoints; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Constructor for serializer. |
| 76 | */ |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 77 | protected LinkCollectionIntent() { |
| 78 | super(); |
| 79 | this.links = null; |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 80 | this.ingressPoints = null; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 81 | this.egressPoints = null; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 84 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 85 | * Returns a new link collection intent builder. The application id, |
| 86 | * ingress point and egress points are required fields. If they are |
| 87 | * not set by calls to the appropriate methods, an exception will |
| 88 | * be thrown. |
| 89 | * |
| 90 | * @return single point to multi point builder |
| 91 | */ |
| 92 | public static Builder builder() { |
| 93 | return new Builder(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Builder of a single point to multi point intent. |
| 98 | */ |
| 99 | public static final class Builder extends ConnectivityIntent.Builder { |
| 100 | Set<Link> links; |
| 101 | Set<ConnectPoint> ingressPoints; |
| 102 | Set<ConnectPoint> egressPoints; |
| 103 | |
| 104 | private Builder() { |
| 105 | // Hide constructor |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public Builder appId(ApplicationId appId) { |
| 110 | return (Builder) super.appId(appId); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public Builder key(Key key) { |
| 115 | return (Builder) super.key(key); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public Builder selector(TrafficSelector selector) { |
| 120 | return (Builder) super.selector(selector); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public Builder treatment(TrafficTreatment treatment) { |
| 125 | return (Builder) super.treatment(treatment); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public Builder constraints(List<Constraint> constraints) { |
| 130 | return (Builder) super.constraints(constraints); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public Builder priority(int priority) { |
| 135 | return (Builder) super.priority(priority); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Sets the ingress point of the single point to multi point intent |
| 140 | * that will be built. |
| 141 | * |
| 142 | * @param ingressPoints ingress connect points |
| 143 | * @return this builder |
| 144 | */ |
| 145 | public Builder ingressPoints(Set<ConnectPoint> ingressPoints) { |
| 146 | this.ingressPoints = ImmutableSet.copyOf(ingressPoints); |
| 147 | return this; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Sets the egress points of the single point to multi point intent |
| 152 | * that will be built. |
| 153 | * |
| 154 | * @param egressPoints egress connect points |
| 155 | * @return this builder |
| 156 | */ |
| 157 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { |
| 158 | this.egressPoints = ImmutableSet.copyOf(egressPoints); |
| 159 | return this; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Sets the links of the link collection intent |
| 164 | * that will be built. |
| 165 | * |
| 166 | * @param links links for the intent |
| 167 | * @return this builder |
| 168 | */ |
| 169 | public Builder links(Set<Link> links) { |
| 170 | this.links = ImmutableSet.copyOf(links); |
| 171 | return this; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /** |
| 176 | * Builds a single point to multi point intent from the |
| 177 | * accumulated parameters. |
| 178 | * |
| 179 | * @return point to point intent |
| 180 | */ |
| 181 | public LinkCollectionIntent build() { |
| 182 | |
| 183 | return new LinkCollectionIntent( |
| 184 | appId, |
| 185 | key, |
| 186 | selector, |
| 187 | treatment, |
| 188 | links, |
| 189 | ingressPoints, |
| 190 | egressPoints, |
| 191 | constraints, |
| 192 | priority |
| 193 | ); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /** |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 199 | * Returns the set of links that represent the network connections needed |
| 200 | * by this intent. |
| 201 | * |
| 202 | * @return Set of links for the network hops needed by this intent |
| 203 | */ |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 204 | public Set<Link> links() { |
| 205 | return links; |
| 206 | } |
| 207 | |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 208 | /** |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 209 | * Returns the ingress points of the intent. |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 210 | * |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 211 | * @return the ingress points |
| 212 | */ |
| 213 | public Set<ConnectPoint> ingressPoints() { |
| 214 | return ingressPoints; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Returns the egress points of the intent. |
| 219 | * |
| 220 | * @return the egress points |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 221 | */ |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 222 | public Set<ConnectPoint> egressPoints() { |
| 223 | return egressPoints; |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 226 | @Override |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 227 | public String toString() { |
| 228 | return MoreObjects.toStringHelper(getClass()) |
| 229 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 230 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 231 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 232 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 233 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 234 | .add("selector", selector()) |
| 235 | .add("treatment", treatment()) |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 236 | .add("links", links()) |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 237 | .add("ingress", ingressPoints()) |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 238 | .add("egress", egressPoints()) |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 239 | .toString(); |
| 240 | } |
| 241 | } |