Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 21 | import org.onosproject.net.FilteredConnectPoint; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ResourceGroup; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 26 | import java.util.Collections; |
| 27 | import java.util.List; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 28 | |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkArgument; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 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 point-to-point connectivity. |
| 34 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 35 | @Beta |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 36 | public final class PointToPointIntent extends ConnectivityIntent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 38 | private final FilteredConnectPoint ingressPoint; |
| 39 | private final FilteredConnectPoint egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 42 | * Returns a new point to point intent builder. The application id, |
| 43 | * ingress point and egress point are required fields. If they are |
| 44 | * not set by calls to the appropriate methods, an exception will |
| 45 | * be thrown. |
| 46 | * |
| 47 | * @return point to point builder |
| 48 | */ |
| 49 | public static PointToPointIntent.Builder builder() { |
| 50 | return new Builder(); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Builder of a point to point intent. |
| 55 | */ |
| 56 | public static final class Builder extends ConnectivityIntent.Builder { |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 57 | FilteredConnectPoint ingressPoint; |
| 58 | FilteredConnectPoint egressPoint; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 59 | |
| 60 | private Builder() { |
| 61 | // Hide constructor |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Builder appId(ApplicationId appId) { |
| 66 | return (Builder) super.appId(appId); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public Builder key(Key key) { |
| 71 | return (Builder) super.key(key); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public Builder selector(TrafficSelector selector) { |
| 76 | return (Builder) super.selector(selector); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public Builder treatment(TrafficTreatment treatment) { |
| 81 | return (Builder) super.treatment(treatment); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Builder constraints(List<Constraint> constraints) { |
| 86 | return (Builder) super.constraints(constraints); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public Builder priority(int priority) { |
| 91 | return (Builder) super.priority(priority); |
| 92 | } |
| 93 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 94 | @Override |
| 95 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 96 | return (Builder) super.resourceGroup(resourceGroup); |
| 97 | } |
| 98 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 99 | /** |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 100 | * Sets the filtered ingress point of the point to |
| 101 | * point intent that will be built. |
| 102 | * |
| 103 | * @param ingressPoint filtered ingress connect point |
| 104 | * @return this builder |
| 105 | */ |
| 106 | public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) { |
| 107 | this.ingressPoint = ingressPoint; |
| 108 | return this; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Sets the filtered egress point of the point to |
| 113 | * point intent that will be built. |
| 114 | * |
| 115 | * @param egressPoint filtered egress connect point |
| 116 | * @return this builder |
| 117 | */ |
| 118 | public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 119 | this.egressPoint = egressPoint; |
| 120 | return this; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Builds a point to point intent from the accumulated parameters. |
| 125 | * |
| 126 | * @return point to point intent |
| 127 | */ |
| 128 | public PointToPointIntent build() { |
| 129 | |
| 130 | return new PointToPointIntent( |
| 131 | appId, |
| 132 | key, |
| 133 | selector, |
| 134 | treatment, |
| 135 | ingressPoint, |
| 136 | egressPoint, |
| 137 | constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 138 | priority, |
| 139 | resourceGroup |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 140 | ); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | |
| 145 | |
| 146 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 147 | * Creates a new point-to-point intent with the supplied ingress/egress |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 148 | * ports and constraints. |
| 149 | * |
| 150 | * @param appId application identifier |
| 151 | * @param key key of the intent |
| 152 | * @param selector traffic selector |
| 153 | * @param treatment treatment |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 154 | * @param ingressPoint filtered ingress port |
| 155 | * @param egressPoint filtered egress port |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 156 | * @param constraints optional list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 157 | * @param priority priority to use for flows generated by this intent |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 158 | * @throws NullPointerException if {@code ingressPoint} or |
| 159 | * {@code egressPoints} or {@code appId} is null. |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 160 | */ |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 161 | private PointToPointIntent(ApplicationId appId, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 162 | Key key, |
| 163 | TrafficSelector selector, |
| 164 | TrafficTreatment treatment, |
| 165 | FilteredConnectPoint ingressPoint, |
| 166 | FilteredConnectPoint egressPoint, |
| 167 | List<Constraint> constraints, |
| 168 | int priority, |
| 169 | ResourceGroup resourceGroup) { |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 170 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 171 | priority, resourceGroup); |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 172 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 173 | checkArgument(!ingressPoint.equals(egressPoint), |
| 174 | "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); |
| 175 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 176 | this.ingressPoint = checkNotNull(ingressPoint); |
| 177 | this.egressPoint = checkNotNull(egressPoint); |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 181 | * Constructor for serializer. |
| 182 | */ |
| 183 | protected PointToPointIntent() { |
| 184 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 185 | this.ingressPoint = null; |
| 186 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 190 | * Returns the filtered port on which the ingress traffic should be connected to the |
| 191 | * egress. |
| 192 | * |
| 193 | * @return ingress port |
| 194 | */ |
| 195 | public FilteredConnectPoint filteredIngressPoint() { |
| 196 | return ingressPoint; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Return the filtered port on which the traffic should exit. |
| 201 | * |
| 202 | * @return egress port |
| 203 | */ |
| 204 | public FilteredConnectPoint filteredEgressPoint() { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 205 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 209 | public String toString() { |
| 210 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 211 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 212 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 213 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 214 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 215 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 216 | .add("selector", selector()) |
| 217 | .add("treatment", treatment()) |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 218 | .add("ingress", filteredIngressPoint()) |
| 219 | .add("egress", filteredEgressPoint()) |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 220 | .add("constraints", constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 221 | .add("resourceGroup", resourceGroup()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 222 | .toString(); |
| 223 | } |
| 224 | |
| 225 | } |