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