3 import org.simgrid.msg.Host;
4 import org.simgrid.msg.HostNotFoundException;
5 import org.simgrid.msg.Msg;
6 import org.simgrid.msg.NativeException;
8 import peersim.core.CommonState;
9 import peersim.core.Network;
10 import peersim.core.Node;
13 * This is the main entry point to Simgrid simulator. This class loads the
14 * different parameters and initializes the simulation.
16 * @author Khaled Baati 14/10/2014
17 * @version version 1.1
19 public class PSGSimulator {
20 public static int size;
24 size = Network.size();
27 // ========================== methods ==================================
28 // =====================================================================
31 * Adds a new event to be scheduled, specifying the number of time units of
32 * delay (in seconds), the node and the protocol identifier to which the
33 * event will be delivered. A {@link psgsim.PSGProcessLauncher} process will
34 * be created according to this event.
37 * The number of time units (seconds in simgrid) before the event
40 * The object associated to this event
42 * The node associated to the event.
44 * The identifier of the protocol to which the event will be
47 public static void add(long delay, Object event, Node src, int pid) {
48 Host host = NodeHost.getHost(src);
49 double startTime = PSGPlatform.psToSgTime(delay) + Msg.getClock();
50 if (startTime < PSGPlatform.psToSgTime(PSGPlatform.getDuration()) ) {
53 * random instruction associated to Heap.add(...) method in
56 CommonState.r.nextInt(1 << 8);
57 new PSGProcessLauncher(host, host.getName(), startTime, event,
59 } catch (HostNotFoundException e) {
60 System.err.println("Host not found");
66 // ========================== main method ==================================
67 // =====================================================================
68 public static void main() throws NativeException, HostNotFoundException {
70 String platformfile = PSGPlatform.platformFile();
71 System.err.println(platformfile + " loaded");
72 String[] arguments = { platformfile, "deployment.xml" };
75 /** construct the platform */
76 Msg.createEnvironment(arguments[0]);
78 PSGPlatform.protocols();
80 /** deploy the application **/
81 Msg.deployApplication(arguments[1]);
83 /** construct the host-node mapping **/
86 /** Process Controller **/
87 PSGPlatform.control();
88 new PSGProcessController(PSGPlatform.hostList[0],
89 PSGPlatform.hostList[0].getName(), null).start();
91 /** Load and execute the initializers classes in the configuration file **/
94 PSGPlatform.delete("deployment.xml");
95 /** execute the simulation. **/