Sho SHIMIZU | 15ed4fd | 2014-08-05 14:40:42 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.api.newintent; |
| 2 | |
| 3 | import com.google.common.base.Objects; |
| 4 | import com.google.common.collect.ImmutableList; |
| 5 | import net.onrc.onos.core.matchaction.action.Action; |
| 6 | import net.onrc.onos.core.matchaction.match.Match; |
| 7 | import net.onrc.onos.core.util.LinkTuple; |
| 8 | import net.onrc.onos.core.util.SwitchPort; |
| 9 | |
| 10 | import java.util.List; |
| 11 | |
| 12 | import static com.google.common.base.Preconditions.checkNotNull; |
| 13 | |
| 14 | /** |
| 15 | * Abstraction of explicitly path specified connectivity intent. |
| 16 | */ |
| 17 | public 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 | } |