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 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 21 | import com.google.common.annotations.Beta; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.flow.TrafficSelector; |
| 25 | import org.onosproject.net.flow.TrafficTreatment; |
| 26 | |
| 27 | import com.google.common.base.MoreObjects; |
| 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 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 38 | private final ConnectPoint ingressPoint; |
| 39 | private final ConnectPoint 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 { |
| 57 | ConnectPoint ingressPoint; |
| 58 | ConnectPoint egressPoint; |
| 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 | |
| 94 | /** |
| 95 | * Sets the ingress point of the point to point intent that will be built. |
| 96 | * |
| 97 | * @param ingressPoint ingress connect point |
| 98 | * @return this builder |
| 99 | */ |
| 100 | public Builder ingressPoint(ConnectPoint ingressPoint) { |
| 101 | this.ingressPoint = ingressPoint; |
| 102 | return this; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the egress point of the point to point intent that will be built. |
| 107 | * |
| 108 | * @param egressPoint egress connect point |
| 109 | * @return this builder |
| 110 | */ |
| 111 | public Builder egressPoint(ConnectPoint egressPoint) { |
| 112 | this.egressPoint = egressPoint; |
| 113 | return this; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Builds a point to point intent from the accumulated parameters. |
| 118 | * |
| 119 | * @return point to point intent |
| 120 | */ |
| 121 | public PointToPointIntent build() { |
| 122 | |
| 123 | return new PointToPointIntent( |
| 124 | appId, |
| 125 | key, |
| 126 | selector, |
| 127 | treatment, |
| 128 | ingressPoint, |
| 129 | egressPoint, |
| 130 | constraints, |
| 131 | priority |
| 132 | ); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 139 | * Creates a new point-to-point intent with the supplied ingress/egress |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 140 | * ports and constraints. |
| 141 | * |
| 142 | * @param appId application identifier |
| 143 | * @param key key of the intent |
| 144 | * @param selector traffic selector |
| 145 | * @param treatment treatment |
| 146 | * @param ingressPoint ingress port |
| 147 | * @param egressPoint egress port |
| 148 | * @param constraints optional list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 149 | * @param priority priority to use for flows generated by this intent |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 150 | * @throws NullPointerException if {@code ingressPoint} or |
| 151 | * {@code egressPoints} or {@code appId} is null. |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 152 | */ |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 153 | private PointToPointIntent(ApplicationId appId, |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 154 | Key key, |
| 155 | TrafficSelector selector, |
| 156 | TrafficTreatment treatment, |
| 157 | ConnectPoint ingressPoint, |
| 158 | ConnectPoint egressPoint, |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 159 | List<Constraint> constraints, |
| 160 | int priority) { |
| 161 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
| 162 | priority); |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 163 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 164 | checkArgument(!ingressPoint.equals(egressPoint), |
| 165 | "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); |
| 166 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 167 | this.ingressPoint = checkNotNull(ingressPoint); |
| 168 | this.egressPoint = checkNotNull(egressPoint); |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 172 | * Constructor for serializer. |
| 173 | */ |
| 174 | protected PointToPointIntent() { |
| 175 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 176 | this.ingressPoint = null; |
| 177 | this.egressPoint = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Returns the port on which the ingress traffic should be connected to |
| 182 | * the egress. |
| 183 | * |
| 184 | * @return ingress port |
| 185 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 186 | public ConnectPoint ingressPoint() { |
| 187 | return ingressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Returns the port on which the traffic should egress. |
| 192 | * |
| 193 | * @return egress port |
| 194 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 195 | public ConnectPoint egressPoint() { |
| 196 | return egressPoint; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 200 | public String toString() { |
| 201 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 202 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 203 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 204 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 205 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 206 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 207 | .add("selector", selector()) |
| 208 | .add("treatment", treatment()) |
| 209 | .add("ingress", ingressPoint) |
| 210 | .add("egress", egressPoint) |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 211 | .add("constraints", constraints()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 212 | .toString(); |
| 213 | } |
| 214 | |
| 215 | } |