blob: 83fe92ac10703665d22b5771ba069c473a9672be [file] [log] [blame]
Brian O'Connor66630c82014-10-02 21:08:19 -07001package org.onlab.onos.net.intent;
2
toma1d16b62014-10-02 23:45:11 -07003import com.google.common.base.MoreObjects;
Thomas Vachuskac96058a2014-10-20 23:00:16 -07004import org.onlab.onos.ApplicationId;
Brian O'Connor66630c82014-10-02 21:08:19 -07005import org.onlab.onos.net.HostId;
6import org.onlab.onos.net.flow.TrafficSelector;
7import org.onlab.onos.net.flow.TrafficTreatment;
8
toma1d16b62014-10-02 23:45:11 -07009import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070010
11/**
tomf5c9d922014-10-03 15:22:03 -070012 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070013 */
Ray Milkeye6684082014-10-16 16:59:47 -070014public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070015
tomf5c9d922014-10-03 15:22:03 -070016 private final HostId one;
17 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070018
19 /**
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070020 * Creates a new host-to-host intent with the supplied host pair.
Brian O'Connor66630c82014-10-02 21:08:19 -070021 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070022 * @param appId application identifier
tomf5c9d922014-10-03 15:22:03 -070023 * @param one first host
24 * @param two second host
toma1d16b62014-10-02 23:45:11 -070025 * @param selector action
26 * @param treatment ingress port
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070027 * @throws NullPointerException if {@code one} or {@code two} is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070028 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070029 public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
tomf5c9d922014-10-03 15:22:03 -070030 TrafficSelector selector,
31 TrafficTreatment treatment) {
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070032 super(id(HostToHostIntent.class, min(one, two), max(one, two),
33 selector, treatment),
Thomas Vachuskac96058a2014-10-20 23:00:16 -070034 appId, null, selector, treatment);
tomf5c9d922014-10-03 15:22:03 -070035 this.one = checkNotNull(one);
36 this.two = checkNotNull(two);
Brian O'Connor66630c82014-10-02 21:08:19 -070037 }
38
Thomas Vachuskad03a56e2014-10-21 00:51:07 -070039 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) {
44 return one.hashCode() > two.hashCode() ? one : two;
45 }
46
Brian O'Connor66630c82014-10-02 21:08:19 -070047 /**
tomf5c9d922014-10-03 15:22:03 -070048 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070049 *
tomf5c9d922014-10-03 15:22:03 -070050 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070051 */
tomf5c9d922014-10-03 15:22:03 -070052 public HostId one() {
53 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070054 }
55
56 /**
tomf5c9d922014-10-03 15:22:03 -070057 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070058 *
tomf5c9d922014-10-03 15:22:03 -070059 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070060 */
tomf5c9d922014-10-03 15:22:03 -070061 public HostId two() {
62 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -070063 }
64
65 @Override
Brian O'Connor66630c82014-10-02 21:08:19 -070066 public String toString() {
67 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070068 .add("id", id())
Thomas Vachuskae291c842014-10-21 02:52:38 -070069 .add("appId", appId())
tom85258ee2014-10-07 00:10:02 -070070 .add("selector", selector())
71 .add("treatment", treatment())
tomf5c9d922014-10-03 15:22:03 -070072 .add("one", one)
73 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -070074 .toString();
75 }
76
77}