blob: 7e40cdc52899867587fc1b58896d89e65bf66cb5 [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
toma1d16b62014-10-02 23:45:11 -07003import com.google.common.base.MoreObjects;
4import com.google.common.collect.Sets;
Thomas Vachuskac96058a2014-10-20 23:00:16 -07005import org.onlab.onos.ApplicationId;
Brian O'Connorb876bf12014-10-02 14:59:37 -07006import org.onlab.onos.net.ConnectPoint;
7import org.onlab.onos.net.flow.TrafficSelector;
8import org.onlab.onos.net.flow.TrafficTreatment;
9
toma1d16b62014-10-02 23:45:11 -070010import 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 single source, multiple destination connectivity intent.
17 */
18public class SinglePointToMultiPointIntent extends ConnectivityIntent {
19
tom85258ee2014-10-07 00:10:02 -070020 private final ConnectPoint ingressPoint;
21 private final Set<ConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070022
23 /**
24 * Creates a new single-to-multi point connectivity intent.
25 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070026 * @param appId application identifier
tom85258ee2014-10-07 00:10:02 -070027 * @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
toma1d16b62014-10-02 23:45:11 -070034 * not more than 1
Brian O'Connorb876bf12014-10-02 14:59:37 -070035 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070036 public SinglePointToMultiPointIntent(ApplicationId appId,
37 TrafficSelector selector,
toma1d16b62014-10-02 23:45:11 -070038 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070039 ConnectPoint ingressPoint,
40 Set<ConnectPoint> egressPoints) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070041 super(id(SinglePointToMultiPointIntent.class, selector, treatment,
42 ingressPoint, egressPoints), appId, null, selector, treatment);
tom85258ee2014-10-07 00:10:02 -070043 checkNotNull(egressPoints);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070044 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
tom85258ee2014-10-07 00:10:02 -070045 this.ingressPoint = checkNotNull(ingressPoint);
46 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 }
48
49 /**
50 * Constructor for serializer.
51 */
52 protected SinglePointToMultiPointIntent() {
53 super();
tom85258ee2014-10-07 00:10:02 -070054 this.ingressPoint = null;
55 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070056 }
57
58 /**
59 * Returns the port on which the ingress traffic should be connected to the egress.
60 *
61 * @return ingress port
62 */
tom85258ee2014-10-07 00:10:02 -070063 public ConnectPoint ingressPoint() {
64 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070065 }
66
67 /**
68 * Returns the set of ports on which the traffic should egress.
69 *
70 * @return set of egress ports
71 */
tom85258ee2014-10-07 00:10:02 -070072 public Set<ConnectPoint> egressPoints() {
73 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070074 }
75
76 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -070077 public String toString() {
78 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -070079 .add("id", id())
80 .add("match", selector())
81 .add("action", treatment())
82 .add("ingressPoint", ingressPoint)
83 .add("egressPort", egressPoints)
Brian O'Connorb876bf12014-10-02 14:59:37 -070084 .toString();
85 }
86
87}