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; |
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 | 85258ee | 2014-10-07 00:10:02 -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 multiple source to single destination connectivity intent. |
| 17 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 18 | public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 25 | * traffic selector and treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 26 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 27 | * @param appId application identifier |
| 28 | * @param selector traffic selector |
| 29 | * @param treatment treatment |
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 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 37 | public MultiPointToSinglePointIntent(ApplicationId appId, |
| 38 | TrafficSelector selector, |
| 39 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 40 | Set<ConnectPoint> ingressPoints, |
| 41 | ConnectPoint egressPoint) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 42 | super(id(MultiPointToSinglePointIntent.class, selector, treatment, |
| 43 | ingressPoints, egressPoint), appId, null, selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 44 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 45 | checkNotNull(ingressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 46 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 48 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
| 49 | this.egressPoint = checkNotNull(egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Constructor for serializer. |
| 54 | */ |
| 55 | protected MultiPointToSinglePointIntent() { |
| 56 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 57 | this.ingressPoints = null; |
| 58 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the set of ports on which ingress traffic should be connected to |
| 63 | * the egress port. |
| 64 | * |
| 65 | * @return set of ingress ports |
| 66 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 67 | public Set<ConnectPoint> ingressPoints() { |
| 68 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the port on which the traffic should egress. |
| 73 | * |
| 74 | * @return egress port |
| 75 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 76 | public ConnectPoint egressPoint() { |
| 77 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 81 | public String toString() { |
| 82 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 83 | .add("id", id()) |
| 84 | .add("match", selector()) |
| 85 | .add("action", treatment()) |
| 86 | .add("ingressPoints", ingressPoints()) |
| 87 | .add("egressPoint", egressPoint()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 88 | .toString(); |
| 89 | } |
| 90 | } |