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