Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 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 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame^] | 18 | import com.google.common.collect.ImmutableList; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.Link; |
| 22 | import org.onosproject.net.NetworkResource; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame^] | 23 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 24 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 27 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 28 | import java.util.Collection; |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 29 | import java.util.Collections; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 30 | import java.util.List; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 31 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 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 connectivity intent for traffic matching some criteria. |
| 36 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 37 | public abstract class ConnectivityIntent extends Intent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 38 | |
| 39 | // TODO: other forms of intents should be considered for this family: |
| 40 | // point-to-point with constraints (waypoints/obstacles) |
| 41 | // multi-to-single point with constraints (waypoints/obstacles) |
| 42 | // single-to-multi point with constraints (waypoints/obstacles) |
| 43 | // concrete path (with alternate) |
| 44 | // ... |
| 45 | |
| 46 | private final TrafficSelector selector; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | private final TrafficTreatment treatment; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 48 | private final List<Constraint> constraints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 51 | * Creates a connectivity intent that matches on the specified selector |
| 52 | * and applies the specified treatment. |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 53 | * <p> |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 54 | * Path will be optimized based on the first constraint if one is given. |
| 55 | * </p> |
| 56 | * |
| 57 | * @param appId application identifier |
| 58 | * @param key explicit key to use for intent |
| 59 | * @param resources required network resources (optional) |
| 60 | * @param selector traffic selector |
| 61 | * @param treatment treatment |
| 62 | * @param constraints optional prioritized list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 63 | * @param priority priority to use for flows generated by this intent |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 64 | * @throws NullPointerException if the selector or treatment is null |
| 65 | */ |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 66 | protected ConnectivityIntent(ApplicationId appId, |
| 67 | Key key, |
| 68 | Collection<NetworkResource> resources, |
| 69 | TrafficSelector selector, |
| 70 | TrafficTreatment treatment, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 71 | List<Constraint> constraints, |
| 72 | int priority) { |
| 73 | super(appId, key, resources, priority); |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 74 | this.selector = checkNotNull(selector); |
| 75 | this.treatment = checkNotNull(treatment); |
| 76 | this.constraints = checkNotNull(constraints); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Creates a connectivity intent that matches on the specified selector |
| 81 | * and applies the specified treatment. |
| 82 | * <p> |
| 83 | * Path will be optimized based on the first constraint if one is given. |
| 84 | * </p> |
| 85 | * |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 86 | * @param appId application identifier |
| 87 | * @param resources required network resources (optional) |
| 88 | * @param selector traffic selector |
| 89 | * @param treatment treatment |
| 90 | * @param constraints optional prioritized list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 91 | * @param priority priority to use for flows generated by this intent |
Ray Milkey | e1dfb50 | 2015-01-13 16:35:46 -0800 | [diff] [blame] | 92 | * @throws NullPointerException if the selector or treatment is null |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 93 | */ |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 94 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 95 | protected ConnectivityIntent(ApplicationId appId, |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 96 | Collection<NetworkResource> resources, |
| 97 | TrafficSelector selector, |
| 98 | TrafficTreatment treatment, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 99 | List<Constraint> constraints, |
| 100 | int priority) { |
| 101 | super(appId, null, resources, priority); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 102 | this.selector = checkNotNull(selector); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 103 | this.treatment = checkNotNull(treatment); |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 104 | this.constraints = checkNotNull(constraints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Constructor for serializer. |
| 109 | */ |
| 110 | protected ConnectivityIntent() { |
| 111 | super(); |
| 112 | this.selector = null; |
| 113 | this.treatment = null; |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 114 | this.constraints = Collections.emptyList(); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame^] | 118 | * Abstract builder for connectivity intents. |
| 119 | */ |
| 120 | public abstract static class Builder extends Intent.Builder { |
| 121 | protected TrafficSelector selector = DefaultTrafficSelector.emptySelector(); |
| 122 | protected TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
| 123 | protected List<Constraint> constraints = ImmutableList.of(); |
| 124 | |
| 125 | @Override |
| 126 | public Builder appId(ApplicationId appId) { |
| 127 | return (Builder) super.appId(appId); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public Builder key(Key key) { |
| 132 | return (Builder) super.key(key); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public Builder priority(int priority) { |
| 137 | return (Builder) super.priority(priority); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * Sets the traffic selector for the intent that will be built. |
| 143 | * |
| 144 | * @param selector selector to use for built intent |
| 145 | * @return this builder |
| 146 | */ |
| 147 | public Builder selector(TrafficSelector selector) { |
| 148 | this.selector = selector; |
| 149 | return this; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets the traffic treatment for the intent that will be built. |
| 154 | * |
| 155 | * @param treatment treatment to use for built intent |
| 156 | * @return this builder |
| 157 | */ |
| 158 | public Builder treatment(TrafficTreatment treatment) { |
| 159 | this.treatment = treatment; |
| 160 | return this; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Sets the constraints for the intent that will be built. |
| 165 | * |
| 166 | * @param constraints constraints to use for built intent |
| 167 | * @return this builder |
| 168 | */ |
| 169 | public Builder constraints(List<Constraint> constraints) { |
| 170 | this.constraints = ImmutableList.copyOf(constraints); |
| 171 | return this; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
| 176 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 177 | * Returns the match specifying the type of traffic. |
| 178 | * |
| 179 | * @return traffic match |
| 180 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 181 | public TrafficSelector selector() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 182 | return selector; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Returns the action applied to the traffic. |
| 187 | * |
| 188 | * @return applied action |
| 189 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 190 | public TrafficTreatment treatment() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 191 | return treatment; |
| 192 | } |
| 193 | |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 194 | /** |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 195 | * Returns the set of connectivity constraints. |
| 196 | * |
| 197 | * @return list of intent constraints |
| 198 | */ |
| 199 | public List<Constraint> constraints() { |
| 200 | return constraints; |
| 201 | } |
| 202 | |
| 203 | /** |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 204 | * Produces a collection of network resources from the given links. |
| 205 | * |
| 206 | * @param links collection of links |
| 207 | * @return collection of link resources |
| 208 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 209 | protected static Collection<NetworkResource> resources(Collection<Link> links) { |
Sho SHIMIZU | f4dbc726 | 2014-11-04 18:49:02 -0800 | [diff] [blame] | 210 | return ImmutableSet.copyOf(links); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | } |