blob: db11f4c1da02e7b514bedad0200ec56b260a8829 [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
40 /**
41 * Returns the links which the traffic goes along.
42 *
43 * @return traversed links
44 */
45 public List<LinkTuple> getPath() {
46 return path;
47 }
48
49 @Override
50 public boolean equals(Object o) {
51 if (this == o) {
52 return true;
53 }
54 if (o == null || getClass() != o.getClass()) {
55 return false;
56 }
57 if (!super.equals(o)) {
58 return false;
59 }
60
61 PathIntent that = (PathIntent) o;
62
63 if (!path.equals(that.path)) {
64 return false;
65 }
66
67 return true;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hashCode(super.hashCode(), path);
73 }
74
75 @Override
76 public String toString() {
77 return Objects.toStringHelper(getClass())
78 .add("id", getId())
79 .add("match", getMatch())
80 .add("action", getAction())
81 .add("ingressPort", getIngressPort())
82 .add("egressPort", getEgressPort())
83 .add("path", path)
84 .toString();
85 }
86}