blob: e2ee22f2c89c2d729844e57c851946a2e76ba49f [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 /**
47 * Returns the port on which the ingress traffic should be connected to the egress.
48 *
49 * @return ingress port
50 */
51 public SwitchPort getIngressPort() {
52 return ingressPort;
53 }
54
55 /**
56 * Returns the set of ports on which the traffic should egress.
57 *
58 * @return set of egress ports
59 */
60 public Set<SwitchPort> getEgressPorts() {
61 return egressPorts;
62 }
63
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) {
67 return true;
68 }
69 if (o == null || getClass() != o.getClass()) {
70 return false;
71 }
72 if (!super.equals(o)) {
73 return false;
74 }
75
76 SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o;
77 return Objects.equal(this.ingressPort, that.ingressPort)
78 && Objects.equal(this.egressPorts, that.egressPorts);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hashCode(super.hashCode(), ingressPort, egressPorts);
84 }
85
86 @Override
87 public String toString() {
88 return Objects.toStringHelper(getClass())
89 .add("id", getId())
90 .add("match", getMatch())
91 .add("action", getAction())
92 .add("ingressPort", ingressPort)
93 .add("egressPort", egressPorts)
94 .toString();
95 }
96
97}