blob: 4c86baee5d7d63ba51e1720b23f59c01d263bb93 [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
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
toma1d16b62014-10-02 23:45:11 -070025 * @param selector traffic selector
26 * @param treatment treatment
Brian O'Connorb876bf12014-10-02 14:59:37 -070027 * @param ingressPort ingress port
28 * @param egressPort egress port
29 * @throws NullPointerException if {@code ingressPort} or {@code egressPort} is null.
30 */
toma1d16b62014-10-02 23:45:11 -070031 public PointToPointIntent(IntentId id, TrafficSelector selector,
32 TrafficTreatment treatment,
33 ConnectPoint ingressPort,
34 ConnectPoint egressPort) {
35 super(id, selector, treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070036 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}