author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 26 May 2008 20:44:19 -0700 | |
changeset 3093 | 117f02923a7e |
parent 2969 | 9d05d2a95dfa |
child 3094 | 6e787ec9c8aa |
permissions | -rw-r--r-- |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
2 |
// |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
3 |
// Copyright (c) 2006 Georgia Tech Research Corporation |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
4 |
// |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
5 |
// This program is free software; you can redistribute it and/or modify |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
6 |
// it under the terms of the GNU General Public License version 2 as |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
7 |
// published by the Free Software Foundation; |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
8 |
// |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
9 |
// This program is distributed in the hope that it will be useful, |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
12 |
// GNU General Public License for more details. |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
13 |
// |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
14 |
// You should have received a copy of the GNU General Public License |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
15 |
// along with this program; if not, write to the Free Software |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
16 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
17 |
// |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
18 |
// Author: Rajib Bhattacharjea<raj.b@gatech.edu> |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
19 |
// |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
20 |
|
373
960c8e8721de
Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards
Tom Henderson <tomh@tomh.org>
parents:
365
diff
changeset
|
21 |
#ifndef DATA_RATE_H |
960c8e8721de
Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards
Tom Henderson <tomh@tomh.org>
parents:
365
diff
changeset
|
22 |
#define DATA_RATE_H |
960c8e8721de
Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards
Tom Henderson <tomh@tomh.org>
parents:
365
diff
changeset
|
23 |
|
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
24 |
#include <string> |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
25 |
#include <iostream> |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
26 |
#include <stdint.h> |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
27 |
#include "ns3/nstime.h" |
2438
e2ac9f9aeeb9
value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2422
diff
changeset
|
28 |
#include "ns3/attribute.h" |
2451
8979f07befd5
value-helper.h -> attribute-helper.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2438
diff
changeset
|
29 |
#include "ns3/attribute-helper.h" |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
30 |
|
614
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
31 |
namespace ns3 { |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
32 |
|
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
33 |
/** |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
34 |
* \brief Class for representing data rates |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
35 |
* |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
36 |
* Allows for natural and familiar use of data rates. Allows construction |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
37 |
* from strings, natural multiplication e.g.: |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
38 |
* \code |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
39 |
* DataRate x("56kbps"); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
40 |
* double nBits = x*ns3::Seconds(19.2); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
41 |
* uint32_t nBytes = 20; |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
42 |
* double txtime = x.CalclulateTxTime(nBytes); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
43 |
* \endcode |
670
ff520b9cb8ec
Added comparison operators for DataRate
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
624
diff
changeset
|
44 |
* This class also supports the regular comparison operators <, >, <=, >=, ==, |
ff520b9cb8ec
Added comparison operators for DataRate
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
624
diff
changeset
|
45 |
* and != |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
46 |
*/ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
47 |
class DataRate |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
48 |
{ |
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
49 |
public: |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
50 |
DataRate (); |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
51 |
/** |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
52 |
* \brief Integer constructor |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
53 |
* |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
54 |
* Construct a data rate from an integer. This class only supports positive |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
55 |
* integer data rates in units of bits/s, meaning 1bit/s is the smallest |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
56 |
* non-trivial bitrate availiable. |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
57 |
*/ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
58 |
DataRate (uint64_t bps); |
2502
50d0da37f02f
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2451
diff
changeset
|
59 |
DataRate (std::string rate); |
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
60 |
|
1825
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
670
diff
changeset
|
61 |
bool operator < (const DataRate& rhs) const; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
670
diff
changeset
|
62 |
bool operator <= (const DataRate& rhs) const; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
670
diff
changeset
|
63 |
bool operator > (const DataRate& rhs) const; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
670
diff
changeset
|
64 |
bool operator >= (const DataRate& rhs) const; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
670
diff
changeset
|
65 |
bool operator == (const DataRate& rhs) const; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
670
diff
changeset
|
66 |
bool operator != (const DataRate& rhs) const; |
670
ff520b9cb8ec
Added comparison operators for DataRate
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
624
diff
changeset
|
67 |
|
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
68 |
/** |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
69 |
* \brief Calculate transmission time |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
70 |
* |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
71 |
* Calculates the transmission time at this data rate |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
72 |
* \param bytes The number of bytes (not bits) for which to calculate |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
73 |
* \return The tranmission time in seconds for the number of bytes specified |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
74 |
*/ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
75 |
double CalculateTxTime(uint32_t bytes) const; |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
76 |
|
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
77 |
/** |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
78 |
* Get the underlying bitrate |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
79 |
* \return The underlying bitrate in bits per second |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
80 |
*/ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
81 |
uint64_t GetBitRate() const; |
2422 | 82 |
|
2412
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
83 |
private: |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
84 |
uint64_t m_bps; |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
85 |
static uint64_t Parse(const std::string); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
86 |
}; |
2412
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
87 |
|
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
88 |
std::ostream &operator << (std::ostream &os, const DataRate &rate); |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
89 |
std::istream &operator >> (std::istream &is, DataRate &rate); |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
90 |
|
2969
9d05d2a95dfa
improve the auto-generated doxygen output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
91 |
/** |
9d05d2a95dfa
improve the auto-generated doxygen output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
92 |
* \class ns3::DataRateValue |
9d05d2a95dfa
improve the auto-generated doxygen output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
93 |
* \brief hold objects of type ns3::DataRate |
9d05d2a95dfa
improve the auto-generated doxygen output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
94 |
*/ |
9d05d2a95dfa
improve the auto-generated doxygen output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
95 |
|
2582
3e28107b870f
rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2558
diff
changeset
|
96 |
ATTRIBUTE_HELPER_HEADER_2 (DataRate); |
2412
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
97 |
|
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
98 |
/** |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
99 |
* \param lhs |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
100 |
* \param rhs |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
101 |
* \return Bits transmitted in rhs seconds at lhs b/s |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
102 |
*/ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
103 |
double operator*(const DataRate& lhs, const TimeUnit<1>& rhs); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
104 |
double operator*(const TimeUnit<1>& lhs, const DataRate& rhs); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
105 |
|
2412
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
106 |
} //namespace ns3 |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
107 |
|
373
960c8e8721de
Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards
Tom Henderson <tomh@tomh.org>
parents:
365
diff
changeset
|
108 |
#endif /* DATA_RATE_H */ |