blob: e69a740a899494cb2bde4789a2527a24d3704382 [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
3import static com.google.common.base.Preconditions.checkArgument;
4import static com.google.common.base.Preconditions.checkNotNull;
5
6import java.util.Objects;
7import java.util.Set;
8
9import org.onlab.onos.net.ConnectPoint;
10import org.onlab.onos.net.flow.TrafficSelector;
11import org.onlab.onos.net.flow.TrafficTreatment;
12
13import com.google.common.base.MoreObjects;
14import com.google.common.collect.Sets;
15
16/**
17 * Abstraction of single source, multiple destination connectivity intent.
18 */
19public class SinglePointToMultiPointIntent extends ConnectivityIntent {
20
21 private final ConnectPoint ingressPort;
22 private final Set<ConnectPoint> egressPorts;
23
24 /**
25 * Creates a new single-to-multi point connectivity intent.
26 *
27 * @param id intent identifier
28 * @param match traffic match
29 * @param action action
30 * @param ingressPort port on which traffic will ingress
31 * @param egressPorts set of ports on which traffic will egress
32 * @throws NullPointerException if {@code ingressPort} or
33 * {@code egressPorts} is null
34 * @throws IllegalArgumentException if the size of {@code egressPorts} is
35 * not more than 1
36 */
37 public SinglePointToMultiPointIntent(IntentId id, TrafficSelector match, TrafficTreatment action,
38 ConnectPoint ingressPort,
39 Set<ConnectPoint> egressPorts) {
40 super(id, match, action);
41
42 checkNotNull(egressPorts);
43 checkArgument(!egressPorts.isEmpty(),
44 "there should be at least one egress port");
45
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}