blob: 78c95cfe295f5f00027d8f863f7e6bf9eb612d3e [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 */
17public 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}