Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -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.ConnectPoint; |
| 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 PointToPointIntent extends ConnectivityIntent { |
| 17 | |
| 18 | private final ConnectPoint ingressPort; |
| 19 | private final ConnectPoint egressPort; |
| 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} is null. |
| 31 | */ |
| 32 | public PointToPointIntent(IntentId id, TrafficSelector match, TrafficTreatment action, |
| 33 | ConnectPoint ingressPort, ConnectPoint egressPort) { |
| 34 | super(id, match, action); |
| 35 | this.ingressPort = checkNotNull(ingressPort); |
| 36 | this.egressPort = checkNotNull(egressPort); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Constructor for serializer. |
| 41 | */ |
| 42 | protected PointToPointIntent() { |
| 43 | super(); |
| 44 | this.ingressPort = null; |
| 45 | this.egressPort = null; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the port on which the ingress traffic should be connected to |
| 50 | * the egress. |
| 51 | * |
| 52 | * @return ingress port |
| 53 | */ |
| 54 | public ConnectPoint getIngressPort() { |
| 55 | return ingressPort; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the port on which the traffic should egress. |
| 60 | * |
| 61 | * @return egress port |
| 62 | */ |
| 63 | public ConnectPoint getEgressPort() { |
| 64 | return egressPort; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object o) { |
| 69 | if (this == o) { |
| 70 | return true; |
| 71 | } |
| 72 | if (o == null || getClass() != o.getClass()) { |
| 73 | return false; |
| 74 | } |
| 75 | if (!super.equals(o)) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | PointToPointIntent that = (PointToPointIntent) o; |
| 80 | return Objects.equals(this.ingressPort, that.ingressPort) |
| 81 | && Objects.equals(this.egressPort, that.egressPort); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return Objects.hash(super.hashCode(), ingressPort, egressPort); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return MoreObjects.toStringHelper(getClass()) |
| 92 | .add("id", getId()) |
| 93 | .add("match", getTrafficSelector()) |
| 94 | .add("action", getTrafficTreatment()) |
| 95 | .add("ingressPort", ingressPort) |
| 96 | .add("egressPort", egressPort) |
| 97 | .toString(); |
| 98 | } |
| 99 | |
| 100 | } |