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