blob: 7a894be6f1fcf11e326a6301d09d9ce65783e777 [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;
Brian O'Connor66630c82014-10-02 21:08:19 -07004import org.onlab.onos.net.HostId;
5import org.onlab.onos.net.flow.TrafficSelector;
6import org.onlab.onos.net.flow.TrafficTreatment;
7
toma1d16b62014-10-02 23:45:11 -07008import java.util.Objects;
9
10import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connor66630c82014-10-02 21:08:19 -070011
12/**
tomf5c9d922014-10-03 15:22:03 -070013 * Abstraction of end-station to end-station bidirectional connectivity.
Brian O'Connor66630c82014-10-02 21:08:19 -070014 */
Ray Milkeye6684082014-10-16 16:59:47 -070015public final class HostToHostIntent extends ConnectivityIntent {
Brian O'Connor66630c82014-10-02 21:08:19 -070016
tomf5c9d922014-10-03 15:22:03 -070017 private final HostId one;
18 private final HostId two;
Brian O'Connor66630c82014-10-02 21:08:19 -070019
20 /**
21 * Creates a new point-to-point intent with the supplied ingress/egress
22 * ports.
23 *
toma1d16b62014-10-02 23:45:11 -070024 * @param intentId intent identifier
tomf5c9d922014-10-03 15:22:03 -070025 * @param one first host
26 * @param two second host
toma1d16b62014-10-02 23:45:11 -070027 * @param selector action
28 * @param treatment ingress port
Brian O'Connor66630c82014-10-02 21:08:19 -070029 * @throws NullPointerException if {@code ingressPort} or {@code egressPort}
toma1d16b62014-10-02 23:45:11 -070030 * is null.
Brian O'Connor66630c82014-10-02 21:08:19 -070031 */
tomf5c9d922014-10-03 15:22:03 -070032 public HostToHostIntent(IntentId intentId, HostId one, HostId two,
33 TrafficSelector selector,
34 TrafficTreatment treatment) {
toma1d16b62014-10-02 23:45:11 -070035 super(intentId, selector, treatment);
tomf5c9d922014-10-03 15:22:03 -070036 this.one = checkNotNull(one);
37 this.two = checkNotNull(two);
Brian O'Connor66630c82014-10-02 21:08:19 -070038 }
39
40 /**
tomf5c9d922014-10-03 15:22:03 -070041 * Returns identifier of the first host.
Brian O'Connor66630c82014-10-02 21:08:19 -070042 *
tomf5c9d922014-10-03 15:22:03 -070043 * @return first host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070044 */
tomf5c9d922014-10-03 15:22:03 -070045 public HostId one() {
46 return one;
Brian O'Connor66630c82014-10-02 21:08:19 -070047 }
48
49 /**
tomf5c9d922014-10-03 15:22:03 -070050 * Returns identifier of the second host.
Brian O'Connor66630c82014-10-02 21:08:19 -070051 *
tomf5c9d922014-10-03 15:22:03 -070052 * @return second host identifier
Brian O'Connor66630c82014-10-02 21:08:19 -070053 */
tomf5c9d922014-10-03 15:22:03 -070054 public HostId two() {
55 return two;
Brian O'Connor66630c82014-10-02 21:08:19 -070056 }
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;
tomf5c9d922014-10-03 15:22:03 -070071 return Objects.equals(this.one, that.one)
72 && Objects.equals(this.two, that.two);
Brian O'Connor66630c82014-10-02 21:08:19 -070073 }
74
75 @Override
76 public int hashCode() {
tomf5c9d922014-10-03 15:22:03 -070077 return Objects.hash(super.hashCode(), one, two);
Brian O'Connor66630c82014-10-02 21:08:19 -070078 }
79
80 @Override
81 public String toString() {
82 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070083 .add("id", id())
84 .add("selector", selector())
85 .add("treatment", treatment())
tomf5c9d922014-10-03 15:22:03 -070086 .add("one", one)
87 .add("two", two)
Brian O'Connor66630c82014-10-02 21:08:19 -070088 .toString();
89 }
90
91}