Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.net.intent; |
| 17 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 18 | import java.util.Collections; |
| 19 | import java.util.List; |
| 20 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 21 | import com.google.common.annotations.Beta; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.ConnectPoint; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 24 | import org.onosproject.net.ResourceGroup; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
| 27 | |
| 28 | import com.google.common.base.MoreObjects; |
| 29 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
| 31 | |
| 32 | /** |
| 33 | * Abstraction of bidirectional connectivity between two points in the network. |
| 34 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 35 | @Beta |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 36 | public final class TwoWayP2PIntent extends ConnectivityIntent { |
| 37 | |
| 38 | private final ConnectPoint one; |
| 39 | private final ConnectPoint two; |
| 40 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Creates a new host-to-host intent with the supplied host pair. |
| 44 | * |
| 45 | * @param appId application identifier |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 46 | * @param key intent key |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 47 | * @param one first host |
| 48 | * @param two second host |
| 49 | * @param selector action |
| 50 | * @param treatment ingress port |
| 51 | * @param constraints optional prioritized list of path selection constraints |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 52 | * @param priority priority to use for flows generated by this intent |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 53 | * @param resourceGroup resource group for this intent |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 54 | * @throws NullPointerException if {@code one} or {@code two} is null. |
| 55 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 56 | private TwoWayP2PIntent(ApplicationId appId, Key key, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 57 | ConnectPoint one, ConnectPoint two, |
| 58 | TrafficSelector selector, |
| 59 | TrafficTreatment treatment, |
| 60 | List<Constraint> constraints, |
| 61 | int priority, |
| 62 | ResourceGroup resourceGroup) { |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 63 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 64 | priority, resourceGroup); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 65 | |
| 66 | // TODO: consider whether the case one and two are same is allowed |
| 67 | this.one = checkNotNull(one); |
| 68 | this.two = checkNotNull(two); |
| 69 | |
| 70 | } |
| 71 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Returns a new two way intent builder. |
| 74 | * |
| 75 | * @return two way intent builder |
| 76 | */ |
| 77 | public static Builder builder() { |
| 78 | return new Builder(); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Builder of a point to point intent. |
| 83 | */ |
| 84 | public static final class Builder extends ConnectivityIntent.Builder { |
| 85 | ConnectPoint one; |
| 86 | ConnectPoint two; |
| 87 | |
| 88 | private Builder() { |
| 89 | // Hide constructor |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public Builder appId(ApplicationId appId) { |
| 94 | return (Builder) super.appId(appId); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public Builder key(Key key) { |
| 99 | return (Builder) super.key(key); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public Builder selector(TrafficSelector selector) { |
| 104 | return (Builder) super.selector(selector); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Builder treatment(TrafficTreatment treatment) { |
| 109 | return (Builder) super.treatment(treatment); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public Builder constraints(List<Constraint> constraints) { |
| 114 | return (Builder) super.constraints(constraints); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public Builder priority(int priority) { |
| 119 | return (Builder) super.priority(priority); |
| 120 | } |
| 121 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 122 | @Override |
| 123 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 124 | return (Builder) super.resourceGroup(resourceGroup); |
| 125 | } |
| 126 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Sets the first connection point of the two way intent that will be built. |
| 129 | * |
| 130 | * @param one first connect point |
| 131 | * @return this builder |
| 132 | */ |
| 133 | public Builder one(ConnectPoint one) { |
| 134 | this.one = one; |
| 135 | return this; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Sets the second connection point of the two way intent that will be built. |
| 140 | * |
| 141 | * @param two second connect point |
| 142 | * @return this builder |
| 143 | */ |
| 144 | public Builder two(ConnectPoint two) { |
| 145 | this.two = two; |
| 146 | return this; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Builds a point to point intent from the accumulated parameters. |
| 151 | * |
| 152 | * @return point to point intent |
| 153 | */ |
| 154 | public TwoWayP2PIntent build() { |
| 155 | |
| 156 | return new TwoWayP2PIntent( |
| 157 | appId, |
| 158 | key, |
| 159 | one, |
| 160 | two, |
| 161 | selector, |
| 162 | treatment, |
| 163 | constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 164 | priority, |
| 165 | resourceGroup |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 166 | ); |
| 167 | } |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Returns identifier of the first host. |
| 172 | * |
| 173 | * @return first host identifier |
| 174 | */ |
| 175 | public ConnectPoint one() { |
| 176 | return one; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns identifier of the second host. |
| 181 | * |
| 182 | * @return second host identifier |
| 183 | */ |
| 184 | public ConnectPoint two() { |
| 185 | return two; |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public String toString() { |
| 190 | return MoreObjects.toStringHelper(getClass()) |
| 191 | .add("id", id()) |
| 192 | .add("key", key()) |
| 193 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 194 | .add("priority", priority()) |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 195 | .add("resources", resources()) |
| 196 | .add("selector", selector()) |
| 197 | .add("treatment", treatment()) |
| 198 | .add("constraints", constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 199 | .add("resourceGroup", resourceGroup()) |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame] | 200 | .add("one", one) |
| 201 | .add("two", two) |
| 202 | .toString(); |
| 203 | } |
| 204 | |
| 205 | } |