blob: 610863ac7580d76090348f14beeedf06d0692e0a [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 multiple source to single destination connectivity intent.
16 */
17public class MultiPointToSinglePointIntent extends ConnectivityIntent {
18
19 private final Set<SwitchPort> ingressPorts;
20 private final SwitchPort egressPort;
21
22 /**
23 * Creates a new multi-to-single point connectivity intent for the specified
24 * traffic match and action.
25 *
26 * @param id intent identifier
27 * @param match traffic match
28 * @param action action
29 * @param ingressPorts set of ports from which ingress traffic originates
30 * @param egressPort port to which traffic will egress
31 * @throws NullPointerException if {@code ingressPorts} or {@code egressPort} is null.
32 * @throws IllegalArgumentException if the size of {@code ingressPorts} is not more than 1
33 */
34 public MultiPointToSinglePointIntent(IntentId id, Match match, Action action,
35 Set<SwitchPort> ingressPorts, SwitchPort egressPort) {
36 super(id, match, action);
37
38 checkNotNull(ingressPorts);
39 checkArgument(ingressPorts.size() > 1, "the number of ingress ports should be more than 1, " +
40 "but actually %s", ingressPorts.size());
41
42 this.ingressPorts = ImmutableSet.copyOf(ingressPorts);
43 this.egressPort = checkNotNull(egressPort);
44 }
45
46 /**
Sho SHIMIZU1674fb32014-08-20 14:44:31 -070047 * Constructor for serializer.
48 */
49 protected MultiPointToSinglePointIntent() {
50 super();
51 this.ingressPorts = null;
52 this.egressPort = null;
53 }
54
55 /**
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -070056 * Returns the set of ports on which ingress traffic should be connected to the egress port.
57 *
58 * @return set of ingress ports
59 */
60 public Set<SwitchPort> getIngressPorts() {
61 return ingressPorts;
62 }
63
64 /**
65 * Returns the port on which the traffic should egress.
66 *
67 * @return egress port
68 */
69 public SwitchPort getEgressPort() {
70 return egressPort;
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 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
86 return Objects.equal(this.ingressPorts, that.ingressPorts)
87 && Objects.equal(this.egressPort, that.egressPort);
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hashCode(super.hashCode(), ingressPorts, egressPort);
93 }
94
95 @Override
96 public String toString() {
97 return Objects.toStringHelper(getClass())
98 .add("id", getId())
99 .add("match", getMatch())
100 .add("aciton", getAction())
101 .add("ingressPorts", getIngressPorts())
102 .add("egressPort", getEgressPort())
103 .toString();
104 }
105}