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