Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.Objects; |
| 5 | import java.util.Set; |
| 6 | |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.ConnectPoint; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.Link; |
| 9 | import org.onlab.onos.net.flow.TrafficSelector; |
| 10 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 11 | |
| 12 | import com.google.common.base.MoreObjects; |
| 13 | |
| 14 | /** |
| 15 | * Abstraction of a connectivity intent that is implemented by a set of path |
| 16 | * segments. |
| 17 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 18 | public final class LinkCollectionIntent extends ConnectivityIntent implements InstallableIntent { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 19 | |
| 20 | private final Set<Link> links; |
| 21 | |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 22 | private final ConnectPoint egressPoint; |
| 23 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 26 | * ports and using the specified explicit path. |
| 27 | * |
| 28 | * @param id intent identifier |
| 29 | * @param selector traffic match |
| 30 | * @param treatment action |
| 31 | * @param links traversed links |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 32 | * @param egressPoint egress point |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 33 | * @throws NullPointerException {@code path} is null |
| 34 | */ |
| 35 | public LinkCollectionIntent(IntentId id, |
| 36 | TrafficSelector selector, |
| 37 | TrafficTreatment treatment, |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 38 | Set<Link> links, |
| 39 | ConnectPoint egressPoint) { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 40 | super(id, selector, treatment); |
| 41 | this.links = links; |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 42 | this.egressPoint = egressPoint; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | protected LinkCollectionIntent() { |
| 46 | super(); |
| 47 | this.links = null; |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 48 | this.egressPoint = null; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Collection<Link> requiredLinks() { |
| 53 | return links; |
| 54 | } |
| 55 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Returns the set of links that represent the network connections needed |
| 58 | * by this intent. |
| 59 | * |
| 60 | * @return Set of links for the network hops needed by this intent |
| 61 | */ |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 62 | public Set<Link> links() { |
| 63 | return links; |
| 64 | } |
| 65 | |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Returns the egress point of the intent. |
| 68 | * |
| 69 | * @return the egress point |
| 70 | */ |
| 71 | public ConnectPoint egressPoint() { |
| 72 | return egressPoint; |
| 73 | } |
| 74 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 75 | @Override |
| 76 | public boolean equals(Object o) { |
| 77 | if (this == o) { |
| 78 | return true; |
| 79 | } |
| 80 | if (o == null || getClass() != o.getClass()) { |
| 81 | return false; |
| 82 | } |
| 83 | if (!super.equals(o)) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | LinkCollectionIntent that = (LinkCollectionIntent) o; |
| 88 | |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 89 | return Objects.equals(this.links, that.links) && |
| 90 | Objects.equals(this.egressPoint, that.egressPoint); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public int hashCode() { |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 95 | return Objects.hash(super.hashCode(), links, egressPoint); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String toString() { |
| 100 | return MoreObjects.toStringHelper(getClass()) |
| 101 | .add("id", id()) |
| 102 | .add("match", selector()) |
| 103 | .add("action", treatment()) |
| 104 | .add("links", links()) |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 105 | .add("egress", egressPoint()) |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 106 | .toString(); |
| 107 | } |
| 108 | } |