blob: 2a17bfe26f25dd7b5e3ce1b27551f132e11fde68 [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;
Brian O'Connorb876bf12014-10-02 14:59:37 -07005import org.onlab.onos.net.ConnectPoint;
6import org.onlab.onos.net.flow.TrafficSelector;
7import org.onlab.onos.net.flow.TrafficTreatment;
8
toma1d16b62014-10-02 23:45:11 -07009import java.util.Objects;
10import 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 *
tom85258ee2014-10-07 00:10:02 -070026 * @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
toma1d16b62014-10-02 23:45:11 -070034 * not more than 1
Brian O'Connorb876bf12014-10-02 14:59:37 -070035 */
toma1d16b62014-10-02 23:45:11 -070036 public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector,
37 TrafficTreatment treatment,
tom85258ee2014-10-07 00:10:02 -070038 ConnectPoint ingressPoint,
39 Set<ConnectPoint> egressPoints) {
toma1d16b62014-10-02 23:45:11 -070040 super(id, selector, treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070041
tom85258ee2014-10-07 00:10:02 -070042 checkNotNull(egressPoints);
43 checkArgument(!egressPoints.isEmpty(),
toma1d16b62014-10-02 23:45:11 -070044 "there should be at least one egress port");
Brian O'Connorb876bf12014-10-02 14:59:37 -070045
tom85258ee2014-10-07 00:10:02 -070046 this.ingressPoint = checkNotNull(ingressPoint);
47 this.egressPoints = Sets.newHashSet(egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070048 }
49
50 /**
51 * Constructor for serializer.
52 */
53 protected SinglePointToMultiPointIntent() {
54 super();
tom85258ee2014-10-07 00:10:02 -070055 this.ingressPoint = null;
56 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070057 }
58
59 /**
60 * Returns the port on which the ingress traffic should be connected to the egress.
61 *
62 * @return ingress port
63 */
tom85258ee2014-10-07 00:10:02 -070064 public ConnectPoint ingressPoint() {
65 return ingressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070066 }
67
68 /**
69 * Returns the set of ports on which the traffic should egress.
70 *
71 * @return set of egress ports
72 */
tom85258ee2014-10-07 00:10:02 -070073 public Set<ConnectPoint> egressPoints() {
74 return egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 }
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;
tom85258ee2014-10-07 00:10:02 -070090 return Objects.equals(this.ingressPoint, that.ingressPoint)
91 && Objects.equals(this.egressPoints, that.egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070092 }
93
94 @Override
95 public int hashCode() {
tom85258ee2014-10-07 00:10:02 -070096 return Objects.hash(super.hashCode(), ingressPoint, egressPoints);
Brian O'Connorb876bf12014-10-02 14:59:37 -070097 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700102 .add("id", id())
103 .add("match", selector())
104 .add("action", treatment())
105 .add("ingressPoint", ingressPoint)
106 .add("egressPort", egressPoints)
Brian O'Connorb876bf12014-10-02 14:59:37 -0700107 .toString();
108 }
109
110}