-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgo.java
More file actions
102 lines (84 loc) · 3.93 KB
/
Copy pathalgo.java
File metadata and controls
102 lines (84 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.network.datacenter.NetworkDatacenter;
import org.cloudbus.cloudsim.network.datacenter.NetworkDatacenterCharacteristics;
import org.cloudbus.cloudsim.network.datacenter.NetworkVm;
import org.cloudbus.cloudsim.network.datacenter.NetworkVmAllocationPolicy;
import org.cloudbus.cloudsim.network.datacenter.NetworkVmAllocationPolicySimple;
import org.cloudbus.cloudsim.network.datacenter.NetworkVmSchedulerTimeShared;
import org.cloudbus.cloudsim.network.datacenter.TaskStage;
import org.cloudbus.cloudsim.network.datacenter.TaskStageEvent;
import org.cloudbus.cloudsim.network.datacenter.VirtualMachineState;
import org.cloudbus.cloudsim.network.datacenter.VmPacket;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelDynamic;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RLSVNESimulator {
private static final int NUM_SUBSTRATE_NODES = 10;
private static final int NUM_VIRTUAL_NODES = 5;
private List<NetworkVm> substrateNodes;
private List<NetworkVm> virtualNodes;
public RLSVNESimulator() {
initializeSubstrateNodes();
initializeVirtualNodes();
}
private void initializeSubstrateNodes() {
substrateNodes = new ArrayList<>();
for (int i = 0; i < NUM_SUBSTRATE_NODES; i++) {
NetworkVm node = new NetworkVm(i, 1000, 1, 1, 1, new UtilizationModelFull(), new UtilizationModelDynamic());
substrateNodes.add(node);
}
}
private void initializeVirtualNodes() {
virtualNodes = new ArrayList<>();
for (int i = 0; i < NUM_VIRTUAL_NODES; i++) {
NetworkVm node = new NetworkVm(i + NUM_SUBSTRATE_NODES, 500, 1, 1, 1, new UtilizationModelFull(), new UtilizationModelDynamic());
virtualNodes.add(node);
}
}
public Map<NetworkVm, NetworkVm> RLSVNE() {
Map<NetworkVm, NetworkVm> mapping = new HashMap<>();
for (NetworkVm vnNode : virtualNodes) {
double maxLrd = 0;
NetworkVm maxSnNode = null;
for (NetworkVm snNode : substrateNodes) {
if (snNode.getState() == VirtualMachineState.RUNNING
&& snNode.getCurrentRequestedMips() >= vnNode.getCurrentRequestedMips()
&& snNode.getCurrentAllocatedBw() >= 1) {
double lrd = calculateLinkRelationDegree(vnNode, snNode);
if (lrd > maxLrd) {
maxLrd = lrd;
maxSnNode = snNode;
}
}
}
if (maxSnNode != null) {
mapping.put(vnNode, maxSnNode);
maxSnNode.setCurrentRequestedMips(maxSnNode.getCurrentRequestedMips() - vnNode.getCurrentRequestedMips());
maxSnNode.setCurrentAllocatedBw(maxSnNode.getCurrentAllocatedBw() - 1);
}
}
return mapping;
}
private double calculateLinkRelationDegree(NetworkVm vnNode, NetworkVm snNode) {
double sil = 0;
if (snNode.getVmPacketHandler() != null) {
for (VmPacket packet : snNode.getVmPacketHandler().getVmPacketList()) {
if (packet.getDestId() == vnNode.getId()) {
sil++;
}
}
}
return (sil + 1) * (snNode.getCurrentAllocatedBw() / snNode.getCurrentRequestedMips());
}
public static void main(String[] args) {
RLSVNESimulator simulator = new RLSVNESimulator();
Map<NetworkVm, NetworkVm> mapping = simulator.RLSVNE();
System.out.println("Virtual Node to Substrate Node Mapping:");
for (Map.Entry<NetworkVm, NetworkVm> entry : mapping.entrySet()) {
System.out.println("Virtual Node " + entry.getKey().getId() + " -> Substrate Node " + entry.getValue().getId());
}
}
}