Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 3 | import com.google.common.base.MoreObjects; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 4 | import org.onlab.onos.net.ConnectPoint; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.Link; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 6 | import org.onlab.onos.net.Path; |
| 7 | import org.onlab.onos.net.flow.TrafficSelector; |
| 8 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 9 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 10 | import java.util.Collection; |
| 11 | import java.util.Objects; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Abstraction of explicitly path specified connectivity intent. |
| 15 | */ |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 16 | public class PathIntent extends PointToPointIntent implements InstallableIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
| 18 | private final Path path; |
| 19 | |
| 20 | /** |
| 21 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 22 | * ports and using the specified explicit path. |
| 23 | * |
| 24 | * @param id intent identifier |
| 25 | * @param match traffic match |
| 26 | * @param action action |
| 27 | * @param ingressPort ingress port |
| 28 | * @param egressPort egress port |
| 29 | * @param path traversed links |
| 30 | * @throws NullPointerException {@code path} is null |
| 31 | */ |
| 32 | public PathIntent(IntentId id, TrafficSelector match, TrafficTreatment action, |
| 33 | ConnectPoint ingressPort, ConnectPoint egressPort, |
| 34 | Path path) { |
| 35 | super(id, match, action, ingressPort, egressPort); |
| 36 | this.path = path; |
| 37 | } |
| 38 | |
| 39 | protected PathIntent() { |
| 40 | super(); |
| 41 | this.path = null; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns the links which the traffic goes along. |
| 46 | * |
| 47 | * @return traversed links |
| 48 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 49 | public Path path() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 50 | return path; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public boolean equals(Object o) { |
| 55 | if (this == o) { |
| 56 | return true; |
| 57 | } |
| 58 | if (o == null || getClass() != o.getClass()) { |
| 59 | return false; |
| 60 | } |
| 61 | if (!super.equals(o)) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | PathIntent that = (PathIntent) o; |
| 66 | |
| 67 | if (!path.equals(that.path)) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int hashCode() { |
| 76 | return Objects.hash(super.hashCode(), path); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 82 | .add("id", id()) |
| 83 | .add("match", selector()) |
| 84 | .add("action", treatment()) |
| 85 | .add("ingressPort", ingressPoint()) |
| 86 | .add("egressPort", egressPoint()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 87 | .add("path", path) |
| 88 | .toString(); |
| 89 | } |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 90 | |
| 91 | @Override |
| 92 | public Collection<Link> requiredLinks() { |
| 93 | return path.links(); |
| 94 | } |
| 95 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 96 | } |