blob: 7b7c18a5009ecf9f1cbf8dccf24f9dd28961f013 [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
toma1d16b62014-10-02 23:45:11 -07003import com.google.common.base.MoreObjects;
Brian O'Connorb876bf12014-10-02 14:59:37 -07004import org.onlab.onos.net.ConnectPoint;
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'Connorb876bf12014-10-02 14:59:37 -070011
12/**
13 * Abstraction of point-to-point connectivity.
14 */
15public class PointToPointIntent extends ConnectivityIntent {
16
tom85258ee2014-10-07 00:10:02 -070017 private final ConnectPoint ingressPoint;
18 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070019
20 /**
21 * Creates a new point-to-point intent with the supplied ingress/egress
22 * ports.
23 *
tom85258ee2014-10-07 00:10:02 -070024 * @param id intent identifier
25 * @param selector traffic selector
26 * @param treatment treatment
27 * @param ingressPoint ingress port
28 * @param egressPoint egress port
29 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
Brian O'Connorb876bf12014-10-02 14:59:37 -070030 */
toma1d16b62014-10-02 23:45:11 -070031 public PointToPointIntent(IntentId id, TrafficSelector selector,
32 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070033 ConnectPoint ingressPoint,
34 ConnectPoint egressPoint) {
toma1d16b62014-10-02 23:45:11 -070035 super(id, selector, treatment);
tom85258ee2014-10-07 00:10:02 -070036 this.ingressPoint = checkNotNull(ingressPoint);
37 this.egressPoint = checkNotNull(egressPoint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070038 }
39
40 /**
41 * Constructor for serializer.
42 */
43 protected PointToPointIntent() {
44 super();
tom85258ee2014-10-07 00:10:02 -070045 this.ingressPoint = null;
46 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 }
48
49 /**
50 * Returns the port on which the ingress traffic should be connected to
51 * the egress.
52 *
53 * @return ingress port
54 */
tom85258ee2014-10-07 00:10:02 -070055 public ConnectPoint ingressPoint() {
56 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070057 }
58
59 /**
60 * Returns the port on which the traffic should egress.
61 *
62 * @return egress port
63 */
tom85258ee2014-10-07 00:10:02 -070064 public ConnectPoint egressPoint() {
65 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070066 }
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;
tom85258ee2014-10-07 00:10:02 -070081 return Objects.equals(this.ingressPoint, that.ingressPoint)
82 && Objects.equals(this.egressPoint, that.egressPoint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070083 }
84
85 @Override
86 public int hashCode() {
tom85258ee2014-10-07 00:10:02 -070087 return Objects.hash(super.hashCode(), ingressPoint, egressPoint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070088 }
89
90 @Override
91 public String toString() {
92 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070093 .add("id", id())
94 .add("match", selector())
95 .add("action", treatment())
96 .add("ingressPoint", ingressPoint)
97 .add("egressPoints", egressPoint)
Brian O'Connorb876bf12014-10-02 14:59:37 -070098 .toString();
99 }
100
101}