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 | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 19 | import org.onlab.onos.core.ApplicationId; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 20 | import org.onlab.onos.net.Link; |
| 21 | import org.onlab.onos.net.NetworkResource; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 22 | import org.onlab.onos.net.flow.TrafficSelector; |
| 23 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 24 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 25 | import java.util.Collection; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 26 | import java.util.List; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 27 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Abstraction of connectivity intent for traffic matching some criteria. |
| 32 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 33 | public abstract class ConnectivityIntent extends Intent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 34 | |
| 35 | // TODO: other forms of intents should be considered for this family: |
| 36 | // point-to-point with constraints (waypoints/obstacles) |
| 37 | // multi-to-single point with constraints (waypoints/obstacles) |
| 38 | // single-to-multi point with constraints (waypoints/obstacles) |
| 39 | // concrete path (with alternate) |
| 40 | // ... |
| 41 | |
| 42 | private final TrafficSelector selector; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 43 | private final TrafficTreatment treatment; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 44 | private final List<Constraint> constraints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 47 | * Creates a connectivity intent that matches on the specified selector |
| 48 | * and applies the specified treatment. |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 49 | * <p> |
| 50 | * Path will be chosen without any constraints. |
| 51 | * </p> |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 52 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 53 | * @param id intent identifier |
| 54 | * @param appId application identifier |
| 55 | * @param resources required network resources (optional) |
| 56 | * @param selector traffic selector |
| 57 | * @param treatment treatment |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 58 | * @throws NullPointerException if the selector or treatement is null |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 59 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 60 | protected ConnectivityIntent(IntentId id, ApplicationId appId, |
| 61 | Collection<NetworkResource> resources, |
| 62 | TrafficSelector selector, |
| 63 | TrafficTreatment treatment) { |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 64 | this(id, appId, resources, selector, treatment, null); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates a connectivity intent that matches on the specified selector |
| 69 | * and applies the specified treatment. |
| 70 | * <p> |
| 71 | * Path will be optimized based on the first constraint if one is given. |
| 72 | * </p> |
| 73 | * |
| 74 | * @param id intent identifier |
| 75 | * @param appId application identifier |
| 76 | * @param resources required network resources (optional) |
| 77 | * @param selector traffic selector |
| 78 | * @param treatment treatment |
| 79 | * @param constraints optional prioritized list of constraints |
| 80 | * @throws NullPointerException if the selector or treatement is null |
| 81 | */ |
| 82 | protected ConnectivityIntent(IntentId id, ApplicationId appId, |
| 83 | Collection<NetworkResource> resources, |
| 84 | TrafficSelector selector, |
| 85 | TrafficTreatment treatment, |
| 86 | List<Constraint> constraints) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 87 | super(id, appId, resources); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 88 | this.selector = checkNotNull(selector); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 89 | this.treatment = checkNotNull(treatment); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 90 | this.constraints = constraints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Constructor for serializer. |
| 95 | */ |
| 96 | protected ConnectivityIntent() { |
| 97 | super(); |
| 98 | this.selector = null; |
| 99 | this.treatment = null; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 100 | this.constraints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns the match specifying the type of traffic. |
| 105 | * |
| 106 | * @return traffic match |
| 107 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 108 | public TrafficSelector selector() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 109 | return selector; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns the action applied to the traffic. |
| 114 | * |
| 115 | * @return applied action |
| 116 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 117 | public TrafficTreatment treatment() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 118 | return treatment; |
| 119 | } |
| 120 | |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 121 | /** |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 122 | * Returns the set of connectivity constraints. |
| 123 | * |
| 124 | * @return list of intent constraints |
| 125 | */ |
| 126 | public List<Constraint> constraints() { |
| 127 | return constraints; |
| 128 | } |
| 129 | |
| 130 | /** |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 131 | * Produces a collection of network resources from the given links. |
| 132 | * |
| 133 | * @param links collection of links |
| 134 | * @return collection of link resources |
| 135 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 136 | protected static Collection<NetworkResource> resources(Collection<Link> links) { |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 137 | return ImmutableSet.<NetworkResource>copyOf((Iterable<? extends NetworkResource>) links); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | } |