blob: 9d0fde88be174b0558647870397ec610175aeb15 [file] [log] [blame]
Ray Milkey0742ec92014-10-13 08:39:55 -07001package org.onlab.onos.net.intent;
2
3import java.util.Collection;
4import java.util.Objects;
5import java.util.Set;
6
7import org.onlab.onos.net.Link;
8import org.onlab.onos.net.flow.TrafficSelector;
9import org.onlab.onos.net.flow.TrafficTreatment;
10
11import com.google.common.base.MoreObjects;
12
13/**
14 * Abstraction of a connectivity intent that is implemented by a set of path
15 * segments.
16 */
Ray Milkeye6684082014-10-16 16:59:47 -070017public final class LinkCollectionIntent extends ConnectivityIntent implements InstallableIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070018
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
Ray Milkeye6684082014-10-16 16:59:47 -070049 /**
50 * Returns the set of links that represent the network connections needed
51 * by this intent.
52 *
53 * @return Set of links for the network hops needed by this intent
54 */
Ray Milkey0742ec92014-10-13 08:39:55 -070055 public Set<Link> links() {
56 return links;
57 }
58
59 @Override
60 public boolean equals(Object o) {
61 if (this == o) {
62 return true;
63 }
64 if (o == null || getClass() != o.getClass()) {
65 return false;
66 }
67 if (!super.equals(o)) {
68 return false;
69 }
70
71 LinkCollectionIntent that = (LinkCollectionIntent) o;
72
73 return Objects.equals(this.links, that.links);
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(super.hashCode(), links);
79 }
80
81 @Override
82 public String toString() {
83 return MoreObjects.toStringHelper(getClass())
84 .add("id", id())
85 .add("match", selector())
86 .add("action", treatment())
87 .add("links", links())
88 .toString();
89 }
90}