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; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 4 | import org.onlab.onos.ApplicationId; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.HostId; |
| 6 | import org.onlab.onos.net.flow.TrafficSelector; |
| 7 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 8 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 9 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 10 | |
| 11 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 12 | * Abstraction of end-station to end-station bidirectional connectivity. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 13 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 14 | public final class HostToHostIntent extends ConnectivityIntent { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 15 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 16 | private final HostId one; |
| 17 | private final HostId two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 18 | |
| 19 | /** |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 20 | * Creates a new host-to-host intent with the supplied host pair. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 21 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 22 | * @param appId application identifier |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 23 | * @param one first host |
| 24 | * @param two second host |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 25 | * @param selector action |
| 26 | * @param treatment ingress port |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 27 | * @throws NullPointerException if {@code one} or {@code two} is null. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 28 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 29 | public HostToHostIntent(ApplicationId appId, HostId one, HostId two, |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 30 | TrafficSelector selector, |
| 31 | TrafficTreatment treatment) { |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 32 | super(id(HostToHostIntent.class, min(one, two), max(one, two), |
| 33 | selector, treatment), |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 34 | appId, null, selector, treatment); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 35 | this.one = checkNotNull(one); |
| 36 | this.two = checkNotNull(two); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 39 | private static HostId min(HostId one, HostId two) { |
| 40 | return one.hashCode() < two.hashCode() ? one : two; |
| 41 | } |
| 42 | |
| 43 | private static HostId max(HostId one, HostId two) { |
Thomas Vachuska | 46c07ad | 2014-10-21 16:01:01 -0700 | [diff] [blame^] | 44 | return one.hashCode() >= two.hashCode() ? one : two; |
Thomas Vachuska | d03a56e | 2014-10-21 00:51:07 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 47 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 48 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 49 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 50 | * @return first host identifier |
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 | public HostId one() { |
| 53 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 57 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 58 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 59 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 60 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 61 | public HostId two() { |
| 62 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 66 | public String toString() { |
| 67 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 68 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 69 | .add("appId", appId()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 70 | .add("selector", selector()) |
| 71 | .add("treatment", treatment()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 72 | .add("one", one) |
| 73 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 74 | .toString(); |
| 75 | } |
| 76 | |
| 77 | } |