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