Description: The configuration of network topology in CloudSim using Java, to use the NetworkTopology class provided by CloudSim.
Steps
Network Topology File (topology.brite): Replace this with the path to your BRITE topology file. This file is essential to set up the network structure.
NetworkTopology.addLink: This method sets the latency and bandwidth between different entities like datacenters and brokers.
CloudSim Classes: The code uses CloudSim core classes to create datacenters, hosts, VMs, and network configurations.
Sample Code
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.network.*;
import java.util.*;
public class NetworkTopologyExample {
public static void main(String[] args) {
try {
// Initialize CloudSim library
int numUser = 1; // Number of cloud users
Calendar calendar = Calendar.getInstance();
boolean traceFlag = false;
CloudSim.init(numUser, calendar, traceFlag);
// Create Datacenter
Datacenter datacenter0 = createDatacenter("Datacenter_0");
// Create broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
// Create virtual machines and cloudlets
List vmList = createVMs(brokerId, 3);
List cloudletList = createCloudlets(brokerId, 5);
broker.submitVmList(vmList);
broker.submitCloudletList(cloudletList);
// Configure network topology
NetworkTopology.buildNetworkTopology("RTFile.brite"); // Use BRITE file for topology
// Set latencies between entities
int datacenterId = datacenter0.getId();
NetworkTopology.addLink(datacenterId, brokerId, 10.0, 5000); // 10ms latency, 5000 BW
// Start simulation
CloudSim.startSimulation();
CloudSim.stopSimulation();
// Print results
List newList = broker.getCloudletReceivedList();
printCloudletList(newList);
System.out.println("Simulation finished!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("Simulation terminated due to an unexpected error.");
}
}
private static Datacenter createDatacenter(String name) {
List hostList = new ArrayList<>();
List peList = new ArrayList<>();
peList.add(new Pe(0, new PeProvisionerSimple(1000))); // 1000 MIPS per core
int hostId = 0;
int ram = 2048; // 2 GB
long storage = 100000; // 100 GB
int bw = 10000; // 10 Gbps
hostList.add(new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerTimeShared(peList)
));
String arch = "x86";
String os = "Linux";
String vmm = "Xen";
double timeZone = 10.0;
double cost = 3.0;
double costPerMem = 0.05;
double costPerStorage = 0.1;
double costPerBw = 0.1;
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, timeZone, cost, costPerMem, costPerStorage, costPerBw);
return new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), new LinkedList<>(), 0);
}
private static DatacenterBroker createBroker() {
DatacenterBroker broker = null;
try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}
private static List createVMs(int brokerId, int numVMs) {
List vms = new ArrayList<>();
for (int i = 0; i < numVMs; i++) {
Vm vm = new Vm(i, brokerId, 1000, 1, 512, 1000, 10000, "Xen", new CloudletSchedulerTimeShared());
vms.add(vm);
}
return vms;
}
private static List createCloudlets(int brokerId, int numCloudlets) {
List cloudlets = new ArrayList<>();
for (int i = 0; i < numCloudlets; i++) {
Cloudlet cloudlet = new Cloudlet(i, 40000, 1, 300, 300, new UtilizationModelFull(),
new UtilizationModelFull(), new UtilizationModelFull());
cloudlet.setUserId(brokerId);
cloudlets.add(cloudlet);
}
return cloudlets;
}
private static void printCloudletList(List list) {
String indent = " ";
System.out.println("========== OUTPUT ==========");
System.out.println("Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
for (Cloudlet cloudlet : list) {
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
System.out.println(cloudlet.getCloudletId() + indent + "SUCCESS" + indent + cloudlet.getResourceId() +
indent + cloudlet.getVmId() + indent + cloudlet.getActualCPUTime() + indent +
cloudlet.getExecStartTime() + indent + cloudlet.getFinishTime());
}
}
}
}
ScreenShots
Process the "RTFile.brite" file to configure the network topology.