blob: 6a8b002d64dba60a3a991f0c77a89ce8c39b3b8f [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
Jonathan Hart6b2ffc32014-10-18 02:09:22 -07007import org.onlab.onos.net.ConnectPoint;
Ray Milkey0742ec92014-10-13 08:39:55 -07008import org.onlab.onos.net.Link;
9import org.onlab.onos.net.flow.TrafficSelector;
10import org.onlab.onos.net.flow.TrafficTreatment;
11
12import 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 Milkeye6684082014-10-16 16:59:47 -070018public final class LinkCollectionIntent extends ConnectivityIntent implements InstallableIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070019
20 private final Set<Link> links;
21
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070022 private final ConnectPoint egressPoint;
23
Ray Milkey0742ec92014-10-13 08:39:55 -070024 /**
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 Hart6b2ffc32014-10-18 02:09:22 -070032 * @param egressPoint egress point
Ray Milkey0742ec92014-10-13 08:39:55 -070033 * @throws NullPointerException {@code path} is null
34 */
35 public LinkCollectionIntent(IntentId id,
36 TrafficSelector selector,
37 TrafficTreatment treatment,
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070038 Set<Link> links,
39 ConnectPoint egressPoint) {
Ray Milkey0742ec92014-10-13 08:39:55 -070040 super(id, selector, treatment);
41 this.links = links;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070042 this.egressPoint = egressPoint;
Ray Milkey0742ec92014-10-13 08:39:55 -070043 }
44
45 protected LinkCollectionIntent() {
46 super();
47 this.links = null;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070048 this.egressPoint = null;
Ray Milkey0742ec92014-10-13 08:39:55 -070049 }
50
51 @Override
52 public Collection<Link> requiredLinks() {
53 return links;
54 }
55
Ray Milkeye6684082014-10-16 16:59:47 -070056 /**
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 Milkey0742ec92014-10-13 08:39:55 -070062 public Set<Link> links() {
63 return links;
64 }
65
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070066 /**
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 Milkey0742ec92014-10-13 08:39:55 -070075 @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 Hart6b2ffc32014-10-18 02:09:22 -070089 return Objects.equals(this.links, that.links) &&
90 Objects.equals(this.egressPoint, that.egressPoint);
Ray Milkey0742ec92014-10-13 08:39:55 -070091 }
92
93 @Override
94 public int hashCode() {
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070095 return Objects.hash(super.hashCode(), links, egressPoint);
Ray Milkey0742ec92014-10-13 08:39:55 -070096 }
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 Hart6b2ffc32014-10-18 02:09:22 -0700105 .add("egress", egressPoint())
Ray Milkey0742ec92014-10-13 08:39:55 -0700106 .toString();
107 }
108}