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