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