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 | |
| 7 | import org.onlab.onos.net.Link; |
| 8 | import org.onlab.onos.net.flow.TrafficSelector; |
| 9 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 10 | |
| 11 | import com.google.common.base.MoreObjects; |
| 12 | |
| 13 | /** |
| 14 | * Abstraction of a connectivity intent that is implemented by a set of path |
| 15 | * segments. |
| 16 | */ |
| 17 | public class LinkCollectionIntent extends ConnectivityIntent implements InstallableIntent { |
| 18 | |
| 19 | private final Set<Link> links; |
| 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 selector traffic match |
| 27 | * @param treatment action |
| 28 | * @param links traversed links |
| 29 | * @throws NullPointerException {@code path} is null |
| 30 | */ |
| 31 | public LinkCollectionIntent(IntentId id, |
| 32 | TrafficSelector selector, |
| 33 | TrafficTreatment treatment, |
| 34 | Set<Link> links) { |
| 35 | super(id, selector, treatment); |
| 36 | this.links = links; |
| 37 | } |
| 38 | |
| 39 | protected LinkCollectionIntent() { |
| 40 | super(); |
| 41 | this.links = null; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public Collection<Link> requiredLinks() { |
| 46 | return links; |
| 47 | } |
| 48 | |
| 49 | public Set<Link> links() { |
| 50 | return links; |
| 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 | LinkCollectionIntent that = (LinkCollectionIntent) o; |
| 66 | |
| 67 | return Objects.equals(this.links, that.links); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | return Objects.hash(super.hashCode(), links); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public String toString() { |
| 77 | return MoreObjects.toStringHelper(getClass()) |
| 78 | .add("id", id()) |
| 79 | .add("match", selector()) |
| 80 | .add("action", treatment()) |
| 81 | .add("links", links()) |
| 82 | .toString(); |
| 83 | } |
| 84 | } |