blob: e28d8b1783fb13fbc77d1885000cd3f06aff53ee [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
Thomas Vachuskac96058a2014-10-20 23:00:16 -07003import com.google.common.collect.ImmutableSet;
4import org.onlab.onos.ApplicationId;
5import org.onlab.onos.net.Link;
6import org.onlab.onos.net.NetworkResource;
Brian O'Connorb876bf12014-10-02 14:59:37 -07007import org.onlab.onos.net.flow.TrafficSelector;
8import org.onlab.onos.net.flow.TrafficTreatment;
9
Thomas Vachuskac96058a2014-10-20 23:00:16 -070010import java.util.Collection;
11
toma1d16b62014-10-02 23:45:11 -070012import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070013
14/**
15 * Abstraction of connectivity intent for traffic matching some criteria.
16 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070017public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070018
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'Connorb876bf12014-10-02 14:59:37 -070027 private final TrafficTreatment treatment;
28
29 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070030 * Creates a connectivity intent that matches on the specified selector
31 * and applies the specified treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070032 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070033 * @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
toma1d16b62014-10-02 23:45:11 -070038 * @throws NullPointerException if the selector or treatement is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070039 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070040 protected ConnectivityIntent(IntentId id, ApplicationId appId,
41 Collection<NetworkResource> resources,
42 TrafficSelector selector,
43 TrafficTreatment treatment) {
44 super(id, appId, resources);
toma1d16b62014-10-02 23:45:11 -070045 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070046 this.treatment = checkNotNull(treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 }
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 */
tom85258ee2014-10-07 00:10:02 -070063 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070064 return selector;
65 }
66
67 /**
68 * Returns the action applied to the traffic.
69 *
70 * @return applied action
71 */
tom85258ee2014-10-07 00:10:02 -070072 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070073 return treatment;
74 }
75
Brian O'Connorb876bf12014-10-02 14:59:37 -070076
Thomas Vachuskac96058a2014-10-20 23:00:16 -070077 protected static Collection<NetworkResource> resources(Collection<Link> links) {
78 return ImmutableSet.<NetworkResource>copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -070079 }
80
81}