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 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 25 | import java.util.List; |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 26 | import java.util.Set; |
| 27 | |
| 28 | import static com.google.common.base.Preconditions.checkArgument; |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Abstraction of multiple source to single destination connectivity intent. |
| 33 | */ |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 34 | public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 36 | private final Set<ConnectPoint> ingressPoints; |
| 37 | private final ConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Creates a new multi-to-single point connectivity intent for the specified |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 41 | * traffic selector and treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 42 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 43 | * @param appId application identifier |
| 44 | * @param selector traffic selector |
| 45 | * @param treatment treatment |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 46 | * @param ingressPoints set of ports from which ingress traffic originates |
| 47 | * @param egressPoint port to which traffic will egress |
| 48 | * @throws NullPointerException if {@code ingressPoints} or |
| 49 | * {@code egressPoint} is null. |
| 50 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 51 | * not more than 1 |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 52 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 53 | public MultiPointToSinglePointIntent(ApplicationId appId, |
| 54 | TrafficSelector selector, |
| 55 | TrafficTreatment treatment, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 56 | Set<ConnectPoint> ingressPoints, |
| 57 | ConnectPoint egressPoint) { |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 58 | super(id(MultiPointToSinglePointIntent.class, selector, treatment, |
| 59 | ingressPoints, egressPoint), appId, null, selector, treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 60 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 61 | checkNotNull(ingressPoints); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 62 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 63 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 64 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
| 65 | this.egressPoint = checkNotNull(egressPoint); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 69 | * Creates a new multi-to-single point connectivity intent for the specified |
| 70 | * traffic selector and treatment. |
| 71 | * |
| 72 | * @param appId application identifier |
| 73 | * @param selector traffic selector |
| 74 | * @param treatment treatment |
| 75 | * @param ingressPoints set of ports from which ingress traffic originates |
| 76 | * @param egressPoint port to which traffic will egress |
| 77 | * @param constraints constraints to apply to the intent |
| 78 | * @throws NullPointerException if {@code ingressPoints} or |
| 79 | * {@code egressPoint} is null. |
| 80 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
| 81 | * not more than 1 |
| 82 | */ |
| 83 | public MultiPointToSinglePointIntent(ApplicationId appId, |
| 84 | TrafficSelector selector, |
| 85 | TrafficTreatment treatment, |
| 86 | Set<ConnectPoint> ingressPoints, |
| 87 | ConnectPoint egressPoint, |
| 88 | List<Constraint> constraints) { |
| 89 | super(id(MultiPointToSinglePointIntent.class, selector, treatment, |
| 90 | ingressPoints, egressPoint), appId, null, selector, treatment, |
| 91 | constraints); |
| 92 | |
| 93 | checkNotNull(ingressPoints); |
| 94 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
| 95 | |
| 96 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
| 97 | this.egressPoint = checkNotNull(egressPoint); |
| 98 | } |
| 99 | |
| 100 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 101 | * Constructor for serializer. |
| 102 | */ |
| 103 | protected MultiPointToSinglePointIntent() { |
| 104 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 105 | this.ingressPoints = null; |
| 106 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns the set of ports on which ingress traffic should be connected to |
| 111 | * the egress port. |
| 112 | * |
| 113 | * @return set of ingress ports |
| 114 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 115 | public Set<ConnectPoint> ingressPoints() { |
| 116 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Returns the port on which the traffic should egress. |
| 121 | * |
| 122 | * @return egress port |
| 123 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 124 | public ConnectPoint egressPoint() { |
| 125 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 129 | public String toString() { |
| 130 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 131 | .add("id", id()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 132 | .add("appId", appId()) |
| 133 | .add("selector", selector()) |
| 134 | .add("treatment", treatment()) |
| 135 | .add("ingress", ingressPoints()) |
| 136 | .add("egress", egressPoint()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 137 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 138 | .toString(); |
| 139 | } |
| 140 | } |