Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkArgument; |
| 4 | import static com.google.common.base.Preconditions.checkNotNull; |
| 5 | |
| 6 | import java.util.Objects; |
| 7 | import java.util.Set; |
| 8 | |
| 9 | import org.onlab.onos.net.ConnectPoint; |
| 10 | import org.onlab.onos.net.flow.TrafficSelector; |
| 11 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 12 | |
| 13 | import com.google.common.base.MoreObjects; |
| 14 | import com.google.common.collect.Sets; |
| 15 | |
| 16 | /** |
| 17 | * Abstraction of multiple source to single destination connectivity intent. |
| 18 | */ |
| 19 | public 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 |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 33 | * @throws NullPointerException if {@code ingressPorts} or |
| 34 | * {@code egressPort} is null. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | * @throws IllegalArgumentException if the size of {@code ingressPorts} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 36 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | */ |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 38 | public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match, |
| 39 | TrafficTreatment action, |
| 40 | Set<ConnectPoint> ingressPorts, |
| 41 | ConnectPoint egressPort) { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 42 | super(id, match, action); |
| 43 | |
| 44 | checkNotNull(ingressPorts); |
| 45 | checkArgument(!ingressPorts.isEmpty(), |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 46 | "there should be at least one ingress port"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | |
| 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 | } |