author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 02 Jul 2008 03:16:36 -0700 | |
changeset 3365 | 6409d2460601 |
parent 2834 | 1aab57845b07 |
child 4010 | 0aab87b46780 |
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 |
|
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
21 |
#include "data-rate.h" |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
22 |
#include "ns3/nstime.h" |
614
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
23 |
#include "ns3/fatal-error.h" |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
24 |
|
614
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
25 |
|
871
0451a0497ca3
fix gcov link
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
670
diff
changeset
|
26 |
static bool |
614
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
27 |
DoParse (const std::string s, uint64_t *v) |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
28 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
29 |
std::string::size_type n = s.find_first_not_of("0123456789."); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
30 |
if (n != std::string::npos) |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
31 |
{ // Found non-numeric |
3365
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
32 |
std::istringstream iss; |
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
33 |
iss.str (s.substr(0, n)); |
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
34 |
double r; |
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
35 |
iss >> r; |
614
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
36 |
std::string trailer = s.substr(n, std::string::npos); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
37 |
if (trailer == "bps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
38 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
39 |
// Bit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
40 |
*v = (uint64_t)r; |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
41 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
42 |
else if (trailer == "b/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
43 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
44 |
// Bit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
45 |
*v = (uint64_t)r; |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
46 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
47 |
else if (trailer == "Bps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
48 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
49 |
// Byte/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
50 |
*v = (uint64_t)(r * 8); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
51 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
52 |
else if (trailer == "B/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
53 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
54 |
// Byte/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
55 |
*v = (uint64_t)(r * 8); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
56 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
57 |
else if (trailer == "kbps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
58 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
59 |
// KiloBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
60 |
*v = (uint64_t)(r * 1000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
61 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
62 |
else if (trailer == "kb/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
63 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
64 |
// KiloBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
65 |
*v = (uint64_t)(r * 1000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
66 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
67 |
else if (trailer == "kBps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
68 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
69 |
// KiloBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
70 |
*v = (uint64_t)(r * 1000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
71 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
72 |
else if (trailer == "kB/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
73 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
74 |
// KiloBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
75 |
*v = (uint64_t)(r * 1000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
76 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
77 |
else if (trailer == "Mbps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
78 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
79 |
// MegaBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
80 |
*v = (uint64_t)(r * 1000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
81 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
82 |
else if (trailer == "Mb/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
83 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
84 |
// MegaBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
85 |
*v = (uint64_t)(r * 1000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
86 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
87 |
else if (trailer == "MBps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
88 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
89 |
// MegaByte/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
90 |
*v = (uint64_t)(r * 8000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
91 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
92 |
else if (trailer == "MB/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
93 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
94 |
// MegaByte/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
95 |
*v = (uint64_t)(r * 8000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
96 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
97 |
else if (trailer == "Gbps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
98 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
99 |
// GigaBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
100 |
*v = (uint64_t)(r * 1000000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
101 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
102 |
else if (trailer == "Gb/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
103 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
104 |
// GigaBit/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
105 |
*v = (uint64_t)(r * 1000000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
106 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
107 |
else if (trailer == "GBps") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
108 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
109 |
// GigaByte/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
110 |
*v = (uint64_t)(r * 8*1000000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
111 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
112 |
else if (trailer == "GB/s") |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
113 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
114 |
// GigaByte/s |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
115 |
*v = (uint64_t)(r * 8*1000000000); |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
116 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
117 |
else |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
118 |
{ |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
119 |
return false; |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
120 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
121 |
return true; |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
122 |
} |
3365
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
123 |
std::istringstream iss; |
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
124 |
iss.str (s); |
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
125 |
iss >> *v; |
614
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
126 |
return true; |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
127 |
} |
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
128 |
|
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
129 |
|
fb21d7015386
add DefaultValue support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
373
diff
changeset
|
130 |
namespace ns3 { |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
131 |
|
2582
3e28107b870f
rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2558
diff
changeset
|
132 |
ATTRIBUTE_HELPER_CPP (DataRate); |
2422 | 133 |
|
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
134 |
DataRate::DataRate () |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
135 |
: m_bps (0) |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
136 |
{} |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
137 |
|
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
138 |
DataRate::DataRate(uint64_t bps) |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
139 |
:m_bps(bps) |
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
140 |
{} |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
141 |
|
1825
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
142 |
bool DataRate::operator < (const DataRate& rhs) const |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
143 |
{ |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
144 |
return m_bps<rhs.m_bps; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
145 |
} |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
146 |
|
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
147 |
bool DataRate::operator <= (const DataRate& rhs) const |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
148 |
{ |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
149 |
return m_bps<=rhs.m_bps; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
150 |
} |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
151 |
|
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
152 |
bool DataRate::operator > (const DataRate& rhs) const |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
153 |
{ |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
154 |
return m_bps>rhs.m_bps; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
155 |
} |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
156 |
|
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
157 |
bool DataRate::operator >= (const DataRate& rhs) const |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
158 |
{ |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
159 |
return m_bps>=rhs.m_bps; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
160 |
} |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
161 |
|
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
162 |
bool DataRate::operator == (const DataRate& rhs) const |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
163 |
{ |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
164 |
return m_bps==rhs.m_bps; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
165 |
} |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
166 |
|
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
167 |
bool DataRate::operator != (const DataRate& rhs) const |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
168 |
{ |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
169 |
return m_bps!=rhs.m_bps; |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
170 |
} |
1544b7c8aa18
minor fix for bug95; also const operators for DataRate
Tom Henderson <tomh@tomh.org>
parents:
871
diff
changeset
|
171 |
|
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
172 |
double DataRate::CalculateTxTime(uint32_t bytes) const |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
173 |
{ |
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
|
174 |
return static_cast<double>(bytes)*8/m_bps; |
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
175 |
} |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
176 |
|
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
177 |
uint64_t DataRate::GetBitRate() const |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
178 |
{ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
179 |
return m_bps; |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
180 |
} |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
181 |
|
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:
2422
diff
changeset
|
182 |
DataRate::DataRate (std::string rate) |
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
183 |
{ |
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:
2422
diff
changeset
|
184 |
bool ok = DoParse (rate, &m_bps); |
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
185 |
if (!ok) |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
186 |
{ |
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:
2422
diff
changeset
|
187 |
NS_FATAL_ERROR ("Could not parse rate: "<<rate); |
2415
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
188 |
} |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
189 |
} |
bbdf1d469f8f
replace ambiguous constructor with separate construction function.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2412
diff
changeset
|
190 |
|
2412
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
191 |
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
|
192 |
{ |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
193 |
os << rate.GetBitRate () << "bps"; |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
194 |
return os; |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
195 |
} |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
196 |
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
|
197 |
{ |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
198 |
std::string value; |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
199 |
is >> value; |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
200 |
uint64_t v; |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
201 |
bool ok = DoParse (value, &v); |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
202 |
if (!ok) |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
203 |
{ |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
204 |
is.setstate (std::ios_base::failbit); |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
205 |
} |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
206 |
rate = DataRate (v); |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
207 |
return is; |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
208 |
} |
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
209 |
|
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
210 |
|
d493ee1f9e9b
add Value support to DataRate
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1826
diff
changeset
|
211 |
|
365
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
212 |
double operator*(const DataRate& lhs, const Time& rhs) |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
213 |
{ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
214 |
return rhs.GetSeconds()*lhs.GetBitRate(); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
215 |
} |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
216 |
|
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
217 |
double operator*(const Time& lhs, const DataRate& rhs) |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
218 |
{ |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
219 |
return lhs.GetSeconds()*rhs.GetBitRate(); |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
220 |
} |
2a5cd7125778
Added in DataRate to common module
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
221 |
|
2558
e03d9fefa80b
kill DataRateDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
222 |
} //namespace ns3 |