f63a60d15529ace9b5e1350cfcef1ea43babf6ed
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / route / impl / src / main / java / com / highstreet / technologies / odl / app / impl / tools / BandwidthCalculator.java
1 /*
2  * Copyright © 2015 ZTE and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package com.highstreet.technologies.odl.app.impl.tools;
9
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import java.text.DecimalFormat;
14
15 import static com.google.common.math.DoubleMath.log2;
16
17 /**
18  * Created by odl on 17-6-8.
19  */
20 public class BandwidthCalculator
21 {
22     private static final Logger LOG = LoggerFactory.getLogger(BandwidthCalculator.class);
23
24     public BandwidthCalculator(Integer txChannelBandwidth, Short modulationCur, Byte codeRateCur)
25     {
26         LOG.info("bandwidth: " + txChannelBandwidth + " modulationCur: " + modulationCur + " codeRate: " + codeRateCur);
27         this.result = txChannelBandwidth * log2(modulationCur) * (0.8) / 1.15;
28     }
29
30     private static DecimalFormat df = new DecimalFormat("#.00");
31     private final double result;
32
33     public Double calc(Unit unit)
34     {
35         return Double.valueOf(df.format(unit.convert(result, Unit.k_bits_s)));
36     }
37
38     public Double calc()
39     {
40         return Double.valueOf(df.format(result));
41     }
42 }