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