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 | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 22 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.net.HostId; |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 25 | import org.onosproject.net.Link; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 26 | import org.onosproject.net.ResourceGroup; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 27 | import org.onosproject.net.flow.TrafficSelector; |
| 28 | import org.onosproject.net.flow.TrafficTreatment; |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 29 | import org.onosproject.net.intent.constraint.LinkTypeConstraint; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 30 | |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 31 | import java.util.List; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 32 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 33 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 36 | * Abstraction of end-station to end-station bidirectional connectivity. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 37 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 38 | @Beta |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 39 | public final class HostToHostIntent extends ConnectivityIntent { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 40 | |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 41 | static final LinkTypeConstraint NOT_OPTICAL = new LinkTypeConstraint(false, Link.Type.OPTICAL); |
| 42 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 43 | private final HostId one; |
| 44 | private final HostId two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 47 | * Returns a new host to host intent builder. |
Thomas Vachuska | 6dd018f | 2014-12-04 15:04:26 -0800 | [diff] [blame] | 48 | * |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 49 | * @return host to host intent builder |
Thomas Vachuska | 6dd018f | 2014-12-04 15:04:26 -0800 | [diff] [blame] | 50 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 51 | public static Builder builder() { |
| 52 | return new Builder(); |
Thomas Vachuska | 6dd018f | 2014-12-04 15:04:26 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 56 | * Builder of a host to host intent. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 57 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 58 | public static final class Builder extends ConnectivityIntent.Builder { |
| 59 | HostId one; |
| 60 | HostId two; |
| 61 | |
| 62 | private Builder() { |
| 63 | // Hide constructor |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Builder appId(ApplicationId appId) { |
| 68 | return (Builder) super.appId(appId); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Builder key(Key key) { |
| 73 | return (Builder) super.key(key); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Builder selector(TrafficSelector selector) { |
| 78 | return (Builder) super.selector(selector); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Builder treatment(TrafficTreatment treatment) { |
| 83 | return (Builder) super.treatment(treatment); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public Builder constraints(List<Constraint> constraints) { |
| 88 | return (Builder) super.constraints(constraints); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public Builder priority(int priority) { |
| 93 | return (Builder) super.priority(priority); |
| 94 | } |
| 95 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 96 | @Override |
| 97 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 98 | return (Builder) super.resourceGroup(resourceGroup); |
| 99 | } |
| 100 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Sets the first host of the intent that will be built. |
| 103 | * |
| 104 | * @param one first host |
| 105 | * @return this builder |
| 106 | */ |
| 107 | public Builder one(HostId one) { |
| 108 | this.one = one; |
| 109 | return this; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Sets the second host of the intent that will be built. |
| 114 | * |
| 115 | * @param two second host |
| 116 | * @return this builder |
| 117 | */ |
| 118 | public Builder two(HostId two) { |
| 119 | this.two = two; |
| 120 | return this; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Builds a host to host intent from the accumulated parameters. |
| 125 | * |
| 126 | * @return point to point intent |
| 127 | */ |
| 128 | public HostToHostIntent build() { |
| 129 | |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 130 | List<Constraint> theConstraints = constraints; |
| 131 | // If not-OPTICAL constraint hasn't been specified, add them |
| 132 | if (!constraints.contains(NOT_OPTICAL)) { |
| 133 | theConstraints = ImmutableList.<Constraint>builder() |
| 134 | .add(NOT_OPTICAL) |
| 135 | .addAll(constraints) |
| 136 | .build(); |
| 137 | } |
| 138 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 139 | return new HostToHostIntent( |
| 140 | appId, |
| 141 | key, |
| 142 | one, |
| 143 | two, |
| 144 | selector, |
| 145 | treatment, |
HIGUCHI Yuta | 584107a | 2015-10-27 18:12:44 -0700 | [diff] [blame] | 146 | theConstraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 147 | priority, |
| 148 | resourceGroup |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 149 | ); |
| 150 | } |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 153 | /** |
| 154 | * Creates a new host-to-host intent with the supplied host pair. |
| 155 | * |
| 156 | * @param appId application identifier |
| 157 | * @param key intent key |
| 158 | * @param one first host |
| 159 | * @param two second host |
| 160 | * @param selector action |
| 161 | * @param treatment ingress port |
| 162 | * @param constraints optional prioritized list of path selection constraints |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 163 | * @param priority priority to use for flows generated by this intent |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 164 | * @param resourceGroup resource group for this intent |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 165 | * @throws NullPointerException if {@code one} or {@code two} is null. |
| 166 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 167 | private HostToHostIntent(ApplicationId appId, Key key, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 168 | HostId one, HostId two, |
| 169 | TrafficSelector selector, |
| 170 | TrafficTreatment treatment, |
| 171 | List<Constraint> constraints, |
| 172 | int priority, |
| 173 | ResourceGroup resourceGroup) { |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 174 | super(appId, key, ImmutableSet.of(one, two), selector, treatment, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 175 | constraints, priority, resourceGroup); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 176 | |
| 177 | // TODO: consider whether the case one and two are same is allowed |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 178 | this.one = checkNotNull(one); |
| 179 | this.two = checkNotNull(two); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 183 | * Returns identifier of the first host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 184 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 185 | * @return first host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 186 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 187 | public HostId one() { |
| 188 | return one; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 192 | * Returns identifier of the second host. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 193 | * |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 194 | * @return second host identifier |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 195 | */ |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 196 | public HostId two() { |
| 197 | return two; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 201 | public String toString() { |
| 202 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 203 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 204 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 205 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 206 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 207 | .add("resources", resources()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 208 | .add("selector", selector()) |
| 209 | .add("treatment", treatment()) |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 210 | .add("constraints", constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 211 | .add("resourceGroup", resourceGroup()) |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 212 | .add("one", one) |
| 213 | .add("two", two) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 214 | .toString(); |
| 215 | } |
| 216 | |
| 217 | } |