Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 3 | import com.google.common.base.Objects; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 4 | import org.onlab.onos.net.flow.TrafficSelector; |
| 5 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 6 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 7 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Abstraction of connectivity intent for traffic matching some criteria. |
| 11 | */ |
| 12 | public 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 |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 28 | * and applies the specified treatement. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 29 | * |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 30 | * @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'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 34 | */ |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 35 | protected ConnectivityIntent(IntentId intentId, TrafficSelector selector, |
| 36 | TrafficTreatment treatement) { |
| 37 | super(intentId); |
| 38 | this.selector = checkNotNull(selector); |
| 39 | this.treatment = checkNotNull(treatement); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 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 | } |