blob: af1e84b5ea98e0700047753e76407a48c811333f [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 multiple source to single destination connectivity intent.
18 */
19public class MultiPointToSinglePointIntent extends ConnectivityIntent {
20
21 private final Set<ConnectPoint> ingressPorts;
22 private final ConnectPoint egressPort;
23
24 /**
25 * Creates a new multi-to-single point connectivity intent for the specified
26 * traffic match and action.
27 *
28 * @param id intent identifier
29 * @param match traffic match
30 * @param action action
31 * @param ingressPorts set of ports from which ingress traffic originates
32 * @param egressPort port to which traffic will egress
toma1d16b62014-10-02 23:45:11 -070033 * @throws NullPointerException if {@code ingressPorts} or
34 * {@code egressPort} is null.
Brian O'Connorb876bf12014-10-02 14:59:37 -070035 * @throws IllegalArgumentException if the size of {@code ingressPorts} is
toma1d16b62014-10-02 23:45:11 -070036 * not more than 1
Brian O'Connorb876bf12014-10-02 14:59:37 -070037 */
toma1d16b62014-10-02 23:45:11 -070038 public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match,
39 TrafficTreatment action,
40 Set<ConnectPoint> ingressPorts,
41 ConnectPoint egressPort) {
Brian O'Connorb876bf12014-10-02 14:59:37 -070042 super(id, match, action);
43
44 checkNotNull(ingressPorts);
45 checkArgument(!ingressPorts.isEmpty(),
toma1d16b62014-10-02 23:45:11 -070046 "there should be at least one ingress port");
Brian O'Connorb876bf12014-10-02 14:59:37 -070047
48 this.ingressPorts = Sets.newHashSet(ingressPorts);
49 this.egressPort = checkNotNull(egressPort);
50 }
51
52 /**
53 * Constructor for serializer.
54 */
55 protected MultiPointToSinglePointIntent() {
56 super();
57 this.ingressPorts = null;
58 this.egressPort = null;
59 }
60
61 /**
62 * Returns the set of ports on which ingress traffic should be connected to
63 * the egress port.
64 *
65 * @return set of ingress ports
66 */
67 public Set<ConnectPoint> getIngressPorts() {
68 return ingressPorts;
69 }
70
71 /**
72 * Returns the port on which the traffic should egress.
73 *
74 * @return egress port
75 */
76 public ConnectPoint getEgressPort() {
77 return egressPort;
78 }
79
80 @Override
81 public boolean equals(Object o) {
82 if (this == o) {
83 return true;
84 }
85 if (o == null || getClass() != o.getClass()) {
86 return false;
87 }
88 if (!super.equals(o)) {
89 return false;
90 }
91
92 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
93 return Objects.equals(this.ingressPorts, that.ingressPorts)
94 && Objects.equals(this.egressPort, that.egressPort);
95 }
96
97 @Override
98 public int hashCode() {
99 return Objects.hash(super.hashCode(), ingressPorts, egressPort);
100 }
101
102 @Override
103 public String toString() {
104 return MoreObjects.toStringHelper(getClass())
105 .add("id", getId())
106 .add("match", getTrafficSelector())
107 .add("action", getTrafficTreatment())
108 .add("ingressPorts", getIngressPorts())
109 .add("egressPort", getEgressPort())
110 .toString();
111 }
112}