-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.cc
78 lines (65 loc) · 1.52 KB
/
client.cc
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
#include "client.hpp"
#include "simulation.hpp"
#include "stats.hpp"
#include "traffic.hpp"
#include "utils_netgen.hpp"
#include "utils.hpp"
#include <boost/property_map/property_map.hpp>
#include <map>
#include <utility>
using namespace std;
client::client(double mht, double mnsc, traffic &tra):
mht(mht), htd(1 / mht), htg(m_rng, htd),
mnsc(mnsc), nscd(mnsc - 1), nscdg(m_rng, nscd),
conn(m_mdl), st(stats::get()), tra(tra)
{
// Try to setup the connection.
if (set_up())
{
// Register the client with the traffic.
tra.insert(this);
// Holding time.
double ht = htg();
// Tear down time.
tdt = now() + ht;
schedule(tdt);
}
else
// We didn't manage to establish the connection, and so the client
// should be deleted.
tra.delete_me_later(this);
}
void client::operator()(double t)
{
destroy();
}
bool client::set_up()
{
// The new demand.
demand d;
// The demand end nodes.
d.first = random_node_pair(m_mdl, m_rng);
// The number of slices the signal requires. It's Poisson + 1.
d.second = nscdg() + 1;
// Set up the connection.
bool status = conn.establish(d);
// Report whether the connection was established or not.
st.established(status);
// If established, report the connection.
if (status)
st.established_conn(conn);
return status;
}
const connection &
client::get_connection() const
{
return conn;
}
void
client::destroy()
{
assert(conn.is_established());
conn.tear_down();
tra.erase(this);
tra.delete_me_later(this);
}