Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [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 | */ |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 16 | package org.onosproject.net.resource.link; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 17 | |
Sho SHIMIZU | f81725b | 2015-05-08 13:36:02 -0700 | [diff] [blame] | 18 | import org.onlab.util.Bandwidth; |
HIGUCHI Yuta | 501c465 | 2015-10-29 14:21:48 -0700 | [diff] [blame] | 19 | import org.onlab.util.DataRateUnit; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
Sho SHIMIZU | f81725b | 2015-05-08 13:36:02 -0700 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 24 | /** |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 25 | * Representation of bandwidth resource in bps. |
Sho SHIMIZU | 364cbac | 2015-10-29 15:47:35 -0700 | [diff] [blame] | 26 | * |
| 27 | * @deprecated in Emu Release |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 28 | */ |
Sho SHIMIZU | 364cbac | 2015-10-29 15:47:35 -0700 | [diff] [blame] | 29 | @Deprecated |
Sho SHIMIZU | 1c221ad | 2015-07-02 10:08:08 -0700 | [diff] [blame] | 30 | public final class BandwidthResource implements LinkResource { |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 31 | |
Sho SHIMIZU | f81725b | 2015-05-08 13:36:02 -0700 | [diff] [blame] | 32 | private final Bandwidth bandwidth; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Creates a new instance with given bandwidth. |
| 36 | * |
| 37 | * @param bandwidth bandwidth value to be assigned |
| 38 | */ |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 39 | public BandwidthResource(Bandwidth bandwidth) { |
Sho SHIMIZU | f81725b | 2015-05-08 13:36:02 -0700 | [diff] [blame] | 40 | this.bandwidth = checkNotNull(bandwidth); |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Thomas Vachuska | 7d0032b | 2014-11-04 17:39:57 -0800 | [diff] [blame] | 43 | // Constructor for serialization |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 44 | private BandwidthResource() { |
Sho SHIMIZU | f81725b | 2015-05-08 13:36:02 -0700 | [diff] [blame] | 45 | this.bandwidth = null; |
Thomas Vachuska | 7d0032b | 2014-11-04 17:39:57 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 48 | /** |
HIGUCHI Yuta | 501c465 | 2015-10-29 14:21:48 -0700 | [diff] [blame] | 49 | * Creates a new bandwidth resource. |
| 50 | * |
| 51 | * @param v amount of bandwidth to request |
| 52 | * @param unit {@link DataRateUnit} of {@code v} |
| 53 | * @return {@link BandwidthResource} instance with given bandwidth |
| 54 | */ |
| 55 | public static BandwidthResource of(double v, DataRateUnit unit) { |
| 56 | return new BandwidthResource(Bandwidth.of(v, unit)); |
| 57 | } |
| 58 | |
| 59 | /** |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 60 | * Returns bandwidth as a double value. |
| 61 | * |
| 62 | * @return bandwidth as a double value |
| 63 | */ |
| 64 | public double toDouble() { |
Sho SHIMIZU | f81725b | 2015-05-08 13:36:02 -0700 | [diff] [blame] | 65 | return bandwidth.bps(); |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public boolean equals(Object obj) { |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 70 | if (obj instanceof BandwidthResource) { |
| 71 | BandwidthResource that = (BandwidthResource) obj; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 72 | return Objects.equals(this.bandwidth, that.bandwidth); |
| 73 | } |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int hashCode() { |
| 79 | return Objects.hashCode(this.bandwidth); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String toString() { |
| 84 | return String.valueOf(this.bandwidth); |
| 85 | } |
| 86 | } |