Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.collect.Sets; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 20 | import org.onlab.onos.core.ApplicationId; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 21 | import org.onlab.onos.net.ConnectPoint; |
| 22 | import org.onlab.onos.net.flow.TrafficSelector; |
| 23 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 24 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 25 | import java.util.Set; |
| 26 | |
| 27 | import static com.google.common.base.Preconditions.checkArgument; |
| 28 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Abstraction of single source, multiple destination connectivity intent. |
| 32 | */ |
| 33 | public class SinglePointToMultiPointIntent extends ConnectivityIntent { |
| 34 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 35 | private final ConnectPoint ingressPoint; |
| 36 | private final Set<ConnectPoint> egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Creates a new single-to-multi point connectivity intent. |
| 40 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 41 | * @param appId application identifier |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 42 | * @param selector traffic selector |
| 43 | * @param treatment treatment |
| 44 | * @param ingressPoint port on which traffic will ingress |
| 45 | * @param egressPoints set of ports on which traffic will egress |
| 46 | * @throws NullPointerException if {@code ingressPoint} or |
| 47 | * {@code egressPoints} is null |
| 48 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 49 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 50 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 51 | public SinglePointToMultiPointIntent(ApplicationId appId, |
| 52 | TrafficSelector selector, |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 53 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 54 | ConnectPoint ingressPoint, |
| 55 | Set<ConnectPoint> egressPoints) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 56 | super(id(SinglePointToMultiPointIntent.class, selector, treatment, |
| 57 | ingressPoint, egressPoints), appId, null, selector, treatment); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 58 | checkNotNull(egressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 59 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 60 | this.ingressPoint = checkNotNull(ingressPoint); |
| 61 | this.egressPoints = Sets.newHashSet(egressPoints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Constructor for serializer. |
| 66 | */ |
| 67 | protected SinglePointToMultiPointIntent() { |
| 68 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 69 | this.ingressPoint = null; |
| 70 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the port on which the ingress traffic should be connected to the egress. |
| 75 | * |
| 76 | * @return ingress port |
| 77 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 78 | public ConnectPoint ingressPoint() { |
| 79 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the set of ports on which the traffic should egress. |
| 84 | * |
| 85 | * @return set of egress ports |
| 86 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 87 | public Set<ConnectPoint> egressPoints() { |
| 88 | return egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 92 | public String toString() { |
| 93 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 94 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 95 | .add("appId", appId()) |
| 96 | .add("selector", selector()) |
| 97 | .add("treatment", treatment()) |
| 98 | .add("ingress", ingressPoint) |
| 99 | .add("egress", egressPoints) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 100 | .toString(); |
| 101 | } |
| 102 | |
| 103 | } |