blob: 1e421abac0291b8873779aef42e47652b57a8de1 [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
33 * @throws NullPointerException if {@code ingressPorts} or
34 * {@code egressPort} is null.
35 * @throws IllegalArgumentException if the size of {@code ingressPorts} is
36 * not more than 1
37 */
38 public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match, TrafficTreatment action,
39 Set<ConnectPoint> ingressPorts, ConnectPoint egressPort) {
40 super(id, match, action);
41
42 checkNotNull(ingressPorts);
43 checkArgument(!ingressPorts.isEmpty(),
44 "there should be at least one ingress port");
45
46 this.ingressPorts = Sets.newHashSet(ingressPorts);
47 this.egressPort = checkNotNull(egressPort);
48 }
49
50 /**
51 * Constructor for serializer.
52 */
53 protected MultiPointToSinglePointIntent() {
54 super();
55 this.ingressPorts = null;
56 this.egressPort = null;
57 }
58
59 /**
60 * Returns the set of ports on which ingress traffic should be connected to
61 * the egress port.
62 *
63 * @return set of ingress ports
64 */
65 public Set<ConnectPoint> getIngressPorts() {
66 return ingressPorts;
67 }
68
69 /**
70 * Returns the port on which the traffic should egress.
71 *
72 * @return egress port
73 */
74 public ConnectPoint getEgressPort() {
75 return egressPort;
76 }
77
78 @Override
79 public boolean equals(Object o) {
80 if (this == o) {
81 return true;
82 }
83 if (o == null || getClass() != o.getClass()) {
84 return false;
85 }
86 if (!super.equals(o)) {
87 return false;
88 }
89
90 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
91 return Objects.equals(this.ingressPorts, that.ingressPorts)
92 && Objects.equals(this.egressPort, that.egressPort);
93 }
94
95 @Override
96 public int hashCode() {
97 return Objects.hash(super.hashCode(), ingressPorts, egressPort);
98 }
99
100 @Override
101 public String toString() {
102 return MoreObjects.toStringHelper(getClass())
103 .add("id", getId())
104 .add("match", getTrafficSelector())
105 .add("action", getTrafficTreatment())
106 .add("ingressPorts", getIngressPorts())
107 .add("egressPort", getEgressPort())
108 .toString();
109 }
110}