blob: 9672690c9bfa9fec69f87161e1e875f9df0edee7 [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
36
37 /**
38 * Returns the port on which the ingress traffic should be connected to
39 * the egress.
40 *
41 * @return ingress port
42 */
43 public SwitchPort getIngressPort() {
44 return ingressPort;
45 }
46
47 /**
48 * Returns the port on which the traffic should egress.
49 *
50 * @return egress port
51 */
52 public SwitchPort getEgressPort() {
53 return egressPort;
54 }
55
56 @Override
57 public boolean equals(Object o) {
58 if (this == o) {
59 return true;
60 }
61 if (o == null || getClass() != o.getClass()) {
62 return false;
63 }
64 if (!super.equals(o)) {
65 return false;
66 }
67
68 PointToPointIntent that = (PointToPointIntent) o;
69 return Objects.equal(this.ingressPort, that.ingressPort)
70 && Objects.equal(this.egressPort, that.egressPort);
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hashCode(super.hashCode(), ingressPort, egressPort);
76 }
77
78 @Override
79 public String toString() {
80 return Objects.toStringHelper(getClass())
81 .add("id", getId())
82 .add("match", getMatch())
83 .add("action", getAction())
84 .add("ingressPort", ingressPort)
85 .add("egressPort", egressPort)
86 .toString();
87 }
88
89}