blob: d57f782521f9405e158507aa4253571f50f41774 [file] [log] [blame]
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -07001package net.onrc.onos.api.newintent;
2
3import com.google.common.base.Objects;
4import net.onrc.onos.core.matchaction.action.Action;
5import net.onrc.onos.core.matchaction.match.Match;
6import net.onrc.onos.core.util.SwitchPort;
7
8import static com.google.common.base.Preconditions.checkNotNull;
9
10/**
11 * Abstraction of point-to-point connectivity.
12 */
13public class PointToPointIntent extends ConnectivityIntent {
14
15 private final SwitchPort ingressPort;
16 private final SwitchPort egressPort;
17
18 /**
19 * Creates a new point-to-point intent with the supplied ingress/egress
20 * ports.
21 *
22 * @param id intent identifier
23 * @param match traffic match
24 * @param action action
25 * @param ingressPort ingress port
26 * @param egressPort egress port
27 * @throws NullPointerException if {@code ingressPort} or {@code egressPort} is null.
28 */
29 public PointToPointIntent(IntentId id, Match match, Action action,
30 SwitchPort ingressPort, SwitchPort egressPort) {
31 super(id, match, action);
32 this.ingressPort = checkNotNull(ingressPort);
33 this.egressPort = checkNotNull(egressPort);
34 }
35
Sho SHIMIZU1674fb32014-08-20 14:44:31 -070036 /**
37 * Constructor for serializer.
38 */
39 protected PointToPointIntent() {
40 super();
41 this.ingressPort = null;
42 this.egressPort = null;
43 }
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -070044
45 /**
46 * Returns the port on which the ingress traffic should be connected to
47 * the egress.
48 *
49 * @return ingress port
50 */
51 public SwitchPort getIngressPort() {
52 return ingressPort;
53 }
54
55 /**
56 * Returns the port on which the traffic should egress.
57 *
58 * @return egress port
59 */
60 public SwitchPort getEgressPort() {
61 return egressPort;
62 }
63
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) {
67 return true;
68 }
69 if (o == null || getClass() != o.getClass()) {
70 return false;
71 }
72 if (!super.equals(o)) {
73 return false;
74 }
75
76 PointToPointIntent that = (PointToPointIntent) o;
77 return Objects.equal(this.ingressPort, that.ingressPort)
78 && Objects.equal(this.egressPort, that.egressPort);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hashCode(super.hashCode(), ingressPort, egressPort);
84 }
85
86 @Override
87 public String toString() {
88 return Objects.toStringHelper(getClass())
89 .add("id", getId())
90 .add("match", getMatch())
91 .add("action", getAction())
92 .add("ingressPort", ingressPort)
93 .add("egressPort", egressPort)
94 .toString();
95 }
96
97}