Skip to content

TheWindISeek/cloudsim-cloudsim-4.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CloudSim: A Framework For Modeling And Simulation Of Cloud Computing Infrastructures And Services

Cloud computing is the leading approach for delivering reliable, secure, fault-tolerant, sustainable, and scalable computational services. Hence timely, repeatable, and controllable methodologies for performance evaluation of new cloud applications and policies before their actual development are reqruied. Because utilization of real testbeds limits the experiments to the scale of the testbed and makes the reproduction of results an extremely difficult undertaking, simulation may be used.

CloudSim goal is to provide a generalized and extensible simulation framework that enables modeling, simulation, and experimentation of emerging Cloud computing infrastructures and application services, allowing its users to focus on specific system design issues that they want to investigate, without getting concerned about the low level details related to Cloud-based infrastructures and services.

CloudSim is developed in the Cloud Computing and Distributed Systems (CLOUDS) Laboratory, at the Computer Science and Software Engineering Department of the University of Melbourne.

More information can be found on the CloudSim's web site.

Main features

  • support for modeling and simulation of large scale Cloud computing data centers
  • support for modeling and simulation of virtualized server hosts, with customizable policies for provisioning host resources to virtual machines
  • support for modeling and simulation of application containers
  • support for modeling and simulation of energy-aware computational resources
  • support for modeling and simulation of data center network topologies and message-passing applications
  • support for modeling and simulation of federated clouds
  • support for dynamic insertion of simulation elements, stop and resume of simulation
  • support for user-defined policies for allocation of hosts to virtual machines and policies for allocation of host resources to virtual machines

Download

The downloaded package contains all the source code, examples, jars, and API html files.

Publications

Aboved are offical introduction, blowed are personal introduction.

安装

首先,访问cloudsim官网,http://www.cloudbus.org/cloudsim/

接着找到Download标题

image-20230328093450797

图 1 下载网址

https://github.com/Cloudslab/cloudsim/releases

点击上述网址进行访问。

image-20230328093541170

图 2 下载页面

找到cloudsim-4.0.zip,或者Source code的zip版本

然后进行下载。

下载链接为:

https://github.com/Cloudslab/cloudsim/releases/download/cloudsim-4.0/cloudsim-4.0.zip

下载后选择目录任意选择目录进行安装。

部署

以IDEA 2020 专业版为例

image-20230328093553303

图 3 找到打开文件夹

然后单击该文件夹。

image-20230328093604196

图 4 打开下载好的cloudsim文件夹

打开后,如果下方有maven的后台工作在正常运行,那说明已经在配置了。否则可以手动重新载入maven, 当然这些都需要下载maven插件。如果没有学过maven,可以查看这几篇文章快速入门。

maven的下载与安装教程(超详细)_maven安装_格子衫111的博客-CSDN博客

通过导入pom.xml导入maven项目(包括开源项目)_maven项目导入pom_祈尘的博客-CSDN博客

Linux 搭建安装Maven环境以及编译打包_pom.xml如何编译_Word哥的博客-CSDN博客

下载maven插件过程如下, 在工作区点两下shift。

在出来的框中输入 Plugins 或者 插件。

image-20230328093614793

图 5 搜索Maven插件

image-20230328093624161

图 6 下载maven插件

亦或者,可以参考maven的命令行操作,导入包的命令为

mvn help:system

image-20230328093635250

图 7 命令行方式导入

运行过程

导入包完成后,可以按照该路径找到样例程序,(如果下的是带样例的包的话)

image-20230328093644776

图 8 找到样例包

之后可以使用maven工具,maven run等命令解决,当然我这边更推荐找到examples.txt,这个文件中有关于如何运行样例文件的详细解释。

image-20230328093654972

图 9 examples.txt的路径

最后,如果出现以下结果,说明运行成功。

image-20230328093704378

图10 正常运行的结果

如果没有下载样例,可以复制一下下面的样例1的代码。

package org.cloudbus.cloudsim.examples;

/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
 *               of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009, The University of Melbourne, Australia
 */

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;

/**
 * A simple example showing how to create a data center with one host and run one cloudlet on it.
 */
public class CloudSimExample1 {
	/** The cloudlet list. */
	private static List<Cloudlet> cloudletList;
	/** The vmlist. */
	private static List<Vm> vmlist;

	/**
	 * Creates main() to run this example.
	 *
	 * @param args the args
	 */
	@SuppressWarnings("unused")
	public static void main(String[] args) {
		Log.printLine("Starting CloudSimExample1...");

		try {
			// First step: Initialize the CloudSim package. It should be called before creating any entities.
			int num_user = 1; // number of cloud users
			Calendar calendar = Calendar.getInstance(); // Calendar whose fields have been initialized with the current date and time.
 			boolean trace_flag = true; // trace events

			/* Comment Start - Dinesh Bhagwat 
			 * Initialize the CloudSim library. 
			 * init() invokes initCommonVariable() which in turn calls initialize() (all these 3 methods are defined in CloudSim.java).
			 * initialize() creates two collections - an ArrayList of SimEntity Objects (named entities which denote the simulation entities) and 
			 * a LinkedHashMap (named entitiesByName which denote the LinkedHashMap of the same simulation entities), with name of every SimEntity as the key.
			 * initialize() creates two queues - a Queue of SimEvents (future) and another Queue of SimEvents (deferred). 
			 * initialize() creates a HashMap of of Predicates (with integers as keys) - these predicates are used to select a particular event from the deferred queue. 
			 * initialize() sets the simulation clock to 0 and running (a boolean flag) to false.
			 * Once initialize() returns (note that we are in method initCommonVariable() now), a CloudSimShutDown (which is derived from SimEntity) instance is created 
			 * (with numuser as 1, its name as CloudSimShutDown, id as -1, and state as RUNNABLE). Then this new entity is added to the simulation 
			 * While being added to the simulation, its id changes to 0 (from the earlier -1). The two collections - entities and entitiesByName are updated with this SimEntity.
			 * the shutdownId (whose default value was -1) is 0    
			 * Once initCommonVariable() returns (note that we are in method init() now), a CloudInformationService (which is also derived from SimEntity) instance is created 
			 * (with its name as CloudInformatinService, id as -1, and state as RUNNABLE). Then this new entity is also added to the simulation. 
			 * While being added to the simulation, the id of the SimEntitiy is changed to 1 (which is the next id) from its earlier value of -1. 
			 * The two collections - entities and entitiesByName are updated with this SimEntity.
			 * the cisId(whose default value is -1) is 1
			 * Comment End - Dinesh Bhagwat 
			 */
			CloudSim.init(num_user, calendar, trace_flag);

			// Second step: Create Datacenters
			// Datacenters are the resource providers in CloudSim. We need at
			// list one of them to run a CloudSim simulation
			Datacenter datacenter0 = createDatacenter("Datacenter_0");

			// Third step: Create Broker
			DatacenterBroker broker = createBroker();
			int brokerId = broker.getId();

			// Fourth step: Create one virtual machine
			vmlist = new ArrayList<Vm>();

			// VM description
			int vmid = 0;
			int mips = 1000;
			long size = 10000; // image size (MB)
			int ram = 512; // vm memory (MB)
			long bw = 1000;
			int pesNumber = 1; // number of cpus
			String vmm = "Xen"; // VMM name

			// create VM
			Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());

			// add the VM to the vmList
			vmlist.add(vm);

			// submit vm list to the broker
			broker.submitVmList(vmlist);

			// Fifth step: Create one Cloudlet
			cloudletList = new ArrayList<Cloudlet>();

			// Cloudlet properties
			int id = 0;
			long length = 400000;
			long fileSize = 300;
			long outputSize = 300;
			UtilizationModel utilizationModel = new UtilizationModelFull();

			Cloudlet cloudlet = 
                                new Cloudlet(id, length, pesNumber, fileSize, 
                                        outputSize, utilizationModel, utilizationModel, 
                                        utilizationModel);
			cloudlet.setUserId(brokerId);
			cloudlet.setVmId(vmid);

			// add the cloudlet to the list
			cloudletList.add(cloudlet);

			// submit cloudlet list to the broker
			broker.submitCloudletList(cloudletList);

			// Sixth step: Starts the simulation
			CloudSim.startSimulation();

			CloudSim.stopSimulation();

			//Final step: Print results when simulation is over
			List<Cloudlet> newList = broker.getCloudletReceivedList();
			printCloudletList(newList);

			Log.printLine("CloudSimExample1 finished!");
		} catch (Exception e) {
			e.printStackTrace();
			Log.printLine("Unwanted errors happen");
		}
	}

	/**
	 * Creates the datacenter.
	 *
	 * @param name the name
	 *
	 * @return the datacenter
	 */
	private static Datacenter createDatacenter(String name) {

		// Here are the steps needed to create a PowerDatacenter:
		// 1. We need to create a list to store
		// our machine
		List<Host> hostList = new ArrayList<Host>();

		// 2. A Machine contains one or more PEs or CPUs/Cores.
		// In this example, it will have only one core.
		List<Pe> peList = new ArrayList<Pe>();

		int mips = 1000;

		// 3. Create PEs and add these into a list.
		peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating

		// 4. Create Host with its id and list of PEs and add them to the list
		// of machines
		int hostId = 0;
		int ram = 2048; // host memory (MB)
		long storage = 1000000; // host storage
		int bw = 10000;

		hostList.add(
			new Host(
				hostId,
				new RamProvisionerSimple(ram),
				new BwProvisionerSimple(bw),
				storage,
				peList,
				new VmSchedulerTimeShared(peList)
			)
		); // This is our machine

		// 5. Create a DatacenterCharacteristics object that stores the
		// properties of a data center: architecture, OS, list of
		// Machines, allocation policy: time- or space-shared, time zone
		// and its price (G$/Pe time unit).
		String arch = "x86"; // system architecture
		String os = "Linux"; // operating system
		String vmm = "Xen";
		double time_zone = 10.0; // time zone this resource located
		double cost = 3.0; // the cost of using processing in this resource
		double costPerMem = 0.05; // the cost of using memory in this resource
		double costPerStorage = 0.001; // the cost of using storage in this
										// resource
		double costPerBw = 0.0; // the cost of using bw in this resource
		LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
													// devices by now

		DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
				arch, os, vmm, hostList, time_zone, cost, costPerMem,
				costPerStorage, costPerBw);

		// 6. Finally, we need to create a PowerDatacenter object.
		Datacenter datacenter = null;
		try {
			datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return datacenter;
	}

	// We strongly encourage users to develop their own broker policies, to
	// submit vms and cloudlets according
	// to the specific rules of the simulated scenario
	/**
	 * Creates the broker.
	 *
	 * @return the datacenter broker
	 */
	private static DatacenterBroker createBroker() {
		DatacenterBroker broker = null;
		try {
			broker = new DatacenterBroker("Broker");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return broker;
	}

	/**
	 * Prints the Cloudlet objects.
	 *
	 * @param list list of Cloudlets
	 */
	private static void printCloudletList(List<Cloudlet> list) {
		int size = list.size();
		Cloudlet cloudlet;

		String indent = "    ";
		Log.printLine();
		Log.printLine("========== OUTPUT ==========");
		Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
				+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent
				+ "Start Time" + indent + "Finish Time");

		DecimalFormat dft = new DecimalFormat("###.##");
		for (int i = 0; i < size; i++) {
			cloudlet = list.get(i);
			Log.print(indent + cloudlet.getCloudletId() + indent + indent);

			if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
				Log.print("SUCCESS");

				Log.printLine(indent + indent + cloudlet.getResourceId()
						+ indent + indent + indent + cloudlet.getVmId()
						+ indent + indent
						+ dft.format(cloudlet.getActualCPUTime()) + indent
						+ indent + dft.format(cloudlet.getExecStartTime())
						+ indent + indent
						+ dft.format(cloudlet.getFinishTime()));
			}
		}
	}
}

不过请自行处理一些报错,如包。

云服务(包括数据中心、网络、主机、容器等)创建、使用和展示

更丰富的内容看参考以下文章:(不过这篇文章是关于Gpu的)

GpuCloudSim初探:示例一(一个基于CloudSim关于Gpu和干扰的仿真器)_5-StarrySky的博客-CSDN博客

接着是几个关键类:

Cloudlet : It stores, despite all the information encapsulated in the Cloudlet, the ID of the VM running it.

它的作用是存放所有放在它这里的VM的信息。

Vm: Represents a Virtual Machine (VM) that runs inside a Host, sharing a hostList with other VMs. It processes cloudlets. This processing happens according to a policy, defined by the CloudletScheduler. Each VM has a owner, which can submit cloudlets to the VM to execute them.

VM是虚拟机的简称,它处理云,这些处理按照被CloudletScheduler定义的规则做。每个VM有一个可以提交给cloudlets去执行它们的拥有者

接着我们来看看具体的代码。

首先,

我们初始化了CloudSim library.

CloudSim.init(num_user, calendar, trace_flag);

这三个参数的含义分别为:多少个用户使用实体将会被创建,开启的日期,以及是否跟踪。

接着我们初始化了数据中心

Datacenter datacenter0 = createDatacenter("Datacenter_0");

这个函数的定义在当前文件的下方。我们可以简单的看一看。

首先我们创建了一些列表去放Host,接着创建了Pe列表去做硬件设备的模拟。(不过例子一只有一个)

之后用上述设备创建了Host列表,接着指定了架构和操作系统后创建了数据中心,并返回。

然后创建了broker,数据中心代理。

DatacenterBroker broker = createBroker();

接着创建了一个虚拟机列表,然后使用具体的虚拟机描述参数实例化了一台,让该列表添加了这台机器。

紧接着,提交当前列表给broker托管。

最后我们来配置cloudlet的属性,同样让broker托管。

之后当我们开始cloudsim模拟后,broker就会自动监管。

不过当前的例子较为简单,开始模拟后直接就关闭了。最后我们打印了一些当前broker托管的云。

参考

由于上述都为文字加链接,便利起见,直接放URL.

https://blog.csdn.net/finghting321/article/details/108596803

https://blog.csdn.net/qq_37431461/article/details/122259698

https://blog.csdn.net/u012660464/article/details/114113349

https://blog.csdn.net/qq_41270298/article/details/94865183

https://www.cnblogs.com/amnotgcs/p/15947198.html


[SJ1]

About

cloudsim-4.0, can run all examples.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages