SOLA
Loading...
Searching...
No Matches
routing_information.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef MINHTON_CORE_ROUTING_INFORMATION_H_
8#define MINHTON_CORE_ROUTING_INFORMATION_H_
9
10#include <functional>
11#include <memory>
12#include <stdexcept>
13#include <string>
14#include <tuple>
15#include <vector>
16
17#include "minhton/core/constants.h"
18#include "minhton/core/node_info.h"
19#include "minhton/core/routing_calculations.h"
20#include "minhton/logging/logger.h"
21
22namespace minhton {
23
30public:
40 RoutingInformation() = default;
41
54 RoutingInformation(minhton::NodeInfo self_node_info, Logger logger);
55
58
59 void resetPosition(uint64_t event_id);
60
66 void setPosition(const minhton::LogicalNodeInfo &peer_position);
67
71 void setNodeStatus(NodeStatus status, uint64_t event_id);
72
75
78 uint16_t getFanout() const;
79
81 std::string getString() const;
82
85
100 void setParent(const minhton::NodeInfo &parent, uint64_t ref_event_id = 0);
101
104 minhton::NodeInfo getChild(uint16_t child_position);
105
107 std::vector<minhton::NodeInfo> getChildren() const;
108
128 void setChild(const minhton::NodeInfo &child, uint16_t position, uint64_t ref_event_id = 0);
129
133
137
150 void setAdjacentLeft(const minhton::NodeInfo &adjacent_left, uint64_t ref_event_id = 0);
151
164 void setAdjacentRight(const minhton::NodeInfo &adjacent_right, uint64_t ref_event_id = 0);
165
168 std::vector<minhton::NodeInfo> getRoutingTableNeighbors() const;
169
172 std::vector<minhton::NodeInfo> getRoutingTableNeighborChildren() const;
173
176 std::vector<minhton::NodeInfo> getInitializedRoutingTableNeighborsAndChildren() const;
177
180 std::vector<minhton::NodeInfo> getLeftRoutingTableNeighborsLeftToRight() const;
181
184 std::vector<minhton::NodeInfo> getRightRoutingTableNeighborsLeftToRight() const;
185
188 std::vector<minhton::NodeInfo> getLeftRoutingTableNeighborChildrenLeftToRight() const;
189
192 std::vector<minhton::NodeInfo> getRightRoutingTableNeighborChildrenLeftToRight() const;
193
196 std::vector<minhton::NodeInfo> getLeftRoutingTableNeighborsRightToLeft() const;
197
200 std::vector<minhton::NodeInfo> getRightRoutingTableNeighborsRightToLeft() const;
201
204 std::vector<minhton::NodeInfo> getLeftRoutingTableNeighborChildrenRightToLeft() const;
205
208 std::vector<minhton::NodeInfo> getRightRoutingTableNeighborChildrenRightToLeft() const;
209
212 std::vector<minhton::NodeInfo> getAllLeftRoutingTableNeighborsAndChildren() const;
213
216 std::vector<minhton::NodeInfo> getAllRightRoutingTableNeighborsAndChildren() const;
217
220 std::vector<minhton::NodeInfo> getRoutingTableNeighborsAndChildren() const;
221
224 std::vector<minhton::NodeInfo> getAllInitializedLeftRoutingTableNeighborsAndChildren() const;
225
228 std::vector<minhton::NodeInfo> getAllInitializedRightRoutingTableNeighborsAndChildren() const;
229
232 std::vector<minhton::NodeInfo> getAllInitializedRoutingTableNeighbors() const;
233
236 std::vector<minhton::NodeInfo> getAllInitializedRoutingTableNeighborChildren() const;
237
242
247
252
257
262
264 bool atLeastOneChildExists() const;
265
267 bool atLeastOneChildIsFree() const;
268
271
274
276 std::vector<minhton::NodeInfo> getInitializedChildren() const;
277
280 bool areChildrenFull() const;
281
283 bool areRoutingTableNeighborsFull() const;
284
287
291
305 void updateRoutingTableNeighbor(minhton::NodeInfo routing_table_neighbor,
306 uint64_t ref_event_id = 0);
307
322 void updateRoutingTableNeighborChild(minhton::NodeInfo routing_table_neighbor_child,
323 uint64_t ref_event_id = 0);
324
338 void resetChild(uint16_t position, uint64_t ref_event_id = 0);
339
352 void resetAdjacentRight(uint64_t ref_event_id = 0);
353
366 void resetAdjacentLeft(uint64_t ref_event_id = 0);
367
383 bool resetRoutingTableNeighbor(const minhton::NodeInfo &routing_table_neighbor,
384 uint64_t ref_event_id = 0);
385
403 const minhton::NodeInfo &routing_table_neighbor_child_or_child, uint64_t ref_event_id = 0);
404
419
435 std::vector<minhton::NodeInfo> getAllUniqueKnownExistingNeighbors() const;
436
454 std::vector<minhton::NodeInfo> getAllUniqueSymmetricalExistingNeighbors() const;
455
475 void removeNeighbor(const minhton::NodeInfo &position_to_remove, uint64_t ref_event_id = 0);
476
492 void updateNeighbor(const minhton::NodeInfo &position_to_update, uint64_t ref_event_id = 0);
493
501 bool resetRoutingTableNeighborChild(const minhton::NodeInfo &routing_table_neighbor_child,
502 uint64_t ref_event_id = 0);
503
513 minhton::NodeInfo getNodeInfoByPosition(uint32_t level, uint32_t number);
514
530 static std::vector<minhton::NodeInfo> calcRoutingTableNeighborParents(
531 const minhton::NodeInfo &node);
532
549 static std::vector<minhton::NodeInfo> combiningNodeVectorsWithoutDuplicate(
550 std::vector<minhton::NodeInfo> v1, const std::vector<minhton::NodeInfo> &v2);
551
563 static std::vector<minhton::NodeInfo> removeRoutingTableNeighborChildrenFromVector(
564 minhton::NodeInfo node, std::vector<minhton::NodeInfo> neighbors);
565
566 void addNeighborChangeSubscription(
567 const std::function<void(const minhton::NodeInfo &new_node, NeighborRelationship relationship,
568 const minhton::NodeInfo &old_node, uint16_t position)> &callback);
569
570 void addNodeInfoChangeSubscription(
571 const std::function<void(const minhton::NodeInfo &previous_node_info,
572 const minhton::NodeInfo &new_node_info)> &callback);
573
574 bool areWeDSN() const;
575 bool areWeTempDSN() const;
576
577 NodeInfo getCoveringDSNOrTempDSN();
578
579 bool nextDSNExists();
580
581 NodeInfo getNextDSN();
582
583private:
585 minhton::NodeInfo self_node_info_;
586
588 minhton::Logger logger_;
589
591 minhton::NodeInfo parent_;
592
594 minhton::NodeInfo adjacent_left_;
595
597 minhton::NodeInfo adjacent_right_;
598
600 std::vector<minhton::NodeInfo> children_;
601
602 // vector of routing table neighbors on our level with specific horizontal distances
603 std::vector<minhton::NodeInfo> routing_table_neighbors_;
604
605 // vector of children of our routing table neighbors
606 std::vector<minhton::NodeInfo> routing_table_neighbor_children_;
607
608 // at this index the first routing table neighbor of the right side starts
609 // simultanously the first routing table neighbor child starts at
610 // (right_table_neighbor_start_index_ * fanout)
611 uint32_t right_table_neighbor_start_index_ = 0;
612
613 std::vector<
614 std::function<void(const minhton::NodeInfo &new_node, NeighborRelationship relationship,
615 const minhton::NodeInfo &old_node, uint16_t position)>>
616 neighbor_change_subscription_callbacks_;
617
618 std::vector<std::function<void(const minhton::NodeInfo &previous_node_info,
619 const minhton::NodeInfo &new_node_info)>>
620 node_info_change_subscription_callbacks_;
621
631 void notifyNeighborChange(const minhton::NodeInfo &new_node, NeighborRelationship relationship,
632 uint64_t ref_event_id,
633 const minhton::NodeInfo &old_node = minhton::NodeInfo(),
634 uint16_t index = 0); // TODO Remove default argument
635
636 void notifyNodeInfoChange(const minhton::NodeInfo &previous_node_info,
637 const minhton::NodeInfo &new_node_info);
638
652 void initRoutingTableNeighbors();
653
667 void initRoutingTableNeighborChildren(uint32_t parent_level, uint32_t parent_number);
668
684 void initParentAndChildren();
685
686 void clearRoutingTable();
687};
688} // namespace minhton
689#endif
Definition logger.h:20
Definition logical_node_info.h:23
Definition node_info.h:24
Definition routing_information.h:29
std::vector< minhton::NodeInfo > getInitializedChildren() const
Definition routing_information_general_helper.cpp:15
std::vector< minhton::NodeInfo > getAllLeftRoutingTableNeighborsAndChildren() const
Definition routing_information_general_helper.cpp:78
bool atLeastOneChildIsFree() const
Definition routing_information_general_helper.cpp:475
std::string getString() const
Definition routing_information.cpp:97
void resetChild(uint16_t position, uint64_t ref_event_id=0)
Definition routing_information.cpp:393
bool atLeastOneRoutingTableNeighborChildIsFree() const
Definition routing_information_general_helper.cpp:486
std::vector< minhton::NodeInfo > getRoutingTableNeighborsAndChildren() const
Definition routing_information_general_helper.cpp:57
minhton::NodeInfo getLeftmostNeighborChild() const
Definition routing_information_general_helper.cpp:340
void updateRoutingTableNeighbor(minhton::NodeInfo routing_table_neighbor, uint64_t ref_event_id=0)
Definition routing_information_general_helper.cpp:108
std::vector< minhton::NodeInfo > getInitializedRoutingTableNeighborsAndChildren() const
Definition routing_information_general_helper.cpp:66
std::vector< minhton::NodeInfo > getLeftRoutingTableNeighborChildrenRightToLeft() const
Definition routing_information_table.cpp:121
bool resetChildOrRoutingTableNeighborChild(const minhton::NodeInfo &routing_table_neighbor_child_or_child, uint64_t ref_event_id=0)
Definition routing_information.cpp:360
std::vector< minhton::NodeInfo > getLeftRoutingTableNeighborsLeftToRight() const
Definition routing_information_table.cpp:63
bool atLeastOneChildExists() const
Definition routing_information_general_helper.cpp:470
bool areRoutingTableNeighborChildrenFull() const
Definition routing_information_general_helper.cpp:49
uint16_t getFanout() const
Definition routing_information.cpp:89
bool areChildrenFull() const
Definition routing_information_general_helper.cpp:25
minhton::NodeInfo getRightmostNeighbor() const
Definition routing_information_general_helper.cpp:332
std::vector< minhton::NodeInfo > getAllRightRoutingTableNeighborsAndChildren() const
Definition routing_information_general_helper.cpp:93
void setNodeStatus(NodeStatus status, uint64_t event_id)
Setting the status of our NodeInfo object.
Definition routing_information.cpp:142
std::vector< minhton::NodeInfo > getRightRoutingTableNeighborChildrenLeftToRight() const
Definition routing_information_table.cpp:96
minhton::NodeInfo getLeftmostNeighbor() const
Definition routing_information_general_helper.cpp:324
void setAdjacentLeft(const minhton::NodeInfo &adjacent_left, uint64_t ref_event_id=0)
Definition routing_information.cpp:245
std::vector< minhton::NodeInfo > getAllInitializedRoutingTableNeighbors() const
Definition routing_information_general_helper.cpp:298
std::vector< minhton::NodeInfo > getAllInitializedRoutingTableNeighborChildren() const
Definition routing_information_general_helper.cpp:258
std::vector< minhton::NodeInfo > getAllUniqueKnownExistingNeighbors() const
Definition routing_information_general_helper.cpp:380
void removeNeighbor(const minhton::NodeInfo &position_to_remove, uint64_t ref_event_id=0)
Definition routing_information_general_helper.cpp:167
static std::vector< minhton::NodeInfo > removeRoutingTableNeighborChildrenFromVector(minhton::NodeInfo node, std::vector< minhton::NodeInfo > neighbors)
Definition routing_information_general_helper.cpp:413
void resetAdjacentRight(uint64_t ref_event_id=0)
Definition routing_information.cpp:305
std::vector< minhton::NodeInfo > getAllInitializedLeftRoutingTableNeighborsAndChildren() const
Definition routing_information_general_helper.cpp:271
void setChild(const minhton::NodeInfo &child, uint16_t position, uint64_t ref_event_id=0)
Definition routing_information.cpp:197
bool resetRoutingTableNeighbor(const minhton::NodeInfo &routing_table_neighbor, uint64_t ref_event_id=0)
Definition routing_information.cpp:331
void updateRoutingTableNeighborChild(minhton::NodeInfo routing_table_neighbor_child, uint64_t ref_event_id=0)
Definition routing_information_general_helper.cpp:136
static std::vector< minhton::NodeInfo > calcRoutingTableNeighborParents(const minhton::NodeInfo &node)
Definition routing_information_general_helper.cpp:229
minhton::NodeInfo getAdjacentLeft() const
Definition routing_information.cpp:241
void updateNeighbor(const minhton::NodeInfo &position_to_update, uint64_t ref_event_id=0)
Definition routing_information_general_helper.cpp:188
minhton::NodeInfo getChild(uint16_t child_position)
Definition routing_information.cpp:229
void setParent(const minhton::NodeInfo &parent, uint64_t ref_event_id=0)
Definition routing_information.cpp:163
bool areRoutingTableNeighborsFull() const
Definition routing_information_general_helper.cpp:33
std::vector< minhton::NodeInfo > getLeftRoutingTableNeighborChildrenLeftToRight() const
Definition routing_information_table.cpp:84
std::vector< minhton::NodeInfo > getAllInitializedRightRoutingTableNeighborsAndChildren() const
Definition routing_information_general_helper.cpp:285
bool resetRoutingTableNeighborChild(const minhton::NodeInfo &routing_table_neighbor_child, uint64_t ref_event_id=0)
Definition routing_information_table.cpp:136
std::vector< minhton::NodeInfo > getRightRoutingTableNeighborsLeftToRight() const
Definition routing_information_table.cpp:73
std::vector< minhton::NodeInfo > getRoutingTableNeighbors() const
Definition routing_information_table.cpp:55
bool areRoutingTableNeighborChildrenEmpty() const
Definition routing_information_general_helper.cpp:41
void setPosition(const minhton::LogicalNodeInfo &peer_position)
Definition routing_information.cpp:36
void setAdjacentRight(const minhton::NodeInfo &adjacent_right, uint64_t ref_event_id=0)
Definition routing_information.cpp:275
minhton::NodeInfo getAdjacentRight() const
Definition routing_information.cpp:243
minhton::NodeInfo getParent() const
Definition routing_information.cpp:193
minhton::NodeInfo getLowestNode() const
Definition routing_information_general_helper.cpp:492
std::vector< minhton::NodeInfo > getRightRoutingTableNeighborsRightToLeft() const
Definition routing_information_table.cpp:114
std::vector< minhton::NodeInfo > getRightRoutingTableNeighborChildrenRightToLeft() const
Definition routing_information_table.cpp:128
minhton::NodeInfo getNodeInfoByPosition(uint32_t level, uint32_t number)
Definition routing_information_general_helper.cpp:391
minhton::NodeInfo getSelfNodeInfo() const
Definition routing_information.cpp:140
std::vector< minhton::NodeInfo > getChildren() const
Definition routing_information.cpp:195
minhton::NodeInfo getDirectLeftNeighbor() const
Definition routing_information_general_helper.cpp:308
~RoutingInformation()=default
Destructor.
std::vector< minhton::NodeInfo > getLeftRoutingTableNeighborsRightToLeft() const
Definition routing_information_table.cpp:108
std::vector< minhton::NodeInfo > getRoutingTableNeighborChildren() const
Definition routing_information_table.cpp:59
static std::vector< minhton::NodeInfo > combiningNodeVectorsWithoutDuplicate(std::vector< minhton::NodeInfo > v1, const std::vector< minhton::NodeInfo > &v2)
Definition routing_information_general_helper.cpp:352
bool atLeastOneRoutingTableNeighborChildExists() const
Definition routing_information_general_helper.cpp:480
minhton::NodeInfo getDirectRightNeighbor() const
Definition routing_information_general_helper.cpp:316
void resetAdjacentLeft(uint64_t ref_event_id=0)
Definition routing_information.cpp:318
std::vector< minhton::NodeInfo > getAllUniqueSymmetricalExistingNeighbors() const
Definition routing_information_general_helper.cpp:430
Definition minhton_watchdog_ns3.cpp:24