Logo AND Algorithmique Numérique Distribuée

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