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; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 5 | import org.onlab.onos.ApplicationId; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 6 | import org.onlab.onos.net.ConnectPoint; |
| 7 | import org.onlab.onos.net.flow.TrafficSelector; |
| 8 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 9 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 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 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 26 | * @param appId application identifier |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 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 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 36 | public SinglePointToMultiPointIntent(ApplicationId appId, |
| 37 | TrafficSelector selector, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 38 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 39 | ConnectPoint ingressPoint, |
| 40 | Set<ConnectPoint> egressPoints) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 41 | super(id(SinglePointToMultiPointIntent.class, selector, treatment, |
| 42 | ingressPoint, egressPoints), appId, null, selector, treatment); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 43 | checkNotNull(egressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 44 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 45 | this.ingressPoint = checkNotNull(ingressPoint); |
| 46 | this.egressPoints = Sets.newHashSet(egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Constructor for serializer. |
| 51 | */ |
| 52 | protected SinglePointToMultiPointIntent() { |
| 53 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 54 | this.ingressPoint = null; |
| 55 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the port on which the ingress traffic should be connected to the egress. |
| 60 | * |
| 61 | * @return ingress port |
| 62 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 63 | public ConnectPoint ingressPoint() { |
| 64 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the set of ports on which the traffic should egress. |
| 69 | * |
| 70 | * @return set of egress ports |
| 71 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 72 | public Set<ConnectPoint> egressPoints() { |
| 73 | return egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 77 | public String toString() { |
| 78 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 79 | .add("id", id()) |
| 80 | .add("match", selector()) |
| 81 | .add("action", treatment()) |
| 82 | .add("ingressPoint", ingressPoint) |
| 83 | .add("egressPort", egressPoints) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 84 | .toString(); |
| 85 | } |
| 86 | |
| 87 | } |