Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent; |
| 2 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 3 | import com.google.common.base.MoreObjects; |
| 4 | import com.google.common.collect.Sets; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.ConnectPoint; |
| 6 | import org.onlab.onos.net.flow.TrafficSelector; |
| 7 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 8 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 9 | import java.util.Objects; |
| 10 | import java.util.Set; |
| 11 | |
| 12 | import static com.google.common.base.Preconditions.checkArgument; |
| 13 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * Abstraction of single source, multiple destination connectivity intent. |
| 17 | */ |
| 18 | public class SinglePointToMultiPointIntent extends ConnectivityIntent { |
| 19 | |
| 20 | private final ConnectPoint ingressPort; |
| 21 | private final Set<ConnectPoint> egressPorts; |
| 22 | |
| 23 | /** |
| 24 | * Creates a new single-to-multi point connectivity intent. |
| 25 | * |
| 26 | * @param id intent identifier |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 27 | * @param selector traffic selector |
| 28 | * @param treatment treatment |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 29 | * @param ingressPort port on which traffic will ingress |
| 30 | * @param egressPorts set of ports on which traffic will egress |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 31 | * @throws NullPointerException if {@code ingressPort} or |
| 32 | * {@code egressPorts} is null |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 33 | * @throws IllegalArgumentException if the size of {@code egressPorts} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 34 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | */ |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 36 | public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector, |
| 37 | TrafficTreatment treatment, |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 38 | ConnectPoint ingressPort, |
| 39 | Set<ConnectPoint> egressPorts) { |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 40 | super(id, selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 41 | |
| 42 | checkNotNull(egressPorts); |
| 43 | checkArgument(!egressPorts.isEmpty(), |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 44 | "there should be at least one egress port"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 45 | |
| 46 | this.ingressPort = checkNotNull(ingressPort); |
| 47 | this.egressPorts = Sets.newHashSet(egressPorts); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Constructor for serializer. |
| 52 | */ |
| 53 | protected SinglePointToMultiPointIntent() { |
| 54 | super(); |
| 55 | this.ingressPort = null; |
| 56 | this.egressPorts = null; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the port on which the ingress traffic should be connected to the egress. |
| 61 | * |
| 62 | * @return ingress port |
| 63 | */ |
| 64 | public ConnectPoint getIngressPort() { |
| 65 | return ingressPort; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the set of ports on which the traffic should egress. |
| 70 | * |
| 71 | * @return set of egress ports |
| 72 | */ |
| 73 | public Set<ConnectPoint> getEgressPorts() { |
| 74 | return egressPorts; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object o) { |
| 79 | if (this == o) { |
| 80 | return true; |
| 81 | } |
| 82 | if (o == null || getClass() != o.getClass()) { |
| 83 | return false; |
| 84 | } |
| 85 | if (!super.equals(o)) { |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o; |
| 90 | return Objects.equals(this.ingressPort, that.ingressPort) |
| 91 | && Objects.equals(this.egressPorts, that.egressPorts); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public int hashCode() { |
| 96 | return Objects.hash(super.hashCode(), ingressPort, egressPorts); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return MoreObjects.toStringHelper(getClass()) |
| 102 | .add("id", getId()) |
| 103 | .add("match", getTrafficSelector()) |
| 104 | .add("action", getTrafficTreatment()) |
| 105 | .add("ingressPort", ingressPort) |
| 106 | .add("egressPort", egressPorts) |
| 107 | .toString(); |
| 108 | } |
| 109 | |
| 110 | } |