Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / Bandwidth.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.sal.core;
11
12 import javax.xml.bind.annotation.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
14
15 import org.apache.commons.lang3.builder.EqualsBuilder;
16 import org.apache.commons.lang3.builder.HashCodeBuilder;
17
18 /**
19  * @file   BandWidth.java
20  *
21  * @brief  Class representing bandwidth
22  *
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
25  * seconds.
26  */
27 @XmlRootElement
28 public class Bandwidth extends Property {
29     private static final long serialVersionUID = 1L;
30
31     @XmlElement
32     protected long bandwidthValue;
33
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);
46
47     public static final String BandwidthPropName = "bandwidth";
48
49     /*
50      * Private constructor used for JAXB mapping
51      */
52     private Bandwidth() {
53         super(BandwidthPropName);
54         this.bandwidthValue = BWUNK;
55         ;
56     }
57
58     public Bandwidth(long bandwidth) {
59         super(BandwidthPropName);
60         this.bandwidthValue = bandwidth;
61     }
62
63     public Bandwidth(int bandwidth) {
64         super(BandwidthPropName);
65         this.bandwidthValue = (long) bandwidth;
66     }
67
68     public Bandwidth(short bandwidth) {
69         super(BandwidthPropName);
70         this.bandwidthValue = (long) bandwidth;
71     }
72     
73     public Bandwidth(String name) {
74         super(name);
75     }
76
77     public Bandwidth clone() {
78         return new Bandwidth(this.bandwidthValue);
79     }
80
81     public long getValue() {
82         return this.bandwidthValue;
83     }
84
85     @Override
86     public int hashCode() {
87         return HashCodeBuilder.reflectionHashCode(this);
88     }
89
90     @Override
91     public boolean equals(Object obj) {
92         return EqualsBuilder.reflectionEquals(this, obj);
93     }
94
95     @Override
96     public String toString() {
97         StringBuffer sb = new StringBuffer();
98
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");
112         }
113
114         sb.append("]");
115         return sb.toString();
116     }
117 }