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