Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -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.MoreObjects; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 4 | import org.onlab.onos.net.HostId; |
| 5 | import org.onlab.onos.net.flow.TrafficSelector; |
| 6 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 7 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 8 | import java.util.Objects; |
| 9 | |
| 10 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 11 | |
| 12 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 13 | * Abstraction of end-station to end-station bidirectional connectivity. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 14 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame^] | 15 | public final class HostToHostIntent extends ConnectivityIntent { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 16 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 17 | private final HostId one; |
| 18 | private final HostId two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 22 | * ports. |
| 23 | * |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 24 | * @param intentId intent identifier |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 25 | * @param one first host |
| 26 | * @param two second host |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 27 | * @param selector action |
| 28 | * @param treatment ingress port |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 29 | * @throws NullPointerException if {@code ingressPort} or {@code egressPort} |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 30 | * is null. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 31 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 32 | public HostToHostIntent(IntentId intentId, HostId one, HostId two, |
| 33 | TrafficSelector selector, |
| 34 | TrafficTreatment treatment) { |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 35 | super(intentId, selector, treatment); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 36 | this.one = checkNotNull(one); |
| 37 | this.two = checkNotNull(two); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 41 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 42 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 43 | * @return first host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 44 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 45 | public HostId one() { |
| 46 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 50 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 51 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 52 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 53 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 54 | public HostId two() { |
| 55 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public boolean equals(Object o) { |
| 60 | if (this == o) { |
| 61 | return true; |
| 62 | } |
| 63 | if (o == null || getClass() != o.getClass()) { |
| 64 | return false; |
| 65 | } |
| 66 | if (!super.equals(o)) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | HostToHostIntent that = (HostToHostIntent) o; |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 71 | return Objects.equals(this.one, that.one) |
| 72 | && Objects.equals(this.two, that.two); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 77 | return Objects.hash(super.hashCode(), one, two); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 83 | .add("id", id()) |
| 84 | .add("selector", selector()) |
| 85 | .add("treatment", treatment()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 86 | .add("one", one) |
| 87 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 88 | .toString(); |
| 89 | } |
| 90 | |
| 91 | } |