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 | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 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; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.flow.TrafficSelector; |
| 23 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 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 |
Jonathan Hart | d0ba217 | 2015-02-11 13:54:33 -0800 | [diff] [blame^] | 67 | * @param key intent key |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 68 | * @param selector traffic selector |
| 69 | * @param treatment treatment |
| 70 | * @param ingressPoints set of ports from which ingress traffic originates |
| 71 | * @param egressPoint port to which traffic will egress |
| 72 | * @param constraints constraints to apply to the intent |
| 73 | * @throws NullPointerException if {@code ingressPoints} or |
| 74 | * {@code egressPoint} is null. |
| 75 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
| 76 | * not more than 1 |
| 77 | */ |
| 78 | public MultiPointToSinglePointIntent(ApplicationId appId, |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 79 | Key key, |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 80 | TrafficSelector selector, |
| 81 | TrafficTreatment treatment, |
| 82 | Set<ConnectPoint> ingressPoints, |
| 83 | ConnectPoint egressPoint, |
| 84 | List<Constraint> constraints) { |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 85 | super(appId, key, Collections.emptyList(), selector, treatment, constraints); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 86 | |
| 87 | checkNotNull(ingressPoints); |
| 88 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 89 | checkNotNull(egressPoint); |
| 90 | checkArgument(!ingressPoints.contains(egressPoint), |
| 91 | "Set of ingresses should not contain egress (egress: %s)", egressPoint); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 92 | |
| 93 | this.ingressPoints = Sets.newHashSet(ingressPoints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 94 | this.egressPoint = egressPoint; |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 98 | * Creates a new multi-to-single point connectivity intent for the specified |
| 99 | * traffic selector and treatment. |
| 100 | * |
| 101 | * @param appId application identifier |
| 102 | * @param selector traffic selector |
| 103 | * @param treatment treatment |
| 104 | * @param ingressPoints set of ports from which ingress traffic originates |
| 105 | * @param egressPoint port to which traffic will egress |
| 106 | * @param constraints constraints to apply to the intent |
| 107 | * @throws NullPointerException if {@code ingressPoints} or |
| 108 | * {@code egressPoint} is null. |
| 109 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
| 110 | * not more than 1 |
| 111 | */ |
| 112 | public MultiPointToSinglePointIntent(ApplicationId appId, |
| 113 | TrafficSelector selector, |
| 114 | TrafficTreatment treatment, |
| 115 | Set<ConnectPoint> ingressPoints, |
| 116 | ConnectPoint egressPoint, |
| 117 | List<Constraint> constraints) { |
| 118 | this(appId, null, selector, treatment, ingressPoints, egressPoint, constraints); |
| 119 | } |
| 120 | |
| 121 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 122 | * Constructor for serializer. |
| 123 | */ |
| 124 | protected MultiPointToSinglePointIntent() { |
| 125 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 126 | this.ingressPoints = null; |
| 127 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns the set of ports on which ingress traffic should be connected to |
| 132 | * the egress port. |
| 133 | * |
| 134 | * @return set of ingress ports |
| 135 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 136 | public Set<ConnectPoint> ingressPoints() { |
| 137 | return ingressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Returns the port on which the traffic should egress. |
| 142 | * |
| 143 | * @return egress port |
| 144 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 145 | public ConnectPoint egressPoint() { |
| 146 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 150 | public String toString() { |
| 151 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 152 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 153 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 154 | .add("appId", appId()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 155 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 156 | .add("selector", selector()) |
| 157 | .add("treatment", treatment()) |
| 158 | .add("ingress", ingressPoints()) |
| 159 | .add("egress", egressPoint()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 160 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 161 | .toString(); |
| 162 | } |
| 163 | } |