SOLA
Loading...
Searching...
No Matches
paxos_proposer.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_PATH_PLANNING_CONSENSUS_PAXOS_PROPOSER_H_
18#define DAISI_PATH_PLANNING_CONSENSUS_PAXOS_PROPOSER_H_
19
20#include <functional>
21#include <memory>
22
23#include "ns3/event-id.h"
24#include "path_planning/consensus/paxos/message/ok_message.h"
25#include "path_planning/consensus/paxos/message/promise_message.h"
26#include "path_planning/consensus/paxos/message/response_message.h"
27#include "path_planning/consensus/paxos/paxos_data.h"
28#include "path_planning/constants.h"
29
30namespace daisi::path_planning::consensus {
33public:
34 explicit PaxosProposer(std::shared_ptr<PaxosContainer> container);
35
36 void findConsensus(const PointTimePairs &points, double seconds_till_start,
37 std::function<void(uint32_t, double)> success_cb,
38 std::function<void(uint32_t)> fail_cb);
39
40 void processPromiseMessage(const PromiseMessage &msg);
41 void processOKMessage(const OKMessage &msg);
42 void processResponseMessage(const ResponseMessage &msg);
43
44private:
45 std::shared_ptr<PaxosContainer> container_;
46
47 enum class Phase { kNone, kPrepare, kAccept, kFinished };
48
50 struct Proposal {
51 PointTimePairs points;
52 double start_time = 0.0;
53 uint32_t instance_id = 0;
54 uint32_t proposal_id = 0;
55 uint32_t needed_for_quorum = 0;
56 uint32_t outstanding_oks = 0;
57 ns3::EventId timeout_event;
58 Phase phase = Phase::kNone;
59 std::function<void(uint32_t, double)> success_cb;
60 std::function<void(uint32_t)> fail_cb;
61
62 [[nodiscard]] bool initialized() const { return !points.empty(); }
63 };
64
65 double calculatePossibleStartTime(const PointTimePairs &points, double seconds_till_start) const;
66
67 void prepareTimeout(uint32_t proposal_id);
68
69 uint32_t remaining_responses_ = 0;
70 Proposal current_proposal_;
71
72 std::unordered_map<InstanceID, uint32_t>
73 instance_to_proposal_id_;
74};
75} // namespace daisi::path_planning::consensus
76
77#endif // DAISI_PATH_PLANNING_CONSENSUS_PAXOS_PROPOSER_H_
Implementation for an proposer in the paxos consensus algorithm.
Definition paxos_proposer.h:32
< OK message from all acceptors to all other participants to commit the requested occupancy
Definition ok_message.h:26
Definition response_message.h:27