-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpart2.cpp
More file actions
executable file
·201 lines (137 loc) · 5.07 KB
/
part2.cpp
File metadata and controls
executable file
·201 lines (137 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* author: abhishekvtangod
* created: 15.04.2020 18:16:46 IST
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
//Calculate bandwidth based on either nyquist or shannon,latency & throughput.
void bandwidth()
{
cout<<"Calculate Bandwidth for?\n1.Noiseless Channel(Nyquist Bit Rate)\n2.Noisy Channel(Shannon's Capacity')\n";
ll n;cin>>n;
if(n==1)
{
// Noiseless Channel: Nyquist Bit Rate
ll levels,bitrate;
cout<<"Enter the Bitrate of the Noiseless Channel in bps : ";
cin>>bitrate;
cout<<"Enter the number of signal levels in the signal that noiseless channel is transmitting : ";
cin>>levels;
// Bitrate = 2 * Bandwidth * log2(L)
// Bandwidth is Bandwidth of the channel
// BitRate is the bit rate in bits per second (Maximum Bitrate)
// L is the number of signal levels used to represent data
ll bw = (bitrate / ((float)2.0 * log2(levels)));
cout<<"--------------------------------------------------------------------------------\n";
cout<<"Bandwidth of Noiseless Channel : "<<bw<<" Hz\n";
cout<<"--------------------------------------------------------------------------------\n";
}
else if(n == 2)
{
//Noisy Channel: Shannon's Capacity
ll capacity,SNR;
cout<<"Enter the Capacity of the Noisy Channel in bps : ";
cin>>capacity;
cout<<"Enter the SNR (signal-to-noise ratio) value : ";
cin>>SNR;
//Capacity = Bandwidth * log2(1 + SNR);
//Bandwidth is the bandwidth of the channel(Hz)
//Capacity is the Capacity of the channel in bits per second
float bw = capacity/((float) log2(1+SNR));
cout<<"--------------------------------------------------------------------------------\n";
cout<<"Bandwidth of the noisy channel is : "<<bw<<" Hz"<<endl;
cout<<"--------------------------------------------------------------------------------\n";
}
else
{
cout<<"Error:Invalid Input\nOnly 1 and 2 are allowed\n";
return;
}
}
void latency()
{
//Defines how long it takes for an entire message to completely
//arrive at the destination from the time the first bit is sent out
//from the source
// Latency = propagation time + transmission time + queuing time + processing delay
//propagation time
ll dist,prop_speed=(2.4 * 1e8);
cout<<"What is the distance between source and destination in km?\n";
cin>>dist;
cout<<"What is the propagation speed in m/s? (2.4 * 10^8 m/s -> light speed)\n";
cin>>prop_speed;
//Propagation time = Distance / Propagation speed
float prop_time = ((dist * 1000)/((float) prop_speed));
cout<<"Propagation Time : "<<prop_time*1000.0<<" ms"<<endl;
//transmission time
float tr_time,msg_size;
ll bw;
cout<<"Enter the message size in kbyte : ";
cin>>msg_size;
cout<<"Enter the Bandwidth of the channel in Gbps: ";
cin>>bw;
//Transmission time = message / Bandwidth
tr_time = ((msg_size*1000*8)/((float)(bw * 1e9)));
cout<<"Transmission time : "<<(tr_time*1000.0)<<" ms\n";
//queuing time and processing delay
float q_time,prc_delay;
cout<<"Enter the Queuing time and processing delay of the network in ms :\n";
cin>>q_time>>prc_delay;
cout<<"--------------------------------------------------------------------------------\n";
cout<<"Queuing time : "<<q_time<<" ms\n";
cout<<"Processing delay : "<<prc_delay<<" ms\n";
cout<<"Transmission time : "<<(tr_time*1000.0)<<" ms\n";
cout<<"Propagation Time : "<<prop_time*1000.0<<" ms"<<endl;
cout<<"Latency = propagation time + transmission time + queuing time + processing delay\n";
cout<<"--------------------------------------------------------------------------------\n";
float latency = tr_time*1000.0 + prop_time*1000.0 + q_time + prc_delay;
cout<<"Latency = "<<latency<<" ms\n";
cout<<"--------------------------------------------------------------------------------\n";
}
void throughput()
{
//Measure of how fast we can actually send data through a network
cout<<"Enter the Bandwidth (in Mbps) of the network : ";
ll bw;cin>>bw;
cout<<"Enter the actual data that can be passed through this link, in frames per minute : ";
ll fpm;cin>>fpm;
cout<<"Enter average number of bits in each frame : ";
ll bits;cin>>bits;
float thpt = ((fpm*bits)/((float)60.0));
cout<<"--------------------------------------------------------------------------------\n";
cout<<"Actual Bandwidth of the network : "<<bw<<" Mbps"<<endl;
cout<<"Throughput : "<<(thpt/(float)1e6)<<" Mbps"<<endl;
cout<<"--------------------------------------------------------------------------------\n";
}
void solve()
{
while(1)
{
cout<<"Calculate:\n1.Bandwidth of the Channel\n2.Latency\n3.Throughput\n4.Exit\n";
cout<<"Enter : ";
ll q;cin>>q;
switch(q)
{
case 1: bandwidth();
break;
case 2: latency();
break;
case 3: throughput();
break;
default: cout<<"Exiting the program...\n";
return;
}
}
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
solve();
return 0;
}