blob: af2616ba632d85dc3ad643542fa07e57b0a168dc [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
20 private final ConnectPoint ingressPort;
21 private final Set<ConnectPoint> egressPorts;
22
23 /**
24 * Creates a new single-to-multi point connectivity intent.
25 *
26 * @param id intent identifier
toma1d16b62014-10-02 23:45:11 -070027 * @param selector traffic selector
28 * @param treatment treatment
Brian O'Connorb876bf12014-10-02 14:59:37 -070029 * @param ingressPort port on which traffic will ingress
30 * @param egressPorts set of ports on which traffic will egress
toma1d16b62014-10-02 23:45:11 -070031 * @throws NullPointerException if {@code ingressPort} or
32 * {@code egressPorts} is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070033 * @throws IllegalArgumentException if the size of {@code egressPorts} 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,
Brian O'Connorb876bf12014-10-02 14:59:37 -070038 ConnectPoint ingressPort,
39 Set<ConnectPoint> egressPorts) {
toma1d16b62014-10-02 23:45:11 -070040 super(id, selector, treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070041
42 checkNotNull(egressPorts);
43 checkArgument(!egressPorts.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
46 this.ingressPort = checkNotNull(ingressPort);
47 this.egressPorts = Sets.newHashSet(egressPorts);
48 }
49
50 /**
51 * Constructor for serializer.
52 */
53 protected SinglePointToMultiPointIntent() {
54 super();
55 this.ingressPort = null;
56 this.egressPorts = null;
57 }
58
59 /**
60 * Returns the port on which the ingress traffic should be connected to the egress.
61 *
62 * @return ingress port
63 */
64 public ConnectPoint getIngressPort() {
65 return ingressPort;
66 }
67
68 /**
69 * Returns the set of ports on which the traffic should egress.
70 *
71 * @return set of egress ports
72 */
73 public Set<ConnectPoint> getEgressPorts() {
74 return egressPorts;
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;
90 return Objects.equals(this.ingressPort, that.ingressPort)
91 && Objects.equals(this.egressPorts, that.egressPorts);
92 }
93
94 @Override
95 public int hashCode() {
96 return Objects.hash(super.hashCode(), ingressPort, egressPorts);
97 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(getClass())
102 .add("id", getId())
103 .add("match", getTrafficSelector())
104 .add("action", getTrafficTreatment())
105 .add("ingressPort", ingressPort)
106 .add("egressPort", egressPorts)
107 .toString();
108 }
109
110}