SOLA
Loading...
Searching...
No Matches
minhton_manager_scheduler.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_MINHTON_NS3_MINHTON_MANAGER_SCHEDULER_H_
18#define DAISI_MINHTON_NS3_MINHTON_MANAGER_SCHEDULER_H_
19
20#include "minhton/algorithms/esearch/boolean_expression.h"
21#include "minhton/algorithms/esearch/node_data.h"
22#include "minhton_manager.h"
23#include "ns3/random-variable-stream.h"
24#include "utils/distribution.h"
25
26namespace daisi::minhton_ns3 {
27
29public:
30 explicit Scheduler(MinhtonManager &manager);
31 void schedule();
32
33private:
34 MinhtonManager &manager_; // ref to parent class
35
36 void setupIndexQueues();
37 void setupRequestingNodes();
38 void setupRootBehavior();
39
40 void executeOneJoinByPosition(uint32_t level, uint32_t number);
41 void executeOneJoinByIndex(uint16_t index);
42 void executeOneJoinOnRoot();
43 void executeOneRandomJoin();
44 void executeOneJoinDiscover();
45
46 void executeOneLeaveByPosition(uint32_t level, uint32_t number);
47 void executeOneLeaveByIndex(uint16_t index);
48 void executeOneLeaveOnRoot();
49 void executeOneRandomLeave();
50
51 void executeOneFailByPosition(uint32_t level, uint32_t number);
52 void executeOneFailByIndex(uint16_t index);
53 void executeOneRandomFail();
54
55 void initiateJoinNow(uint32_t node_to_join_to_index, uint32_t entering_node_index);
56 void initiateJoinNowDiscover(uint32_t entering_node_index);
57 void initiateLeaveNow(uint64_t node_to_leave_to_index);
58 void initiateFailureNow(uint64_t node_to_fail_to_index);
59
60 void scheduleSearchExactAll(ns3::Time delay);
61 void scheduleSearchExactMany(ns3::Time delay, uint32_t number);
62 void executeOneSearchExact(ns3::Ptr<MinhtonApplication> src_app, uint32_t dest_level,
63 uint32_t dest_number);
64 void executeOneRandomSearchExact();
65 void executeFindQuery(minhton::FindQuery query);
66 void executeStaticNetworkBuild(uint32_t number);
67
68 void scheduleMixedExecution(uint64_t join_num, uint64_t leave_num, uint64_t search_num,
69 ns3::Time current_time, ns3::Time delay);
70 void scheduleValidateLeave(ns3::Time delay);
71
72 uint64_t getRootIndex();
73 std::vector<uint64_t> getInitializedNodeIndexes();
74 std::tuple<std::vector<uint64_t>, std::vector<std::tuple<uint16_t, uint16_t>>>
75 getExistingPositions();
76 ns3::Ptr<MinhtonApplication> getApplicationAtPosition(uint32_t level, uint32_t number);
77
78 std::deque<uint64_t> uninit_index_deque_;
79 std::deque<uint64_t> init_index_deque_;
80 uint64_t latest_root_index_ = 0;
81
82 // parsing
83 void schedule(JoinOne step, ns3::Time &current_time);
84 void schedule(JoinMany step, ns3::Time &current_time);
85 void schedule(LeaveOne step, ns3::Time &current_time);
86 void schedule(LeaveMany step, ns3::Time &current_time);
87 void schedule(SearchMany step, ns3::Time &current_time);
88 void schedule(SearchAll step, ns3::Time &current_time);
89 void schedule(FailOne step, ns3::Time &current_time);
90 void schedule(FailMany step, ns3::Time &current_time);
91 void schedule(MixedExecution step, ns3::Time &current_time);
92 void schedule(ValidateLeave step, ns3::Time &current_time);
93 void schedule(FindQuery step, ns3::Time &current_time);
94 void schedule(RequestCountdown step, ns3::Time &current_time);
95 void schedule(Time step, ns3::Time &current_time);
96 void schedule(StaticBuild step, ns3::Time &current_time);
97
98 void parseNodeAttributes();
99 void setRequestNodeSetup(RandomNode random);
100 void setRequestNodeSetup(Absolute absolute);
101 void setRequestFrequencySetup(Gaussian gaussian);
102 void setRequestFrequencySetup(StaticTime static_time);
103 void setRequestDepthSetup(Uniform uniform);
104 void setRequestDepthSetup(Static static_val);
105 void setRequestValiditySetup(ConstantTime threshold);
106
107 // peer discovery environment
108
109 struct NodeAttribute {
110 std::string name;
111
112 minhton::NodeData::ValueType value_type;
113
114 float presence_percentage;
115
116 // delay in milliseconds
117 Dist<uint64_t> update_delay_distribution;
118
119 ns3::Ptr<ns3::RandomVariableStream> content_distribution;
120
121 // false -> NodeData::Values
122 bool content_is_numerical;
123
124 // ns3 random variable streams only return doubles
125 // -> mapping a casted double to the actual value, specified in the testfile
126 std::unordered_map<uint8_t, minhton::NodeData::Value> empirical_value_mapping;
127
128 minhton::NodeData::Value getRandomContent() {
129 minhton::NodeData::Value value;
130
131 if (content_is_numerical) {
132 value = (float)content_distribution->GetValue();
133 } else {
134 uint8_t num_val = content_distribution->GetInteger();
135 value = empirical_value_mapping[num_val];
136 }
137 return value;
138 }
139 };
140
141 void parseRequests();
142 void setAttributeContentBehavior(Choice choice, Scheduler::NodeAttribute &node_attribute);
143 void setAttributeContentBehavior(Constant constant, Scheduler::NodeAttribute &node_attribute);
144 void setAttributeContentBehavior(Gaussian gaussian, Scheduler::NodeAttribute &node_attribute);
145 void setAttributeContentBehavior(Uniform uniform, Scheduler::NodeAttribute &node_attribute);
146 void setAttributeUpdateBehavior(ConstantTime constant, NodeAttribute &node_attribute);
147 void setAttributeUpdateBehavior(Gaussian gaussian, NodeAttribute &node_attribute);
148 void setAttributeUpdateBehavior(Uniform uniform, NodeAttribute &node_attribute);
149 void setAttributeUpdateBehavior(StaticUpdate static_update, NodeAttribute &node_attribute);
150
151 std::vector<NodeAttribute> node_content_attributes_;
152 std::vector<std::string> attribute_names_;
153
154 struct {
155 Dist<uint8_t> query_depth_distribution;
156 Dist<uint64_t> request_delay_distribution;
157 Dist<uint64_t> validity_threshold_distribution;
158
159 std::optional<float> random_nodes_percentage;
160 std::optional<int> absolute_nodes_number;
161
162 bool query_inquire_outdated = false;
163 bool query_inquire_unknown = false;
164
165 } requests_;
166
167 void initiatePeerDiscoverEnvironmentAfterStaticBuild(ns3::Ptr<MinhtonApplication> app,
168 uint64_t index);
169 void initiatePeerDiscoverEnvironmentAfterJoin(ns3::Ptr<MinhtonApplication> app);
170 void initiatePeerDiscoverEnvironment(ns3::Ptr<MinhtonApplication> app,
171 uint64_t init_content_delay, uint64_t init_request_delay);
172
173 void initiateNodeContent(ns3::Ptr<MinhtonApplication> app);
174 void updateNodeAttribute(ns3::Ptr<MinhtonApplication> app, minhton::NodeData::Key key);
175
176 void initiateRequestsOnAllNodes();
177 void makeRequest(ns3::Ptr<MinhtonApplication> app);
178 minhton::FindQuery createFindQuery(uint8_t depth);
179 std::shared_ptr<minhton::BooleanExpression> createBooleanExpression(uint8_t depth);
180 std::shared_ptr<minhton::BooleanExpression> createBooleanExpressionRecursive(
181 std::vector<minhton::NodeData::Key> open_keys);
182 std::shared_ptr<minhton::BooleanExpression> createBooleanExpressionForKey(
183 minhton::NodeData::Key key);
184 void activateRequestCountdown(uint16_t limit);
185
186 std::uniform_real_distribution<double> uniform_zero_one_distribution_ =
187 std::uniform_real_distribution<double>(0.0, 1.0);
188
189 bool attributes_off_ = false;
190 bool requests_off_ = false;
191
192 uint16_t requests_counter_ = 0;
193 uint16_t requests_limit_ = 0;
194 bool requests_limit_on_ = false;
195
196 std::vector<std::string> requesting_nodes_ips_;
197};
198
199} // namespace daisi::minhton_ns3
200
201#endif
Definition minhton_manager_scheduler.h:28
Definition minhton_manager.h:28
Definition find_query.h:21
Definition distribution.h:29
Definition peer_discovery_requests.h:41
Definition peer_discovery_attributes.h:53
Definition peer_discovery_general.h:45
Definition peer_discovery_attributes.h:61
Definition scenario_steps.h:125
Definition scenario_steps.h:109
Definition scenario_steps.h:161
Definition peer_discovery_general.h:27
Definition scenario_steps.h:45
Definition scenario_steps.h:29
Definition scenario_steps.h:75
Definition scenario_steps.h:59
Definition scenario_steps.h:137
Definition peer_discovery_requests.h:49
Definition scenario_steps.h:195
Definition scenario_steps.h:101
Definition scenario_steps.h:89
Definition scenario_steps.h:187
Definition peer_discovery_requests.h:67
Definition peer_discovery_attributes.h:83
Definition peer_discovery_requests.h:85
Definition scenario_steps.h:179
Definition peer_discovery_general.h:36
Definition scenario_steps.h:153