blob: ed0c5cc89375227976add4122ab950f3dd239fbf [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
toma1d16b62014-10-02 23:45:11 -07003import com.google.common.base.Objects;
Brian O'Connorb876bf12014-10-02 14:59:37 -07004import org.onlab.onos.net.flow.TrafficSelector;
5import org.onlab.onos.net.flow.TrafficTreatment;
6
toma1d16b62014-10-02 23:45:11 -07007import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -07008
9/**
10 * Abstraction of connectivity intent for traffic matching some criteria.
11 */
12public abstract class ConnectivityIntent extends AbstractIntent {
13
14 // TODO: other forms of intents should be considered for this family:
15 // point-to-point with constraints (waypoints/obstacles)
16 // multi-to-single point with constraints (waypoints/obstacles)
17 // single-to-multi point with constraints (waypoints/obstacles)
18 // concrete path (with alternate)
19 // ...
20
21 private final TrafficSelector selector;
22 // TODO: should consider which is better for multiple actions,
23 // defining compound action class or using list of actions.
24 private final TrafficTreatment treatment;
25
26 /**
27 * Creates a connectivity intent that matches on the specified intent
toma1d16b62014-10-02 23:45:11 -070028 * and applies the specified treatement.
Brian O'Connorb876bf12014-10-02 14:59:37 -070029 *
toma1d16b62014-10-02 23:45:11 -070030 * @param intentId intent identifier
31 * @param selector traffic selector
32 * @param treatement treatement
33 * @throws NullPointerException if the selector or treatement is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070034 */
toma1d16b62014-10-02 23:45:11 -070035 protected ConnectivityIntent(IntentId intentId, TrafficSelector selector,
36 TrafficTreatment treatement) {
37 super(intentId);
38 this.selector = checkNotNull(selector);
39 this.treatment = checkNotNull(treatement);
Brian O'Connorb876bf12014-10-02 14:59:37 -070040 }
41
42 /**
43 * Constructor for serializer.
44 */
45 protected ConnectivityIntent() {
46 super();
47 this.selector = null;
48 this.treatment = null;
49 }
50
51 /**
52 * Returns the match specifying the type of traffic.
53 *
54 * @return traffic match
55 */
tom85258ee2014-10-07 00:10:02 -070056 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070057 return selector;
58 }
59
60 /**
61 * Returns the action applied to the traffic.
62 *
63 * @return applied action
64 */
tom85258ee2014-10-07 00:10:02 -070065 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070066 return treatment;
67 }
68
69 @Override
70 public boolean equals(Object o) {
71 if (!super.equals(o)) {
72 return false;
73 }
74 ConnectivityIntent that = (ConnectivityIntent) o;
75 return Objects.equal(this.selector, that.selector)
76 && Objects.equal(this.treatment, that.treatment);
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hashCode(super.hashCode(), selector, treatment);
82 }
83
84}