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.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
16 * @file BandWidth.java
18 * @brief Class representing bandwidth
20 * Describe Bandwidth which could be of a link or whatever could have
21 * bandwidth as description. It's intended in multiple of bits per
25 public class Bandwidth extends Property {
26 private static final long serialVersionUID = 1L;
28 @XmlElement(name="value")
29 protected long bandwidthValue;
31 public static final long BWUNK = 0;
32 public static final long BW1Kbps = (long) Math.pow(10, 3);
33 public static final long BW1Mbps = (long) Math.pow(10, 6);
34 public static final long BW10Mbps = (long) Math.pow(10, 7);
35 public static final long BW100Mbps = (long) Math.pow(10, 8);
36 public static final long BW1Gbps = (long) Math.pow(10, 9);
37 public static final long BW10Gbps = (long) Math.pow(10, 10);
38 public static final long BW40Gbps = 4 * (long) Math.pow(10, 10);
39 public static final long BW100Gbps = (long) Math.pow(10, 11);
40 public static final long BW400Gbps = 4 * (long) Math.pow(10, 11);
41 public static final long BW1Tbps = (long) Math.pow(10, 12);
42 public static final long BW1Pbps = (long) Math.pow(10, 15);
44 public static final String BandwidthPropName = "bandwidth";
47 * Private constructor used for JAXB mapping
50 super(BandwidthPropName);
51 this.bandwidthValue = BWUNK;
55 public Bandwidth(long bandwidth) {
56 super(BandwidthPropName);
57 this.bandwidthValue = bandwidth;
60 public Bandwidth(int bandwidth) {
61 super(BandwidthPropName);
62 this.bandwidthValue = (long) bandwidth;
65 public Bandwidth(short bandwidth) {
66 super(BandwidthPropName);
67 this.bandwidthValue = (long) bandwidth;
70 public Bandwidth(String name) {
75 public Bandwidth clone() {
76 return new Bandwidth(this.bandwidthValue);
79 public long getValue() {
80 return this.bandwidthValue;
84 public int hashCode() {
86 int result = super.hashCode();
87 result = prime * result
88 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
93 public boolean equals(Object obj) {
96 if (!super.equals(obj))
98 if (getClass() != obj.getClass())
100 Bandwidth other = (Bandwidth) obj;
101 if (bandwidthValue != other.bandwidthValue)
107 public String toString() {
108 return "BandWidth[" + getStringValue() + "]";
112 public String getStringValue() {
113 if (this.bandwidthValue == 0) {
115 } else if (this.bandwidthValue < BW1Kbps) {
116 return(this.bandwidthValue + "bps");
117 } else if (this.bandwidthValue < BW1Mbps) {
118 return(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
119 } else if (this.bandwidthValue < BW1Gbps) {
120 return(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
121 } else if (this.bandwidthValue < BW1Tbps) {
122 return(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
123 } else if (this.bandwidthValue < BW1Pbps) {
124 return(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
126 return(this.bandwidthValue + "bps");