1
- #ifndef LOAD_BALANCER_HH // NOLINT
2
- #define LOAD_BALANCER_HH // NOLINT
1
+ /*
2
+ * Copyright (C) 2025 TU Dresden
3
+ * All rights reserved.
4
+ *
5
+ * Authors:
6
+ * Tassilo Tanneberger
7
+ */
3
8
4
- #include < reactor-cpp/reactor-cpp.hh>
9
+ #ifndef MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT
10
+ #define MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT
5
11
6
- #include " reactor-cpp/mutations/multiport.hh"
12
+ #include < reactor-cpp/mutations/multiport.hh>
13
+ #include < reactor-cpp/reactor-cpp.hh>
7
14
8
15
using namespace reactor ;
9
16
using namespace std ::chrono_literals;
@@ -19,24 +26,21 @@ class LoadBalancer final : public Reactor { // NOLINT
19
26
if (std::rand () % 15 == 0 ) { // NOLINT
20
27
scale_bank.set (std::rand () % 20 + 1 ); // NOLINT
21
28
}
22
- const unsigned sel = std::rand () % outbound.size (); // NOLINT
23
- // std::cout << "Sending out to:" << sel << '\n';
24
- outbound[sel].set (inbound.get ());
25
- outbound[std::min (4ul , outbound.size () - 1 )].set (inbound.get ());
29
+ const unsigned outbound_port = std::rand () % outbound.size (); // NOLINT
30
+ outbound[outbound_port].set (inbound.get ());
26
31
}
27
32
28
33
friend LoadBalancer;
29
34
};
30
35
31
36
Inner _lf_inner;
32
- Reaction process{" process" , 2 , this , [this ]() { Inner::reaction_1 (this ->inbound , this ->scale_bank , this ->out ); }};
37
+ Reaction process{" process" , 1 , this , [this ]() { Inner::reaction_1 (this ->inbound , this ->scale_bank , this ->out ); }};
33
38
34
39
public:
35
40
LoadBalancer (const std::string& name, Environment* env)
36
41
: Reactor(name, env)
37
42
, _lf_inner(this ) {
38
43
out.reserve (4 );
39
- std::cout << " creating instance of load balancer" << ' \n ' ;
40
44
for (size_t _lf_idx = 0 ; _lf_idx < 4 ; _lf_idx++) {
41
45
out.create_new_port ();
42
46
}
@@ -45,16 +49,16 @@ public:
45
49
46
50
ModifableMultiport<Output<unsigned >> out{" out" , this }; // NOLINT
47
51
std::size_t out_size_ = 0 ;
52
+
48
53
Input<unsigned > inbound{" inbound" , this }; // NOLINT
49
54
Output<unsigned > scale_bank{" scale_bank" , this }; // NOLINT
50
55
51
56
void assemble () override {
52
- std::cout << " assemble LoadBalancer\n " ;
53
57
for (auto & _lf_port : out) {
54
58
process.declare_antidependency (&_lf_port);
55
59
}
56
60
process.declare_trigger (&inbound);
57
61
}
58
62
};
59
63
60
- #endif // LOAD_BALANCER_HH
64
+ #endif // MULTIPORT_MUTATION_LOAD_BALANCER_HH
0 commit comments