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