Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more include cleanups
[simgrid.git] / src / plugins / vm / VmLiveMigration.hpp
1 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Engine.hpp"
7 #include "simgrid/s4u/Mailbox.hpp"
8 #include "simgrid/s4u/VirtualMachine.hpp"
9
10 #ifndef VM_LIVE_MIGRATION_HPP_
11 #define VM_LIVE_MIGRATION_HPP_
12
13 namespace simgrid {
14 namespace vm {
15 class VmMigrationExt {
16 public:
17   s4u::ActorPtr issuer_ = nullptr;
18   s4u::ActorPtr tx_     = nullptr;
19   s4u::ActorPtr rx_     = nullptr;
20   static simgrid::xbt::Extension<simgrid::s4u::Host, VmMigrationExt> EXTENSION_ID;
21   explicit VmMigrationExt(s4u::ActorPtr issuer, s4u::ActorPtr rx, s4u::ActorPtr tx) : issuer_(issuer), tx_(tx), rx_(rx)
22   {
23   }
24   static void ensureVmMigrationExtInstalled();
25 };
26
27 class MigrationRx {
28   /* The migration_rx process uses mbox_ctl to let the caller of do_migration()  know the completion of the migration.
29    */
30   s4u::Mailbox* mbox_ctl;
31   /* The migration_rx and migration_tx processes use mbox to transfer migration data. */
32   s4u::Mailbox* mbox;
33   s4u::VirtualMachine* vm_;
34   s4u::Host* src_pm_ = nullptr;
35   s4u::Host* dst_pm_ = nullptr;
36
37 public:
38   explicit MigrationRx(s4u::VirtualMachine* vm, s4u::Host* dst_pm) : vm_(vm), dst_pm_(dst_pm)
39   {
40     src_pm_ = vm_->get_pm();
41
42     mbox_ctl = s4u::Mailbox::by_name(std::string("__mbox_mig_ctl:") + vm_->get_cname() + "(" + src_pm_->get_cname() +
43                                      "-" + dst_pm_->get_cname() + ")");
44     mbox = s4u::Mailbox::by_name(std::string("__mbox_mig_src_dst:") + vm_->get_cname() + "(" + src_pm_->get_cname() +
45                                  "-" + dst_pm_->get_cname() + ")");
46   }
47   void operator()();
48 };
49
50 class MigrationTx {
51   /* The migration_rx and migration_tx processes use mbox to transfer migration data. */
52   s4u::Mailbox* mbox;
53   s4u::VirtualMachine* vm_;
54   s4u::Host* src_pm_ = nullptr;
55   s4u::Host* dst_pm_ = nullptr;
56
57 public:
58   explicit MigrationTx(s4u::VirtualMachine* vm, s4u::Host* dst_pm) : vm_(vm), dst_pm_(dst_pm)
59   {
60     src_pm_ = vm_->get_pm();
61     mbox    = s4u::Mailbox::by_name(std::string("__mbox_mig_src_dst:") + vm_->get_cname() + "(" + src_pm_->get_cname() +
62                                  "-" + dst_pm_->get_cname() + ")");
63   }
64   void operator()();
65   sg_size_t sendMigrationData(sg_size_t size, int stage, int stage2_round, double mig_speed, double timeout);
66 };
67 }
68 }
69 #endif