Logo AND Algorithmique Numérique Distribuée

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