-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrun.h
382 lines (348 loc) · 15.3 KB
/
mrun.h
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Jinhui Song<[email protected]>
*/
#ifndef MRUN_H
#define MRUN_H
// #include "ns3/mbox.h"
#include "ns3/mbox-module.h"
using namespace std;
using namespace ns3;
namespace ns3 {
// NS_LOG_COMPONENT_DEFINE ("RunningModule");
/**
* Capability Helper at receiver side, which can help get the tag No. from UDP packet, set ack No.
* for capability (of UDP), set the app for sending back ack and send ack back on RX. Members include
* RX net device (for tracing), flow ID (node No.), ack socket, ack sending app.
*/
class CapabilityHelper
{
public:
CapabilityHelper() = default;
CapabilityHelper(uint32_t flow_id, Ptr<Node> node, Ptr<NetDevice> device, Address addr);// given flow ID and net device, initialize the socket and app for sending ACK
// CapabilityHelper(const CapabilityHelper &);
// CapabilityHelper & operator = (const CapabilityHelper);
// ~CapabilityHelper(); // need to form a vector
vector<int> GetNumFromTag(Ptr<const Packet> p); // given packet, extract the flow id and seq No.
void SendAck(Ptr<const Packet> p); // given Ack No. send back one ACK
void install(uint32_t flow_id, Ptr<Node> node, Ptr<NetDevice> device, Address addr); // similar to ctor, set the tracing for on RX and set the app
uint32_t getFlowId();
vector<uint32_t> getCurAck(); // use the MyApp's value
private:
uint32_t flow_id;
uint32_t curAckNo;
Ptr<PointToPointNetDevice> device;
Ptr<MyApp> ackApp;
};
// should first set before building the topology
class Group
{
public:
Group() = default;
Group(vector<uint32_t> rtid, map<uint32_t, string> tx2rate1, map<uint32_t, ProtocolType> tx2prot1, vector<uint32_t> rxId1, map<string, uint32_t> rate2port1, vector<double> w = vector<double>()):
routerId(rtid), tx2rate(tx2rate1), tx2prot(tx2prot1), rxId(rxId1), rate2port(rate2port1)
{
// some direct visit exist? no at least from stackoverflow
// need unit testing!
for(pair<uint32_t, string> pid:tx2rate)
{
// txId and rates vector construction
if(find(txId.begin(), txId.end(), pid.first) == txId.end())
txId.push_back(pid.first);
if(find(rates.begin(), rates.end(), pid.second) == rates.end()) // need testing
rates.push_back(pid.second);
// rate 2 tx map initialization
if(rate2tx.find(pid.second) == rate2tx.end())
rate2tx[pid.second] = vector<uint32_t>();
rate2tx[pid.second].push_back(pid.first);
}
N = txId.size() + rxId.size() + 2;
if(w.size() > 0) weight = w;
else weight = vector<double> (txId.size(), 1.0 / (double)txId.size());
for(pair<string, uint32_t> pid:rate2port)
{
if(find(ports.begin(), ports.end(), pid.second) == ports.end())
ports.push_back(pid.second);
}
/* Print path vector to console */
cout << "TX ID: ";
copy(txId.begin(), txId.end(), ostream_iterator<uint32_t>(cout, " "));
cout << "\nrates vector: ";
copy(rates.begin(), rates.end(), ostream_iterator<string>(cout, " "));
cout << "\nports: ";
copy(ports.begin(), ports.end(), ostream_iterator<uint32_t>(cout, " "));
cout << "\nprotocols: ";
for (auto tp:tx2prot) cout << tp.first << ": " << (tp.second == TCP? "TCP":"UDP") << ", ";
cout << "\nN: " << N << endl << endl;
}
Group(const Group &) = default;
~Group() {}
void insertLink(uint32_t tx, uint32_t rx)
{
tx2rx.insert(pair<uint32_t, uint32_t>(tx, rx));
}
/* links: txs[i] -> rxs[i] */
void insertLink(vector<uint32_t> txs, vector<uint32_t> rxs)
{
for(uint32_t i = 0; i < txs.size(); i ++)
insertLink(txs.at(i), rxs.at(i));
}
public:
uint32_t N; // number of all nodes including router
// vector<uint32_t> nodeId; // collection of all nodes with the same mbox (except routers), seems not needed now??
vector<uint32_t> routerId; // router ID, [tx router, rx router]
vector<uint32_t> txId;
vector<uint32_t> rxId;
vector<string> rates; // collection all rate in this group
vector<uint32_t> ports;
multimap <uint32_t, uint32_t> tx2rx; // tx-rx node map: m-in-n-out map, test m!=n in later version
map <string, vector<uint32_t>> rate2tx; // sort each node by its data rate (like client, attacker before)
map <uint32_t, string> tx2rate; // tx node to rate
map <uint32_t, ProtocolType> tx2prot; // tx node to transport protocol
map <string, uint32_t> rate2port; // port for every rate level (abstract for client and attacker)
vector <double> weight; // weight for each sender (current version)
};
class RunningModule
{
public:
/**
* \brief Initialize the running module, including setting start and stop time, the
* bottleneck link, the data rates and the topology. Currently should use dumpbell to
* realize the symmetric topology.
*
* \param t Vector containing start and stop time.
* \param grp Vector containing node group which specifies their rates and mboxes.
* \param pt Protocal type, TCP or UDP.
* \param delay Bottleneck link delay.
* \param rate Vector of different level of data rate, e.g. {1kbps, 10kbps, 1Mbps}
* for three groups.
* \param size Packet size, 1000 B by default.
*/
RunningModule(vector<double> t, vector<Group> grp, ProtocolType pt, vector<string> bnBw, vector<string> bnDelay, string delay, vector<bool> fls = {false, true}, uint32_t size = 1000);
~RunningModule ();
/**
* \brief Build the network topology from link (p2p) to network layer (stack). p2p link
* attributes should be carefully set (not including queue setting and IP assignment).
* Note the routerId of Group should be completed.
*
* \param grp Vector including node group with rate level.
*/
void buildTopology(vector<Group> grp);
/**
* \brief Configure all the network entities after finishing building the topology. The process
* is: queue, ip assignment (in setQueue), sink app and sender app setting, mbox installation, start
* and stop the module. Note that all the argument of configure take effect.
*
* \param stopTime Relative stop time of this run.
* \param pt Transport Protocol.
* \param bw Vector of the bottleneck links.
* \param delay Delay of the links. (to be determined)
* \param Th In format [MinTh, MaxTh].
*/
void configure(double stopTime, ProtocolType pt, vector<string> bw, vector<string> delay, vector<MiddlePoliceBox>& mboxes, vector<double> Th=vector<double>());
/**
* \brief Set queue (RED by default, may need other function for other queue) and return
* a queue disc container for tracing the packet drop by RED queue. Later assign Ipv4
* addresses for all p2p net devices.
*
* \param grp Vector including node group with rate level.
* \param Th In format [MinTh, MaxTh], if empty, then use ns-3 default.
* \param bw Bottleneck Link bandwidth collection.
* \param delay Bottleneck link delay.
*
* \returns A queue disc container on router that we are interested in.
*/
QueueDiscContainer setQueue(vector<Group> grp, vector<string> bw, vector<string> delay, vector<double> Th=vector<double>());
/**
* \brief Set prio queue (2 RED), one for priviledged. No use now.
*
* \param grp Vector including node group with rate level.
* \param Th In format [MinTh, MaxTh], if empty, then use ns-3 default.
* \param bw Bottleneck Link bandwidth collection.
* \param delay Bottleneck link delay.
*
* \returns A queue disc container on router that we are interested in.
*/
// QueueDiscContainer setPrioQueue(vector<Group> grp, vector<string> bw, vector<string> delay, vector<double> Th=vector<double>());
/**
* \brief Set the address for sender, receiver and router.
*
* \returns A ipv4 internet container for later specifying destination's address.
*/
Ipv4InterfaceContainer setAddress();
/**
* \brief Set the sink application (fetch protocol from member)
*
* \param Node group with rate level (containing port for different rate).
*
* \returns An application container for all sink apps.
*/
ApplicationContainer setSink(vector<Group> grp, ProtocolType pt);
/**
* \brief Set the capability helper at the receiver side.
*
* \param Node group with rate level (containing port for different rate).
*
* \returns A vector of all capability helpers.
*/
vector< CapabilityHelper > setCapabilityHelper(vector<Group> grp);
/**
* \brief Set the sender application (may set from outside)
*
* \param Node group with rate level (containing port for different rate).
* \param pt Protocol type, TCP or UDP;
*
* \returns A collection of all the pointer of MyApp.
*/
vector< Ptr<MyApp> > setSender(vector<Group> grp, ProtocolType pt);
/**
* \brief Set one single network flow from sender to sink. Basically called by setSender.
* Note rate and port are already specified in member groups.
*
* \param i Group id.
* \param tId Tx id in the group of the flow.
* \param rId Rx id in the group of the flow.
* \param tag Tag value attached to this flow.
*
* \returns A pointer to this application.
*/
Ptr<MyApp> netFlow(uint32_t i, uint32_t tId, uint32_t rId, uint32_t tag);
/**
* \brief Connect to the installed mboxes and begin tracing.
*
* \param grp Node group with rate level.
* \param interval Interval of mbox's detection.
* \param logInterval Interval of mbox's logging for e.g. data rate, llr, slr.
* \param ruInterval Interval for real time tx & Ebrc rate update.
*/
void connectMbox(vector<Group> grp, double interval, double logInterval, double ruInterval);
/**
* \brief Stop the installed mboxes and disconnect the tracing.
*
* \param grp Node group with rate level.
*/
void disconnectMbox(vector<Group> grp);
/**
* \brief Pause the mbox, i.e. stop control (early drop) but continue detecting packets.
*
* \param grp Node group with rate level.
*/
void pauseMbox(vector<Group> grp);
/**
* \brief Resume the mbox, i.e. continue to both detect and drop the packets.
*
* \param grp Node group with rate level.
*/
void resumeMbox(vector<Group> grp);
/**
* \brief Start all the application from Now() and also start the mbox detection by tracing.
*/
void start();
/**
* \brief Stop all the application from Now() and also stop the mbox detection by disconnecting
* tracing.
*/
void stop();
/**
* \brief Create node given group and id.
*
* \param i The index of group in groups.
* \param id Node id in group g.
* \return Index of nodes.
*/
uint32_t SetNode(uint32_t i, uint32_t id);
/**
* \brief Create node given group and n (inside group No. ).
*
* \param type The type of node: sender/receiver/router: 0/1.
* \param i The index of group in groups.
* \param n The inside group No.
* \return Index of nodes.
*/
uint32_t SetNode(uint32_t type, uint32_t i, uint32_t n);
/**
* \brief Set the pointer of router into node.
*
* \param
*/
uint32_t SetRouter(Ptr<Node> pt, uint32_t i, uint32_t id);
/**
* \brief Get node from group and id. Should be exactly inverse of SetNode();
*
* \param i The index of group in groups.
* \param id Node id in group g.
*/
Ptr<Node> GetNode(uint32_t i, uint32_t id);
/**
* \brief Get ipv4 address for socket destination setting.
*
* \param i The index of group in groups.
* \param k The No. of the device installed on that node (maybe larger than 0).
* \param id Node id in group g.
*/
Ipv4Address GetIpv4Addr(uint32_t i, uint32_t id, uint32_t k = 0);
void txSink(Ptr<const Packet> p); // !< for test and debug
void onCwndChange(string context, uint32_t oldValue, uint32_t newValue);
uint32_t GetId();
// static void onCwndChangeWo(uint32_t oldValue, uint32_t newValue);
public: // network entity
NodeContainer nodes; // all nodes in the topology
NodeContainer routers;
NetDeviceContainer txDevice;
NetDeviceContainer rxDevice;
NetDeviceContainer txRouterDevice;
NetDeviceContainer rxRouterDevice;
NetDeviceContainer routerDevice;
map< uint32_t, uint32_t > id2nodeIndex; // mapping from node ID (tx/rx/rt ID) to the index in NodeContainer
QueueDiscContainer qc; // queue container for trace
Ipv4InterfaceContainer ifc; // ipv4 interface container for flow destination specification
map< pair<uint32_t,uint32_t>, uint32_t > id2ipv4Index; // mapping from node ID and device No. to index of ipv4 container
map<Ipv4Address, ProtocolType> ip2prot;
ApplicationContainer sinkApp; // sink app
vector< CapabilityHelper > chelpers; // capability helpers on RX nodes
vector< Ptr<MyApp> > senderApp; // sender app: need testing!
vector<PointToPointDumbbellHelper> dv; // use to preserve channel information
vector<MiddlePoliceBox> mboxes; // use to make the mboxes consistent
PointToPointHelper bottleneck;
private: // parameters
// basic
uint32_t ID;
uint32_t nSender;
uint32_t nReceiver;
vector<Group> groups; // group node by different mbox: need testing such vector declaration
uint32_t pktSize; // 1000 kB
uint32_t u; // unit size of group leaves
double rtStart; // start time of this run (the initial one)
double rtStop; // stop time of this run
vector<double> txStart; // start time of TX flows
vector<double> txEnd; // end time of Tx flows
ProtocolType protocol;
// queue
string qType = "RED"; // specified for queue disc
double minTh = 100;
double maxTh = 200;
// link related
string normalBw = "1Gbps";
vector<string> bottleneckBw = vector<string>();
vector<string> bottleneckDelay = vector<string>();
string delay;
string mtu = "1599"; // p2p link setting
bool isTrackPkt;
bool bypassMacRx;
vector<string> fnames;
};
}
#endif