Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -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 | a1d16b6 | 2014-10-02 23:45:11 -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 single source, multiple destination connectivity intent. |
| 17 | */ |
| 18 | public class SinglePointToMultiPointIntent extends ConnectivityIntent { |
| 19 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 20 | private final ConnectPoint ingressPoint; |
| 21 | private final Set<ConnectPoint> egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Creates a new single-to-multi point connectivity intent. |
| 25 | * |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 26 | * @param id intent identifier |
| 27 | * @param selector traffic selector |
| 28 | * @param treatment treatment |
| 29 | * @param ingressPoint port on which traffic will ingress |
| 30 | * @param egressPoints set of ports on which traffic will egress |
| 31 | * @throws NullPointerException if {@code ingressPoint} or |
| 32 | * {@code egressPoints} is null |
| 33 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 34 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | */ |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 36 | public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector, |
| 37 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 38 | ConnectPoint ingressPoint, |
| 39 | Set<ConnectPoint> egressPoints) { |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 40 | super(id, selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 41 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 42 | checkNotNull(egressPoints); |
| 43 | checkArgument(!egressPoints.isEmpty(), |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 44 | "there should be at least one egress port"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 45 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 46 | this.ingressPoint = checkNotNull(ingressPoint); |
| 47 | this.egressPoints = Sets.newHashSet(egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Constructor for serializer. |
| 52 | */ |
| 53 | protected SinglePointToMultiPointIntent() { |
| 54 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 55 | this.ingressPoint = null; |
| 56 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the port on which the ingress traffic should be connected to the egress. |
| 61 | * |
| 62 | * @return ingress port |
| 63 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 64 | public ConnectPoint ingressPoint() { |
| 65 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the set of ports on which the traffic should egress. |
| 70 | * |
| 71 | * @return set of egress ports |
| 72 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 73 | public Set<ConnectPoint> egressPoints() { |
| 74 | return egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object o) { |
| 79 | if (this == o) { |
| 80 | return true; |
| 81 | } |
| 82 | if (o == null || getClass() != o.getClass()) { |
| 83 | return false; |
| 84 | } |
| 85 | if (!super.equals(o)) { |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o; |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 90 | return Objects.equals(this.ingressPoint, that.ingressPoint) |
| 91 | && Objects.equals(this.egressPoints, that.egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public int hashCode() { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 96 | return Objects.hash(super.hashCode(), ingressPoint, egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 102 | .add("id", id()) |
| 103 | .add("match", selector()) |
| 104 | .add("action", treatment()) |
| 105 | .add("ingressPoint", ingressPoint) |
| 106 | .add("egressPort", egressPoints) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 107 | .toString(); |
| 108 | } |
| 109 | |
| 110 | } |