BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[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.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
16
17 /**
18  * @file   BandWidth.java
19  *
20  * @brief  Class representing bandwidth
21  *
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
24  * seconds.
25  */
26 @XmlRootElement
27 @XmlAccessorType(XmlAccessType.NONE)
28 public class Bandwidth extends Property {
29     private static final long serialVersionUID = 1L;
30
31     @XmlElement(name="value")
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     public Bandwidth(long bandwidth) {
58         super(BandwidthPropName);
59         this.bandwidthValue = bandwidth;
60     }
61
62     public Bandwidth(int bandwidth) {
63         super(BandwidthPropName);
64         this.bandwidthValue = (long) bandwidth;
65     }
66
67     public Bandwidth(short bandwidth) {
68         super(BandwidthPropName);
69         this.bandwidthValue = (long) bandwidth;
70     }
71
72     public Bandwidth(String name) {
73         super(name);
74     }
75
76     @Override
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         final int prime = 31;
88         int result = super.hashCode();
89         result = prime * result
90                 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
91         return result;
92     }
93
94     @Override
95     public boolean equals(Object obj) {
96         if (this == obj)
97             return true;
98         if (!super.equals(obj))
99             return false;
100         if (getClass() != obj.getClass())
101             return false;
102         Bandwidth other = (Bandwidth) obj;
103         if (bandwidthValue != other.bandwidthValue)
104             return false;
105         return true;
106     }
107
108     @Override
109     public String toString() {
110         return "BandWidth[" + getStringValue() + "]";
111     }
112
113     @Override
114     public String getStringValue() {
115         if (this.bandwidthValue == 0) {
116             return("UnKnown");
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");
127         } else {
128             return(this.bandwidthValue + "bps");
129         }
130     }
131 }