Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [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 | |
| 17 | package org.onosproject.pce.pceservice; |
| 18 | |
| 19 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 20 | |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 21 | import java.util.Collection; |
| 22 | import java.util.List; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 25 | import org.onlab.rest.BaseResource; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 26 | import org.onlab.util.DataRateUnit; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 27 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 28 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 29 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 30 | import org.onosproject.net.intent.Constraint; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 31 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 32 | import org.onosproject.pce.pcestore.api.PceStore; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Implementation of an entity which provides functionalities of pce path. |
| 36 | */ |
| 37 | public final class DefaultPcePath implements PcePath { |
| 38 | |
| 39 | private TunnelId id; // path id |
| 40 | private String source; // Ingress |
| 41 | private String destination; // Egress |
| 42 | private LspType lspType; // LSP type |
| 43 | private String name; // symbolic-path-name |
| 44 | private Constraint costConstraint; // cost constraint |
| 45 | private Constraint bandwidthConstraint; // bandwidth constraint |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 46 | private Collection<ExplicitPathInfo> explicitPathInfo; //list of explicit path info |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Initializes PCE path attributes. |
| 50 | * |
| 51 | * @param id path id |
| 52 | * @param src ingress |
| 53 | * @param dst egress |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 54 | * @param lspType LSP type |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 55 | * @param name symbolic-path-name |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 56 | * @param costConstrnt cost constraint |
| 57 | * @param bandwidthConstrnt bandwidth constraint |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 58 | * @param explicitPathInfo list of explicit path info |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 59 | */ |
| 60 | private DefaultPcePath(TunnelId id, String src, String dst, LspType lspType, |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 61 | String name, Constraint costConstrnt, Constraint bandwidthConstrnt, |
| 62 | Collection<ExplicitPathInfo> explicitPathInfo) { |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 63 | this.id = id; |
| 64 | this.source = src; |
| 65 | this.destination = dst; |
| 66 | this.lspType = lspType; |
| 67 | this.name = name; |
| 68 | this.costConstraint = costConstrnt; |
| 69 | this.bandwidthConstraint = bandwidthConstrnt; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 70 | this.explicitPathInfo = explicitPathInfo; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public TunnelId id() { |
| 75 | return id; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void id(TunnelId id) { |
| 80 | this.id = id; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public String source() { |
| 85 | return source; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void source(String src) { |
| 90 | this.source = src; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public String destination() { |
| 95 | return destination; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void destination(String dst) { |
| 100 | this.destination = dst; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public LspType lspType() { |
| 105 | return lspType; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public String name() { |
| 110 | return name; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public Constraint costConstraint() { |
| 115 | return costConstraint; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public Constraint bandwidthConstraint() { |
| 120 | return bandwidthConstraint; |
| 121 | } |
| 122 | |
| 123 | @Override |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 124 | public Collection<ExplicitPathInfo> explicitPathInfo() { |
| 125 | return explicitPathInfo; |
| 126 | } |
| 127 | |
| 128 | @Override |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 129 | public PcePath copy(PcePath path) { |
| 130 | if (null != path.source()) { |
| 131 | this.source = path.source(); |
| 132 | } |
| 133 | if (null != path.destination()) { |
| 134 | this.destination = path.destination(); |
| 135 | } |
| 136 | |
| 137 | this.lspType = path.lspType(); |
| 138 | |
| 139 | if (null != path.name()) { |
| 140 | this.name = path.name(); |
| 141 | } |
| 142 | if (null != path.costConstraint()) { |
| 143 | this.costConstraint = path.costConstraint(); |
| 144 | } |
| 145 | if (null != path.bandwidthConstraint()) { |
| 146 | this.bandwidthConstraint = path.bandwidthConstraint(); |
| 147 | } |
| 148 | return this; |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public int hashCode() { |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 153 | return Objects.hash(id, source, destination, lspType, name, costConstraint, bandwidthConstraint, |
| 154 | explicitPathInfo); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public boolean equals(Object obj) { |
| 159 | if (this == obj) { |
| 160 | return true; |
| 161 | } |
| 162 | if (obj instanceof DefaultPcePath) { |
| 163 | DefaultPcePath that = (DefaultPcePath) obj; |
| 164 | return Objects.equals(id, that.id) |
| 165 | && Objects.equals(source, that.source) |
| 166 | && Objects.equals(destination, that.destination) |
| 167 | && Objects.equals(lspType, that.lspType) |
| 168 | && Objects.equals(name, that.name) |
| 169 | && Objects.equals(costConstraint, that.costConstraint) |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 170 | && Objects.equals(bandwidthConstraint, that.bandwidthConstraint) |
| 171 | && Objects.equals(explicitPathInfo, that.explicitPathInfo); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 172 | } |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public String toString() { |
| 178 | return toStringHelper(this) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 179 | .omitNullValues() |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 180 | .add("id", id()) |
| 181 | .add("source", source) |
| 182 | .add("destination", destination) |
| 183 | .add("lsptype", lspType) |
| 184 | .add("name", name) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 185 | .add("costConstraint", costConstraint) |
| 186 | .add("bandwidthConstraint", bandwidthConstraint) |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 187 | .add("explicitPathInfo", explicitPathInfo) |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 188 | .toString(); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Creates an instance of the pce path builder. |
| 193 | * |
| 194 | * @return instance of builder |
| 195 | */ |
| 196 | public static Builder builder() { |
| 197 | return new Builder(); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Builder class for pce path. |
| 202 | */ |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 203 | public static final class Builder extends BaseResource implements PcePath.Builder { |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 204 | private TunnelId id; |
| 205 | private String source; |
| 206 | private String destination; |
| 207 | private LspType lspType; |
| 208 | private String name; |
| 209 | private Constraint costConstraint; |
| 210 | private Constraint bandwidthConstraint; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 211 | private Collection<ExplicitPathInfo> explicitPathInfo; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 212 | |
| 213 | @Override |
| 214 | public Builder id(String id) { |
| 215 | this.id = TunnelId.valueOf(id); |
| 216 | return this; |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public Builder source(String source) { |
| 221 | this.source = source; |
| 222 | return this; |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public Builder destination(String destination) { |
| 227 | this.destination = destination; |
| 228 | return this; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public Builder lspType(String type) { |
| 233 | if (null != type) { |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 234 | this.lspType = LspType.values()[Integer.valueOf(type)]; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 235 | } |
| 236 | return this; |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public Builder name(String name) { |
| 241 | this.name = name; |
| 242 | return this; |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public Builder costConstraint(String cost) { |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 247 | this.costConstraint = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(cost) - 1]); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 248 | return this; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public Builder bandwidthConstraint(String bandwidth) { |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 253 | this.bandwidthConstraint = BandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit |
| 254 | .valueOf("BPS")); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 255 | return this; |
| 256 | } |
| 257 | |
| 258 | @Override |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 259 | public Builder explicitPathInfo(Collection<ExplicitPathInfo> explicitPathInfo) { |
| 260 | this.explicitPathInfo = explicitPathInfo; |
| 261 | return this; |
| 262 | } |
| 263 | |
| 264 | @Override |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 265 | public Builder of(Tunnel tunnel) { |
| 266 | this.id = TunnelId.valueOf(tunnel.tunnelId().id()); |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 267 | this.source = tunnel.path().src().deviceId().toString(); |
| 268 | this.destination = tunnel.path().dst().deviceId().toString(); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 269 | this.name = tunnel.tunnelName().toString(); |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 270 | // LSP type |
| 271 | String lspType = tunnel.annotations().value(PcepAnnotationKeys.LSP_SIG_TYPE); |
| 272 | if (lspType != null) { |
Priyanka B | b977f56 | 2016-07-22 13:02:03 +0530 | [diff] [blame] | 273 | this.lspType = LspType.values()[LspType.valueOf(lspType).type()]; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 274 | } |
Priyanka B | b977f56 | 2016-07-22 13:02:03 +0530 | [diff] [blame] | 275 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 276 | // Cost type |
| 277 | String costType = tunnel.annotations().value(PcepAnnotationKeys.COST_TYPE); |
| 278 | if (costType != null) { |
Priyanka B | b977f56 | 2016-07-22 13:02:03 +0530 | [diff] [blame] | 279 | this.costConstraint = CostConstraint.of(CostConstraint.Type.valueOf(costType)); |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 280 | } |
Priyanka B | b977f56 | 2016-07-22 13:02:03 +0530 | [diff] [blame] | 281 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 282 | // Bandwidth |
| 283 | String bandwidth = tunnel.annotations().value(PcepAnnotationKeys.BANDWIDTH); |
| 284 | if (bandwidth != null) { |
| 285 | this.bandwidthConstraint = BandwidthConstraint.of(Double.parseDouble(bandwidth), |
| 286 | DataRateUnit.valueOf("BPS")); |
| 287 | } |
| 288 | |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 289 | PceStore pceStore = get(PceStore.class); |
| 290 | List<ExplicitPathInfo> explicitPathInfoList = pceStore |
| 291 | .getTunnelNameExplicitPathInfoMap(tunnel.tunnelName().value()); |
| 292 | if (explicitPathInfoList != null) { |
| 293 | this.explicitPathInfo = explicitPathInfoList; |
| 294 | } |
| 295 | |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 296 | return this; |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public PcePath build() { |
| 301 | return new DefaultPcePath(id, source, destination, lspType, name, |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 302 | costConstraint, bandwidthConstraint, explicitPathInfo); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | } |