3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.core;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
18 * @file BandWidth.java
20 * @brief Class representing bandwidth
22 * Describe Bandwidth which could be of a link or whatever could have
23 * bandwidth as description. It's intended in multiple of bits per
27 @XmlAccessorType(XmlAccessType.NONE)
28 public class Bandwidth extends Property {
29 private static final long serialVersionUID = 1L;
31 @XmlElement(name="value")
32 protected long bandwidthValue;
34 public static final long BWUNK = 0;
35 public static final long BW1Kbps = (long) Math.pow(10, 3);
36 public static final long BW1Mbps = (long) Math.pow(10, 6);
37 public static final long BW10Mbps = (long) Math.pow(10, 7);
38 public static final long BW100Mbps = (long) Math.pow(10, 8);
39 public static final long BW1Gbps = (long) Math.pow(10, 9);
40 public static final long BW10Gbps = (long) Math.pow(10, 10);
41 public static final long BW40Gbps = 4 * (long) Math.pow(10, 10);
42 public static final long BW100Gbps = (long) Math.pow(10, 11);
43 public static final long BW400Gbps = 4 * (long) Math.pow(10, 11);
44 public static final long BW1Tbps = (long) Math.pow(10, 12);
45 public static final long BW1Pbps = (long) Math.pow(10, 15);
47 public static final String BandwidthPropName = "bandwidth";
50 * Private constructor used for JAXB mapping
53 super(BandwidthPropName);
54 this.bandwidthValue = BWUNK;
57 public Bandwidth(long bandwidth) {
58 super(BandwidthPropName);
59 this.bandwidthValue = bandwidth;
62 public Bandwidth(int bandwidth) {
63 super(BandwidthPropName);
64 this.bandwidthValue = (long) bandwidth;
67 public Bandwidth(short bandwidth) {
68 super(BandwidthPropName);
69 this.bandwidthValue = (long) bandwidth;
72 public Bandwidth(String name) {
77 public Bandwidth clone() {
78 return new Bandwidth(this.bandwidthValue);
81 public long getValue() {
82 return this.bandwidthValue;
86 public int hashCode() {
88 int result = super.hashCode();
89 result = prime * result
90 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
95 public boolean equals(Object obj) {
98 if (!super.equals(obj))
100 if (getClass() != obj.getClass())
102 Bandwidth other = (Bandwidth) obj;
103 if (bandwidthValue != other.bandwidthValue)
109 public String toString() {
110 return "BandWidth[" + getStringValue() + "]";
114 public String getStringValue() {
115 if (this.bandwidthValue == 0) {
117 } else if (this.bandwidthValue < BW1Kbps) {
118 return(this.bandwidthValue + "bps");
119 } else if (this.bandwidthValue < BW1Mbps) {
120 return(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
121 } else if (this.bandwidthValue < BW1Gbps) {
122 return(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
123 } else if (this.bandwidthValue < BW1Tbps) {
124 return(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
125 } else if (this.bandwidthValue < BW1Pbps) {
126 return(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
128 return(this.bandwidthValue + "bps");