blob: 99c1c02fd314b45f39134ab6a69d19cc965e84bd [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 /**
47 * Returns the set of ports on which ingress traffic should be connected to the egress port.
48 *
49 * @return set of ingress ports
50 */
51 public Set<SwitchPort> getIngressPorts() {
52 return ingressPorts;
53 }
54
55 /**
56 * Returns the port on which the traffic should egress.
57 *
58 * @return egress port
59 */
60 public SwitchPort getEgressPort() {
61 return egressPort;
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 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
77 return Objects.equal(this.ingressPorts, that.ingressPorts)
78 && Objects.equal(this.egressPort, that.egressPort);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hashCode(super.hashCode(), ingressPorts, egressPort);
84 }
85
86 @Override
87 public String toString() {
88 return Objects.toStringHelper(getClass())
89 .add("id", getId())
90 .add("match", getMatch())
91 .add("aciton", getAction())
92 .add("ingressPorts", getIngressPorts())
93 .add("egressPort", getEgressPort())
94 .toString();
95 }
96}