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;
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) {
74 public Bandwidth clone() {
75 return new Bandwidth(this.bandwidthValue);
78 public long getValue() {
79 return this.bandwidthValue;
83 public int hashCode() {
85 int result = super.hashCode();
86 result = prime * result
87 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
92 public boolean equals(Object obj) {
95 if (!super.equals(obj))
97 if (getClass() != obj.getClass())
99 Bandwidth other = (Bandwidth) obj;
100 if (bandwidthValue != other.bandwidthValue)
106 public String toString() {
107 StringBuffer sb = new StringBuffer();
109 sb.append("BandWidth[");
110 if (this.bandwidthValue == 0) {
111 sb.append("UnKnown");
112 } else if (this.bandwidthValue < BW1Kbps) {
113 sb.append(this.bandwidthValue + "bps");
114 } else if (this.bandwidthValue < BW1Mbps) {
115 sb.append(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
116 } else if (this.bandwidthValue < BW1Gbps) {
117 sb.append(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
118 } else if (this.bandwidthValue < BW1Tbps) {
119 sb.append(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
120 } else if (this.bandwidthValue < BW1Pbps) {
121 sb.append(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
125 return sb.toString();