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 | 85258ee | 2014-10-07 00:10:02 -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 | 85258ee | 2014-10-07 00:10:02 -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 multiple source to single destination connectivity intent. |
| 32 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 33 | public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 34 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 35 | private final Set<ConnectPoint> ingressPoints; |
| 36 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Creates a new multi-to-single point connectivity intent for the specified |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 40 | * traffic selector and treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 41 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 42 | * @param appId application identifier |
| 43 | * @param selector traffic selector |
| 44 | * @param treatment treatment |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 45 | * @param ingressPoints set of ports from which ingress traffic originates |
| 46 | * @param egressPoint port to which traffic will egress |
| 47 | * @throws NullPointerException if {@code ingressPoints} or |
| 48 | * {@code egressPoint} is null. |
| 49 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 50 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 51 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 52 | public MultiPointToSinglePointIntent(ApplicationId appId, |
| 53 | TrafficSelector selector, |
| 54 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 55 | Set<ConnectPoint> ingressPoints, |
| 56 | ConnectPoint egressPoint) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 57 | super(id(MultiPointToSinglePointIntent.class, selector, treatment, |
| 58 | ingressPoints, egressPoint), appId, null, selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 59 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 60 | checkNotNull(ingressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 61 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 62 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 63 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
| 64 | this.egressPoint = checkNotNull(egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Constructor for serializer. |
| 69 | */ |
| 70 | protected MultiPointToSinglePointIntent() { |
| 71 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 72 | this.ingressPoints = null; |
| 73 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the set of ports on which ingress traffic should be connected to |
| 78 | * the egress port. |
| 79 | * |
| 80 | * @return set of ingress ports |
| 81 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 82 | public Set<ConnectPoint> ingressPoints() { |
| 83 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns the port on which the traffic should egress. |
| 88 | * |
| 89 | * @return egress port |
| 90 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 91 | public ConnectPoint egressPoint() { |
| 92 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 96 | public String toString() { |
| 97 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 98 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 99 | .add("appId", appId()) |
| 100 | .add("selector", selector()) |
| 101 | .add("treatment", treatment()) |
| 102 | .add("ingress", ingressPoints()) |
| 103 | .add("egress", egressPoint()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 104 | .toString(); |
| 105 | } |
| 106 | } |