blob: 629a9d1db9ecc37925e79533944bb7b90d5c58e5 [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
3import static com.google.common.base.Preconditions.checkNotNull;
4
5import org.onlab.onos.net.flow.TrafficSelector;
6import org.onlab.onos.net.flow.TrafficTreatment;
7
8import com.google.common.base.Objects;
9
10/**
11 * Abstraction of connectivity intent for traffic matching some criteria.
12 */
13public abstract class ConnectivityIntent extends AbstractIntent {
14
15 // TODO: other forms of intents should be considered for this family:
16 // point-to-point with constraints (waypoints/obstacles)
17 // multi-to-single point with constraints (waypoints/obstacles)
18 // single-to-multi point with constraints (waypoints/obstacles)
19 // concrete path (with alternate)
20 // ...
21
22 private final TrafficSelector selector;
23 // TODO: should consider which is better for multiple actions,
24 // defining compound action class or using list of actions.
25 private final TrafficTreatment treatment;
26
27 /**
28 * Creates a connectivity intent that matches on the specified intent
29 * and applies the specified action.
30 *
31 * @param id intent identifier
32 * @param match traffic match
33 * @param action action
34 * @throws NullPointerException if the match or action is null
35 */
36 protected ConnectivityIntent(IntentId id, TrafficSelector match, TrafficTreatment action) {
37 super(id);
38 this.selector = checkNotNull(match);
39 this.treatment = checkNotNull(action);
40 }
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 */
56 public TrafficSelector getTrafficSelector() {
57 return selector;
58 }
59
60 /**
61 * Returns the action applied to the traffic.
62 *
63 * @return applied action
64 */
65 public TrafficTreatment getTrafficTreatment() {
66 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}