-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathshortflows.cpp
More file actions
executable file
·74 lines (56 loc) · 2.08 KB
/
Copy pathshortflows.cpp
File metadata and controls
executable file
·74 lines (56 loc) · 2.08 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
#include "shortflows.h"
#include <iostream>
string ntoa(double n);
ShortFlows::ShortFlows(double lambda, EventList& eventlist, vector<const Route*>*** n,
ConnectionMatrix* conns,Logfile* logfile,TcpRtxTimerScanner * rtx)
: EventSource(eventlist,"ShortFlows")
{
eventlist.sourceIsPendingRel(*this, timeFromMs(1000));
net_paths = n;
_traffic_matrix = conns->getAllConnections();
this->logfile = logfile;
this->_lambda = lambda;
tcpRtxScanner = rtx;
}
ShortFlow* ShortFlows::createConnection(int src, int dst, simtime_picosec starttime){
ShortFlow* f = new ShortFlow();
f->src = new TcpSrcTransfer(NULL,NULL,eventlist(),70000,net_paths[src][dst]);
f->snk = new TcpSinkTransfer();
int pos = connections[src][dst].size();
f->src->setName("sf_" + ntoa(src) + "_" + ntoa(dst)+"("+ntoa(pos)+")");
logfile->writeName(*(f->src));
f->snk->setName("sf_sink_" + ntoa(src) + "_" + ntoa(dst)+ "("+ntoa(pos)+")");
logfile->writeName(*(f->snk));
tcpRtxScanner->registerTcp(*(f->src));
int choice = rand()%net_paths[src][dst]->size();
Route* routeout = new Route(*(net_paths[src][dst]->at(choice)));
routeout->push_back(f->snk);
Route* routein = new Route();
routein->push_back(f->src);
f->src->connect(*routeout, *routein, *(f->snk), starttime);
return f;
}
void ShortFlows::doNextEvent() {
run();
simtime_picosec nextArrival = (simtime_picosec)(exponential(_lambda)*timeFromSec(1));
eventlist().sourceIsPendingRel(*this, nextArrival);
}
void ShortFlows::run(){
//randomly choose connection to activate.
int pos = rand()%_traffic_matrix->size();
//look for inactive connection
connection* c = _traffic_matrix->at(pos);
ShortFlow* f = NULL;
for (unsigned int i=0;i<connections[c->src][c->dst].size();i++){
f = connections[c->src][c->dst][i];
if (!f->src->_is_active)
break;
}
if (!f||f->src->_is_active){
f = createConnection(c->src,c->dst,eventlist().now());
connections[c->src][c->dst].push_back(f);
}
else {
f->src->reset(70000, true);
}
}