Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add/update copyright notices.
[simgrid.git] / examples / java / cloud / migration / Test.java
1 /* Copyright (c) 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package cloud.migration;
8
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11
12 public class Test extends Process{
13
14     Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException  {
15         super(host, name, args);
16     }
17
18     public void main(String[] strings) throws MsgException {
19
20        double startTime = 0;
21        double endTime = 0;
22
23        /* get hosts 1 and 2*/
24         Host host0 = null;
25         Host host1 = null;
26
27         try {
28             host0 = Host.getByName("host0");
29             host1 = Host.getByName("host1");
30         }catch (HostNotFoundException e) {
31             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
32         }
33
34       /* Create VM1 */
35         int dpRate = 70;
36         int load1 = 90;
37         int load2 = 80;
38
39         XVM vm1 = null;
40         vm1 = new XVM(
41                 host0,
42                 "vm0",
43                 1, // Nb of vcpu
44                 2048, // Ramsize,
45                 125, // Net Bandwidth
46                 null, //VM disk image
47                 -1,   //size of disk image,
48                 125, // Net bandwidth,
49                 dpRate // Memory intensity
50         );
51
52
53         vm1.start();
54
55         /* Collocated VMs */
56         int collocatedSrc = 6;
57         int vmSrcLoad[] = {
58                 80,
59                 0,
60                 90,
61                 40,
62                 30,
63                 90,
64         };
65
66         XVM tmp = null;
67         for (int i=1 ; i<= collocatedSrc ; i++){
68             tmp = new XVM(
69                     host0,
70                     "vm"+i,
71                     1, // Nb of vcpu
72                     2048, // Ramsize,
73                     125, // Net Bandwidth
74                     null, //VM disk image
75                     -1,   //size of disk image,
76                     125, // Net bandwidth,
77                     dpRate // Memory intensity
78             );
79             tmp.start();
80             tmp.setLoad(vmSrcLoad[i-1]);
81         }
82
83         int collocatedDst = 6;
84         int vmDstLoad[] = {
85                 0,
86                 40,
87                 90,
88                 100,
89                 0,
90                 80,
91         };
92
93         for (int i=1 ; i <= collocatedDst ; i++){
94             tmp = new XVM(
95                     host1,
96                     "vm"+i+collocatedSrc,
97                     1, // Nb of vcpu
98                     2048, // Ramsize,
99                     125, // Net Bandwidth
100                     null, //VM disk image
101                     -1,   //size of disk image,
102                     125, // Net bandwidth,
103                     dpRate // Memory intensity
104             );
105             tmp.start();
106             tmp.setLoad(vmDstLoad[i-1]);
107         }
108
109
110
111
112
113         Msg.info("Round trip of VM1 (load "+load1+"%)");
114         vm1.setLoad(load1);
115         Msg.info("     - Launch migration from host 0 to host 1");
116         startTime = Msg.getClock();
117         vm1.migrate(host1);
118         endTime = Msg.getClock();
119         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
120         Msg.info("     - Launch migration from host 1 to host 0");
121         startTime = Msg.getClock();
122         vm1.migrate(host0);
123         endTime = Msg.getClock();
124         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
125
126         Msg.info("\n \n \nRound trip of VM1 (load "+load2+"%)");
127         vm1.setLoad(load2);
128         Msg.info("     - Launch migration from host 0 to host 1");
129         startTime = Msg.getClock();
130         vm1.migrate(host1);
131         endTime = Msg.getClock();
132         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
133         Msg.info("     - Launch migration from host 1 to host 0");
134         startTime = Msg.getClock();
135         vm1.migrate(host0);
136         endTime = Msg.getClock();
137         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
138
139         waitFor(100000);
140         Main.setEndOfTest();
141     }
142 }