Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import org.onlab.onos.ApplicationId; |
| 5 | import org.onlab.onos.net.Link; |
| 6 | import org.onlab.onos.net.NetworkResource; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.flow.TrafficSelector; |
| 8 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 9 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 10 | import java.util.Collection; |
| 11 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 12 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * Abstraction of connectivity intent for traffic matching some criteria. |
| 16 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 17 | public abstract class ConnectivityIntent extends Intent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 18 | |
| 19 | // TODO: other forms of intents should be considered for this family: |
| 20 | // point-to-point with constraints (waypoints/obstacles) |
| 21 | // multi-to-single point with constraints (waypoints/obstacles) |
| 22 | // single-to-multi point with constraints (waypoints/obstacles) |
| 23 | // concrete path (with alternate) |
| 24 | // ... |
| 25 | |
| 26 | private final TrafficSelector selector; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 27 | private final TrafficTreatment treatment; |
| 28 | |
| 29 | /** |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 30 | * Creates a connectivity intent that matches on the specified selector |
| 31 | * and applies the specified treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 32 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 33 | * @param id intent identifier |
| 34 | * @param appId application identifier |
| 35 | * @param resources required network resources (optional) |
| 36 | * @param selector traffic selector |
| 37 | * @param treatment treatment |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 38 | * @throws NullPointerException if the selector or treatement is null |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 39 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 40 | protected ConnectivityIntent(IntentId id, ApplicationId appId, |
| 41 | Collection<NetworkResource> resources, |
| 42 | TrafficSelector selector, |
| 43 | TrafficTreatment treatment) { |
| 44 | super(id, appId, resources); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 45 | this.selector = checkNotNull(selector); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 46 | this.treatment = checkNotNull(treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Constructor for serializer. |
| 51 | */ |
| 52 | protected ConnectivityIntent() { |
| 53 | super(); |
| 54 | this.selector = null; |
| 55 | this.treatment = null; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the match specifying the type of traffic. |
| 60 | * |
| 61 | * @return traffic match |
| 62 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 63 | public TrafficSelector selector() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 64 | return selector; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the action applied to the traffic. |
| 69 | * |
| 70 | * @return applied action |
| 71 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 72 | public TrafficTreatment treatment() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 73 | return treatment; |
| 74 | } |
| 75 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 76 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame^] | 77 | protected static Collection<NetworkResource> resources(Collection<Link> links) { |
| 78 | return ImmutableSet.<NetworkResource>copyOf(links); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } |