blob: d46197fb7e7015de9b825c54633ae177481300be [file] [log] [blame]
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -07001package net.onrc.onos.api.newintent;
2
3import com.google.common.base.Objects;
4import com.google.common.collect.ImmutableSet;
5import net.onrc.onos.core.matchaction.action.Action;
6import net.onrc.onos.core.matchaction.match.Match;
7import net.onrc.onos.core.util.SwitchPort;
8
9import java.util.Set;
10
11import static com.google.common.base.Preconditions.checkArgument;
12import static com.google.common.base.Preconditions.checkNotNull;
13
14/**
15 * Abstraction of single source, multiple destination connectivity intent.
16 */
17public class SinglePointToMultiPointIntent extends ConnectivityIntent {
18
19 private final SwitchPort ingressPort;
20 private final Set<SwitchPort> egressPorts;
21
22 /**
23 * Creates a new single-to-multi point connectivity intent.
24 *
25 * @param id intent identifier
26 * @param match traffic match
27 * @param action action
28 * @param ingressPort port on which traffic will ingress
29 * @param egressPorts set of ports on which traffic will egress
30 * @throws NullPointerException if {@code ingressPort} or {@code egressPorts} is null
31 * @throws IllegalArgumentException if the size of {@code egressPorts} is not more than 1
32 */
33 public SinglePointToMultiPointIntent(IntentId id, Match match, Action action,
34 SwitchPort ingressPort,
35 Set<SwitchPort> egressPorts) {
36 super(id, match, action);
37
38 checkNotNull(egressPorts);
39 checkArgument(egressPorts.size() > 1, "the number of egress ports should be more than 1, " +
40 "but actually %s", egressPorts.size());
41
42 this.ingressPort = checkNotNull(ingressPort);
43 this.egressPorts = ImmutableSet.copyOf(egressPorts);
44 }
45
46 /**
Sho SHIMIZU1674fb32014-08-20 14:44:31 -070047 * Constructor for serializer.
48 */
49 protected SinglePointToMultiPointIntent() {
50 super();
51 this.ingressPort = null;
52 this.egressPorts = null;
53 }
54
55 /**
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -070056 * Returns the port on which the ingress traffic should be connected to the egress.
57 *
58 * @return ingress port
59 */
60 public SwitchPort getIngressPort() {
61 return ingressPort;
62 }
63
64 /**
65 * Returns the set of ports on which the traffic should egress.
66 *
67 * @return set of egress ports
68 */
69 public Set<SwitchPort> getEgressPorts() {
70 return egressPorts;
71 }
72
73 @Override
74 public boolean equals(Object o) {
75 if (this == o) {
76 return true;
77 }
78 if (o == null || getClass() != o.getClass()) {
79 return false;
80 }
81 if (!super.equals(o)) {
82 return false;
83 }
84
85 SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o;
86 return Objects.equal(this.ingressPort, that.ingressPort)
87 && Objects.equal(this.egressPorts, that.egressPorts);
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hashCode(super.hashCode(), ingressPort, egressPorts);
93 }
94
95 @Override
96 public String toString() {
97 return Objects.toStringHelper(getClass())
98 .add("id", getId())
99 .add("match", getMatch())
100 .add("action", getAction())
101 .add("ingressPort", ingressPort)
102 .add("egressPort", egressPorts)
103 .toString();
104 }
105
106}