blob: 8ee4a9ea60fd623dcd0c8b3f874a3c446abd571f [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
tom85258ee2014-10-07 00:10:02 -07003import com.google.common.base.MoreObjects;
4import com.google.common.collect.Sets;
Brian O'Connorb876bf12014-10-02 14:59:37 -07005import org.onlab.onos.net.ConnectPoint;
6import org.onlab.onos.net.flow.TrafficSelector;
7import org.onlab.onos.net.flow.TrafficTreatment;
8
tom85258ee2014-10-07 00:10:02 -07009import java.util.Objects;
10import java.util.Set;
11
12import static com.google.common.base.Preconditions.checkArgument;
13import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070014
15/**
16 * Abstraction of multiple source to single destination connectivity intent.
17 */
Ray Milkeye6684082014-10-16 16:59:47 -070018public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070019
tom85258ee2014-10-07 00:10:02 -070020 private final Set<ConnectPoint> ingressPoints;
21 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070022
23 /**
24 * Creates a new multi-to-single point connectivity intent for the specified
25 * traffic match and action.
26 *
27 * @param id intent identifier
28 * @param match traffic match
29 * @param action action
tom85258ee2014-10-07 00:10:02 -070030 * @param ingressPoints set of ports from which ingress traffic originates
31 * @param egressPoint port to which traffic will egress
32 * @throws NullPointerException if {@code ingressPoints} or
33 * {@code egressPoint} is null.
34 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
toma1d16b62014-10-02 23:45:11 -070035 * not more than 1
Brian O'Connorb876bf12014-10-02 14:59:37 -070036 */
toma1d16b62014-10-02 23:45:11 -070037 public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match,
38 TrafficTreatment action,
tom85258ee2014-10-07 00:10:02 -070039 Set<ConnectPoint> ingressPoints,
40 ConnectPoint egressPoint) {
Brian O'Connorb876bf12014-10-02 14:59:37 -070041 super(id, match, action);
42
tom85258ee2014-10-07 00:10:02 -070043 checkNotNull(ingressPoints);
44 checkArgument(!ingressPoints.isEmpty(),
toma1d16b62014-10-02 23:45:11 -070045 "there should be at least one ingress port");
Brian O'Connorb876bf12014-10-02 14:59:37 -070046
tom85258ee2014-10-07 00:10:02 -070047 this.ingressPoints = Sets.newHashSet(ingressPoints);
48 this.egressPoint = checkNotNull(egressPoint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070049 }
50
51 /**
52 * Constructor for serializer.
53 */
54 protected MultiPointToSinglePointIntent() {
55 super();
tom85258ee2014-10-07 00:10:02 -070056 this.ingressPoints = null;
57 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070058 }
59
60 /**
61 * Returns the set of ports on which ingress traffic should be connected to
62 * the egress port.
63 *
64 * @return set of ingress ports
65 */
tom85258ee2014-10-07 00:10:02 -070066 public Set<ConnectPoint> ingressPoints() {
67 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070068 }
69
70 /**
71 * Returns the port on which the traffic should egress.
72 *
73 * @return egress port
74 */
tom85258ee2014-10-07 00:10:02 -070075 public ConnectPoint egressPoint() {
76 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070077 }
78
79 @Override
80 public boolean equals(Object o) {
81 if (this == o) {
82 return true;
83 }
84 if (o == null || getClass() != o.getClass()) {
85 return false;
86 }
87 if (!super.equals(o)) {
88 return false;
89 }
90
91 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
tom85258ee2014-10-07 00:10:02 -070092 return Objects.equals(this.ingressPoints, that.ingressPoints)
93 && Objects.equals(this.egressPoint, that.egressPoint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070094 }
95
96 @Override
97 public int hashCode() {
tom85258ee2014-10-07 00:10:02 -070098 return Objects.hash(super.hashCode(), ingressPoints, egressPoint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070099 }
100
101 @Override
102 public String toString() {
103 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700104 .add("id", id())
105 .add("match", selector())
106 .add("action", treatment())
107 .add("ingressPoints", ingressPoints())
108 .add("egressPoint", egressPoint())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700109 .toString();
110 }
111}