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;
15 import org.apache.commons.lang3.builder.EqualsBuilder;
16 import org.apache.commons.lang3.builder.HashCodeBuilder;
19 * @file BandWidth.java
21 * @brief Class representing bandwidth
23 * Describe Bandwidth which could be of a link or whatever could have
24 * bandwidth as description. It's intended in multiple of bits per
28 public class Bandwidth extends Property {
29 private static final long serialVersionUID = 1L;
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;
58 public Bandwidth(long bandwidth) {
59 super(BandwidthPropName);
60 this.bandwidthValue = bandwidth;
63 public Bandwidth(int bandwidth) {
64 super(BandwidthPropName);
65 this.bandwidthValue = (long) bandwidth;
68 public Bandwidth(short bandwidth) {
69 super(BandwidthPropName);
70 this.bandwidthValue = (long) bandwidth;
73 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() {
87 return HashCodeBuilder.reflectionHashCode(this);
91 public boolean equals(Object obj) {
92 return EqualsBuilder.reflectionEquals(this, obj);
96 public String toString() {
97 StringBuffer sb = new StringBuffer();
99 sb.append("BandWidth[");
100 if (this.bandwidthValue == 0) {
101 sb.append("UnKnown");
102 } else if (this.bandwidthValue < BW1Kbps) {
103 sb.append(this.bandwidthValue + "bps");
104 } else if (this.bandwidthValue < BW1Mbps) {
105 sb.append(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
106 } else if (this.bandwidthValue < BW1Gbps) {
107 sb.append(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
108 } else if (this.bandwidthValue < BW1Tbps) {
109 sb.append(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
110 } else if (this.bandwidthValue < BW1Pbps) {
111 sb.append(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
115 return sb.toString();