Release notes 1- Cloud server processing was simplified in the initial version, it is handled via cloudsim components now. 2- Cloud server manager, edge server manager, mobile device manager and vm allocation policy are used as abstract class in factory pattern to allow developers to use different business logic without modifying EdgeCloudSim source code. 3- The task and place types are no longer defined as enumeration. They are used as integer value in order to manipulate more place type without modifying enum variable. 4- Two sample applications (one of them is simple and the other one extended application) are added along with the corresponding matlab files to plot statistics. 5- Cloud server properties are added to the simulation settings file 6- New log items are added to simulation result files 7- Code refactoring is applied including the modification of comments
86 lines
2.8 KiB
Java
86 lines
2.8 KiB
Java
/*
|
|
* Title: EdgeCloudSim - Simulation Utils
|
|
*
|
|
* Description: Utility class providing helper functions
|
|
*
|
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
|
*/
|
|
|
|
package edu.boun.edgecloudsim.utils;
|
|
|
|
import java.io.File;
|
|
import java.util.Date;
|
|
import java.util.Random;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
public class SimUtils {
|
|
|
|
public static final Random RNG = new Random(System.currentTimeMillis());
|
|
|
|
public static int getRandomNumber(int start, int end) {
|
|
//return pd.sample();
|
|
long range = (long)end - (long)start + 1;
|
|
long fraction = (long)(range * RNG.nextDouble());
|
|
return (int)(fraction + start);
|
|
}
|
|
public static double getRandomDoubleNumber(double start, double end) {
|
|
//return pd.sample();
|
|
double range = end - start;
|
|
double fraction = (range * RNG.nextDouble());
|
|
return (fraction + start);
|
|
}
|
|
public static long getRandomLongNumber(int start, int end) {
|
|
//return pd.sample();
|
|
long range = (long)end - (long)start + 1;
|
|
long fraction = (long)(range * RNG.nextDouble());
|
|
return (fraction + start);
|
|
}
|
|
|
|
public static void cleanOutputFolder(String outputFolder){
|
|
//clean the folder where the result files will be saved
|
|
File dir = new File(outputFolder);
|
|
if(dir.exists() && dir.isDirectory())
|
|
{
|
|
for (File f: dir.listFiles())
|
|
{
|
|
if (f.exists() && f.isFile())
|
|
{
|
|
if(!f.delete())
|
|
{
|
|
SimLogger.printLine("file cannot be cleared: " + f.getAbsolutePath());
|
|
System.exit(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
SimLogger.printLine("Output folder is not available: " + outputFolder);
|
|
System.exit(0);
|
|
}
|
|
}
|
|
public static String getTimeDifference(Date startDate, Date endDate){
|
|
String result = "";
|
|
long duration = endDate.getTime() - startDate.getTime();
|
|
|
|
long diffInMilli = TimeUnit.MILLISECONDS.toMillis(duration);
|
|
long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
|
|
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration);
|
|
long diffInHours = TimeUnit.MILLISECONDS.toHours(duration);
|
|
long diffInDays = TimeUnit.MILLISECONDS.toDays(duration);
|
|
|
|
if(diffInDays>0)
|
|
result += diffInDays + ((diffInDays>1 == true) ? " Days " : " Day ");
|
|
if(diffInHours>0)
|
|
result += diffInHours % 24 + ((diffInHours>1 == true) ? " Hours " : " Hour ");
|
|
if(diffInMinutes>0)
|
|
result += diffInMinutes % 60 + ((diffInMinutes>1 == true) ? " Minutes " : " Minute ");
|
|
if(diffInSeconds>0)
|
|
result += diffInSeconds % 60 + ((diffInSeconds>1 == true) ? " Seconds" : " Second");
|
|
if(diffInMilli>0 && result.isEmpty())
|
|
result += diffInMilli + ((diffInMilli>1 == true) ? " Milli Seconds" : " Milli Second");
|
|
|
|
return result;
|
|
}
|
|
}
|