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