Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 3 | import com.google.common.base.MoreObjects; |
| 4 | import com.google.common.collect.Sets; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.ConnectPoint; |
| 6 | import org.onlab.onos.net.flow.TrafficSelector; |
| 7 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 8 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 9 | import java.util.Objects; |
| 10 | import java.util.Set; |
| 11 | |
| 12 | import static com.google.common.base.Preconditions.checkArgument; |
| 13 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * Abstraction of multiple source to single destination connectivity intent. |
| 17 | */ |
| 18 | public class MultiPointToSinglePointIntent extends ConnectivityIntent { |
| 19 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 20 | private final Set<ConnectPoint> ingressPoints; |
| 21 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 22 | |
| 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 |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 30 | * @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 |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 35 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 36 | */ |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 37 | public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match, |
| 38 | TrafficTreatment action, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 39 | Set<ConnectPoint> ingressPoints, |
| 40 | ConnectPoint egressPoint) { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 41 | super(id, match, action); |
| 42 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 43 | checkNotNull(ingressPoints); |
| 44 | checkArgument(!ingressPoints.isEmpty(), |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 45 | "there should be at least one ingress port"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 46 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 47 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
| 48 | this.egressPoint = checkNotNull(egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Constructor for serializer. |
| 53 | */ |
| 54 | protected MultiPointToSinglePointIntent() { |
| 55 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 56 | this.ingressPoints = null; |
| 57 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 58 | } |
| 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 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 66 | public Set<ConnectPoint> ingressPoints() { |
| 67 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the port on which the traffic should egress. |
| 72 | * |
| 73 | * @return egress port |
| 74 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 75 | public ConnectPoint egressPoint() { |
| 76 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 77 | } |
| 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; |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 92 | return Objects.equals(this.ingressPoints, that.ingressPoints) |
| 93 | && Objects.equals(this.egressPoint, that.egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public int hashCode() { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 98 | return Objects.hash(super.hashCode(), ingressPoints, egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 104 | .add("id", id()) |
| 105 | .add("match", selector()) |
| 106 | .add("action", treatment()) |
| 107 | .add("ingressPoints", ingressPoints()) |
| 108 | .add("egressPoint", egressPoint()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 109 | .toString(); |
| 110 | } |
| 111 | } |