Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
snake_case s4u::Mailbox
[simgrid.git] / src / plugins / vm / VmLiveMigration.hpp
1 /* Copyright (c) 2004-2018. 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/Comm.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Mailbox.hpp"
9 #include "simgrid/s4u/VirtualMachine.hpp"
10
11 #ifndef VM_LIVE_MIGRATION_HPP_
12 #define VM_LIVE_MIGRATION_HPP_
13
14 namespace simgrid {
15 namespace vm {
16 class VmMigrationExt {
17 public:
18   s4u::ActorPtr issuer_ = nullptr;
19   s4u::ActorPtr tx_     = nullptr;
20   s4u::ActorPtr rx_     = nullptr;
21   static simgrid::xbt::Extension<simgrid::s4u::Host, VmMigrationExt> EXTENSION_ID;
22   virtual ~VmMigrationExt() = default;
23   explicit VmMigrationExt(s4u::ActorPtr issuer, s4u::ActorPtr rx, s4u::ActorPtr tx) : issuer_(issuer), tx_(tx), rx_(rx)
24   {
25   }
26   static void ensureVmMigrationExtInstalled();
27 };
28
29 class MigrationRx {
30   /* The miration_rx process uses mbox_ctl to let the caller of do_migration()  know the completion of the migration. */
31   s4u::MailboxPtr mbox_ctl;
32   /* The migration_rx and migration_tx processes use mbox to transfer migration data. */
33   s4u::MailboxPtr mbox;
34   s4u::VirtualMachine* vm_;
35   s4u::Host* src_pm_ = nullptr;
36   s4u::Host* dst_pm_ = nullptr;
37
38 public:
39   explicit MigrationRx(s4u::VirtualMachine* vm, s4u::Host* dst_pm) : vm_(vm), dst_pm_(dst_pm)
40   {
41     src_pm_ = vm_->getPm();
42
43     mbox_ctl = s4u::Mailbox::by_name(std::string("__mbox_mig_ctl:") + vm_->get_cname() + "(" + src_pm_->get_cname() +
44                                      "-" + dst_pm_->get_cname() + ")");
45     mbox = s4u::Mailbox::by_name(std::string("__mbox_mig_src_dst:") + vm_->get_cname() + "(" + src_pm_->get_cname() +
46                                  "-" + dst_pm_->get_cname() + ")");
47   }
48   void operator()();
49 };
50
51 class MigrationTx {
52   /* The migration_rx and migration_tx processes use mbox to transfer migration data. */
53   s4u::MailboxPtr mbox;
54   s4u::VirtualMachine* vm_;
55   s4u::Host* src_pm_ = nullptr;
56   s4u::Host* dst_pm_ = nullptr;
57
58 public:
59   explicit MigrationTx(s4u::VirtualMachine* vm, s4u::Host* dst_pm) : vm_(vm), dst_pm_(dst_pm)
60   {
61     src_pm_ = vm_->getPm();
62     mbox    = s4u::Mailbox::by_name(std::string("__mbox_mig_src_dst:") + vm_->get_cname() + "(" + src_pm_->get_cname() +
63                                  "-" + dst_pm_->get_cname() + ")");
64   }
65   void operator()();
66   sg_size_t sendMigrationData(sg_size_t size, int stage, int stage2_round, double mig_speed, double timeout);
67 };
68 }
69 }
70 #endif