From: Martin Quinson Date: Wed, 17 Feb 2016 18:00:28 +0000 (+0100) Subject: Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid X-Git-Tag: v3_13~797^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/946b604fdce1a3ca5bfd2f512aa69d78b3259a13?hp=7e8ebb31f1398dde2eb6ffc16a20a7f3a1063fd6 Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid --- diff --git a/doc/HelloWorld/CMakeLists.txt b/doc/HelloWorld/CMakeLists.txt deleted file mode 100644 index 02d42f5c9f..0000000000 --- a/doc/HelloWorld/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -### This is a template for building targets with simgrid -cmake_minimum_required(VERSION 2.8) - -### Need to set rc ccompiler before enable language -if(WIN32) - SET(CMAKE_RC_COMPILER "windres") - set(LIBRARIES_DEP simgrid ws2_32 pthread) -else() - set(LIBRARIES_DEP simgrid pthread) -endif() - -project(MY_SIMGRID_PROJECT C) - -set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE) -set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE) - -############################### -# Test the build dependencies # -############################### -message(STATUS "Looking for lib Simgrid") -if("$ENV{SIMGRID_ROOT}" STREQUAL "") - message(STATUS "Looking for lib Simgrid - Not found") - message(FATAL_ERROR "Simgrid not found, reinstall it or set SIMGRID_ROOT") -else() - link_directories($ENV{SIMGRID_ROOT}/lib) - include_directories($ENV{SIMGRID_ROOT}/include) - include_directories($ENV{SIMGRID_ROOT}/src) - include_directories($ENV{SIMGRID_ROOT}/src/include) - message(STATUS "Looking for lib Simgrid - found") -endif() - -################ -# FIND TARGETS # -################ -file(GLOB SOURCE_FILE - RELATIVE ${CMAKE_HOME_DIRECTORY}/ - "*.c" - ) -string(REPLACE ".c" "" TARGET_NAME ${SOURCE_FILE}) - -foreach(target "${TARGET_NAME}") - add_executable(${target} "${target}.c") - message(STATUS "source_file: ${target}.c") - message(STATUS "target name: ${target}.exe") - # Any targets need to be linked with libraries - target_link_libraries(${target} ${LIBRARIES_DEP}) -endforeach(target ${SOURCE_FILE}) diff --git a/doc/HelloWorld/HelloWorld.c b/doc/HelloWorld/HelloWorld.c deleted file mode 100644 index 72c6d04ad6..0000000000 --- a/doc/HelloWorld/HelloWorld.c +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (c) 2011-2012, 2014. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include -#include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(HelloWorld, - "Messages specific for this Hello World example"); -void main() -{ - XBT_INFO("Hello World !!!"); -} diff --git a/doc/HelloWorld/README b/doc/HelloWorld/README deleted file mode 100644 index 67b0585fd9..0000000000 --- a/doc/HelloWorld/README +++ /dev/null @@ -1,32 +0,0 @@ -This is a very simple example to explain how to compile with simgrid. - -1) How to compile an example: (HelloWorld) - -- Run windows shell "cmd". -- Open HelloWorld Directory ('cd' command line). -- Create a build directory and change directory. (optional) -- Type 'cmake -G"MinGW Makefiles" ' -- Run mingw32-make -- You should obtain a runnable example ("HelloWorld.exe"). - -2) Content of this directory - -- HelloWorld.c - The example source file. -- CMakeLists.txt - It allows to configure the project. -- README - This explaination. - -3) How to add and compile a new example - -- Put your source file into the helloWord directory. -- Edit CMakeLists.txt : - * In the Targets section add those two lines: - add_executable(TARGET_NAME SOURCES) - target_link_libraries(TARGET_NAME simgrid) - * It creates a target called 'TARGET_NAME.exe' with the sources 'SOURCES'. -- To initialize your project, you'll need to run 'cmake -G"Unix Makefiles" .' -- To build you project, run "cmake ." -- Run "gmake" -- You should obtain "TARGET_NAME.exe". \ No newline at end of file diff --git a/examples/java/async/AsyncTest.java b/examples/java/async/AsyncTest.java index 983fecd64a..0c6d1fecde 100644 --- a/examples/java/async/AsyncTest.java +++ b/examples/java/async/AsyncTest.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,28 +10,20 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class AsyncTest { - - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - - if (args.length < 2) { - Msg.info("Usage : Async platform_file deployment_file"); - Msg.info("example : Async basic_platform.xml basic_deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); - } + public static void main(String[] args) throws NativeException { + Msg.init(args); + + if (args.length < 2) { + Msg.info("Usage : AsyncTest platform_file deployment_file"); + Msg.info("example : AsyncTest ../platforms/platform.xml asyncDeployment.xml"); + System.exit(1); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/async/CMakeLists.txt b/examples/java/async/CMakeLists.txt index 25d266cc3a..6aa09feac5 100644 --- a/examples/java/async/CMakeLists.txt +++ b/examples/java/async/CMakeLists.txt @@ -32,9 +32,6 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/README diff --git a/examples/java/async/FinalizeTask.java b/examples/java/async/FinalizeTask.java index 1e7b43923e..39b1a4f9b6 100644 --- a/examples/java/async/FinalizeTask.java +++ b/examples/java/async/FinalizeTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,9 +7,8 @@ package async; import org.simgrid.msg.Task; -public class FinalizeTask extends Task { - public FinalizeTask() { - super("finalize",0,0); - } +public class FinalizeTask extends Task { + public FinalizeTask() { + super("finalize",0,0); + } } - \ No newline at end of file diff --git a/examples/java/async/Forwarder.java b/examples/java/async/Forwarder.java index fbf394faf0..965bb8c72f 100644 --- a/examples/java/async/Forwarder.java +++ b/examples/java/async/Forwarder.java @@ -1,57 +1,57 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package async; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; - +import org.simgrid.msg.MsgException; public class Forwarder extends Process { - public Forwarder(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - if (args.length < 3) { - Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)"); - Msg.info("Got "+args.length+" instead"); - System.exit(1); - } - int input = Integer.valueOf(args[0]).intValue(); - int firstOutput = Integer.valueOf(args[1]).intValue(); - int lastOutput = Integer.valueOf(args[2]).intValue(); - - int taskCount = 0; - int slavesCount = lastOutput - firstOutput + 1; - Msg.info("Receiving on 'slave_"+input+"'"); - while(true) { - Task task = Task.receive("slave_"+input); - - if (task instanceof FinalizeTask) { - Msg.info("Got a finalize task. Let's forward (asynchronously) that we're done, and then sleep 20 seconds so that nobody gets a message from a terminated process."); - - for (int cpt = firstOutput; cpt<=lastOutput; cpt++) { - Task tf = new FinalizeTask(); - tf.dsend("slave_"+cpt); - } - waitFor(20); - break; - } - int dest = firstOutput + (taskCount % slavesCount); - - Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\""); - task.send("slave_"+dest); - - taskCount++; - } - - - Msg.info("I'm done. See you!"); - } + public Forwarder(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + if (args.length < 3) { + Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)"); + Msg.info("Got "+args.length+" instead"); + System.exit(1); + } + int input = Integer.valueOf(args[0]).intValue(); + int firstOutput = Integer.valueOf(args[1]).intValue(); + int lastOutput = Integer.valueOf(args[2]).intValue(); + + int taskCount = 0; + int slavesCount = lastOutput - firstOutput + 1; + Msg.info("Receiving on 'slave_"+input+"'"); + while(true) { + Task task = Task.receive("slave_"+input); + + if (task instanceof FinalizeTask) { + Msg.info("Got a finalize task. Let's forward (asynchronously) that we're done, and then sleep 20 seconds"+ + " so that nobody gets a message from a terminated process."); + + for (int cpt = firstOutput; cpt<=lastOutput; cpt++) { + Task tf = new FinalizeTask(); + tf.dsend("slave_"+cpt); + } + waitFor(20); + break; + } + int dest = firstOutput + (taskCount % slavesCount); + + Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\""); + task.send("slave_"+dest); + + taskCount++; + } + + Msg.info("I'm done. See you!"); + } } diff --git a/examples/java/async/Master.java b/examples/java/async/Master.java index 4960b75645..19e66ea9ff 100644 --- a/examples/java/async/Master.java +++ b/examples/java/async/Master.java @@ -1,6 +1,4 @@ -/* Master of a basic master/slave example in Java */ - -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -9,63 +7,63 @@ package async; import java.util.ArrayList; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Master extends Process { - public Master(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - if (args.length < 4) { - Msg.info("Master needs 4 arguments"); - System.exit(1); - } + public Master(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + if (args.length < 4) { + Msg.info("Master needs 4 arguments"); + System.exit(1); + } + + int tasksCount = Integer.valueOf(args[0]).intValue(); + double taskComputeSize = Double.valueOf(args[1]).doubleValue(); + double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); + + int slavesCount = Integer.valueOf(args[3]).intValue(); - int tasksCount = Integer.valueOf(args[0]).intValue(); - double taskComputeSize = Double.valueOf(args[1]).doubleValue(); - double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); + Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); + ArrayList comms = new ArrayList(); - int slavesCount = Integer.valueOf(args[3]).intValue(); + for (int i = 0; i < tasksCount; i++) { + Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); + Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\""); + Comm comm = task.isend("slave_"+(i%slavesCount)); + comms.add(comm); + } - Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); - ArrayList comms = new ArrayList(); - - for (int i = 0; i < tasksCount; i++) { - Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); - Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\""); - //task.send("slave_"+(i%slavesCount)); - Comm comm = task.isend("slave_"+(i%slavesCount)); - comms.add(comm); - } - - while (comms.size() > 0) { - for (int i = 0; i < comms.size(); i++) { - try { - if (comms.get(i).test()) { - comms.remove(i); - i--; - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - waitFor(1); - } - - Msg.info("All tasks have been dispatched. Let's tell (asynchronously) everybody the computation is over, and sleep 20s so that nobody gets a message from a terminated process."); + while (comms.size() > 0) { + for (int i = 0; i < comms.size(); i++) { + try { + if (comms.get(i).test()) { + comms.remove(i); + i--; + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + waitFor(1); + } + Msg.info("All tasks have been dispatched. Let's tell (asynchronously) everybody the computation is over,"+ + " and sleep 20s so that nobody gets a message from a terminated process."); - for (int i = 0; i < slavesCount; i++) { - FinalizeTask task = new FinalizeTask(); - task.dsend("slave_"+(i%slavesCount)); - } - waitFor(20); + for (int i = 0; i < slavesCount; i++) { + FinalizeTask task = new FinalizeTask(); + task.dsend("slave_"+(i%slavesCount)); + } + waitFor(20); - Msg.info("Goodbye now!"); - } + Msg.info("Goodbye now!"); + } } diff --git a/examples/java/async/Slave.java b/examples/java/async/Slave.java index 1d4f5679cc..3d32d2a0e2 100644 --- a/examples/java/async/Slave.java +++ b/examples/java/async/Slave.java @@ -1,67 +1,64 @@ -/* Copyright (c) 2006-2007, 2010, 2013-2014. The SimGrid Team. +/* Copyright (c) 2006-2007, 2010, 2013-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package async; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.HostFailureException; -import org.simgrid.msg.Msg; -import org.simgrid.msg.Process; import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.HostFailureException; import org.simgrid.msg.TaskCancelledException; import org.simgrid.msg.TimeoutException; import org.simgrid.msg.TransferFailureException; public class Slave extends Process { - public Slave(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { - if (args.length < 1) { - Msg.info("Slave needs 1 argument (its number)"); - System.exit(1); - } + public Slave(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { + if (args.length < 1) { + Msg.info("Slave needs 1 argument (its number)"); + System.exit(1); + } + int num = Integer.valueOf(args[0]).intValue(); + Comm comm = null; + boolean slaveFinished = false; + while(!slaveFinished) { + try { + if (comm == null) { + Msg.info("Receiving on 'slave_" + num + "'"); + comm = Task.irecv("slave_" + num); + } else { + if (comm.test()) { + Task task = comm.getTask(); - int num = Integer.valueOf(args[0]).intValue(); - Comm comm = null; - boolean slaveFinished = false; - while(!slaveFinished) { - try - { - if (comm == null) { - Msg.info("Receiving on 'slave_" + num + "'"); - comm = Task.irecv("slave_" + num); - } - else { - if (comm.test()) { - Task task = comm.getTask(); - - if (task instanceof FinalizeTask) { - comm = null; - break; - } - Msg.info("Received a task"); - Msg.info("Received \"" + task.getName() + "\". Processing it."); - try { - task.execute(); - } catch (TaskCancelledException e) { - - } - comm = null; - } - else { - waitFor(1); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - Msg.info("Received Finalize. I'm done. See you!"); - waitFor(20); - } + if (task instanceof FinalizeTask) { + comm = null; + break; + } + Msg.info("Received a task"); + Msg.info("Received \"" + task.getName() + "\". Processing it."); + try { + task.execute(); + } catch (TaskCancelledException e) { + + } + comm = null; + } else { + waitFor(1); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + Msg.info("Received Finalize. I'm done. See you!"); + waitFor(20); + } } \ No newline at end of file diff --git a/examples/java/async/asyncDeployment.xml b/examples/java/async/asyncDeployment.xml index 0ec92a0c5d..7ef4d13b62 100644 --- a/examples/java/async/asyncDeployment.xml +++ b/examples/java/async/asyncDeployment.xml @@ -7,7 +7,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/examples/java/bittorrent/Bittorrent.java b/examples/java/bittorrent/Bittorrent.java index b488195123..7478c3c34c 100644 --- a/examples/java/bittorrent/Bittorrent.java +++ b/examples/java/bittorrent/Bittorrent.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014,2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,21 +10,19 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; public class Bittorrent { - public static void main(String[] args) throws MsgException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : Bittorrent platform_file deployment_file"); - Msg.info("example : Bittorrent platform.xml deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); - } + public static void main(String[] args) throws MsgException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Bittorrent platform_file deployment_file"); + Msg.info("example : Bittorrent ../platforms/platform.xml bittorrent.xml"); + System.exit(1); + } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/bittorrent/CMakeLists.txt b/examples/java/bittorrent/CMakeLists.txt index 8fe864c52a..6d7c80e7ab 100644 --- a/examples/java/bittorrent/CMakeLists.txt +++ b/examples/java/bittorrent/CMakeLists.txt @@ -34,9 +34,6 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/generate.py diff --git a/examples/java/bittorrent/Common.java b/examples/java/bittorrent/Common.java index 1fe856e3da..2f030f3339 100644 --- a/examples/java/bittorrent/Common.java +++ b/examples/java/bittorrent/Common.java @@ -1,63 +1,36 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package bittorrent; -/** - * Common constants for use in the simulation - */ -public class Common { - - public static String TRACKER_MAILBOX = "tracker_mailbox"; - - public static int FILE_SIZE = 5120; - public static int FILE_PIECE_SIZE = 512; - public static int FILE_PIECES = 10; - public static int PIECES_BLOCKS = 5; - - public static int BLOCKS_REQUESTED = 2; - - public static int PIECE_COMM_SIZE = 1; - /** - * Information message size - */ - public static int MESSAGE_SIZE = 1; - /** - * Max number of pairs sent by the tracker to clients - */ - public static int MAXIMUM_PEERS = 50; - /** - * Interval of time where the peer should send a request to the tracker - */ - public static int TRACKER_QUERY_INTERVAL = 1000; - /** - * Communication size for a task to the tracker - */ - public static double TRACKER_COMM_SIZE = 0.01; - /** - * Timeout for the get peers data - */ - public static int GET_PEERS_TIMEOUT = 10000; - /** - * Timeout for "standard" messages. - */ - public static int TIMEOUT_MESSAGE = 10; - /** - * Timeout for tracker receive. - */ - public static int TRACKER_RECEIVE_TIMEOUT = 10; - /** - * Number of peers that can be unchocked at a given time - */ - public static int MAX_UNCHOKED_PEERS = 4; - /** - * Interval between each update of the choked peers - */ - public static int UPDATE_CHOKED_INTERVAL = 30; - /** - * Number of pieces the peer asks for simultaneously - */ - public static int MAX_PIECES = 1; + +/* Common constants for use in the simulation */ +public class Common { + public static String TRACKER_MAILBOX = "tracker_mailbox"; + public static int FILE_SIZE = 5120; + public static int FILE_PIECE_SIZE = 512; + public static int FILE_PIECES = 10; + public static int PIECES_BLOCKS = 5; + public static int BLOCKS_REQUESTED = 2; + public static int PIECE_COMM_SIZE = 1; + /* Information message size */ + public static int MESSAGE_SIZE = 1; + /* Max number of peers sent by the tracker to clients */ + public static int MAXIMUM_PEERS = 50; + /* Interval of time where the peer should send a request to the tracker */ + public static int TRACKER_QUERY_INTERVAL = 1000; + /* Communication size for a task to the tracker */ + public static double TRACKER_COMM_SIZE = 0.01; + /* Timeout for the get peers data */ + public static int GET_PEERS_TIMEOUT = 10000; + public static int TIMEOUT_MESSAGE = 10; + public static int TRACKER_RECEIVE_TIMEOUT = 10; + /* Number of peers that can be unchocked at a given time */ + public static int MAX_UNCHOKED_PEERS = 4; + /* Interval between each update of the choked peers */ + public static int UPDATE_CHOKED_INTERVAL = 30; + /* Number of pieces the peer asks for simultaneously */ + public static int MAX_PIECES = 1; } diff --git a/examples/java/bittorrent/Connection.java b/examples/java/bittorrent/Connection.java index 4ca20fd2e2..ff15fd34a1 100644 --- a/examples/java/bittorrent/Connection.java +++ b/examples/java/bittorrent/Connection.java @@ -1,77 +1,44 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package bittorrent; - import java.util.Arrays; + public class Connection { - /** - * Remote peer id - */ - public int id; - /** - * Remote peer bitfield. - */ - public char bitfield[]; - /** - * Remote peer mailbox - */ - public String mailbox; - /** - * Indicates if we are interested in something this peer has - */ - public boolean amInterested = false; - /** - * Indicates if the peer is interested in one of our pieces - */ - public boolean interested = false; - /** - * Indicates if the peer is choked for the current peer - */ - public boolean chokedUpload = true; - /** - * Indicates if the peer has choked the current peer - */ - public boolean chokedDownload = true; - /** - * Number of messages we have received from the peer - */ - public int messagesCount = 0; - /** - * Peer speed. - */ - public double peerSpeed = 0; - /** - * Last time the peer was unchoked - */ - public double lastUnchoke = 0; - /** - * Constructor - */ - public Connection(int id) { - this.id = id; - this.mailbox = Integer.toString(id); - } - /** - * Add a new value to the peer speed average - */ - public void addSpeedValue(double speed) { - peerSpeed = peerSpeed * 0.55 + speed * 0.45; - // peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount); - } - - @Override - public String toString() { - return "Connection [id=" + id + ", bitfield=" - + Arrays.toString(bitfield) + ", mailbox=" + mailbox - + ", amInterested=" + amInterested + ", interested=" - + interested + ", chokedUpload=" + chokedUpload - + ", chokedDownload=" + chokedDownload + "]"; - } - - + public int id; + public char bitfield[]; + public String mailbox; + // Indicates if we are interested in something this peer has + public boolean amInterested = false; + // Indicates if the peer is interested in one of our pieces + public boolean interested = false; + // Indicates if the peer is choked for the current peer + public boolean chokedUpload = true; + // Indicates if the peer has choked the current peer + public boolean chokedDownload = true; + // Number of messages we have received from the peer + public int messagesCount = 0; + public double peerSpeed = 0; + public double lastUnchoke = 0; + + public Connection(int id) { + this.id = id; + this.mailbox = Integer.toString(id); + } + + // Add a new value to the peer speed average + public void addSpeedValue(double speed) { + peerSpeed = peerSpeed * 0.55 + speed * 0.45; + // peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount); + } + + @Override + public String toString() { + return "Connection [id=" + id + ", bitfield=" + Arrays.toString(bitfield) + ", mailbox=" + mailbox + + ", amInterested=" + amInterested + ", interested=" + interested + ", chokedUpload=" + chokedUpload + + ", chokedDownload=" + chokedDownload + "]"; + } } - \ No newline at end of file diff --git a/examples/java/bittorrent/MessageTask.java b/examples/java/bittorrent/MessageTask.java index 3c98d15eed..b204ff9d9f 100644 --- a/examples/java/bittorrent/MessageTask.java +++ b/examples/java/bittorrent/MessageTask.java @@ -1,81 +1,65 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package bittorrent; - import org.simgrid.msg.Task; -/** - * Tasks sent between peers - */ + public class MessageTask extends Task { - public enum Type { - HANDSHAKE, - CHOKE, - UNCHOKE, - INTERESTED, - NOTINTERESTED, - HAVE, - BITFIELD, - REQUEST, - PIECE - }; - public Type type; - public String issuerHostname; - public String mailbox; - public int peerId; - public char bitfield[]; - public int index; - public int blockIndex; - public int blockLength; - public boolean stalled; - /** - * Constructor, builds a value-less message - * @param type - * @param issuerHostname - * @param mailbox - * @param peerId - */ - public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) { - this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1); - } - /** - * Constructor, builds a new "have/request/piece" message - * @param type - * @param issuerHostname - * @param mailbox - * @param peerId - * @param index - */ - public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) { - this(type,issuerHostname,mailbox,peerId,index,false,-1,-1); - } - /** - * Constructor, builds a new bitfield message - */ - public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char bitfield[]) { - this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1); - this.bitfield = bitfield; - } - /** - * Constructor, build a new "request" message - */ - public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, int blockIndex, int blockLength) { - this(type,issuerHostname,mailbox,peerId,index,false,blockIndex,blockLength); - } - /** - * Constructor, build a new "piece" message - */ - public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled, int blockIndex, int blockLength) { - this.type = type; - this.issuerHostname = issuerHostname; - this.mailbox = mailbox; - this.peerId = peerId; - this.index = index; - this.stalled = stalled; - this.blockIndex = blockIndex; - this.blockLength = blockLength; - } + public enum Type { + HANDSHAKE, + CHOKE, + UNCHOKE, + INTERESTED, + NOTINTERESTED, + HAVE, + BITFIELD, + REQUEST, + PIECE + }; + + public Type type; + public String issuerHostname; + public String mailbox; + public int peerId; + public char bitfield[]; + public int index; + public int blockIndex; + public int blockLength; + public boolean stalled; + + public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) { + this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1); + } + + public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) { + this(type,issuerHostname,mailbox,peerId,index,false,-1,-1); + } + + // builds a new bitfield message + public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char bitfield[]) { + this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1); + this.bitfield = bitfield; + } + + // build a new "request" message + public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, int blockIndex, + int blockLength) { + this(type,issuerHostname,mailbox,peerId,index,false,blockIndex,blockLength); + } + + // build a new "piece" message + public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled, + int blockIndex, int blockLength) { + this.type = type; + this.issuerHostname = issuerHostname; + this.mailbox = mailbox; + this.peerId = peerId; + this.index = index; + this.stalled = stalled; + this.blockIndex = blockIndex; + this.blockLength = blockLength; + } } diff --git a/examples/java/bittorrent/Peer.java b/examples/java/bittorrent/Peer.java index 569e8b88b8..53fe246000 100644 --- a/examples/java/bittorrent/Peer.java +++ b/examples/java/bittorrent/Peer.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -11,678 +11,621 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Task; import org.simgrid.msg.Process; import org.simgrid.msg.RngStream; -import org.simgrid.msg.Task; +import org.simgrid.msg.MsgException; -/** - * Main class for peers execution - */ public class Peer extends Process { - protected int round = 0; - - protected double beginReceiveTime; - protected double deadline; - - protected static RngStream stream = new RngStream(); - - protected int id; - protected String mailbox; - protected String mailboxTracker; - protected String hostname; - protected int pieces = 0; - protected char[] bitfield = new char[Common.FILE_PIECES]; - protected char[][] bitfieldBlocks = new char[Common.FILE_PIECES][Common.PIECES_BLOCKS]; - - protected short[] piecesCount = new short[Common.FILE_PIECES]; - - protected int piecesRequested = 0; - - protected ArrayList currentPieces = new ArrayList(); - protected int currentPiece = -1; - - protected HashMap activePeers = new HashMap(); - protected HashMap peers = new HashMap(); - - protected Comm commReceived = null; - - public Peer(Host host, String name, String[]args) { - super(host,name,args); - } - - @Override - public void main(String[] args) throws MsgException { - //Check arguments - if (args.length != 3 && args.length != 2) { - Msg.info("Wrong number of arguments"); - } - if (args.length == 3) { - init(Integer.valueOf(args[0]),true); - } - else { - init(Integer.valueOf(args[0]),false); - } - //Retrieve the deadline - deadline = Double.valueOf(args[1]); - if (deadline < 0) { - Msg.info("Wrong deadline supplied"); - return; - } - Msg.info("Hi, I'm joining the network with id " + id); - //Getting peer data from the tracker - if (getPeersData()) { - Msg.debug("Got " + peers.size() + " peers from the tracker"); - Msg.debug("Here is my current status: " + getStatus()); - beginReceiveTime = Msg.getClock(); - if (hasFinished()) { - pieces = Common.FILE_PIECES; - sendHandshakeAll(); - seedLoop(); - } - else { - leechLoop(); - seedLoop(); - } - } - else { - Msg.info("Couldn't contact the tracker."); - } - Msg.info("Here is my current status: " + getStatus()); - } - /** - * Peer main loop when it is leeching. - */ - private void leechLoop() { - double nextChokedUpdate = Msg.getClock() + Common.UPDATE_CHOKED_INTERVAL; - Msg.debug("Start downloading."); - /** - * Send a "handshake" message to all the peers it got - * (it couldn't have gotten more than 50 peers anyway) - */ - sendHandshakeAll(); - //Wait for at least one "bitfield" message. - waitForPieces(); - Msg.debug("Starting main leech loop"); - while (Msg.getClock() < deadline && pieces < Common.FILE_PIECES) { - if (commReceived == null) { - commReceived = Task.irecv(mailbox); - } - try { - if (commReceived.test()) { - handleMessage(commReceived.getTask()); - commReceived = null; - } - else { - //If the user has a pending interesting - if (currentPiece != -1) { - sendInterestedToPeers(); - } - else { - if (currentPieces.size() < Common.MAX_PIECES) { - updateCurrentPiece(); - } - } - //We don't execute the choke algorithm if we don't already have a piece - if (Msg.getClock() >= nextChokedUpdate && pieces > 0) { - updateChokedPeers(); - nextChokedUpdate += Common.UPDATE_CHOKED_INTERVAL; - } - else { - waitFor(1); - } - } - } - catch (MsgException e) { - commReceived = null; - } - } - } - - /** - * Peer main loop when it is seeding - */ - private void seedLoop() { - double nextChokedUpdate = Msg.getClock() + Common.UPDATE_CHOKED_INTERVAL; - Msg.debug("Start seeding."); - //start the main seed loop - while (Msg.getClock() < deadline) { - if (commReceived == null) { - commReceived = Task.irecv(mailbox); - } - try { - if (commReceived.test()) { - handleMessage(commReceived.getTask()); - commReceived = null; - } - else { - if (Msg.getClock() >= nextChokedUpdate) { - updateChokedPeers(); - //TODO: Change the choked peer algorithm when seeding - nextChokedUpdate += Common.UPDATE_CHOKED_INTERVAL; - } - else { - waitFor(1); - } - } - } - catch (MsgException e) { - commReceived = null; - } - - } - } - - /** - * Initialize the various peer data - * @param id id of the peer to take in the network - * @param seed indicates if the peer is a seed - */ - private void init(int id, boolean seed) { - this.id = id; - this.mailbox = Integer.toString(id); - this.mailboxTracker = "tracker_" + Integer.toString(id); - if (seed) { - for (int i = 0; i < bitfield.length; i++) { - bitfield[i] = '1'; - for (int j = 0; j < bitfieldBlocks[i].length; j++) { - bitfieldBlocks[i][j] = '1'; - } - } - } - else { - for (int i = 0; i < bitfield.length; i++) { - bitfield[i] = '0'; - for (int j = 0; j < bitfieldBlocks[i].length; j++) { - bitfieldBlocks[i][j] = '0' ; - } - } - } - this.hostname = getHost().getName(); - } - /** - * Retrieves the peer list from the tracker - */ - private boolean getPeersData() { - - boolean success = false, sendSuccess = false; - double timeout = Msg.getClock() + Common.GET_PEERS_TIMEOUT; - //Build the task to send to the tracker - TrackerTask taskSend = new TrackerTask(hostname, mailboxTracker, id); - - while (!sendSuccess && Msg.getClock() < timeout) { - try { - Msg.debug("Sending a peer request to the tracker."); - taskSend.send(Common.TRACKER_MAILBOX,Common.GET_PEERS_TIMEOUT); - sendSuccess = true; - } - catch (MsgException e) { - - } - } - while (!success && Msg.getClock() < timeout) { - commReceived = Task.irecv(this.mailboxTracker); - try { - commReceived.waitCompletion(Common.GET_PEERS_TIMEOUT); - if (commReceived.getTask() instanceof TrackerTask) { - TrackerTask task = (TrackerTask)commReceived.getTask(); - for (Integer peerId: task.peers) { - if (peerId != this.id) { - peers.put(peerId, new Connection(peerId)); - } - } - success = true; - } - } - catch (MsgException e) { - - } - commReceived = null; - } - commReceived = null; - return success; - } - /** - * Handle a received message sent by another peer - * @param task task received. - */ - void handleMessage(Task task) { - MessageTask message = (MessageTask)task; - Connection remotePeer = peers.get(message.peerId); - switch (message.type) { - case HANDSHAKE: - Msg.debug("Received a HANDSHAKE message from " + message.mailbox); - //Check if the peer is in our connection list - if (remotePeer == null) { - peers.put(message.peerId, new Connection(message.peerId)); - sendHandshake(message.mailbox); - } - //Send our bitfield to the pair - sendBitfield(message.mailbox); - break; - case BITFIELD: - Msg.debug("Received a BITFIELD message from " + message.peerId + " (" + message.issuerHostname + ")"); - //update the pieces list - updatePiecesCountFromBitfield(message.bitfield); - //Update the current piece - if (currentPiece == -1 && pieces < Common.FILE_PIECES && currentPieces.size() < Common.MAX_PIECES) { - updateCurrentPiece(); - } - remotePeer.bitfield = message.bitfield.clone(); - break; - case INTERESTED: - Msg.debug("Received an INTERESTED message from " + message.peerId + " (" + message.issuerHostname + ")"); - assert remotePeer != null; - remotePeer.interested = true; - break; - case NOTINTERESTED: - Msg.debug("Received a NOTINTERESTED message from " + message.peerId + " (" + message.issuerHostname + ")"); - assert remotePeer != null; - remotePeer.interested = false; - break; - case UNCHOKE: - Msg.debug("Received an UNCHOKE message from " + message.peerId + "(" + message.issuerHostname + ")"); - assert remotePeer != null; - remotePeer.chokedDownload = false; - activePeers.put(remotePeer.id,remotePeer); - sendRequestsToPeer(remotePeer); - break; - case CHOKE: - Msg.debug("Received a CHOKE message from " + message.peerId + " (" + message.issuerHostname + ")"); - assert remotePeer != null; - remotePeer.chokedDownload = true; - activePeers.remove(remotePeer.id); - break; - case HAVE: - if (remotePeer.bitfield == null) { - return; - } - Msg.debug("Received a HAVE message from " + message.peerId + " (" + message.issuerHostname + ")"); - assert message.index >= 0 && message.index < Common.FILE_PIECES; - assert remotePeer.bitfield != null; - remotePeer.bitfield[message.index] = '1'; - piecesCount[message.index]++; - //Send interested message to the peer if he has what we want - if (!remotePeer.amInterested && currentPieces.contains(message.index) ) { - remotePeer.amInterested = true; - sendInterested(remotePeer.mailbox); - } - - if (currentPieces.contains(message.index)) { - int blockIndex = getFirstBlock(message.index); - int blockLength = Common.PIECES_BLOCKS - blockIndex ; - blockLength = blockLength > Common.BLOCKS_REQUESTED ? Common.BLOCKS_REQUESTED : blockLength; - sendRequest(message.mailbox,message.index,blockIndex,blockLength); - } - break; - case REQUEST: - assert message.index >= 0 && message.index < Common.FILE_PIECES; - if (!remotePeer.chokedUpload) { - Msg.debug("Received a REQUEST from " + message.peerId + "(" + message.issuerHostname + ") for " + message.peerId); - if (bitfield[message.index] == '1') { - sendPiece(message.mailbox,message.index,false,message.blockIndex,message.blockLength); - } - else { - Msg.debug("Received a REQUEST from " + message.peerId + " (" + message.issuerHostname + ") but he is choked" ); - } - } - break; - case PIECE: - if (message.stalled) { - Msg.debug("The received piece " + message.index + " from " + message.peerId + " (" + message.issuerHostname + ") is stalled"); - } - else { - Msg.debug("Received piece " + message.index + " from " + message.peerId + " (" + message.issuerHostname + ")"); - if (bitfield[message.index] == '0') { - updateBitfieldBlocks(message.index,message.blockIndex,message.blockLength); - if (pieceComplete(message.index)) { - piecesRequested--; - //Removing the piece from our piece list. - if (!currentPieces.remove((Object)Integer.valueOf(message.index))) { - } - //Setting the fact that we have the piece - bitfield[message.index] = '1'; - pieces++; - Msg.debug("My status is now " + getStatus()); - //Sending the information to all the peers we are connected to - sendHave(message.index); - //sending UNINTERESTED to peers that doesn't have what we want. - updateInterestedAfterReceive(); - } - } - else { - Msg.debug("However, we already have it."); - } - } - break; - } - if (remotePeer != null) { - remotePeer.addSpeedValue(1 / (Msg.getClock() - beginReceiveTime)); - } - beginReceiveTime = Msg.getClock(); - } - /** - * Wait for the node to receive interesting bitfield messages (ie: non empty) - * to be received - */ - void waitForPieces() { - boolean finished = false; - while (Msg.getClock() < deadline && !finished) { - if (commReceived == null) { - commReceived = Task.irecv(mailbox); - } - try { - commReceived.waitCompletion(Common.TIMEOUT_MESSAGE); - handleMessage(commReceived.getTask()); - if (currentPiece != -1) { - finished = true; - } - commReceived = null; - } - catch (MsgException e) { - commReceived = null; - } - } - } - - private boolean hasFinished() { - for (int i = 0; i < bitfield.length; i++) { - if (bitfield[i] == '1') { - return true; - } - } - return false; - } - /** - * Updates the list of who has a piece from a bitfield - * @param bitfield bitfield - */ - private void updatePiecesCountFromBitfield(char bitfield[]) { - for (int i = 0; i < Common.FILE_PIECES; i++) { - if (bitfield[i] == '1') { - piecesCount[i]++; - } - } - } - /** - * Update the piece the peer is currently interested in. - * There is two cases (as described in "Bittorrent Architecture Protocol", Ryan Toole : - * If the peer has less than 3 pieces, he chooses a piece at random. - * If the peer has more than pieces, he downloads the pieces that are the less - * replicated - */ - void updateCurrentPiece() { - if (currentPieces.size() >= (Common.FILE_PIECES - pieces)) { - return; - } - if (true || pieces < 3) { - int peerPiece; - do { - currentPiece = stream.randInt(0,Common.FILE_PIECES - 1); - } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece))); - } - else { - //trivial min algorithm. - //TODO - } - currentPieces.add(currentPiece); - Msg.debug("New interested piece: " + currentPiece); - assert currentPiece >= 0 && currentPiece < Common.FILE_PIECES; - } - /** - * Update the list of current choked and unchoked peers, using the - * choke algorithm - */ - private void updateChokedPeers() { - round = (round + 1) % 3; - if (peers.size() == 0) { - return; - } - //remove a peer from the list - Iterator> it = activePeers.entrySet().iterator(); - if (it.hasNext()) { - Entry e = it.next(); - Connection peerChoked = e.getValue(); - peerChoked.chokedUpload = true; - sendChoked(peerChoked.mailbox); - activePeers.remove(e.getKey()); - } - Connection peerChoosed = null; - //Separate the case from when the peer is seeding. - if (pieces == Common.FILE_PIECES) { - //Find the last unchoked peer. - double unchokeTime = deadline + 1; - for (Connection connection : peers.values()) { - if (connection.lastUnchoke < unchokeTime && connection.interested) { - peerChoosed = connection; - unchokeTime = connection.lastUnchoke; - } - } - } - else { - //Random optimistic unchoking - if (round == 0) { - int j = 0, i; - do { - i = 0; - int idChosen = stream.randInt(0,peers.size() - 1); - for (Connection connection : peers.values()) { - if (i == idChosen) { - peerChoosed = connection; - break; - } - i++; - } //TODO: Not really the best way ever - if (!peerChoosed.interested) { - peerChoosed = null; - } - j++; - } while (peerChoosed == null && j < Common.MAXIMUM_PEERS); - } - else { - Connection fastest = null; - double fastestSpeed = 0; - for (Connection c : peers.values()) { - if (c.peerSpeed > fastestSpeed && c.interested && c.chokedUpload) { - fastest = c; - fastestSpeed = c.peerSpeed; - } - } - peerChoosed = fastest; - } - } - if (peerChoosed != null) { - activePeers.put(peerChoosed.id,peerChoosed); - peerChoosed.chokedUpload = false; - peerChoosed.lastUnchoke = Msg.getClock(); - sendUnchoked(peerChoosed.mailbox); - } - } - /** - * Updates our "interested" state about peers: send "not interested" to peers - * that don't have any more pieces we want. - */ - private void updateInterestedAfterReceive() { - boolean interested; - for (Connection connection : peers.values()) { - interested = false; - if (connection.amInterested) { - for (Integer piece : currentPieces) { - if (connection.bitfield[piece] == '1') { - interested = true; - break; - } - } - if (!interested) { - connection.amInterested = false; - sendNotInterested(connection.mailbox); - } - } - } - } - private void updateBitfieldBlocks(int index, int blockIndex, int blockLength) { - for (int i = blockIndex; i < (blockIndex + blockLength); i++) { - bitfieldBlocks[index][i] = '1'; - } - } - /** - * Returns if a piece is complete in the peer's bitfield. - * @param index the index of the piece. - */ - private boolean pieceComplete(int index) { - for (int i = 0; i < bitfieldBlocks[index].length; i++) { - if (bitfieldBlocks[index][i] == '0') { - return false; - } - } - return true; - } - /** - * Returns the first block of a piece that we don't have. - */ - private int getFirstBlock(int piece) { - int blockIndex = -1; - for (int i = 0; i < Common.PIECES_BLOCKS; i++) { - if (bitfieldBlocks[piece][i] == '0') { - blockIndex = i; - break; - } - } - return blockIndex; - } - /** - * Send request messages to a peer that have unchoked us - * @param remotePeer peer data to the peer we want to send the request - */ - private void sendRequestsToPeer(Connection remotePeer) { - if (remotePeer.bitfield == null) { - return; - } - for (Integer piece : currentPieces) { - //Getting the block to send. - int blockIndex = -1, blockLength = 0; - blockIndex = getFirstBlock(piece); - blockLength = Common.PIECES_BLOCKS - blockIndex ; - blockLength = blockLength > Common.BLOCKS_REQUESTED ? Common.BLOCKS_REQUESTED : blockLength; - if (remotePeer.bitfield[piece] == '1') { - sendRequest(remotePeer.mailbox, piece, blockIndex, blockLength); - } - } - } - /** - * Find the peers that have the current interested piece and send them - * the "interested" message - */ - private void sendInterestedToPeers() { - if (currentPiece == -1) { - return; - } - for (Connection connection : peers.values()) { - if (connection.bitfield != null && connection.bitfield[currentPiece] == '1' && !connection.amInterested) { - connection.amInterested = true; - MessageTask task = new MessageTask(MessageTask.Type.INTERESTED, hostname, this.mailbox, this.id); - task.dsend(connection.mailbox); - } - } - currentPiece = -1; - piecesRequested++; - } - /** - * Send a "interested" message to a peer. - */ - private void sendInterested(String mailbox) { - MessageTask task = new MessageTask(MessageTask.Type.INTERESTED, hostname, this.mailbox, this.id); - task.dsend(mailbox); - } - /** - * Send a "not interested" message to a peer - * @param mailbox mailbox destination mailbox - */ - private void sendNotInterested(String mailbox) { - MessageTask task = new MessageTask(MessageTask.Type.NOTINTERESTED, hostname, this.mailbox, this.id); - task.dsend(mailbox); - } - /** - * Send a handshake message to all the peers the peer has. - * @param peer peer data - */ - private void sendHandshakeAll() { - for (Connection remotePeer : peers.values()) { - MessageTask task = new MessageTask(MessageTask.Type.HANDSHAKE, hostname, mailbox, - id); - task.dsend(remotePeer.mailbox); - } - } - /** - * Send a "handshake" message to an user - * @param mailbox mailbox where to we send the message - */ - private void sendHandshake(String mailbox) { - Msg.debug("Sending a HANDSHAKE to " + mailbox); - MessageTask task = new MessageTask(MessageTask.Type.HANDSHAKE, hostname, this.mailbox, this.id); - task.dsend(mailbox); - } - /** - * Send a "choked" message to a peer - */ - private void sendChoked(String mailbox) { - Msg.debug("Sending a CHOKE to " + mailbox); - MessageTask task = new MessageTask(MessageTask.Type.CHOKE, hostname, this.mailbox, this.id); - task.dsend(mailbox); - } - /** - * Send a "unchoked" message to a peer - */ - private void sendUnchoked(String mailbox) { - Msg.debug("Sending a UNCHOKE to " + mailbox); - MessageTask task = new MessageTask(MessageTask.Type.UNCHOKE, hostname, this.mailbox, this.id); - task.dsend(mailbox); - } - /** - * Send a "HAVE" message to all peers we are connected to - */ - private void sendHave(int piece) { - Msg.debug("Sending HAVE message to all my peers"); - for (Connection remotePeer : peers.values()) { - MessageTask task = new MessageTask(MessageTask.Type.HAVE, hostname, this.mailbox, this.id, piece); - task.dsend(remotePeer.mailbox); - } - } - /** - * Send a bitfield message to all the peers the peer has. - * @param peer peer data - */ - private void sendBitfield(String mailbox) { - Msg.debug("Sending a BITFIELD to " + mailbox); - MessageTask task = new MessageTask(MessageTask.Type.BITFIELD, hostname, this.mailbox, this.id, this.bitfield); - task.dsend(mailbox); - } - /** - * Send a "request" message to a pair, containing a request for a piece - */ - private void sendRequest(String mailbox, int piece, int blockIndex, int blockLength) { - Msg.debug("Sending a REQUEST to " + mailbox + " for piece " + piece + " and blocks " + blockIndex + "," + (blockIndex + blockLength)); - MessageTask task = new MessageTask(MessageTask.Type.REQUEST, hostname, this.mailbox, this.id, piece, blockIndex, blockLength); - task.dsend(mailbox); - } - /** - * Send a "piece" message to a pair, containing a piece of the file - */ - private void sendPiece(String mailbox, int piece, boolean stalled, int blockIndex, int blockLength) { - Msg.debug("Sending the PIECE " + piece + " to " + mailbox); - MessageTask task = new MessageTask(MessageTask.Type.PIECE, hostname, this.mailbox, this.id, piece, stalled, blockIndex, blockLength); - task.dsend(mailbox); - } - - private String getStatus() { - String s = ""; - for (int i = 0; i < Common.FILE_PIECES; i++) { - s = s + bitfield[i]; - } - return s; - } + protected int round = 0; + protected double beginReceiveTime; + protected double deadline; + protected static RngStream stream = new RngStream(); + protected int id; + protected String mailbox; + protected String mailboxTracker; + protected String hostname; + protected int pieces = 0; + protected char[] bitfield = new char[Common.FILE_PIECES]; + protected char[][] bitfieldBlocks = new char[Common.FILE_PIECES][Common.PIECES_BLOCKS]; + protected short[] piecesCount = new short[Common.FILE_PIECES]; + protected int piecesRequested = 0; + protected ArrayList currentPieces = new ArrayList(); + protected int currentPiece = -1; + protected HashMap activePeers = new HashMap(); + protected HashMap peers = new HashMap(); + protected Comm commReceived = null; + + public Peer(Host host, String name, String[]args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + //Check arguments + if (args.length != 3 && args.length != 2) { + Msg.info("Wrong number of arguments"); + } + if (args.length == 3) { + init(Integer.valueOf(args[0]),true); + } else { + init(Integer.valueOf(args[0]),false); + } + //Retrieve the deadline + deadline = Double.valueOf(args[1]); + if (deadline < 0) { + Msg.info("Wrong deadline supplied"); + return; + } + Msg.info("Hi, I'm joining the network with id " + id); + //Getting peer data from the tracker + if (getPeersData()) { + Msg.debug("Got " + peers.size() + " peers from the tracker"); + Msg.debug("Here is my current status: " + getStatus()); + beginReceiveTime = Msg.getClock(); + if (hasFinished()) { + pieces = Common.FILE_PIECES; + sendHandshakeAll(); + seedLoop(); + } else { + leechLoop(); + seedLoop(); + } + } else { + Msg.info("Couldn't contact the tracker."); + } + Msg.info("Here is my current status: " + getStatus()); + } + + private void leechLoop() { + double nextChokedUpdate = Msg.getClock() + Common.UPDATE_CHOKED_INTERVAL; + Msg.debug("Start downloading."); + // Send a "handshake" message to all the peers it got(it couldn't have gotten more than 50 peers anyway) + sendHandshakeAll(); + //Wait for at least one "bitfield" message. + waitForPieces(); + Msg.debug("Starting main leech loop"); + while (Msg.getClock() < deadline && pieces < Common.FILE_PIECES) { + if (commReceived == null) { + commReceived = Task.irecv(mailbox); + } + try { + if (commReceived.test()) { + handleMessage(commReceived.getTask()); + commReceived = null; + } else { + //If the user has a pending interesting + if (currentPiece != -1) { + sendInterestedToPeers(); + } else { + if (currentPieces.size() < Common.MAX_PIECES) { + updateCurrentPiece(); + } + } + //We don't execute the choke algorithm if we don't already have a piece + if (Msg.getClock() >= nextChokedUpdate && pieces > 0) { + updateChokedPeers(); + nextChokedUpdate += Common.UPDATE_CHOKED_INTERVAL; + } else { + waitFor(1); + } + } + } + catch (MsgException e) { + commReceived = null; + } + } + } + + private void seedLoop() { + double nextChokedUpdate = Msg.getClock() + Common.UPDATE_CHOKED_INTERVAL; + Msg.debug("Start seeding."); + //start the main seed loop + while (Msg.getClock() < deadline) { + if (commReceived == null) { + commReceived = Task.irecv(mailbox); + } + try { + if (commReceived.test()) { + handleMessage(commReceived.getTask()); + commReceived = null; + } else { + if (Msg.getClock() >= nextChokedUpdate) { + updateChokedPeers(); + //TODO: Change the choked peer algorithm when seeding + nextChokedUpdate += Common.UPDATE_CHOKED_INTERVAL; + } else { + waitFor(1); + } + } + } + catch (MsgException e) { + commReceived = null; + } + } + } + + /** + * @brief Initialize the various peer data + * @param id id of the peer to take in the network + * @param seed indicates if the peer is a seed + */ + private void init(int id, boolean seed) { + this.id = id; + this.mailbox = Integer.toString(id); + this.mailboxTracker = "tracker_" + Integer.toString(id); + if (seed) { + for (int i = 0; i < bitfield.length; i++) { + bitfield[i] = '1'; + for (int j = 0; j < bitfieldBlocks[i].length; j++) { + bitfieldBlocks[i][j] = '1'; + } + } + } else { + for (int i = 0; i < bitfield.length; i++) { + bitfield[i] = '0'; + for (int j = 0; j < bitfieldBlocks[i].length; j++) { + bitfieldBlocks[i][j] = '0' ; + } + } + } + this.hostname = getHost().getName(); + } + + private boolean getPeersData() { + boolean success = false, sendSuccess = false; + double timeout = Msg.getClock() + Common.GET_PEERS_TIMEOUT; + //Build the task to send to the tracker + TrackerTask taskSend = new TrackerTask(hostname, mailboxTracker, id); + + while (!sendSuccess && Msg.getClock() < timeout) { + try { + Msg.debug("Sending a peer request to the tracker."); + taskSend.send(Common.TRACKER_MAILBOX,Common.GET_PEERS_TIMEOUT); + sendSuccess = true; + } + catch (MsgException e) { + } + } + while (!success && Msg.getClock() < timeout) { + commReceived = Task.irecv(this.mailboxTracker); + try { + commReceived.waitCompletion(Common.GET_PEERS_TIMEOUT); + if (commReceived.getTask() instanceof TrackerTask) { + TrackerTask task = (TrackerTask)commReceived.getTask(); + for (Integer peerId: task.peers) { + if (peerId != this.id) { + peers.put(peerId, new Connection(peerId)); + } + } + success = true; + } + } + catch (MsgException e) {} + commReceived = null; + } + commReceived = null; + return success; + } + + void handleMessage(Task task) { + MessageTask message = (MessageTask)task; + Connection remotePeer = peers.get(message.peerId); + switch (message.type) { + case HANDSHAKE: + Msg.debug("Received a HANDSHAKE message from " + message.mailbox); + //Check if the peer is in our connection list + if (remotePeer == null) { + peers.put(message.peerId, new Connection(message.peerId)); + sendHandshake(message.mailbox); + } + //Send our bitfield to the pair + sendBitfield(message.mailbox); + break; + case BITFIELD: + Msg.debug("Received a BITFIELD message from " + message.peerId + " (" + message.issuerHostname + ")"); + //update the pieces list + updatePiecesCountFromBitfield(message.bitfield); + //Update the current piece + if (currentPiece == -1 && pieces < Common.FILE_PIECES && currentPieces.size() < Common.MAX_PIECES) { + updateCurrentPiece(); + } + remotePeer.bitfield = message.bitfield.clone(); + break; + case INTERESTED: + Msg.debug("Received an INTERESTED message from " + message.peerId + " (" + message.issuerHostname + ")"); + assert remotePeer != null; + remotePeer.interested = true; + break; + case NOTINTERESTED: + Msg.debug("Received a NOTINTERESTED message from " + message.peerId + " (" + message.issuerHostname + ")"); + assert remotePeer != null; + remotePeer.interested = false; + break; + case UNCHOKE: + Msg.debug("Received an UNCHOKE message from " + message.peerId + "(" + message.issuerHostname + ")"); + assert remotePeer != null; + remotePeer.chokedDownload = false; + activePeers.put(remotePeer.id,remotePeer); + sendRequestsToPeer(remotePeer); + break; + case CHOKE: + Msg.debug("Received a CHOKE message from " + message.peerId + " (" + message.issuerHostname + ")"); + assert remotePeer != null; + remotePeer.chokedDownload = true; + activePeers.remove(remotePeer.id); + break; + case HAVE: + if (remotePeer.bitfield == null) { + return; + } + Msg.debug("Received a HAVE message from " + message.peerId + " (" + message.issuerHostname + ")"); + assert message.index >= 0 && message.index < Common.FILE_PIECES; + assert remotePeer.bitfield != null; + remotePeer.bitfield[message.index] = '1'; + piecesCount[message.index]++; + //Send interested message to the peer if he has what we want + if (!remotePeer.amInterested && currentPieces.contains(message.index) ) { + remotePeer.amInterested = true; + sendInterested(remotePeer.mailbox); + } + + if (currentPieces.contains(message.index)) { + int blockIndex = getFirstBlock(message.index); + int blockLength = Common.PIECES_BLOCKS - blockIndex ; + blockLength = blockLength > Common.BLOCKS_REQUESTED ? Common.BLOCKS_REQUESTED : blockLength; + sendRequest(message.mailbox,message.index,blockIndex,blockLength); + } + break; + case REQUEST: + assert message.index >= 0 && message.index < Common.FILE_PIECES; + if (!remotePeer.chokedUpload) { + Msg.debug("Received a REQUEST from " + message.peerId + "(" + message.issuerHostname + ") for " + + message.peerId); + if (bitfield[message.index] == '1') { + sendPiece(message.mailbox,message.index,false,message.blockIndex,message.blockLength); + } else { + Msg.debug("Received a REQUEST from " + message.peerId + " (" + message.issuerHostname + + ") but he is choked" ); + } + } + break; + case PIECE: + if (message.stalled) { + Msg.debug("The received piece " + message.index + " from " + message.peerId + " (" + message.issuerHostname + + ") is stalled"); + } else { + Msg.debug("Received piece " + message.index + " from " + message.peerId + " (" + + message.issuerHostname + ")"); + if (bitfield[message.index] == '0') { + updateBitfieldBlocks(message.index,message.blockIndex,message.blockLength); + if (pieceComplete(message.index)) { + piecesRequested--; + //Removing the piece from our piece list. + currentPieces.remove((Object)Integer.valueOf(message.index)); + //Setting the fact that we have the piece + bitfield[message.index] = '1'; + pieces++; + Msg.debug("My status is now " + getStatus()); + //Sending the information to all the peers we are connected to + sendHave(message.index); + //sending UNINTERESTED to peers that doesn't have what we want. + updateInterestedAfterReceive(); + } + } else { + Msg.debug("However, we already have it."); + } + } + break; + } + if (remotePeer != null) { + remotePeer.addSpeedValue(1 / (Msg.getClock() - beginReceiveTime)); + } + beginReceiveTime = Msg.getClock(); + } + + void waitForPieces() { + boolean finished = false; + while (Msg.getClock() < deadline && !finished) { + if (commReceived == null) { + commReceived = Task.irecv(mailbox); + } + try { + commReceived.waitCompletion(Common.TIMEOUT_MESSAGE); + handleMessage(commReceived.getTask()); + if (currentPiece != -1) { + finished = true; + } + commReceived = null; + } + catch (MsgException e) { + commReceived = null; + } + } + } + + private boolean hasFinished() { + for (int i = 0; i < bitfield.length; i++) { + if (bitfield[i] == '1') { + return true; + } + } + return false; + } + + /** + * @brief Updates the list of who has a piece from a bitfield + * @param bitfield bitfield + */ + private void updatePiecesCountFromBitfield(char bitfield[]) { + for (int i = 0; i < Common.FILE_PIECES; i++) { + if (bitfield[i] == '1') { + piecesCount[i]++; + } + } + } + + /** + * Update the piece the peer is currently interested in. + * There is two cases (as described in "Bittorrent Architecture Protocol", Ryan Toole : + * If the peer has less than 3 pieces, he chooses a piece at random. + * If the peer has more than pieces, he downloads the pieces that are the less + * replicated + */ + void updateCurrentPiece() { + if (currentPieces.size() >= (Common.FILE_PIECES - pieces)) { + return; + } + if (true || pieces < 3) { + int peerPiece; + do { + currentPiece = stream.randInt(0,Common.FILE_PIECES - 1); + } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece))); + } + else { + //trivial min algorithm. + //TODO + } + currentPieces.add(currentPiece); + Msg.debug("New interested piece: " + currentPiece); + assert currentPiece >= 0 && currentPiece < Common.FILE_PIECES; + } + + // Update the list of current choked and unchoked peers, using the choke algorithm + private void updateChokedPeers() { + round = (round + 1) % 3; + if (peers.size() == 0) { + return; + } + //remove a peer from the list + Iterator> it = activePeers.entrySet().iterator(); + if (it.hasNext()) { + Entry e = it.next(); + Connection peerChoked = e.getValue(); + peerChoked.chokedUpload = true; + sendChoked(peerChoked.mailbox); + activePeers.remove(e.getKey()); + } + Connection peerChoosed = null; + //Separate the case from when the peer is seeding. + if (pieces == Common.FILE_PIECES) { + //Find the last unchoked peer. + double unchokeTime = deadline + 1; + for (Connection connection : peers.values()) { + if (connection.lastUnchoke < unchokeTime && connection.interested) { + peerChoosed = connection; + unchokeTime = connection.lastUnchoke; + } + } + } else { + //Random optimistic unchoking + if (round == 0) { + int j = 0, i; + do { + i = 0; + int idChosen = stream.randInt(0,peers.size() - 1); + for (Connection connection : peers.values()) { + if (i == idChosen) { + peerChoosed = connection; + break; + } + i++; + } //TODO: Not really the best way ever + if (!peerChoosed.interested) { + peerChoosed = null; + } + j++; + } while (peerChoosed == null && j < Common.MAXIMUM_PEERS); + } else { + Connection fastest = null; + double fastestSpeed = 0; + for (Connection c : peers.values()) { + if (c.peerSpeed > fastestSpeed && c.interested && c.chokedUpload) { + fastest = c; + fastestSpeed = c.peerSpeed; + } + } + peerChoosed = fastest; + } + } + if (peerChoosed != null) { + activePeers.put(peerChoosed.id,peerChoosed); + peerChoosed.chokedUpload = false; + peerChoosed.lastUnchoke = Msg.getClock(); + sendUnchoked(peerChoosed.mailbox); + } + } + + // Updates our "interested" state about peers: send "not interested" to peers that don't have any more pieces we want. + private void updateInterestedAfterReceive() { + boolean interested; + for (Connection connection : peers.values()) { + interested = false; + if (connection.amInterested) { + for (Integer piece : currentPieces) { + if (connection.bitfield[piece] == '1') { + interested = true; + break; + } + } + if (!interested) { + connection.amInterested = false; + sendNotInterested(connection.mailbox); + } + } + } + } + + private void updateBitfieldBlocks(int index, int blockIndex, int blockLength) { + for (int i = blockIndex; i < (blockIndex + blockLength); i++) { + bitfieldBlocks[index][i] = '1'; + } + } + + // Returns if a piece is complete in the peer's bitfield. + private boolean pieceComplete(int index) { + for (int i = 0; i < bitfieldBlocks[index].length; i++) { + if (bitfieldBlocks[index][i] == '0') { + return false; + } + } + return true; + } + + // Returns the first block of a piece that we don't have. + private int getFirstBlock(int piece) { + int blockIndex = -1; + for (int i = 0; i < Common.PIECES_BLOCKS; i++) { + if (bitfieldBlocks[piece][i] == '0') { + blockIndex = i; + break; + } + } + return blockIndex; + } + + /** + * @brief Send request messages to a peer that have unchoked us + * @param remotePeer peer data to the peer we want to send the request + */ + private void sendRequestsToPeer(Connection remotePeer) { + if (remotePeer.bitfield == null) { + return; + } + for (Integer piece : currentPieces) { + //Getting the block to send. + int blockIndex = -1, blockLength = 0; + blockIndex = getFirstBlock(piece); + blockLength = Common.PIECES_BLOCKS - blockIndex ; + blockLength = blockLength > Common.BLOCKS_REQUESTED ? Common.BLOCKS_REQUESTED : blockLength; + if (remotePeer.bitfield[piece] == '1') { + sendRequest(remotePeer.mailbox, piece, blockIndex, blockLength); + } + } + } + + // Find the peers that have the current interested piece and send them the "interested" message + private void sendInterestedToPeers() { + if (currentPiece == -1) { + return; + } + for (Connection connection : peers.values()) { + if (connection.bitfield != null && connection.bitfield[currentPiece] == '1' && !connection.amInterested) { + connection.amInterested = true; + MessageTask task = new MessageTask(MessageTask.Type.INTERESTED, hostname, this.mailbox, this.id); + task.dsend(connection.mailbox); + } + } + currentPiece = -1; + piecesRequested++; + } + + // Send a "interested" message to a peer. + private void sendInterested(String mailbox) { + MessageTask task = new MessageTask(MessageTask.Type.INTERESTED, hostname, this.mailbox, this.id); + task.dsend(mailbox); + } + + /** + * @brief Send a "not interested" message to a peer + * @param mailbox mailbox destination mailbox + */ + private void sendNotInterested(String mailbox) { + MessageTask task = new MessageTask(MessageTask.Type.NOTINTERESTED, hostname, this.mailbox, this.id); + task.dsend(mailbox); + } + + // Send a handshake message to all the peers the peer has. + private void sendHandshakeAll() { + for (Connection remotePeer : peers.values()) { + MessageTask task = new MessageTask(MessageTask.Type.HANDSHAKE, hostname, mailbox, id); + task.dsend(remotePeer.mailbox); + } + } + + /** + * @brief Send a "handshake" message to an user + * @param mailbox mailbox where to we send the message + */ + private void sendHandshake(String mailbox) { + Msg.debug("Sending a HANDSHAKE to " + mailbox); + MessageTask task = new MessageTask(MessageTask.Type.HANDSHAKE, hostname, this.mailbox, this.id); + task.dsend(mailbox); + } + + // Send a "choked" message to a peer + private void sendChoked(String mailbox) { + Msg.debug("Sending a CHOKE to " + mailbox); + MessageTask task = new MessageTask(MessageTask.Type.CHOKE, hostname, this.mailbox, this.id); + task.dsend(mailbox); + } + + // Send a "unchoked" message to a peer + private void sendUnchoked(String mailbox) { + Msg.debug("Sending a UNCHOKE to " + mailbox); + MessageTask task = new MessageTask(MessageTask.Type.UNCHOKE, hostname, this.mailbox, this.id); + task.dsend(mailbox); + } + + // Send a "HAVE" message to all peers we are connected to + private void sendHave(int piece) { + Msg.debug("Sending HAVE message to all my peers"); + for (Connection remotePeer : peers.values()) { + MessageTask task = new MessageTask(MessageTask.Type.HAVE, hostname, this.mailbox, this.id, piece); + task.dsend(remotePeer.mailbox); + } + } + // Send a bitfield message to all the peers the peer has. + private void sendBitfield(String mailbox) { + Msg.debug("Sending a BITFIELD to " + mailbox); + MessageTask task = new MessageTask(MessageTask.Type.BITFIELD, hostname, this.mailbox, this.id, this.bitfield); + task.dsend(mailbox); + } + // Send a "request" message to a peer, containing a request for a piece + private void sendRequest(String mailbox, int piece, int blockIndex, int blockLength) { + Msg.debug("Sending a REQUEST to " + mailbox + " for piece " + piece + " and blocks " + blockIndex + "," + + (blockIndex + blockLength)); + MessageTask task = new MessageTask(MessageTask.Type.REQUEST, hostname, this.mailbox, this.id, piece, blockIndex, + blockLength); + task.dsend(mailbox); + } + + // Send a "piece" message to a peer, containing a piece of the file + private void sendPiece(String mailbox, int piece, boolean stalled, int blockIndex, int blockLength) { + Msg.debug("Sending the PIECE " + piece + " to " + mailbox); + MessageTask task = new MessageTask(MessageTask.Type.PIECE, hostname, this.mailbox, this.id, piece, stalled, + blockIndex, blockLength); + task.dsend(mailbox); + } + + private String getStatus() { + String s = ""; + for (int i = 0; i < Common.FILE_PIECES; i++) { + s = s + bitfield[i]; + } + return s; + } } - diff --git a/examples/java/bittorrent/Tracker.java b/examples/java/bittorrent/Tracker.java index 338b763468..6af9eb2879 100644 --- a/examples/java/bittorrent/Tracker.java +++ b/examples/java/bittorrent/Tracker.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2026. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,87 +7,74 @@ package bittorrent; import java.util.ArrayList; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Task; import org.simgrid.msg.Process; import org.simgrid.msg.RngStream; -import org.simgrid.msg.Task; -/** - * Tracker, handle requests from peers. - */ +import org.simgrid.msg.MsgException; + public class Tracker extends Process { - protected RngStream stream; - /** - * Peers list - */ - protected ArrayList peersList; - /** - * End time for the simulation - */ - protected double deadline; - /** - * Current comm received - */ - protected Comm commReceived = null; - - public Tracker(Host host, String name, String[]args) { - super(host,name,args); - } - - @Override - public void main(String[] args) throws MsgException { - if (args.length != 1) { - Msg.info("Wrong number of arguments for the tracker."); - return; - } - //Build the RngStream object for randomness - stream = new RngStream("tracker"); - //Retrieve the end time - deadline = Double.valueOf(args[0]); - //Building peers array - peersList = new ArrayList(); - - Msg.info("Tracker launched."); - while (Msg.getClock() < deadline) { - if (commReceived == null) { - commReceived = Task.irecv(Common.TRACKER_MAILBOX); - } - try { - if (commReceived.test()) { - Task task = commReceived.getTask(); - if (task instanceof TrackerTask) { - TrackerTask tTask = (TrackerTask)task; - //Sending peers to the peer - int nbPeers = 0; - while (nbPeers < Common.MAXIMUM_PEERS && nbPeers < peersList.size()) { - int nextPeer; - do { - nextPeer = stream.randInt(0, peersList.size() - 1); - } while (tTask.peers.contains(nextPeer)); - tTask.peers.add(peersList.get(nextPeer)); - nbPeers++; - } - //Adding the peer to our list - peersList.add(tTask.peerId); - tTask.type = TrackerTask.Type.ANSWER; - //Setting the interval - tTask.interval = Common.TRACKER_QUERY_INTERVAL; - //Sending the task back to the peer - tTask.dsend(tTask.mailbox); - } - commReceived = null; - } - else { - waitFor(1); - } - } - catch (MsgException e) { - commReceived = null; - } - } - Msg.info("Tracker is leaving"); - } + protected RngStream stream; + protected ArrayList peersList; + protected double deadline; + protected Comm commReceived = null; + + public Tracker(Host host, String name, String[]args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + if (args.length != 1) { + Msg.info("Wrong number of arguments for the tracker."); + return; + } + //Build the RngStream object for randomness + stream = new RngStream("tracker"); + //Retrieve the end time + deadline = Double.valueOf(args[0]); + //Building peers array + peersList = new ArrayList(); + Msg.info("Tracker launched."); + while (Msg.getClock() < deadline) { + if (commReceived == null) { + commReceived = Task.irecv(Common.TRACKER_MAILBOX); + } + try { + if (commReceived.test()) { + Task task = commReceived.getTask(); + if (task instanceof TrackerTask) { + TrackerTask tTask = (TrackerTask)task; + //Sending peers to the peer + int nbPeers = 0; + while (nbPeers < Common.MAXIMUM_PEERS && nbPeers < peersList.size()) { + int nextPeer; + do { + nextPeer = stream.randInt(0, peersList.size() - 1); + } while (tTask.peers.contains(nextPeer)); + tTask.peers.add(peersList.get(nextPeer)); + nbPeers++; + } + //Adding the peer to our list + peersList.add(tTask.peerId); + tTask.type = TrackerTask.Type.ANSWER; + //Setting the interval + tTask.interval = Common.TRACKER_QUERY_INTERVAL; + //Sending the task back to the peer + tTask.dsend(tTask.mailbox); + } + commReceived = null; + } else { + waitFor(1); + } + } + catch (MsgException e) { + commReceived = null; + } + } + Msg.info("Tracker is leaving"); + } } diff --git a/examples/java/bittorrent/TrackerTask.java b/examples/java/bittorrent/TrackerTask.java index beaf7b82f9..8e4158daf5 100644 --- a/examples/java/bittorrent/TrackerTask.java +++ b/examples/java/bittorrent/TrackerTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -9,41 +9,36 @@ import java.util.ArrayList; import org.simgrid.msg.Task; -/** - * Task exchanged between the tracker - * and the peers. - */ +/* Task exchanged between the tracker and the peers. */ public class TrackerTask extends Task { - /** - * Type of the tasks - */ - public enum Type { - REQUEST, - ANSWER - }; - public Type type; - public String hostname; - public String mailbox; - public int peerId; - public int uploaded; - public int downloaded; - public int left; - public double interval; - public ArrayList peers; - - public TrackerTask(String hostname, String mailbox, int peerId) { - this(hostname, mailbox, peerId, 0, 0, Common.FILE_SIZE); - } - public TrackerTask(String hostname, String mailbox, int peerId, int uploaded, int downloaded, int left) { - super("", 0, Common.TRACKER_COMM_SIZE); - this.type = Type.REQUEST; - this.hostname = hostname; - this.mailbox = mailbox; - this.peerId = peerId; - this.uploaded = uploaded; - this.downloaded = downloaded; - this.left = left; - this.peers = new ArrayList(); - } - + public enum Type { + REQUEST, + ANSWER + }; + + public Type type; + public String hostname; + public String mailbox; + public int peerId; + public int uploaded; + public int downloaded; + public int left; + public double interval; + public ArrayList peers; + + public TrackerTask(String hostname, String mailbox, int peerId) { + this(hostname, mailbox, peerId, 0, 0, Common.FILE_SIZE); + } + + public TrackerTask(String hostname, String mailbox, int peerId, int uploaded, int downloaded, int left) { + super("", 0, Common.TRACKER_COMM_SIZE); + this.type = Type.REQUEST; + this.hostname = hostname; + this.mailbox = mailbox; + this.peerId = peerId; + this.uploaded = uploaded; + this.downloaded = downloaded; + this.left = left; + this.peers = new ArrayList(); + } } diff --git a/examples/java/bittorrent/bittorrent.xml b/examples/java/bittorrent/bittorrent.xml index c1989eaa51..7d0459bc8a 100644 --- a/examples/java/bittorrent/bittorrent.xml +++ b/examples/java/bittorrent/bittorrent.xml @@ -1,39 +1,37 @@ - - + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - diff --git a/examples/java/chord/Chord.java b/examples/java/chord/Chord.java index 2f3d7faea1..954b50fa62 100644 --- a/examples/java/chord/Chord.java +++ b/examples/java/chord/Chord.java @@ -9,19 +9,18 @@ package chord; import org.simgrid.msg.Msg; public class Chord { - public static void main(String[] args) { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : Chord platform_file deployment_file"); - Msg.info("example : Chord platform.xml deployment.xml"); - System.exit(1); - } - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); - } + public static void main(String[] args) { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Chord platform_file deployment_file"); + Msg.info("example : Chord ../platforms/platform.xml chord.xml"); + System.exit(1); + } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/chord/ChordTask.java b/examples/java/chord/ChordTask.java index b10940ca32..b78bb8fcc3 100644 --- a/examples/java/chord/ChordTask.java +++ b/examples/java/chord/ChordTask.java @@ -6,21 +6,18 @@ package chord; +import chord.Common; import org.simgrid.msg.Task; -import chord.Common; -/** - * Base class for all Tasks in Chord. - */ public class ChordTask extends Task { - public String issuerHostName; - public String answerTo; - public ChordTask() { - this(null,null); - } - public ChordTask(String issuerHostName, String answerTo) { - super(null, Common.COMP_SIZE, Common.COMM_SIZE); - this.issuerHostName = issuerHostName; - this.answerTo = answerTo; - } + public String issuerHostName; + public String answerTo; + public ChordTask() { + this(null,null); + } + public ChordTask(String issuerHostName, String answerTo) { + super(null, Common.COMP_SIZE, Common.COMM_SIZE); + this.issuerHostName = issuerHostName; + this.answerTo = answerTo; + } } diff --git a/examples/java/chord/Common.java b/examples/java/chord/Common.java index 7031c23185..2bda08167f 100644 --- a/examples/java/chord/Common.java +++ b/examples/java/chord/Common.java @@ -5,19 +5,17 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ package chord; -/** - * Common constants used over the simulation - */ + public class Common { - public final static int COMM_SIZE = 10; - public final static int COMP_SIZE = 0; - - public final static int NB_BITS = 24; - public final static int NB_KEYS = 16777216; - public final static int TIMEOUT = 50; - public final static int MAX_SIMULATION_TIME = 1000; - public final static int PERIODIC_STABILIZE_DELAY = 20; - public final static int PERIODIC_FIX_FINGERS_DELAY = 120; - public final static int PERIODIC_CHECK_PREDECESSOR_DELAY = 120; - public final static int PERIODIC_LOOKUP_DELAY = 10; + public final static int COMM_SIZE = 10; + public final static int COMP_SIZE = 0; + + public final static int NB_BITS = 24; + public final static int NB_KEYS = 16777216; + public final static int TIMEOUT = 50; + public final static int MAX_SIMULATION_TIME = 1000; + public final static int PERIODIC_STABILIZE_DELAY = 20; + public final static int PERIODIC_FIX_FINGERS_DELAY = 120; + public final static int PERIODIC_CHECK_PREDECESSOR_DELAY = 120; + public final static int PERIODIC_LOOKUP_DELAY = 10; } diff --git a/examples/java/chord/FindSuccessorAnswerTask.java b/examples/java/chord/FindSuccessorAnswerTask.java index a740872bd2..5dee45fef5 100644 --- a/examples/java/chord/FindSuccessorAnswerTask.java +++ b/examples/java/chord/FindSuccessorAnswerTask.java @@ -7,10 +7,10 @@ package chord; public class FindSuccessorAnswerTask extends ChordTask { - public int answerId; + public int answerId; - public FindSuccessorAnswerTask(String issuerHostname, String answerTo, int answerId) { - super(issuerHostname,answerTo); - this.answerId = answerId; - } + public FindSuccessorAnswerTask(String issuerHostname, String answerTo, int answerId) { + super(issuerHostname,answerTo); + this.answerId = answerId; + } } diff --git a/examples/java/chord/FindSuccessorTask.java b/examples/java/chord/FindSuccessorTask.java index db770279f2..b8f84c2b87 100644 --- a/examples/java/chord/FindSuccessorTask.java +++ b/examples/java/chord/FindSuccessorTask.java @@ -7,10 +7,10 @@ package chord; public class FindSuccessorTask extends ChordTask { - public int requestId; - - public FindSuccessorTask(String issuerHostname, String answerTo, int requestId) { - super(issuerHostname, answerTo); - this.requestId = requestId; - } + public int requestId; + + public FindSuccessorTask(String issuerHostname, String answerTo, int requestId) { + super(issuerHostname, answerTo); + this.requestId = requestId; + } } diff --git a/examples/java/chord/GetPredecessorAnswerTask.java b/examples/java/chord/GetPredecessorAnswerTask.java index ac1b1426d3..d8a9a9a4e8 100644 --- a/examples/java/chord/GetPredecessorAnswerTask.java +++ b/examples/java/chord/GetPredecessorAnswerTask.java @@ -7,9 +7,9 @@ package chord; public class GetPredecessorAnswerTask extends ChordTask { - public int answerId; - public GetPredecessorAnswerTask(String issuerHostname, String answerTo, int answerId) { - super(issuerHostname,answerTo); - this.answerId = answerId; - } + public int answerId; + public GetPredecessorAnswerTask(String issuerHostname, String answerTo, int answerId) { + super(issuerHostname,answerTo); + this.answerId = answerId; + } } diff --git a/examples/java/chord/GetPredecessorTask.java b/examples/java/chord/GetPredecessorTask.java index 38fecabccc..6320d7a3ba 100644 --- a/examples/java/chord/GetPredecessorTask.java +++ b/examples/java/chord/GetPredecessorTask.java @@ -7,7 +7,7 @@ package chord; public class GetPredecessorTask extends ChordTask { - public GetPredecessorTask(String issuerHostName, String answerTo) { - super(issuerHostName, answerTo); - } + public GetPredecessorTask(String issuerHostName, String answerTo) { + super(issuerHostName, answerTo); + } } diff --git a/examples/java/chord/Node.java b/examples/java/chord/Node.java index 93099237ae..6456b6b3c4 100644 --- a/examples/java/chord/Node.java +++ b/examples/java/chord/Node.java @@ -6,473 +6,410 @@ package chord; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; import org.simgrid.msg.TimeoutException; -/** - * Node data - */ public class Node extends Process { - /** - * Node id - */ - protected int id; - /** - * Node mailbox - */ - protected String mailbox; - /** - * Predecessor id - */ - protected int predId; - /** - * Predecessor mailbox - */ - protected String predMailbox; - /** - * Index of the next finger to fix - */ - protected int nextFingerToFix; - /** - * Current communication - */ - protected Comm commReceive; - /** - * Last time I changed a finger or my predecessor - */ - protected double lastChangeDate; - /** - * Node fingers - */ - int fingers[]; - /** - * Constructor - */ - public Node(Host host, String name, String[] args) { - super(host,name,args); - } - @Override - public void main(String[] args) throws MsgException { - if (args.length != 2 && args.length != 4) { - Msg.info("You need to provide 2 or 4 arguments."); - return; - } - double initTime = Msg.getClock(); - int i; - boolean joinSuccess = false; - double deadline; - - double nextStabilizeDate = initTime + Common.PERIODIC_STABILIZE_DELAY; - double nextFixFingersDate = initTime + Common.PERIODIC_FIX_FINGERS_DELAY; - double nextCheckPredecessorDate = initTime + Common.PERIODIC_CHECK_PREDECESSOR_DELAY; - double nextLookupDate = initTime + Common.PERIODIC_LOOKUP_DELAY; - - id = Integer.valueOf(args[0]); - mailbox = Integer.toString(id); - - fingers = new int[Common.NB_BITS]; - for (i = 0; i < Common.NB_BITS; i++) { - fingers[i] = -1; - setFinger(i,this.id); - } - - //First node - if (args.length == 2) { - deadline = Integer.valueOf(args[1]); - create(); - joinSuccess = true; - } - else { - int knownId = Integer.valueOf(args[1]); - deadline = Integer.valueOf(args[3]); - //Msg.info("Hey! Let's join the system with the id " + id + "."); - - joinSuccess = join(knownId); - } - if (joinSuccess) { - double currentClock = Msg.getClock(); - while (currentClock < (initTime + deadline) && currentClock < Common.MAX_SIMULATION_TIME) { - if (commReceive == null) { - commReceive = Task.irecv(this.mailbox); - } - try { - if (!commReceive.test()) { - if (currentClock >= nextStabilizeDate) { - stabilize(); - nextStabilizeDate = Msg.getClock() + Common.PERIODIC_STABILIZE_DELAY; - } - else if (currentClock >= nextFixFingersDate) { - fixFingers(); - nextFixFingersDate = Msg.getClock() + Common.PERIODIC_FIX_FINGERS_DELAY; - } - else if (currentClock >= nextCheckPredecessorDate) { - this.checkPredecessor(); - nextCheckPredecessorDate = Msg.getClock() + Common.PERIODIC_CHECK_PREDECESSOR_DELAY; - } - else if (currentClock >= nextLookupDate) { - this.randomLookup(); - nextLookupDate = Msg.getClock() + Common.PERIODIC_LOOKUP_DELAY; - } - else { - waitFor(5); - } - currentClock = Msg.getClock(); - } - else { - handleTask(commReceive.getTask()); - currentClock = Msg.getClock(); - commReceive = null; - - } - } - catch (Exception e) { - currentClock = Msg.getClock(); - commReceive = null; - } - - } - leave(); - if (commReceive != null) { - commReceive = null; - } - } - else { - Msg.info("I couldn't join the ring"); - } - } - void handleTask(Task task) { - if (task instanceof FindSuccessorTask) { - FindSuccessorTask fTask = (FindSuccessorTask)task; - Msg.debug("Receiving a 'Find Successor' request from " + fTask.issuerHostName + " for id " + fTask.requestId); - // is my successor the successor? - if (isInInterval(fTask.requestId, this.id + 1, fingers[0])) { - //Msg.info("Send the request to " + fTask.answerTo + " with answer " + fingers[0]); - FindSuccessorAnswerTask answer = new FindSuccessorAnswerTask(getHost().getName(), mailbox, fingers[0]); - answer.dsend(fTask.answerTo); - } - else { - // otherwise, forward the request to the closest preceding finger in my table - int closest = closestPrecedingNode(fTask.requestId); - //Msg.info("Forward the request to " + closest); - fTask.dsend(Integer.toString(closest)); - } - } - else if (task instanceof GetPredecessorTask) { - GetPredecessorTask gTask = (GetPredecessorTask)(task); - Msg.debug("Receiving a 'Get Predecessor' request from " + gTask.issuerHostName); - GetPredecessorAnswerTask answer = new GetPredecessorAnswerTask(getHost().getName(), mailbox, predId); - answer.dsend(gTask.answerTo); - } - else if (task instanceof NotifyTask) { - NotifyTask nTask = (NotifyTask)task; - notify(nTask.requestId); - } - else { - Msg.debug("Ignoring unexpected task of type:" + task); - } - } - /** - * @brief Makes the current node quit the system - */ - void leave() { - Msg.debug("Well Guys! I Think it's time for me to quit ;)"); - quitNotify(1); //Notify my successor - quitNotify(-1); //Notify my predecessor. - // TODO ... - } - /** - * @brief Notifies the successor or the predecessor of the current node - * of the departure - * @param to 1 to notify the successor, -1 to notify the predecessor - */ - static void quitNotify( int to) { - //TODO - } - /** - * @brief Initializes the current node as the first one of the system. - */ - void create() { - Msg.debug("Create a new Chord ring..."); - setPredecessor(-1); - - } - /** - * Makes the current node join the ring, knowing the id of a node - * already in the ring - */ - boolean join(int knownId) { - Msg.info("Joining the ring with id " + this.id + " knowing node " + knownId); - setPredecessor(-1); - int successorId = remoteFindSuccessor(knownId, this.id); - if (successorId == -1) { - Msg.info("Cannot join the ring."); - } - else { - setFinger(0, successorId); - } - return successorId != -1; - } - - /** - * Sets the node predecessor - */ - void setPredecessor(int predecessorId) { - if (predecessorId != predId) { - predId = predecessorId; - if (predecessorId != -1) { - predMailbox = Integer.toString(predId); - } - lastChangeDate = Msg.getClock(); - } - } - /** - * @brief Asks another node its predecessor. - * @param askTo the node to ask to - * @return the id of its predecessor node, or -1 if the request failed - * (or if the node does not know its predecessor) - */ - int remoteGetPredecessor(int askTo) { - int predecessorId = -1; - boolean stop = false; - Msg.debug("Sending a 'Get Predecessor' request to " + askTo); - String mailboxTo = Integer.toString(askTo); - GetPredecessorTask sendTask = new GetPredecessorTask(getHost().getName(), this.mailbox); - try { - sendTask.send(mailboxTo, Common.TIMEOUT); - try { - do { - if (commReceive == null) { - commReceive = Task.irecv(this.mailbox); - } - commReceive.waitCompletion(Common.TIMEOUT); - Task taskReceived = commReceive.getTask(); - if (taskReceived instanceof GetPredecessorAnswerTask) { - predecessorId = ((GetPredecessorAnswerTask) taskReceived).answerId; - stop = true; - } - else { - handleTask(taskReceived); - } - commReceive = null; - } while (!stop); - - } - catch (MsgException e) { - commReceive = null; - stop = true; - } - } - catch (MsgException e) { - Msg.debug("Failed to send the Get Predecessor request"); - } - - - return predecessorId; - } - /** - * @brief Makes the current node find the successor node of an id. - * @param node the current node - * @param id the id to find - * @return the id of the successor node, or -1 if the request failed - */ - int findSuccessor(int id) { - if (isInInterval(id, this.id + 1, fingers[0])) { - return fingers[0]; - } - - int closest = this.closestPrecedingNode(id); - return remoteFindSuccessor(closest, id); - } - /** - * @brief Asks another node the successor node of an id. - */ - int remoteFindSuccessor(int askTo, int id) { - int successor = -1; - boolean stop = false; - String mailbox = Integer.toString(askTo); - Task sendTask = new FindSuccessorTask(getHost().getName(), this.mailbox, id); - Msg.debug("Sending a 'Find Successor' request to " + mailbox + " for id " + id); - try { - sendTask.send(mailbox, Common.TIMEOUT); - do { - if (commReceive == null) { - commReceive = Task.irecv(this.mailbox); - } - try { - commReceive.waitCompletion(Common.TIMEOUT); - Task task = commReceive.getTask(); - if (task instanceof FindSuccessorAnswerTask) { - //TODO: Check if this this our answer. - FindSuccessorAnswerTask fTask = (FindSuccessorAnswerTask) task; - stop = true; - successor = fTask.answerId; - } - else { - handleTask(task); - } - commReceive = null; - } - catch (TimeoutException e) { - stop = true; - commReceive = null; - } - } while (!stop); - } - catch (TimeoutException e) { - Msg.debug("Failed to send the 'Find Successor' request"); - } - catch (MsgException e) { - Msg.debug("Failed to receive Find Successor"); - } - - return successor; - - } - /** - * @brief This function is called periodically. It checks the immediate - * successor of the current node. - */ - void stabilize() { - Msg.debug("Stabilizing node"); - int candidateId; - int successorId = fingers[0]; - if (successorId != this.id){ - candidateId = remoteGetPredecessor(successorId); - } - else { - candidateId = predId; - } - //This node is a candidate to become my new successor - if (candidateId != -1 && isInInterval(candidateId, this.id + 1, successorId - 1)) { - setFinger(0, candidateId); - } - if (successorId != this.id) { - remoteNotify(successorId, this.id); - } - - } - /** - * \brief Notifies the current node that its predecessor may have changed. - * \param candidate_id the possible new predecessor - */ - void notify(int predecessorCandidateId) { - if (predId == -1 || isInInterval(predecessorCandidateId, predId + 1, this.id - 1 )) { - setPredecessor(predecessorCandidateId); - } - else { - //Don't have to change the predecessor. - } - } - /** - * \brief Notifies a remote node that its predecessor may have changed. - * \param notify_id id of the node to notify - * \param candidate_id the possible new predecessor - */ - void remoteNotify(int notifyId, int predecessorCandidateId) { - Msg.debug("Sending a 'Notify' request to " + notifyId); - Task sentTask = new NotifyTask(getHost().getName(), this.mailbox, predecessorCandidateId); - sentTask.dsend(Integer.toString(notifyId)); - } - /** - * \brief This function is called periodically. - * It refreshes the finger table of the current node. - */ - void fixFingers() { - Msg.debug("Fixing fingers"); - int i = this.nextFingerToFix; - int id = this.findSuccessor(this.id + (int)Math.pow(2,i)); //FIXME: SLOW - if (id != -1) { - if (id != fingers[i]) { - setFinger(i, id); - } - nextFingerToFix = (i + 1) % Common.NB_BITS; - } - } - /** - * \brief This function is called periodically. - * It checks whether the predecessor has failed - */ - void checkPredecessor() { - //TODO - } - /** - * \brief Performs a find successor request to a random id. - */ - void randomLookup() { - int id = 1337; - //Msg.info("Making a lookup request for id " + id); - findSuccessor(id); - } - - - - /** - * @brief Returns the closest preceding finger of an id - * with respect to the finger table of the current node. - * @param id the id to find - * \return the closest preceding finger of that id - */ - int closestPrecedingNode(int id) { - int i; - for (i = Common.NB_BITS - 1; i >= 0; i--) { - if (isInInterval(fingers[i], this.id + 1, id - 1)) { - return fingers[i]; - } - } - return this.id; - } - /** - * @brief Returns whether an id belongs to the interval [start, end]. - * - * The parameters are noramlized to make sure they are between 0 and nb_keys - 1). - * 1 belongs to [62, 3] - * 1 does not belong to [3, 62] - * 63 belongs to [62, 3] - * 63 does not belong to [3, 62] - * 24 belongs to [21, 29] - * 24 does not belong to [29, 21] - * - * \param id id to check - * \param start lower bound - * \param end upper bound - * \return a non-zero value if id in in [start, end] - */ - static boolean isInInterval(int id, int start, int end) { - id = normalize(id); - start = normalize(start); - end = normalize(end); - - // make sure end >= start and id >= start - if (end < start) { - end += Common.NB_KEYS; - } - if (id < start) { - id += Common.NB_KEYS; - } - return (id <= end); - - } - /** - * @brief Turns an id into an equivalent id in [0, nb_keys). - * @param id an id - * @return the corresponding normalized id - */ - static int normalize(int id) { - return id & (Common.NB_KEYS - 1); - } - /** - * \brief Sets a finger of the current node. - * \param finger_index index of the finger to set (0 to nb_bits - 1) - * \param id the id to set for this finger - */ - void setFinger(int fingerIndex, int id) { - if (id != fingers[fingerIndex]) { - fingers[fingerIndex] = id; - lastChangeDate = Msg.getClock(); - } - } + protected int id; + protected String mailbox; + protected int predId; + protected String predMailbox; + protected int nextFingerToFix; + protected Comm commReceive; + ///Last time I changed a finger or my predecessor + protected double lastChangeDate; + int fingers[]; + + public Node(Host host, String name, String[] args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + if (args.length != 2 && args.length != 4) { + Msg.info("You need to provide 2 or 4 arguments."); + return; + } + double initTime = Msg.getClock(); + int i; + boolean joinSuccess = false; + double deadline; + + double nextStabilizeDate = initTime + Common.PERIODIC_STABILIZE_DELAY; + double nextFixFingersDate = initTime + Common.PERIODIC_FIX_FINGERS_DELAY; + double nextCheckPredecessorDate = initTime + Common.PERIODIC_CHECK_PREDECESSOR_DELAY; + double nextLookupDate = initTime + Common.PERIODIC_LOOKUP_DELAY; + + id = Integer.valueOf(args[0]); + mailbox = Integer.toString(id); + + fingers = new int[Common.NB_BITS]; + for (i = 0; i < Common.NB_BITS; i++) { + fingers[i] = -1; + setFinger(i,this.id); + } + + //First node + if (args.length == 2) { + deadline = Integer.valueOf(args[1]); + create(); + joinSuccess = true; + } else { + int knownId = Integer.valueOf(args[1]); + deadline = Integer.valueOf(args[3]); + //Msg.info("Hey! Let's join the system with the id " + id + "."); + + joinSuccess = join(knownId); + } + if (joinSuccess) { + double currentClock = Msg.getClock(); + while (currentClock < (initTime + deadline) && currentClock < Common.MAX_SIMULATION_TIME) { + if (commReceive == null) { + commReceive = Task.irecv(this.mailbox); + } + try { + if (!commReceive.test()) { + if (currentClock >= nextStabilizeDate) { + stabilize(); + nextStabilizeDate = Msg.getClock() + Common.PERIODIC_STABILIZE_DELAY; + } else if (currentClock >= nextFixFingersDate) { + fixFingers(); + nextFixFingersDate = Msg.getClock() + Common.PERIODIC_FIX_FINGERS_DELAY; + } else if (currentClock >= nextCheckPredecessorDate) { + this.checkPredecessor(); + nextCheckPredecessorDate = Msg.getClock() + Common.PERIODIC_CHECK_PREDECESSOR_DELAY; + } else if (currentClock >= nextLookupDate) { + this.randomLookup(); + nextLookupDate = Msg.getClock() + Common.PERIODIC_LOOKUP_DELAY; + } else { + waitFor(5); + } + currentClock = Msg.getClock(); + } else { + handleTask(commReceive.getTask()); + currentClock = Msg.getClock(); + commReceive = null; + } + } + catch (Exception e) { + currentClock = Msg.getClock(); + commReceive = null; + } + } + leave(); + if (commReceive != null) { + commReceive = null; + } + } else { + Msg.info("I couldn't join the ring"); + } + } + + void handleTask(Task task) { + if (task instanceof FindSuccessorTask) { + FindSuccessorTask fTask = (FindSuccessorTask)task; + Msg.debug("Receiving a 'Find Successor' request from " + fTask.issuerHostName + " for id " + fTask.requestId); + // is my successor the successor? + if (isInInterval(fTask.requestId, this.id + 1, fingers[0])) { + //Msg.info("Send the request to " + fTask.answerTo + " with answer " + fingers[0]); + FindSuccessorAnswerTask answer = new FindSuccessorAnswerTask(getHost().getName(), mailbox, fingers[0]); + answer.dsend(fTask.answerTo); + } else { + // otherwise, forward the request to the closest preceding finger in my table + int closest = closestPrecedingNode(fTask.requestId); + //Msg.info("Forward the request to " + closest); + fTask.dsend(Integer.toString(closest)); + } + } else if (task instanceof GetPredecessorTask) { + GetPredecessorTask gTask = (GetPredecessorTask)(task); + Msg.debug("Receiving a 'Get Predecessor' request from " + gTask.issuerHostName); + GetPredecessorAnswerTask answer = new GetPredecessorAnswerTask(getHost().getName(), mailbox, predId); + answer.dsend(gTask.answerTo); + } else if (task instanceof NotifyTask) { + NotifyTask nTask = (NotifyTask)task; + notify(nTask.requestId); + } else { + Msg.debug("Ignoring unexpected task of type:" + task); + } + } + + void leave() { + Msg.debug("Well Guys! I Think it's time for me to quit ;)"); + quitNotify(1); //Notify my successor + quitNotify(-1); //Notify my predecessor. + } + + /** + * @brief Notifies the successor or the predecessor of the current node of the departure + * @param to 1 to notify the successor, -1 to notify the predecessor + */ + static void quitNotify( int to) { + //TODO + } + + /** + * @brief Initializes the current node as the first one of the system. + */ + void create() { + Msg.debug("Create a new Chord ring..."); + setPredecessor(-1); + } + + // Makes the current node join the ring, knowing the id of a node already in the ring + boolean join(int knownId) { + Msg.info("Joining the ring with id " + this.id + " knowing node " + knownId); + setPredecessor(-1); + int successorId = remoteFindSuccessor(knownId, this.id); + if (successorId == -1) { + Msg.info("Cannot join the ring."); + } else { + setFinger(0, successorId); + } + return successorId != -1; + } + + void setPredecessor(int predecessorId) { + if (predecessorId != predId) { + predId = predecessorId; + if (predecessorId != -1) { + predMailbox = Integer.toString(predId); + } + lastChangeDate = Msg.getClock(); + } + } + + /** + * @brief Asks another node its predecessor. + * @param askTo the node to ask to + * @return the id of its predecessor node, or -1 if the request failed(or if the node does not know its predecessor) + */ + int remoteGetPredecessor(int askTo) { + int predecessorId = -1; + boolean stop = false; + Msg.debug("Sending a 'Get Predecessor' request to " + askTo); + String mailboxTo = Integer.toString(askTo); + GetPredecessorTask sendTask = new GetPredecessorTask(getHost().getName(), this.mailbox); + try { + sendTask.send(mailboxTo, Common.TIMEOUT); + try { + do { + if (commReceive == null) { + commReceive = Task.irecv(this.mailbox); + } + commReceive.waitCompletion(Common.TIMEOUT); + Task taskReceived = commReceive.getTask(); + if (taskReceived instanceof GetPredecessorAnswerTask) { + predecessorId = ((GetPredecessorAnswerTask) taskReceived).answerId; + stop = true; + } else { + handleTask(taskReceived); + } + commReceive = null; + } while (!stop); + } + catch (MsgException e) { + commReceive = null; + stop = true; + } + } + catch (MsgException e) { + Msg.debug("Failed to send the Get Predecessor request"); + } + return predecessorId; + } + + /** + * @brief Makes the current node find the successor node of an id. + * @param node the current node + * @param id the id to find + * @return the id of the successor node, or -1 if the request failed + */ + int findSuccessor(int id) { + if (isInInterval(id, this.id + 1, fingers[0])) { + return fingers[0]; + } + + int closest = this.closestPrecedingNode(id); + return remoteFindSuccessor(closest, id); + } + + // Asks another node the successor node of an id. + int remoteFindSuccessor(int askTo, int id) { + int successor = -1; + boolean stop = false; + String mailbox = Integer.toString(askTo); + Task sendTask = new FindSuccessorTask(getHost().getName(), this.mailbox, id); + Msg.debug("Sending a 'Find Successor' request to " + mailbox + " for id " + id); + try { + sendTask.send(mailbox, Common.TIMEOUT); + do { + if (commReceive == null) { + commReceive = Task.irecv(this.mailbox); + } + try { + commReceive.waitCompletion(Common.TIMEOUT); + Task task = commReceive.getTask(); + if (task instanceof FindSuccessorAnswerTask) { + //TODO: Check if this this our answer. + FindSuccessorAnswerTask fTask = (FindSuccessorAnswerTask) task; + stop = true; + successor = fTask.answerId; + } else { + handleTask(task); + } + commReceive = null; + } + catch (TimeoutException e) { + stop = true; + commReceive = null; + } + } while (!stop); + } + catch (TimeoutException e) { + Msg.debug("Failed to send the 'Find Successor' request"); + } + catch (MsgException e) { + Msg.debug("Failed to receive Find Successor"); + } + + return successor; + } + + // This function is called periodically. It checks the immediate successor of the current node. + void stabilize() { + Msg.debug("Stabilizing node"); + int candidateId; + int successorId = fingers[0]; + if (successorId != this.id){ + candidateId = remoteGetPredecessor(successorId); + } else { + candidateId = predId; + } + //This node is a candidate to become my new successor + if (candidateId != -1 && isInInterval(candidateId, this.id + 1, successorId - 1)) { + setFinger(0, candidateId); + } + if (successorId != this.id) { + remoteNotify(successorId, this.id); + } + } + + /** + * @brief Notifies the current node that its predecessor may have changed. + * @param candidate_id the possible new predecessor + */ + void notify(int predecessorCandidateId) { + if (predId == -1 || isInInterval(predecessorCandidateId, predId + 1, this.id - 1 )) { + setPredecessor(predecessorCandidateId); + } + } + + /** + * @brief Notifies a remote node that its predecessor may have changed. + * @param notify_id id of the node to notify + * @param candidate_id the possible new predecessor + */ + void remoteNotify(int notifyId, int predecessorCandidateId) { + Msg.debug("Sending a 'Notify' request to " + notifyId); + Task sentTask = new NotifyTask(getHost().getName(), this.mailbox, predecessorCandidateId); + sentTask.dsend(Integer.toString(notifyId)); + } + + // This function is called periodically. + // It refreshes the finger table of the current node. + void fixFingers() { + Msg.debug("Fixing fingers"); + int i = this.nextFingerToFix; + int id = this.findSuccessor(this.id + (int)Math.pow(2,i)); //FIXME: SLOW + if (id != -1) { + if (id != fingers[i]) { + setFinger(i, id); + } + nextFingerToFix = (i + 1) % Common.NB_BITS; + } + } + + // This function is called periodically. + // It checks whether the predecessor has failed + void checkPredecessor() { + //TODO + } + + // Performs a find successor request to a random id. + void randomLookup() { + int id = 1337; + //Msg.info("Making a lookup request for id " + id); + findSuccessor(id); + } + + /** + * @brief Returns the closest preceding finger of an id with respect to the finger table of the current node. + * @param id the id to find + * @return the closest preceding finger of that id + */ + int closestPrecedingNode(int id) { + int i; + for (i = Common.NB_BITS - 1; i >= 0; i--) { + if (isInInterval(fingers[i], this.id + 1, id - 1)) { + return fingers[i]; + } + } + return this.id; + } + + /** + * @brief Returns whether an id belongs to the interval [start, end]. + * + * The parameters are noramlized to make sure they are between 0 and nb_keys - 1). + * 1 belongs to [62, 3] + * 1 does not belong to [3, 62] + * 63 belongs to [62, 3] + * 63 does not belong to [3, 62] + * 24 belongs to [21, 29] + * 24 does not belong to [29, 21] + * + * @param id id to check + * @param start lower bound + * @param end upper bound + * @return a non-zero value if id in in [start, end] + */ + static boolean isInInterval(int id, int start, int end) { + id = normalize(id); + start = normalize(start); + end = normalize(end); + + // make sure end >= start and id >= start + if (end < start) { + end += Common.NB_KEYS; + } + if (id < start) { + id += Common.NB_KEYS; + } + return (id <= end); + } + + /** + * @brief Turns an id into an equivalent id in [0, nb_keys). + * @param id an id + * @return the corresponding normalized id + */ + static int normalize(int id) { + return id & (Common.NB_KEYS - 1); + } + + /** + * @brief Sets a finger of the current node. + * @param finger_index index of the finger to set (0 to nb_bits - 1) + * @param id the id to set for this finger + */ + void setFinger(int fingerIndex, int id) { + if (id != fingers[fingerIndex]) { + fingers[fingerIndex] = id; + lastChangeDate = Msg.getClock(); + } + } } diff --git a/examples/java/chord/NotifyTask.java b/examples/java/chord/NotifyTask.java index b36c4caf6d..b7b69197c1 100644 --- a/examples/java/chord/NotifyTask.java +++ b/examples/java/chord/NotifyTask.java @@ -7,9 +7,9 @@ package chord; public class NotifyTask extends ChordTask { - public int requestId; - public NotifyTask(String issuerHostname, String answerTo, int requestId) { - super(issuerHostname, answerTo); - this.requestId = requestId; - } + public int requestId; + public NotifyTask(String issuerHostname, String answerTo, int requestId) { + super(issuerHostname, answerTo); + this.requestId = requestId; + } } diff --git a/examples/java/chord/chord.xml b/examples/java/chord/chord.xml index a96ae02bdb..6aa3bdfe61 100644 --- a/examples/java/chord/chord.xml +++ b/examples/java/chord/chord.xml @@ -1,59 +1,50 @@ - - + - - + - - + - - + - - + - - + - - + - - + - diff --git a/examples/java/cloud/CMakeLists.txt b/examples/java/cloud/CMakeLists.txt index ee6b4f31b1..9a643921fe 100644 --- a/examples/java/cloud/CMakeLists.txt +++ b/examples/java/cloud/CMakeLists.txt @@ -30,9 +30,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/cloud/Cloud.java b/examples/java/cloud/Cloud.java index 9848bc3e8d..f5f2cd9de7 100644 --- a/examples/java/cloud/Cloud.java +++ b/examples/java/cloud/Cloud.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,35 +6,34 @@ package cloud; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; +import org.simgrid.msg.Host; import org.simgrid.msg.MsgException; -/** - * Example showing the use of the new experimental Cloud API. - */ + public class Cloud { - public static final double task_comp_size = 10; - public static final double task_comm_size = 10; - public static final int hostNB = 2 ; - public static void main(String[] args) throws MsgException { - Msg.init(args); - - if (args.length < 1) { - Msg.info("Usage : Cloud platform_file"); - Msg.info("Usage : Cloud platform.xml"); - System.exit(1); - } - /* Construct the platform */ - Msg.createEnvironment(args[0]); - Host[] hosts = Host.all(); - if (hosts.length < hostNB+1) { - Msg.info("I need at least "+ (hostNB+1) +" hosts in the platform file, but " + args[0] + " contains only " + hosts.length + " hosts"); - System.exit(42); - } - Msg.info("Start"+ hostNB +" hosts"); - new Master(hosts[0],"Master",hosts).start(); - /* Execute the simulation */ - Msg.run(); - + public static final double task_comp_size = 10; + public static final double task_comm_size = 10; + public static final int hostNB = 2 ; + public static void main(String[] args) throws MsgException { + Msg.init(args); + + if (args.length < 1) { + Msg.info("Usage : Cloud platform_file"); + Msg.info("Usage : Cloud ../platforms/platform.xml"); + System.exit(1); + } + + /* Construct the platform */ + Msg.createEnvironment(args[0]); + Host[] hosts = Host.all(); + if (hosts.length < hostNB+1) { + Msg.info("I need at least "+ (hostNB+1) +" hosts in the platform file, but " + args[0] + " contains only " + + hosts.length + " hosts"); + System.exit(42); } + Msg.info("Start"+ hostNB +" hosts"); + new Master(hosts[0],"Master",hosts).start(); + /* Execute the simulation */ + Msg.run(); + } } diff --git a/examples/java/cloud/FinalizeTask.java b/examples/java/cloud/FinalizeTask.java index b710b2fa54..d0cebd084f 100644 --- a/examples/java/cloud/FinalizeTask.java +++ b/examples/java/cloud/FinalizeTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014,2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -9,7 +9,7 @@ package cloud; import org.simgrid.msg.Task; public class FinalizeTask extends Task { - public FinalizeTask(double compSize, double commSize) { - super("Finalize",compSize,commSize); - } + public FinalizeTask(double compSize, double commSize) { + super("Finalize",compSize,commSize); + } } \ No newline at end of file diff --git a/examples/java/cloud/Master.java b/examples/java/cloud/Master.java index d3606c90dc..c1e13731d6 100644 --- a/examples/java/cloud/Master.java +++ b/examples/java/cloud/Master.java @@ -8,88 +8,87 @@ package cloud; import java.util.ArrayList; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; -import org.simgrid.msg.Task; import org.simgrid.msg.VM; +import org.simgrid.msg.Host; +import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Master extends Process { - private Host[] hosts; - - public Master(Host host, String name, Host[] hosts) { - super(host,name,null); - this.hosts = hosts; - } - public void main(String[] args) throws MsgException { - int slavesCount = Cloud.hostNB; - - ArrayList vms = new ArrayList(); - - // Create one VM per host and bind a process inside each one. - for (int i = 0; i < slavesCount; i++) { - Msg.info("create VM0"+i); - VM vm = new VM(hosts[i+1],"VM0"+i); - vm.start(); - vms.add(vm); - Slave slave = new Slave(vm,i); - Msg.info("Put Worker "+slave.getName()+ " on "+vm.getName()); - slave.start(); - - } - Msg.info("Launched " + vms.size() + " VMs"); - - Msg.info("Send a first batch of work to everyone"); - workBatch(slavesCount); - - Msg.info("Suspend all VMs"); - for (int i = 0; i < vms.size(); i++) { - Msg.info("Suspend "+vms.get(i).getName()); - vms.get(i).suspend(); - } - - Msg.info("Wait a while"); - waitFor(2); - - Msg.info("Resume all VMs."); - for (int i = 0; i < vms.size(); i++) { - vms.get(i).resume(); - } - - Msg.info("Sleep long enough for everyone to be done with previous batch of work"); - waitFor(1000 - Msg.getClock()); - -/* Msg.info("Add one more process per VM."); - for (int i = 0; i < vms.size(); i++) { - VM vm = vms.get(i); - Slave slave = new Slave(vm,i + vms.size()); - slave.start(); - } - - workBatch(slavesCount * 2); + private Host[] hosts; + + public Master(Host host, String name, Host[] hosts) { + super(host,name,null); + this.hosts = hosts; + } + + public void main(String[] args) throws MsgException { + int slavesCount = Cloud.hostNB; + ArrayList vms = new ArrayList(); + + // Create one VM per host and bind a process inside each one. + for (int i = 0; i < slavesCount; i++) { + Msg.info("create VM0"+i); + VM vm = new VM(hosts[i+1],"VM0"+i); + vm.start(); + vms.add(vm); + Slave slave = new Slave(vm,i); + Msg.info("Put Worker "+slave.getName()+ " on "+vm.getName()); + slave.start(); + } + + Msg.info("Launched " + vms.size() + " VMs"); + + Msg.info("Send a first batch of work to everyone"); + workBatch(slavesCount); + + Msg.info("Suspend all VMs"); + for (int i = 0; i < vms.size(); i++) { + Msg.info("Suspend "+vms.get(i).getName()); + vms.get(i).suspend(); + } + + Msg.info("Wait a while"); + waitFor(2); + + Msg.info("Resume all VMs."); + for (int i = 0; i < vms.size(); i++) { + vms.get(i).resume(); + } + + Msg.info("Sleep long enough for everyone to be done with previous batch of work"); + waitFor(1000 - Msg.getClock()); + +/* Msg.info("Add one more process per VM."); + for (int i = 0; i < vms.size(); i++) { + VM vm = vms.get(i); + Slave slave = new Slave(vm,i + vms.size()); + slave.start(); + } + + workBatch(slavesCount * 2); */ - Msg.info("Migrate everyone to "+hosts[3].getName()); - for (int i = 0; i < vms.size(); i++) { - Msg.info("Migrate "+vms.get(i).getName()+"from"+hosts[i+1].getName()+"to "+hosts[3].getName()); - vms.get(i).migrate(hosts[3]); - } - - - Msg.info("Let's shut down the simulation and kill everyone."); - - for (int i = 0; i < vms.size(); i++) { - vms.get(i).shutdown(); - } - Msg.info("Master done."); - } - - public void workBatch(int slavesCount) throws MsgException { - for (int i = 0; i < slavesCount; i++) { - Task task = new Task("Task0" + i, Cloud.task_comp_size, Cloud.task_comm_size); - Msg.info("Sending to WRK0" + i); - task.send("MBOX:WRK0" + i); - } - } + Msg.info("Migrate everyone to "+hosts[3].getName()); + for (int i = 0; i < vms.size(); i++) { + Msg.info("Migrate "+vms.get(i).getName()+"from"+hosts[i+1].getName()+"to "+hosts[3].getName()); + vms.get(i).migrate(hosts[3]); + } + + Msg.info("Let's shut down the simulation and kill everyone."); + + for (int i = 0; i < vms.size(); i++) { + vms.get(i).shutdown(); + } + Msg.info("Master done."); + } + + public void workBatch(int slavesCount) throws MsgException { + for (int i = 0; i < slavesCount; i++) { + Task task = new Task("Task0" + i, Cloud.task_comp_size, Cloud.task_comm_size); + Msg.info("Sending to WRK0" + i); + task.send("MBOX:WRK0" + i); + } + } } diff --git a/examples/java/cloud/Slave.java b/examples/java/cloud/Slave.java index d97b0be612..b8b3728da2 100644 --- a/examples/java/cloud/Slave.java +++ b/examples/java/cloud/Slave.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,41 +6,39 @@ package cloud; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Slave extends Process { - private int number; - public Slave(Host host, int number) { - super(host,"WRK0" + number,null); - this.number = number; - } - public void main(String[] args) throws MsgException { - Msg.info(this.getName() +" is listenning on MBOX:WRK0"+ number); - while(true) { - Task task; - try { - task = Task.receive("MBOX:WRK0"+number); - } catch (MsgException e) { - Msg.debug("Received failed. I'm done. See you!"); - break; - } - if (task instanceof FinalizeTask) { - Msg.info("Received Finalize. I'm done. See you!"); - break; - } - Msg.info("Received \"" + task.getName() + "\". Processing it."); - try { - task.execute(); - } catch (MsgException e) { - - } - Msg.info(this.getName() +" executed task (" + task.getName()+")"); - } + private int number; + public Slave(Host host, int number) { + super(host,"WRK0" + number,null); + this.number = number; + } - - } + public void main(String[] args) throws MsgException { + Msg.info(this.getName() +" is listenning on MBOX:WRK0"+ number); + while(true) { + Task task; + try { + task = Task.receive("MBOX:WRK0"+number); + } catch (MsgException e) { + Msg.debug("Received failed. I'm done. See you!"); + break; + } + if (task instanceof FinalizeTask) { + Msg.info("Received Finalize. I'm done. See you!"); + break; + } + Msg.info("Received \"" + task.getName() + "\". Processing it."); + try { + task.execute(); + } catch (MsgException e) { + } + Msg.info(this.getName() +" executed task (" + task.getName()+")"); + } + } } diff --git a/examples/java/cloud/energy/CMakeLists.txt b/examples/java/cloud/energy/CMakeLists.txt index 10612d9aa0..b02fcf6e04 100644 --- a/examples/java/cloud/energy/CMakeLists.txt +++ b/examples/java/cloud/energy/CMakeLists.txt @@ -28,9 +28,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/cloud/energy/EnergyVMRunner.java b/examples/java/cloud/energy/EnergyVMRunner.java index f967fa1220..17d8e09be0 100644 --- a/examples/java/cloud/energy/EnergyVMRunner.java +++ b/examples/java/cloud/energy/EnergyVMRunner.java @@ -8,63 +8,64 @@ package cloud.energy; import org.simgrid.msg.*; import org.simgrid.msg.Process; -/* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within the VMs */ +/* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */ public class EnergyVMRunner extends Process { - public class DummyProcess extends Process { - public DummyProcess (Host host, String name) { - super(host, name); - } - - public void main(String[] args) { - Task task = new Task(this.getHost().getName()+"-task", 300E6 , 0); - try { - task.execute(); - } catch (Exception e) { - e.printStackTrace(); - } - Msg.info("This worker is done."); - } - } - - EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException, NativeException { - super(host, name, args); - } - - public void main(String[] strings) throws MsgException, HostNotFoundException { - double startTime = 0; - double endTime = 0; - - /* get hosts */ - Host host1 = Host.getByName("MyHost1"); - Host host2 = Host.getByName("MyHost2"); - Host host3 = Host.getByName("MyHost3"); - - Msg.info("Creating and starting two VMs"); - VM vmHost1 = new VM(host1, "vmHost1", 4, 2048, 100, null, 1024 * 20, 10,50); - vmHost1.start(); - - VM vmHost3 = new VM(host3, "vmHost3", 4, 2048, 100, null, 1024 * 20, 10,50); - vmHost3.start(); - - Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host"); - new DummyProcess (vmHost1, "p11"); - new DummyProcess (host1, "p12"); - - Msg.info("Create two tasks on Host2: both directly on the host"); - new DummyProcess (host2, "p21"); - new DummyProcess (host2, "p22"); - - Msg.info("Create two tasks on Host3: both inside a VM"); - new DummyProcess (vmHost3, "p31"); - new DummyProcess (vmHost3, "p312"); - - Msg.info("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, so they run for 6 seconds)"); - waitFor(5); - Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); - waitFor(5); - - vmHost1.shutdown(); - vmHost3.shutdown(); - } + public class DummyProcess extends Process { + public DummyProcess (Host host, String name) { + super(host, name); + } + + public void main(String[] args) { + Task task = new Task(this.getHost().getName()+"-task", 300E6 , 0); + try { + task.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + Msg.info("This worker is done."); + } + } + + EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException, NativeException { + super(host, name, args); + } + + public void main(String[] strings) throws MsgException, HostNotFoundException { + double startTime = 0; + double endTime = 0; + + /* get hosts */ + Host host1 = Host.getByName("MyHost1"); + Host host2 = Host.getByName("MyHost2"); + Host host3 = Host.getByName("MyHost3"); + + Msg.info("Creating and starting two VMs"); + VM vmHost1 = new VM(host1, "vmHost1", 4, 2048, 100, null, 1024 * 20, 10,50); + vmHost1.start(); + + VM vmHost3 = new VM(host3, "vmHost3", 4, 2048, 100, null, 1024 * 20, 10,50); + vmHost3.start(); + + Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host"); + new DummyProcess (vmHost1, "p11"); + new DummyProcess (host1, "p12"); + + Msg.info("Create two tasks on Host2: both directly on the host"); + new DummyProcess (host2, "p21"); + new DummyProcess (host2, "p22"); + + Msg.info("Create two tasks on Host3: both inside a VM"); + new DummyProcess (vmHost3, "p31"); + new DummyProcess (vmHost3, "p312"); + + Msg.info("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, " + + "so they run for 6 seconds)"); + waitFor(5); + Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); + waitFor(5); + + vmHost1.shutdown(); + vmHost3.shutdown(); + } } diff --git a/examples/java/cloud/energy/Main.java b/examples/java/cloud/energy/Main.java index 931d2fd50f..1913e4d9f4 100644 --- a/examples/java/cloud/energy/Main.java +++ b/examples/java/cloud/energy/Main.java @@ -5,29 +5,28 @@ package cloud.energy; +import org.simgrid.msg.Msg; import org.simgrid.msg.Host; import org.simgrid.msg.HostNotFoundException; -import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class Main { - public static void main(String[] args) throws NativeException, HostNotFoundException { - /* Init. internal values */ - Msg.energyInit(); - Msg.init(args); + public static void main(String[] args) throws NativeException, HostNotFoundException { + Msg.energyInit(); + Msg.init(args); - if (args.length < 1) { - Msg.info("Usage: Main platform_file.xml"); - System.exit(1); - } + if (args.length < 1) { + Msg.info("Usage: Main ../platforms/energy_platform_file.xml"); + System.exit(1); + } - /* construct the platform */ - Msg.createEnvironment(args[0]); - - /* Create and start a runner for the experiment */ - new EnergyVMRunner(Host.all()[0],"energy VM runner",null).start(); + /* construct the platform */ + Msg.createEnvironment(args[0]); + + /* Create and start a runner for the experiment */ + new EnergyVMRunner(Host.all()[0],"energy VM runner",null).start(); - Msg.run(); - } + Msg.run(); + } } diff --git a/examples/java/cloud/migration/CMakeLists.txt b/examples/java/cloud/migration/CMakeLists.txt index d321f403e5..4cd57c4617 100644 --- a/examples/java/cloud/migration/CMakeLists.txt +++ b/examples/java/cloud/migration/CMakeLists.txt @@ -32,9 +32,6 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) set(txt_files ${CMAKE_CURRENT_SOURCE_DIR}/README ${txt_files} diff --git a/examples/java/cloud/migration/Main.java b/examples/java/cloud/migration/Main.java index cd0a6ae670..df35b648d5 100644 --- a/examples/java/cloud/migration/Main.java +++ b/examples/java/cloud/migration/Main.java @@ -6,37 +6,34 @@ package cloud.migration; +import org.simgrid.msg.Msg; import org.simgrid.msg.Host; import org.simgrid.msg.HostNotFoundException; -import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class Main { - private static boolean endOfTest = false; - - public static void setEndOfTest(){ - endOfTest=true; - } + private static boolean endOfTest = false; - public static boolean isEndOfTest(){ - return endOfTest; - } - - public static void main(String[] args) throws NativeException { - /* Init. internal values */ - Msg.init(args); + public static void setEndOfTest(){ + endOfTest=true; + } - if (args.length < 2) { - Msg.info("Usage : Main platform_file.xml dployment_file.xml"); - System.exit(1); - } + public static boolean isEndOfTest(){ + return endOfTest; + } - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); + public static void main(String[] args) throws NativeException { + Msg.init(args); - Msg.run(); + if (args.length < 2) { + Msg.info("Usage : Main platform_file.xml dployment_file.xml"); + System.exit(1); + } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); - } + Msg.run(); + } } diff --git a/examples/java/cloud/migration/Test.java b/examples/java/cloud/migration/Test.java index b697049f8e..e67b32c4e6 100644 --- a/examples/java/cloud/migration/Test.java +++ b/examples/java/cloud/migration/Test.java @@ -1,152 +1,148 @@ -/* Copyright (c) 2014. The SimGrid Team. +/* Copyright (c) 2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package cloud.migration; +import java.util.ArrayList; +import java.util.List; + import org.simgrid.msg.*; import org.simgrid.msg.Process; -import java.util.ArrayList; -import java.util.List; public class Test extends Process{ - Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException { - super(host, name, args); + Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException { + super(host, name, args); + } + + public void main(String[] strings) throws MsgException { + double startTime = 0; + double endTime = 0; + + /* get hosts 1 and 2*/ + Host host0 = null; + Host host1 = null; + + try { + host0 = Host.getByName("host0"); + host1 = Host.getByName("host1"); + }catch (HostNotFoundException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } - public void main(String[] strings) throws MsgException { - - double startTime = 0; - double endTime = 0; - - /* get hosts 1 and 2*/ - Host host0 = null; - Host host1 = null; - - try { - host0 = Host.getByName("host0"); - host1 = Host.getByName("host1"); - }catch (HostNotFoundException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - - List vms = new ArrayList(); - - /* Create VM1 */ - int dpRate = 70; - int load1 = 90; - int load2 = 80; - - - Msg.info("This example evaluates the migration time of a VM in presence of collocated VMs on the source and the dest nodes"); - Msg.info("The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% \"(see cloudcom 2013 paper \"Adding a Live Migration Model Into SimGrid\" for further information) "); - - Msg.info("Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see whether it impacts or not the migration time"); - XVM vm1 = null; - vm1 = new XVM( - host0, - "vm0", - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity + List vms = new ArrayList(); + + /* Create VM1 */ + int dpRate = 70; + int load1 = 90; + int load2 = 80; + + Msg.info("This example evaluates the migration time of a VM in presence of collocated VMs on the source and " + + "the dest nodes"); + Msg.info("The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% \" " + +"(see cloudcom 2013 paper \"Adding a Live Migration Model Into SimGrid\" for further information) "); + + Msg.info("Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see " + + "whether it impacts or not the migration time"); + XVM vm1 = null; + vm1 = new XVM(host0, "vm0", + 1, // Nb of vcpu + 2048, // Ramsize, + 125, // Net Bandwidth + null, //VM disk image + -1, //size of disk image, + 125, // Net bandwidth, + dpRate // Memory intensity ); - vms.add(vm1); - vm1.start(); - - /* Collocated VMs */ - int collocatedSrc = 6; - int vmSrcLoad[] = { - 80, - 0, - 90, - 40, - 30, - 90, - }; - - XVM tmp = null; - for (int i=1 ; i<= collocatedSrc ; i++){ - tmp = new XVM( - host0, - "vm"+i, - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity - ); - vms.add(tmp); - tmp.start(); - tmp.setLoad(vmSrcLoad[i-1]); - } - - int collocatedDst = 6; - int vmDstLoad[] = { - 0, - 40, - 90, - 100, - 0, - 80, - }; - - for (int i=1 ; i <= collocatedDst ; i++){ - tmp = new XVM( - host1, - "vm"+(i+collocatedSrc), - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity - ); - vms.add(tmp); - tmp.start(); - tmp.setLoad(vmDstLoad[i-1]); - } - - Msg.info("Round trip of VM1 (load "+load1+"%)"); - vm1.setLoad(load1); - Msg.info(" - Launch migration from host 0 to host 1"); - startTime = Msg.getClock(); - vm1.migrate(host1); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")"); - Msg.info(" - Launch migration from host 1 to host 0"); - startTime = Msg.getClock(); - vm1.migrate(host0); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")"); - - - Msg.info("\n \n \nRound trip of VM1 (load "+load2+"%)"); - vm1.setLoad(load2); - Msg.info(" - Launch migration from host 0 to host 1"); - startTime = Msg.getClock(); - vm1.migrate(host1); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")"); - Msg.info(" - Launch migration from host 1 to host 0"); - startTime = Msg.getClock(); - vm1.migrate(host0); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")"); - - Main.setEndOfTest(); - Msg.info("Forcefully destroy VMs"); - for (VM vm: vms) - vm.finalize(); - + vms.add(vm1); + vm1.start(); + + /* Collocated VMs */ + int collocatedSrc = 6; + int vmSrcLoad[] = { + 80, + 0, + 90, + 40, + 30, + 90, + }; + + XVM tmp = null; + for (int i=1 ; i<= collocatedSrc ; i++){ + tmp = new XVM(host0, "vm"+i, + 1, // Nb of vcpu + 2048, // Ramsize, + 125, // Net Bandwidth + null, //VM disk image + -1, //size of disk image, + 125, // Net bandwidth, + dpRate // Memory intensity + ); + vms.add(tmp); + tmp.start(); + tmp.setLoad(vmSrcLoad[i-1]); } + + int collocatedDst = 6; + int vmDstLoad[] = { + 0, + 40, + 90, + 100, + 0, + 80, + }; + + for (int i=1 ; i <= collocatedDst ; i++){ + tmp = new XVM(host1, "vm"+(i+collocatedSrc), + 1, // Nb of vcpu + 2048, // Ramsize, + 125, // Net Bandwidth + null, //VM disk image + -1, //size of disk image, + 125, // Net bandwidth, + dpRate // Memory intensity + ); + vms.add(tmp); + tmp.start(); + tmp.setLoad(vmDstLoad[i-1]); + } + + Msg.info("Round trip of VM1 (load "+load1+"%)"); + vm1.setLoad(load1); + Msg.info(" - Launch migration from host 0 to host 1"); + startTime = Msg.getClock(); + vm1.migrate(host1); + endTime = Msg.getClock(); + Msg.info(" - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")"); + Msg.info(" - Launch migration from host 1 to host 0"); + startTime = Msg.getClock(); + vm1.migrate(host0); + endTime = Msg.getClock(); + Msg.info(" - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")"); + + Msg.info(""); + Msg.info(""); + Msg.info("Round trip of VM1 (load "+load2+"%)"); + vm1.setLoad(load2); + Msg.info(" - Launch migration from host 0 to host 1"); + startTime = Msg.getClock(); + vm1.migrate(host1); + endTime = Msg.getClock(); + Msg.info(" - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")"); + Msg.info(" - Launch migration from host 1 to host 0"); + startTime = Msg.getClock(); + vm1.migrate(host0); + endTime = Msg.getClock(); + Msg.info(" - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")"); + + Main.setEndOfTest(); + Msg.info("Forcefully destroy VMs"); + for (VM vm: vms) + vm.finalize(); + } } diff --git a/examples/java/cloud/migration/TestHostOnOff.java b/examples/java/cloud/migration/TestHostOnOff.java index 47467bd178..a564bb937c 100644 --- a/examples/java/cloud/migration/TestHostOnOff.java +++ b/examples/java/cloud/migration/TestHostOnOff.java @@ -6,179 +6,164 @@ package cloud.migration; -import org.simgrid.msg.*; -import org.simgrid.msg.Process; import java.util.ArrayList; import java.util.List; import java.util.Random; -// This test aims at validating that the migration process is robust in face of host turning off either on the SRC node or on the DST node. +import org.simgrid.msg.*; +import org.simgrid.msg.Process; +// This test aims at validating that the migration process is robust in face of host turning off either on the SRC +// node or on the DST node. public class TestHostOnOff extends Process{ - public static Host host0 = null; - public static Host host1 = null; - public static Host host2 = null; - + public static Host host0 = null; + public static Host host1 = null; + public static Host host2 = null; - TestHostOnOff(Host host, String name, String[] args) throws HostNotFoundException, NativeException { - super(host, name, args); - } - public void main(String[] strings) throws MsgException { + TestHostOnOff(Host host, String name, String[] args) throws HostNotFoundException, NativeException { + super(host, name, args); + } - double startTime = 0; - double endTime = 0; + public void main(String[] strings) throws MsgException { + double startTime = 0; + double endTime = 0; - /* get hosts 1 and 2*/ - try { - host0 = Host.getByName("host0"); - host1 = Host.getByName("host1"); - host1 = Host.getByName("host2"); - }catch (HostNotFoundException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - - // Robustness on the SRC node - //for (int i =0 ; i < 55000 ; i++) - // test_vm_migrate(host1, i); - - // Robustness on the DST node - //for (int i =0 ; i < 55000 ; i++) - // test_vm_migrate(host2, i); - - /* End of Tests */ - Msg.info("Nor more tests, Bye Bye !"); - Main.setEndOfTest(); + /* get hosts 1 and 2*/ + try { + host0 = Host.getByName("host0"); + host1 = Host.getByName("host1"); + host1 = Host.getByName("host2"); + }catch (HostNotFoundException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } - public static void test_vm_migrate (Host hostToKill, long killAt) throws MsgException { - Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****"); - Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and turn off either the SRC or DST"); - - host1.off(); - host2.off(); - host1.on(); - host2.on(); - - // Create VM0 - int dpRate = 70; - XVM vm0 = null; - vm0 = new XVM( - host1, - "vm0", - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity + // Robustness on the SRC node + //for (int i =0 ; i < 55000 ; i++) + // test_vm_migrate(host1, i); + + // Robustness on the DST node + //for (int i =0 ; i < 55000 ; i++) + // test_vm_migrate(host2, i); + + /* End of Tests */ + Msg.info("Nor more tests, Bye Bye !"); + Main.setEndOfTest(); + } + + public static void test_vm_migrate (Host hostToKill, long killAt) throws MsgException { + Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****"); + Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and " + + "turn off either the SRC or DST"); + + host1.off(); + host2.off(); + host1.on(); + host2.on(); + + // Create VM0 + int dpRate = 70; + XVM vm0 = null; + vm0 = new XVM(host1, "vm0", + 1, // Nb of vcpu + 2048, // Ramsize, + 125, // Net Bandwidth + null, //VM disk image + -1, //size of disk image, + 125, // Net bandwidth, + dpRate // Memory intensity ); - vm0.start(); - vm0.setLoad(90); - - String[] args = new String[3]; - - args[0] = "vm0"; - args[1] = "host1"; - args[2] = "host2"; - new Process(host1, "Migrate-" + new Random().nextDouble(), args) { - public void main(String[] args) { - Host destHost = null; - Host sourceHost = null; - - try { - sourceHost = Host.getByName(args[1]); - destHost = Host.getByName(args[2]); - } catch (Exception e) { - e.printStackTrace(); - System.err.println("You are trying to migrate from/to a non existing node"); - } - if (destHost != null) { - if (sourceHost.isOn() && destHost.isOn()) { - - try { - Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName()); - VM.getVMByName(args[0]).migrate(destHost); - } catch (HostFailureException e) { - e.printStackTrace(); - Msg.info("Something occurs during the migration that cannot validate the operation"); - } - } - } - + vm0.start(); + vm0.setLoad(90); + + String[] args = new String[3]; + + args[0] = "vm0"; + args[1] = "host1"; + args[2] = "host2"; + new Process(host1, "Migrate-" + new Random().nextDouble(), args) { + public void main(String[] args) { + Host destHost = null; + Host sourceHost = null; + + try { + sourceHost = Host.getByName(args[1]); + destHost = Host.getByName(args[2]); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("You are trying to migrate from/to a non existing node"); + } + if (destHost != null) { + if (sourceHost.isOn() && destHost.isOn()) { + try { + Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName()); + VM.getVMByName(args[0]).migrate(destHost); + } catch (HostFailureException e) { + e.printStackTrace(); + Msg.info("Something occurs during the migration that cannot validate the operation"); } - }.start(); - - // Wait killAt ms before killing thehost - Process.sleep(killAt); - hostToKill.off(); - Process.sleep(5); - Msg.info("The migration process should be stopped and we should catch an exception\n"); - Process.sleep(5); - - Process.sleep(50000); - Msg.info("Destroy VMs"); - vm0.shutdown(); - Process.sleep(20000); - } - - - public static void test_vm_shutdown_destroy () throws HostFailureException { - - Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****"); - Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " + - "and check whether you can reallocate the same VM"); - - - // Create VM0 - int dpRate = 70; - XVM vm0 = null; - vm0 = new XVM( - host1, - "vm0", - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity + } + } + } + }.start(); + + // Wait killAt ms before killing thehost + Process.sleep(killAt); + hostToKill.off(); + Process.sleep(5); + Msg.info("The migration process should be stopped and we should catch an exception\n"); + Process.sleep(5); + + Process.sleep(50000); + Msg.info("Destroy VMs"); + vm0.shutdown(); + Process.sleep(20000); + } + + public static void test_vm_shutdown_destroy () throws HostFailureException { + Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****"); + Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " + + "and check whether you can reallocate the same VM"); + + // Create VM0 + int dpRate = 70; + XVM vm0 = null; + vm0 = new XVM(host1, "vm0", + 1, // Nb of vcpu + 2048, // Ramsize, + 125, // Net Bandwidth + null, //VM disk image + -1, //size of disk image, + 125, // Net bandwidth, + dpRate // Memory intensity ); - Msg.info("Start VM0"); - vm0.start(); - vm0.setLoad(90); - - Process.sleep(5000); - - Msg.info("Shutdown VM0"); - vm0.shutdown(); - Process.sleep(5000); - - Msg.info("Restart VM0"); - vm0 = new XVM( - host1, - "vm0", - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity + Msg.info("Start VM0"); + vm0.start(); + vm0.setLoad(90); + + Process.sleep(5000); + + Msg.info("Shutdown VM0"); + vm0.shutdown(); + Process.sleep(5000); + + Msg.info("Restart VM0"); + vm0 = new XVM(host1, "vm0", + 1, // Nb of vcpu + 2048, // Ramsize, + 125, // Net Bandwidth + null, //VM disk image + -1, //size of disk image, + 125, // Net bandwidth, + dpRate // Memory intensity ); - vm0.start(); - vm0.setLoad(90); - - Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok"); - - Process.sleep(5000); - vm0.shutdown(); - } - -} - - + vm0.start(); + vm0.setLoad(90); + Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok"); + Process.sleep(5000); + vm0.shutdown(); + } +} diff --git a/examples/java/cloud/migration/XVM.java b/examples/java/cloud/migration/XVM.java index 6e3671e866..f34da08607 100644 --- a/examples/java/cloud/migration/XVM.java +++ b/examples/java/cloud/migration/XVM.java @@ -6,77 +6,71 @@ package cloud.migration; +import org.simgrid.msg.Msg; +import org.simgrid.msg.VM; import org.simgrid.msg.Host; import org.simgrid.msg.HostNotFoundException; import org.simgrid.msg.HostFailureException; -import org.simgrid.msg.Msg; -import org.simgrid.msg.VM; -/** - * A stupid VM extension to associate a daemon to the VM - */ public class XVM extends VM { + private int dpIntensity; + private int netBW; + private int ramsize; + private int currentLoad; + private Daemon daemon; - private int dpIntensity; - private int netBW; - private int ramsize; - private int currentLoad; - - private Daemon daemon; - - public XVM(Host host, String name, - int nbCores, int ramsize, int netBW, String diskPath, int diskSize, int migNetBW, int dpIntensity){ - super(host, name, nbCores, ramsize, netBW, diskPath, diskSize, (int)(migNetBW*0.9), dpIntensity); - this.currentLoad = 0; - this.netBW = netBW ; - this. dpIntensity = dpIntensity ; - this.ramsize= ramsize; - this.daemon = new Daemon(this, 100); + public XVM(Host host, String name, + int nbCores, int ramsize, int netBW, String diskPath, int diskSize, int migNetBW, int dpIntensity){ + super(host, name, nbCores, ramsize, netBW, diskPath, diskSize, (int)(migNetBW*0.9), dpIntensity); + this.currentLoad = 0; + this.netBW = netBW ; + this. dpIntensity = dpIntensity ; + this.ramsize= ramsize; + this.daemon = new Daemon(this, 100); + } + public void setLoad(int load){ + if (load >0) { + this.setBound(load); + // this.getDaemon().setLoad(load); + daemon.resume(); + } else{ + daemon.suspend(); } + currentLoad = load ; + } - public void setLoad(int load){ - if (load >0) { - this.setBound(load); - // this.getDaemon().setLoad(load); - daemon.resume(); - } - else{ - daemon.suspend(); - } - currentLoad = load ; + public void start(){ + super.start(); + try { + daemon.start(); + } catch (HostNotFoundException e) { + e.printStackTrace(); } + this.setLoad(0); + } - public void start(){ - super.start(); - try { - daemon.start(); - } catch (HostNotFoundException e) { - e.printStackTrace(); - } - this.setLoad(0); + public Daemon getDaemon(){ + return this.daemon; + } - } - public Daemon getDaemon(){ - return this.daemon; - } - public int getLoad(){ - System.out.println("Remaining comp:" + this.daemon.getRemaining()); - return this.currentLoad; - } + public int getLoad(){ + System.out.println("Remaining comp:" + this.daemon.getRemaining()); + return this.currentLoad; + } - public void migrate(Host host) throws HostFailureException { - Msg.info("Start migration of VM " + this.getName() + " to " + host.getName()); - Msg.info(" currentLoad:" + this.currentLoad + "/ramSize:" + this.ramsize + "/dpIntensity:" + this.dpIntensity - + "/remaining:" + String.format(java.util.Locale.US, "%.2E",this.daemon.getRemaining())); - try{ - super.migrate(host); - } catch (Exception e){ - Msg.info("Something wrong during the live migration of VM "+this.getName()); - throw new HostFailureException(); - } - this.setLoad(this.currentLoad); //Fixed the fact that setBound is not propagated to the new node. - Msg.info("End of migration of VM " + this.getName() + " to node " + host.getName()); + public void migrate(Host host) throws HostFailureException { + Msg.info("Start migration of VM " + this.getName() + " to " + host.getName()); + Msg.info(" currentLoad:" + this.currentLoad + "/ramSize:" + this.ramsize + "/dpIntensity:" + this.dpIntensity + + "/remaining:" + String.format(java.util.Locale.US, "%.2E",this.daemon.getRemaining())); + try{ + super.migrate(host); + } catch (Exception e){ + Msg.info("Something wrong during the live migration of VM "+this.getName()); + throw new HostFailureException(); } + this.setLoad(this.currentLoad); //Fixed the fact that setBound is not propagated to the new node. + Msg.info("End of migration of VM " + this.getName() + " to node " + host.getName()); + } } diff --git a/examples/java/cloud/migration/deploy_simple.xml b/examples/java/cloud/migration/deploy_simple.xml index cdf9b7c143..0b5dffa14d 100644 --- a/examples/java/cloud/migration/deploy_simple.xml +++ b/examples/java/cloud/migration/deploy_simple.xml @@ -1,6 +1,5 @@ - - + diff --git a/examples/java/cloud/migration/migration.tesh b/examples/java/cloud/migration/migration.tesh index 34b2b219d9..fd5c496e2a 100644 --- a/examples/java/cloud/migration/migration.tesh +++ b/examples/java/cloud/migration/migration.tesh @@ -3,7 +3,7 @@ $ java -classpath ${classpath:=.} cloud/migration/Main ${srcdir:=.}/../platforms/two_hosts_platform.xml ${srcdir:=.}/cloud/migration/deploy_simple.xml > [0.000000] [jmsg/INFO] Using regular java threads. > [host0:cloud/migration/Test:(1) 0.000000] [jmsg/INFO] This example evaluates the migration time of a VM in presence of collocated VMs on the source and the dest nodes -> [host0:cloud/migration/Test:(1) 0.000000] [jmsg/INFO] The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% "(see cloudcom 2013 paper "Adding a Live Migration Model Into SimGrid" for further information) +> [host0:cloud/migration/Test:(1) 0.000000] [jmsg/INFO] The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% " (see cloudcom 2013 paper "Adding a Live Migration Model Into SimGrid" for further information) > [host0:cloud/migration/Test:(1) 0.000000] [jmsg/INFO] Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see whether it impacts or not the migration time > [0.000000] [surf_vm/INFO] Create VM(vm0)@PM(host0) with 0 mounted disks > [0.000000] [surf_vm/INFO] Create VM(vm1)@PM(host0) with 0 mounted disks @@ -32,9 +32,8 @@ $ java -classpath ${classpath:=.} cloud/migration/Main ${srcdir:=.}/../platforms > [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] End of migration of VM vm0 to node host0 > [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] - End of Migration from host 1 to host 0 (duration:32.46684874546391) > [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] -> -> -> Round trip of VM1 (load 80%) +> [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] +> [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] Round trip of VM1 (load 80%) > [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] - Launch migration from host 0 to host 1 > [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] Start migration of VM vm0 to host1 > [host0:cloud/migration/Test:(1) 67.551019] [jmsg/INFO] currentLoad:80/ramSize:2048/dpIntensity:70/remaining:4.64E+11 diff --git a/examples/java/commTime/CMakeLists.txt b/examples/java/commTime/CMakeLists.txt index fbaa0c6c01..5014ac6e7b 100644 --- a/examples/java/commTime/CMakeLists.txt +++ b/examples/java/commTime/CMakeLists.txt @@ -31,10 +31,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - ${CMAKE_CURRENT_SOURCE_DIR}/README - PARENT_SCOPE) diff --git a/examples/java/commTime/CommTimeTest.java b/examples/java/commTime/CommTimeTest.java index 417aa27898..46bf24c6c2 100644 --- a/examples/java/commTime/CommTimeTest.java +++ b/examples/java/commTime/CommTimeTest.java @@ -9,28 +9,21 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class CommTimeTest { - - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); + public static void main(String[] args) throws NativeException { - if(args.length < 2) { - Msg.info("Usage : CommTime platform_file deployment_file"); - Msg.info("example : CommTime comm_time_platform.xml comm_time_deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); + Msg.init(args); + + if(args.length < 2) { + Msg.info("Usage : CommTime platform_file deployment_file"); + Msg.info("example : CommTime ../platforms/platform.xml commTimeDeployment.xml"); + System.exit(1); } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/commTime/FinalizeTask.java b/examples/java/commTime/FinalizeTask.java index f5dcc1815f..f11da7535a 100644 --- a/examples/java/commTime/FinalizeTask.java +++ b/examples/java/commTime/FinalizeTask.java @@ -7,9 +7,8 @@ package commTime; import org.simgrid.msg.*; -public class FinalizeTask extends Task { - public FinalizeTask() { - super("",0,0); - } +public class FinalizeTask extends Task { + public FinalizeTask() { + super("",0,0); + } } - \ No newline at end of file diff --git a/examples/java/commTime/Master.java b/examples/java/commTime/Master.java index 9193702e32..37da76882b 100644 --- a/examples/java/commTime/Master.java +++ b/examples/java/commTime/Master.java @@ -1,5 +1,3 @@ -/* Master of a basic master/slave example in Java */ - /* Copyright (c) 2006-2014. The SimGrid Team. * All rights reserved. */ @@ -15,37 +13,37 @@ import org.simgrid.msg.Process; import org.simgrid.msg.Task; public class Master extends Process { - public Master(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - if (args.length < 4) { - Msg.info("Master needs 4 arguments"); - System.exit(1); - } - - int tasksCount = Integer.valueOf(args[0]).intValue(); - double taskComputeSize = Double.valueOf(args[1]).doubleValue(); - double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); - - int slavesCount = Integer.valueOf(args[3]).intValue(); - - Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); - - for (int i = 0; i < tasksCount; i++) { - Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); - if (i%1000==0) - Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\""); - task.send("slave_"+(i%slavesCount)); - } - - Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over."); - - for (int i = 0; i < slavesCount; i++) { - FinalizeTask task = new FinalizeTask(); - task.send("slave_"+(i%slavesCount)); - } - - Msg.info("Goodbye now!"); + public Master(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + if (args.length < 4) { + Msg.info("Master needs 4 arguments"); + System.exit(1); + } + + int tasksCount = Integer.valueOf(args[0]).intValue(); + double taskComputeSize = Double.valueOf(args[1]).doubleValue(); + double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); + + int slavesCount = Integer.valueOf(args[3]).intValue(); + + Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); + + for (int i = 0; i < tasksCount; i++) { + Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); + if (i%1000==0) + Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\""); + task.send("slave_"+(i%slavesCount)); + } + + Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over."); + + for (int i = 0; i < slavesCount; i++) { + FinalizeTask task = new FinalizeTask(); + task.send("slave_"+(i%slavesCount)); } + Msg.info("Goodbye now!"); + } } diff --git a/examples/java/commTime/README b/examples/java/commTime/README deleted file mode 100644 index 6512acd7fe..0000000000 --- a/examples/java/commTime/README +++ /dev/null @@ -1,5 +0,0 @@ -This directory is almost exactly the same example than the -master/slave, the only differences are: - * there is no forwarder here - * the outputs are a bit less verbose - * the example give a lot more work to do (this is used for benchmarking) \ No newline at end of file diff --git a/examples/java/commTime/Slave.java b/examples/java/commTime/Slave.java index c90ad64b68..7711a92c71 100644 --- a/examples/java/commTime/Slave.java +++ b/examples/java/commTime/Slave.java @@ -5,31 +5,28 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ package commTime; - import org.simgrid.msg.*; public class Slave extends org.simgrid.msg.Process { - public Slave(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - if (args.length < 1) { - Msg.info("Slave needs 1 argument (its number)"); - System.exit(1); - } + public Slave(Host host, String name, String[]args) { + super(host,name,args); + } + public void main(String[] args) throws MsgException { + if (args.length < 1) { + Msg.info("Slave needs 1 argument (its number)"); + System.exit(1); + } - int num = Integer.valueOf(args[0]).intValue(); - Msg.info("Receiving on 'slave_"+num+"'"); - - while(true) { - Task task = Task.receive("slave_"+num); - - if (task instanceof FinalizeTask) { - break; - } - task.execute(); - } - - Msg.info("Received Finalize. I'm done. See you!"); + int num = Integer.valueOf(args[0]).intValue(); + Msg.info("Receiving on 'slave_"+num+"'"); + + while(true) { + Task task = Task.receive("slave_"+num); + if (task instanceof FinalizeTask) { + break; + } + task.execute(); } + Msg.info("Received Finalize. I'm done. See you!"); + } } \ No newline at end of file diff --git a/examples/java/commTime/commTimeDeployment.xml b/examples/java/commTime/commTimeDeployment.xml index 3a1fa8f226..a229c374eb 100644 --- a/examples/java/commTime/commTimeDeployment.xml +++ b/examples/java/commTime/commTimeDeployment.xml @@ -7,49 +7,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/java/energy/CMakeLists.txt b/examples/java/energy/CMakeLists.txt index 7388cd37fe..2ad4d43d35 100644 --- a/examples/java/energy/CMakeLists.txt +++ b/examples/java/energy/CMakeLists.txt @@ -28,9 +28,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/energy/Energy.java b/examples/java/energy/Energy.java index 8f70b7b13e..5d6884d706 100644 --- a/examples/java/energy/Energy.java +++ b/examples/java/energy/Energy.java @@ -6,36 +6,34 @@ package energy; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; +import org.simgrid.msg.Host; import org.simgrid.msg.MsgException; -/** - * Example showing the use of the new experimental Cloud API. - */ + public class Energy { - public static final double task_comp_size = 10; - public static final double task_comm_size = 10; - public static final int hostNB = 2 ; - public static void main(String[] args) throws MsgException { - Msg.energyInit(); - Msg.init(args); - - if (args.length < 1) { - Msg.info("Usage : Cloud platform_file"); - Msg.info("Usage : Cloud platform.xml"); - System.exit(1); - } - /* Construct the platform */ - Msg.createEnvironment(args[0]); - Host[] hosts = Host.all(); - if (hosts.length < 1) { - Msg.info("I need at least one host in the platform file, but " + args[0] + " contains only " + hosts.length + " hosts"); - System.exit(42); - } - /* Instanciate a process */ - new EnergyConsumer(hosts[0],"energyConsumer",null).start(); - /* Execute the simulation */ - Msg.run(); - + public static final double task_comp_size = 10; + public static final double task_comm_size = 10; + public static final int hostNB = 2 ; + + public static void main(String[] args) throws MsgException { + Msg.energyInit(); + Msg.init(args); + + if (args.length < 1) { + Msg.info("Usage : Energy platform_file"); + Msg.info("Usage : Energy ../platforms/energy_platform.xml"); + System.exit(1); + } + /* Construct the platform */ + Msg.createEnvironment(args[0]); + Host[] hosts = Host.all(); + if (hosts.length < 1) { + Msg.info("I need at least one host in the platform file, but " + args[0] + " has no host at all"); + System.exit(42); } + /* Instanciate a process */ + new EnergyConsumer(hosts[0],"energyConsumer",null).start(); + /* Execute the simulation */ + Msg.run(); + } } diff --git a/examples/java/energy/EnergyConsumer.java b/examples/java/energy/EnergyConsumer.java index 50b6ea8cbf..bf3be525b0 100644 --- a/examples/java/energy/EnergyConsumer.java +++ b/examples/java/energy/EnergyConsumer.java @@ -6,24 +6,25 @@ package energy; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; import org.simgrid.msg.TimeoutException; public class EnergyConsumer extends Process { - public EnergyConsumer(Host host, String name, String[] args) { - super(host,name,args); - } - @Override - public void main(String[] args) throws MsgException { - Msg.info("Currently consumed energy: "+getHost().getConsumedEnergy()); - this.waitFor(10); - Msg.info("Currently consumed energy after sleeping 10 sec: "+getHost().getConsumedEnergy()); - new Task(null, 1E9, 0).execute(); - Msg.info("Currently consumed energy after executing 1E9 flops: "+getHost().getConsumedEnergy()); - } + public EnergyConsumer(Host host, String name, String[] args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + Msg.info("Currently consumed energy: "+getHost().getConsumedEnergy()); + this.waitFor(10); + Msg.info("Currently consumed energy after sleeping 10 sec: "+getHost().getConsumedEnergy()); + new Task(null, 1E9, 0).execute(); + Msg.info("Currently consumed energy after executing 1E9 flops: "+getHost().getConsumedEnergy()); + } } diff --git a/examples/java/io/CMakeLists.txt b/examples/java/io/CMakeLists.txt index 49f15e3d2f..c761d3bd24 100644 --- a/examples/java/io/CMakeLists.txt +++ b/examples/java/io/CMakeLists.txt @@ -21,6 +21,7 @@ endif() set(tesh_files ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/storage.tesh PARENT_SCOPE) set(xml_files ${xml_files} @@ -29,9 +30,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/io/Client.java b/examples/java/io/Client.java index b8d718f277..fdddde7320 100644 --- a/examples/java/io/Client.java +++ b/examples/java/io/Client.java @@ -20,59 +20,51 @@ package io; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Process; -import org.simgrid.msg.HostNotFoundException; import org.simgrid.msg.Storage; +import org.simgrid.msg.HostNotFoundException; +import org.simgrid.msg.MsgException; public class Client extends Process { - public Client(Host host, int number) throws HostNotFoundException { super(host, Integer.toString(number), null); } - + public void main(String[] args) throws MsgException { - - // Retrieve all mount points of current host + // Retrieve all mount points of current host Storage[] storages = getHost().getMountedStorage(); - - for (int i = 0; i < storages.length; i++) { - // For each disk mounted on host - Msg.info("------------------------------------"); - Msg.info("Disk name: "+storages[i].getName()); - Msg.info("Size: "+storages[i].getSize()+" bytes."); - Msg.info("Free Size: "+storages[i].getFreeSize()+" bytes."); - Msg.info("Used Size: "+storages[i].getUsedSize()+" bytes."); - - } - - Storage st = Storage.getByName("Disk2"); - Msg.info("Disk name: "+st.getName()); - Msg.info("Attached to host:"+st.getHost()); - - - st.setProperty("key","Pierre"); - Msg.info("Property key: "+st.getProperty("key")); - - Host h = Host.currentHost(); - h.setProperty("key2","Pierre"); - Msg.info("Property key2: "+h.getProperty("key")); - - - String[] attach = h.getAttachedStorage(); - for (int j = 0; j < attach.length; j++) { - Msg.info("Disk attached: "+attach[j]); - } - - Msg.info("**************** ALL *************************"); - - Storage[] stos = Storage.all(); - for (int i = 0; i < stos.length; i++) { - Msg.info("Disk: "+ stos[i].getName()); - } - - + + for (int i = 0; i < storages.length; i++) { + // For each disk mounted on host + Msg.info("------------------------------------"); + Msg.info("Disk name: "+storages[i].getName()); + Msg.info("Size: "+storages[i].getSize()+" bytes."); + Msg.info("Free Size: "+storages[i].getFreeSize()+" bytes."); + Msg.info("Used Size: "+storages[i].getUsedSize()+" bytes."); + } + + Storage st = Storage.getByName("Disk2"); + Msg.info("Disk name: "+st.getName()); + Msg.info("Attached to host:"+st.getHost()); + + st.setProperty("key","Pierre"); + Msg.info("Property key: "+st.getProperty("key")); + + Host h = Host.currentHost(); + h.setProperty("key2","Pierre"); + Msg.info("Property key2: "+h.getProperty("key2")); + + String[] attach = h.getAttachedStorage(); + for (int j = 0; j < attach.length; j++) { + Msg.info("Disk attached: "+attach[j]); + } + + Msg.info("**************** ALL *************************"); + Storage[] stos = Storage.all(); + for (int i = 0; i < stos.length; i++) { + Msg.info("Disk: "+ stos[i].getName()); + } } } \ No newline at end of file diff --git a/examples/java/io/IO.java b/examples/java/io/IO.java index 4c94dcf2e3..f9de388706 100644 --- a/examples/java/io/IO.java +++ b/examples/java/io/IO.java @@ -6,31 +6,28 @@ package io; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; +import org.simgrid.msg.Host; import org.simgrid.msg.MsgException; -/** - * This example demonstrates of how to use the other - * kind of resources, such as disk or GPU. These resources are quite - * experimental for now, but here we go anyway. - */ + public class IO { - public static void main(String[] args) throws MsgException { - Msg.init(args); - if(args.length < 1) { - Msg.info("Usage : IO platform_file "); - Msg.info("example : IO platform.xml "); - System.exit(1); - } - Msg.createEnvironment(args[0]); - - Host[] hosts = Host.all(); - - Msg.info("Number of hosts:" + hosts.length); - for (int i = 0; i < hosts.length && i < 4; i++) { - new io.Node(hosts[i],i).start(); - } - - Msg.run(); + public static void main(String[] args) throws MsgException { + Msg.init(args); + if(args.length < 1) { + Msg.info("Usage : IO platform_file "); + Msg.info("example : IO ../platforms/storage/storage.xml "); + System.exit(1); + } + + Msg.createEnvironment(args[0]); + + Host[] hosts = Host.all(); + + Msg.info("Number of hosts:" + hosts.length); + for (int i = 0; i < hosts.length && i < 4; i++) { + new io.Node(hosts[i],i).start(); } + + Msg.run(); + } } \ No newline at end of file diff --git a/examples/java/io/Node.java b/examples/java/io/Node.java index 4a139b7ab4..42e84b89b2 100644 --- a/examples/java/io/Node.java +++ b/examples/java/io/Node.java @@ -6,59 +6,61 @@ package io; +import org.simgrid.msg.Msg; import org.simgrid.msg.File; import org.simgrid.msg.Host; +import org.simgrid.msg.Process; import org.simgrid.msg.HostNotFoundException; -import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; public class Node extends Process { - private static String FILENAME1 = "/doc/simgrid/examples/platforms/g5k.xml"; - private static String FILENAME2 = "\\Windows\\setupact.log"; - private static String FILENAME3 = "/doc/simgrid/examples/platforms/g5k_cabinets.xml"; - private static String FILENAME4 = "/doc/simgrid/examples/platforms/nancy.xml"; - - protected int number; - - public Node(Host host, int number) throws HostNotFoundException { - super(host, Integer.toString(number), null); - this.number = number; - } - public void main(String[] args) throws MsgException { - String mount = ""; - String filename; - switch (number) { - case 0: - mount = "/home"; - filename = mount + FILENAME1; - break; - case 1: - mount = "c:"; - filename = mount + FILENAME2; - break; - case 2: - mount = "/home"; - filename = mount + FILENAME3; - break; - case 3: - mount = "/home"; - filename = mount + FILENAME4; - break; - default: - mount = "/home"; - filename = mount + FILENAME1; - } - Msg.info("Open file " + filename); - File file = new File(filename); + private static String FILENAME1 = "/doc/simgrid/examples/platforms/g5k.xml"; + private static String FILENAME2 = "\\Windows\\setupact.log"; + private static String FILENAME3 = "/doc/simgrid/examples/platforms/g5k_cabinets.xml"; + private static String FILENAME4 = "/doc/simgrid/examples/platforms/nancy.xml"; + + protected int number; + + public Node(Host host, int number) throws HostNotFoundException { + super(host, Integer.toString(number), null); + this.number = number; + } + + public void main(String[] args) throws MsgException { + String mount = ""; + String filename; + switch (number) { + case 0: + mount = "/home"; + filename = mount + FILENAME1; + break; + case 1: + mount = "c:"; + filename = mount + FILENAME2; + break; + case 2: + mount = "/home"; + filename = mount + FILENAME3; + break; + case 3: + mount = "/home"; + filename = mount + FILENAME4; + break; + default: + mount = "/home"; + filename = mount + FILENAME1; + } + + Msg.info("Open file " + filename); + File file = new File(filename); + + long read = file.read(10000000,1); + Msg.info("Having read " + read + " on " + filename); - long read = file.read(10000000,1); - Msg.info("Having read " + read + " on " + filename); - - long write = file.read(100000,1); - Msg.info("Having write " + write + " on " + filename); + long write = file.read(100000,1); + Msg.info("Having write " + write + " on " + filename); - read = file.read(10000000,1); - Msg.info("Having read " + read + " on " + filename); - } + read = file.read(10000000,1); + Msg.info("Having read " + read + " on " + filename); + } } diff --git a/examples/java/io/Storage.java b/examples/java/io/Storage.java index dc2c9e6b52..ae2488d8cf 100644 --- a/examples/java/io/Storage.java +++ b/examples/java/io/Storage.java @@ -4,29 +4,25 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ - - package io; - -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; +import org.simgrid.msg.Host; import org.simgrid.msg.MsgException; +public class Storage { + public static void main(String[] args) throws MsgException { + Msg.init(args); + if(args.length < 1) { + Msg.info("Usage : Storage platform_file "); + Msg.info("example : Storage ../platforms/storage/storage.xml "); + System.exit(1); + } + Msg.createEnvironment(args[0]); -public class Storage { - public static void main(String[] args) throws MsgException { - Msg.init(args); - if(args.length < 1) { - Msg.info("Usage : storage platform_file "); - Msg.info("example : storage platform.xml "); - System.exit(1); - } - Msg.createEnvironment(args[0]); - - Host[] hosts = Host.all(); - new io.Client(hosts[0],0).start(); + Host[] hosts = Host.all(); + new io.Client(hosts[0],0).start(); - Msg.run(); + Msg.run(); } } diff --git a/examples/java/io/storage.tesh b/examples/java/io/storage.tesh new file mode 100644 index 0000000000..f8d9db4c97 --- /dev/null +++ b/examples/java/io/storage.tesh @@ -0,0 +1,46 @@ +#! tesh + +$ java -classpath ${classpath:=.} io/Storage ${srcdir:=.}/../platforms/storage/storage.xml +> [0.000000] [jmsg/INFO] Using regular java threads. +> [denise:0:(1) 0.000000] [jmsg/INFO] ------------------------------------ +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk name: Disk2 +> [denise:0:(1) 0.000000] [jmsg/INFO] Size: 536870912000 bytes. +> [denise:0:(1) 0.000000] [jmsg/INFO] Free Size: 534479374867 bytes. +> [denise:0:(1) 0.000000] [jmsg/INFO] Used Size: 2391537133 bytes. +> [denise:0:(1) 0.000000] [jmsg/INFO] ------------------------------------ +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk name: Disk4 +> [denise:0:(1) 0.000000] [jmsg/INFO] Size: 536870912000 bytes. +> [denise:0:(1) 0.000000] [jmsg/INFO] Free Size: 536857690006 bytes. +> [denise:0:(1) 0.000000] [jmsg/INFO] Used Size: 13221994 bytes. +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk name: Disk2 +> [denise:0:(1) 0.000000] [jmsg/INFO] Attached to host:alice +> [denise:0:(1) 0.000000] [jmsg/INFO] Property key: Pierre +> [denise:0:(1) 0.000000] [jmsg/INFO] Property key2: Pierre +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk attached: Disk4 +> [denise:0:(1) 0.000000] [jmsg/INFO] **************** ALL ************************* +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk: Disk1 +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk: Disk2 +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk: Disk3 +> [denise:0:(1) 0.000000] [jmsg/INFO] Disk: Disk4 +> [0.000000] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... + +$ java -classpath ${classpath:=.} io/IO ${srcdir:=.}/../platforms/storage/storage.xml +> [0.000000] [jmsg/INFO] Using regular java threads. +> [0.000000] [jmsg/INFO] Number of hosts:4 +> [denise:0:(1) 0.000000] [jmsg/INFO] Open file /home/doc/simgrid/examples/platforms/g5k.xml +> [alice:1:(2) 0.000000] [jmsg/INFO] Open file c:\Windows\setupact.log +> [carl:2:(3) 0.000000] [jmsg/INFO] Open file /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [bob:3:(4) 0.000000] [jmsg/INFO] Open file /home/doc/simgrid/examples/platforms/nancy.xml +> [bob:3:(4) 0.000040] [jmsg/INFO] Having read 4028 on /home/doc/simgrid/examples/platforms/nancy.xml +> [bob:3:(4) 0.000040] [jmsg/INFO] Having write 0 on /home/doc/simgrid/examples/platforms/nancy.xml +> [bob:3:(4) 0.000040] [jmsg/INFO] Having read 0 on /home/doc/simgrid/examples/platforms/nancy.xml +> [denise:0:(1) 0.000085] [jmsg/INFO] Having read 17028 on /home/doc/simgrid/examples/platforms/g5k.xml +> [denise:0:(1) 0.000085] [jmsg/INFO] Having write 0 on /home/doc/simgrid/examples/platforms/g5k.xml +> [denise:0:(1) 0.000085] [jmsg/INFO] Having read 0 on /home/doc/simgrid/examples/platforms/g5k.xml +> [carl:2:(3) 0.000226] [jmsg/INFO] Having read 22645 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [carl:2:(3) 0.000226] [jmsg/INFO] Having write 0 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [carl:2:(3) 0.000226] [jmsg/INFO] Having read 0 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [alice:1:(2) 0.000508] [jmsg/INFO] Having read 101663 on c:\Windows\setupact.log +> [alice:1:(2) 0.000508] [jmsg/INFO] Having write 0 on c:\Windows\setupact.log +> [alice:1:(2) 0.000508] [jmsg/INFO] Having read 0 on c:\Windows\setupact.log +> [0.000508] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... diff --git a/examples/java/kademlia/Answer.java b/examples/java/kademlia/Answer.java index ff0a25b219..24164a498c 100644 --- a/examples/java/kademlia/Answer.java +++ b/examples/java/kademlia/Answer.java @@ -1,98 +1,73 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package kademlia; - import java.util.ArrayList; import java.util.Collections; -/** - * Answer to a "FIND_NODE" query. Contains the nodes closest to - * an id given. - */ +/* Answer to a "FIND_NODE" query. Contains the nodes closest to an id given */ public class Answer { - /** - * Id of the node we're trying to find - */ - private int destinationId; - /** - * Closest nodes in the answer. - */ - private ArrayList nodes; - - /** - * Constructor - */ - public Answer(int destinationId) { - this.destinationId = destinationId; - nodes = new ArrayList(); - } - /** - * Returns the destination id - */ - int getDestinationId() { - return destinationId; - } - /** - * Returns the list of the nodes in the answer - */ - ArrayList getNodes() { - return nodes; - } - /** - * Returns the answer array size - */ - int size() { - return nodes.size(); - } - /** - * Remove an element from the answer. - */ - public void remove(int index) { - nodes.remove(index); - } - /** - * Add a contact to the answer. - */ - public void add(Contact contact) { - nodes.add(contact); - } - /** - * Merge the contents of this answer with another answer - */ - public int merge(Answer answer) { - int nbAdded = 0; - - for (Contact c: answer.getNodes()) { - if (!nodes.contains(c)) { - nbAdded++; - nodes.add(c); - } - } - Collections.sort(nodes); - //Trim the list - while (answer.size() > Common.BUCKET_SIZE) { - answer.remove(answer.size() - 1); - } - return nbAdded; - } - /** - * Returns if the destination has been found - */ - public boolean destinationFound() { - if (nodes.size() < 1) { - return false; - } - Contact tail = nodes.get(0); - return tail.getDistance() == 0; - } - @Override - public String toString() { - return "Answer [destinationId=" + destinationId + ", nodes=" + nodes - + "]"; - } - + private int destinationId; + /* Closest nodes in the answer. */ + private ArrayList nodes; + + public Answer(int destinationId) { + this.destinationId = destinationId; + nodes = new ArrayList(); + } + + int getDestinationId() { + return destinationId; + } + + ArrayList getNodes() { + return nodes; + } + + int size() { + return nodes.size(); + } + + public void remove(int index) { + nodes.remove(index); + } + + public void add(Contact contact) { + nodes.add(contact); + } + + /* Merge the contents of this answer with another answer */ + public int merge(Answer answer) { + int nbAdded = 0; + + for (Contact c: answer.getNodes()) { + if (!nodes.contains(c)) { + nbAdded++; + nodes.add(c); + } + } + Collections.sort(nodes); + //Trim the list + while (answer.size() > Common.BUCKET_SIZE) { + answer.remove(answer.size() - 1); + } + return nbAdded; + } + + /* Returns if the destination has been found */ + public boolean destinationFound() { + if (nodes.size() < 1) { + return false; + } + Contact tail = nodes.get(0); + return tail.getDistance() == 0; + } + + @Override + public String toString() { + return "Answer [destinationId=" + destinationId + ", nodes=" + nodes + "]"; + } } diff --git a/examples/java/kademlia/Bucket.java b/examples/java/kademlia/Bucket.java index 8ad2326e95..41d391d63c 100644 --- a/examples/java/kademlia/Bucket.java +++ b/examples/java/kademlia/Bucket.java @@ -1,77 +1,58 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package kademlia; - import java.util.ArrayList; -/** - * Stores the information held in a bucket - */ public class Bucket { - private ArrayList nodes; - private int id; - - /** - * Constructor - */ - public Bucket(int id) { - this.nodes = new ArrayList(); - this.id = id; - } - /** - * Returns the bucket's id. - */ - public int getId() { - return this.id; - } - /** - * Returns how many nodes there is in the bucket - */ - public int size() { - return nodes.size(); - } - /** - * Returns if the bucket contains the element - */ - public boolean contains(int id) { - return nodes.contains(id); - } - /** - * Add an to the front of the bucket - */ - public void add(int id) { - nodes.add(0,id); - } - /** - * Pushs an element into the front of a bucket. - */ - public void pushToFront(int id) { - int i = nodes.indexOf(id); - nodes.remove(i); - nodes.add(0, id); - } - /** - * Returns a node - */ - public int getNode(int id) { - return nodes.get(id); - } - /** - * Adds the content of the bucket into a answer object. - */ - public void addToAnswer(Answer answer, int destination) { - for (int id : this.nodes) { - answer.getNodes().add(new Contact(id,id ^ destination)); - } - } - - @Override - public String toString() { - return "Bucket [id= " + id + " nodes=" + nodes + "]"; - } - + private ArrayList nodes; + private int id; + + public Bucket(int id) { + this.nodes = new ArrayList(); + this.id = id; + } + + public int getId() { + return this.id; + } + + public int size() { + return nodes.size(); + } + + public boolean contains(int id) { + return nodes.contains(id); + } + + /* Add a node to the front of the bucket */ + public void add(int id) { + nodes.add(0,id); + } + + /* Push a node to the front of a bucket */ + public void pushToFront(int id) { + int i = nodes.indexOf(id); + nodes.remove(i); + nodes.add(0, id); + } + + public int getNode(int id) { + return nodes.get(id); + } + + /* Add the content of the bucket into a answer object. */ + public void addToAnswer(Answer answer, int destination) { + for (int id : this.nodes) { + answer.getNodes().add(new Contact(id,id ^ destination)); + } + } + + @Override + public String toString() { + return "Bucket [id= " + id + " nodes=" + nodes + "]"; + } } diff --git a/examples/java/kademlia/CMakeLists.txt b/examples/java/kademlia/CMakeLists.txt index d49e24f06f..5767cd2dd4 100644 --- a/examples/java/kademlia/CMakeLists.txt +++ b/examples/java/kademlia/CMakeLists.txt @@ -39,9 +39,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/kademlia/Common.java b/examples/java/kademlia/Common.java index 7df08e782e..0c3d425263 100644 --- a/examples/java/kademlia/Common.java +++ b/examples/java/kademlia/Common.java @@ -1,46 +1,32 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package kademlia; -/** - * Common constants used all over the simulation - */ + public class Common { - public final static int COMM_SIZE = 1; - public final static int COMP_SIZE = 0; - - public final static int RANDOM_LOOKUP_INTERVAL = 100; - - public final static int alpha = 3; - /** - * Size of the nodes identifier - */ - public final static int IDENTIFIER_SIZE = 32; - /** - * Maximum size of the buckets - */ - public final static int BUCKET_SIZE = 20; - /** - * Maximum number of trial for the "JOIN" request - */ - public final static int MAX_JOIN_TRIALS = 4; - /** - * Timeout for a "FIND_NODE" request to a node - */ - public final static int FIND_NODE_TIMEOUT = 10; - /** - * Global timeout for a FIND_NODE. - */ - public final static int FIND_NODE_GLOBAL_TIMEOUT = 50; - /** - * Timeout for a "PING" request - */ - public final static int PING_TIMEOUT = 35; - - public final static int MAX_STEPS = 10; + /* Common constants used all over the simulation */ + public final static int COMM_SIZE = 1; + public final static int COMP_SIZE = 0; + + public final static int RANDOM_LOOKUP_INTERVAL = 100; + + public final static int alpha = 3; + + public final static int IDENTIFIER_SIZE = 32; + /* Maximum size of the buckets */ + public final static int BUCKET_SIZE = 20; + /* Maximum number of trials for the "JOIN" request */ + public final static int MAX_JOIN_TRIALS = 4; + /* Timeout for a "FIND_NODE" request to a node */ + public final static int FIND_NODE_TIMEOUT = 10; + /* Global timeout for a FIND_NODE request */ + public final static int FIND_NODE_GLOBAL_TIMEOUT = 50; + /* Timeout for a "PING" request */ + public final static int PING_TIMEOUT = 35; - public final static int JOIN_BUCKETS_QUERIES = 1; + public final static int MAX_STEPS = 10; + public final static int JOIN_BUCKETS_QUERIES = 1; } diff --git a/examples/java/kademlia/Contact.java b/examples/java/kademlia/Contact.java index 16d3906f60..76e155bc92 100644 --- a/examples/java/kademlia/Contact.java +++ b/examples/java/kademlia/Contact.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,47 +6,43 @@ package kademlia; -/** - * Contains the information about a foreign node according to - * a node we are trying to find. - */ public class Contact implements Comparable { - private int id; - private int distance; - - public Contact(int id, int distance) { - this.id = id; - this.distance = distance; - } - - public int getId() { - return id; - } - - public int getDistance() { - return distance; - } - - public boolean equals(Object x) { - return x.equals(id) ; - } - - public int compareTo(Object o) { - Contact c = (Contact)o; - if (distance < c.distance) { - return -1; - } - else if (distance == c.distance) { - return 0; - } - else { - return 1; - } - } - - @Override - public String toString() { - return "Contact [id=" + id + ", distance=" + distance + "]"; - } - + private int id; + private int distance; + + public Contact(int id, int distance) { + this.id = id; + this.distance = distance; + } + + public int getId() { + return id; + } + + public int getDistance() { + return distance; + } + + public boolean equals(Object x) { + return x.equals(id) ; + } + + public int compareTo(Object o) { + Contact c = (Contact)o; + if (distance < c.distance) { + return -1; + } + else if (distance == c.distance) { + return 0; + } + else { + return 1; + } + } + + @Override + public String toString() { + return "Contact [id=" + id + ", distance=" + distance + "]"; + } + } \ No newline at end of file diff --git a/examples/java/kademlia/FindNodeAnswerTask.java b/examples/java/kademlia/FindNodeAnswerTask.java index cb036da177..b4cad24262 100644 --- a/examples/java/kademlia/FindNodeAnswerTask.java +++ b/examples/java/kademlia/FindNodeAnswerTask.java @@ -1,35 +1,25 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package kademlia; - import kademlia.Answer; public class FindNodeAnswerTask extends KademliaTask { - /** - * Destination id - */ - protected int destinationId; - /** - * Answer to the FIND_NODE query. - */ - protected Answer answer; - /** - * Constructor - */ - public FindNodeAnswerTask(int senderId, int destinationId, Answer answer) { - super(senderId); - this.destinationId = destinationId; - this.answer = answer; - } - public int getDestinationId() { - return destinationId; - } - public Answer getAnswer() { - return answer; - } - + protected int destinationId; + protected Answer answer; + + public FindNodeAnswerTask(int senderId, int destinationId, Answer answer) { + super(senderId); + this.destinationId = destinationId; + this.answer = answer; + } + public int getDestinationId() { + return destinationId; + } + public Answer getAnswer() { + return answer; + } } diff --git a/examples/java/kademlia/FindNodeTask.java b/examples/java/kademlia/FindNodeTask.java index 9ee53a9972..f2020aa038 100644 --- a/examples/java/kademlia/FindNodeTask.java +++ b/examples/java/kademlia/FindNodeTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,27 +7,19 @@ package kademlia; /** - * @brief Find node tasks sent by a node to another - * "Find Node" task sent by a node to another. Ask him for - * its closest nodes from a destination. + * @brief Find node tasks sent by a node to another "Find Node" task sent by a node to another. Ask him for its closest + * nodes from a destination. */ public class FindNodeTask extends KademliaTask { - /** - * Id of the node we are trying to find: the destination - */ - private int destination; - /** - * Constructor - */ - public FindNodeTask(int senderId, int destination) { - super(senderId); - this.destination = destination; - } + /* Id of the node we are trying to find: the destination */ + private int destination; + public FindNodeTask(int senderId, int destination) { + super(senderId); + this.destination = destination; + } - - public int getDestination() { - return destination; - } - + public int getDestination() { + return destination; + } } diff --git a/examples/java/kademlia/Kademlia.java b/examples/java/kademlia/Kademlia.java index a9c05c4281..01fcef2d0c 100644 --- a/examples/java/kademlia/Kademlia.java +++ b/examples/java/kademlia/Kademlia.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,24 +7,21 @@ package kademlia; import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; -/** - * Main class of the simulation. Launch the simulation. - */ + public class Kademlia { - public static void main(String[] args) throws MsgException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : Kademlia platform_file deployment_file"); - Msg.info("example : Kademlia platform.xml deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); - } + public static void main(String[] args) throws MsgException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Kademlia platform_file deployment_file"); + Msg.info("example : Kademlia ../platforms/platform.xml kademlia.xml"); + System.exit(1); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/kademlia/KademliaTask.java b/examples/java/kademlia/KademliaTask.java index 9ca0c5f96d..0a549b41fe 100644 --- a/examples/java/kademlia/KademliaTask.java +++ b/examples/java/kademlia/KademliaTask.java @@ -1,32 +1,23 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package kademlia; - import kademlia.Common; import org.simgrid.msg.Task; -/** - * @brief Base class for all the tasks related to Kademlia. - */ public class KademliaTask extends Task { - /** - * Sender id - */ - protected int senderId; - - /** - * Constructor - */ - public KademliaTask(int senderId) { - super("kademliatask",Common.COMP_SIZE,Common.COMM_SIZE); - this.senderId = senderId; - } - public int getSenderId() { - return senderId; - } + protected int senderId; + + public KademliaTask(int senderId) { + super("kademliatask",Common.COMP_SIZE,Common.COMM_SIZE); + this.senderId = senderId; + } + + public int getSenderId() { + return senderId; + } } diff --git a/examples/java/kademlia/Node.java b/examples/java/kademlia/Node.java index 0a9478185e..5dd2ae2290 100644 --- a/examples/java/kademlia/Node.java +++ b/examples/java/kademlia/Node.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -8,345 +8,312 @@ package kademlia; import org.simgrid.msg.Host; -import org.simgrid.msg.Comm; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; -import org.simgrid.msg.Process; +import org.simgrid.msg.Comm; import org.simgrid.msg.Task; -/** - * Main class of the simulation, contains the logic of a node. - */ +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; + public class Node extends Process { - /** - * Id in the network. - */ - protected int id; - /** - * Routing table - */ - protected RoutingTable table; - /** - * Deadline - */ - protected int deadline; - /** - * FIND_NODE which have succeeded. - */ - protected int findNodeSuccedded = 0; - /** - * FIND_NODE which have failed - */ - protected int findNodeFailed = 0; - - protected Comm comm; + protected int id; + protected RoutingTable table; + protected int deadline; + protected int findNodeSuccedded = 0; + protected int findNodeFailed = 0; + protected Comm comm; + + public Node(Host host, String name, String[]args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + //Check the number of arguments. + if (args.length != 2 && args.length != 3) { + Msg.info("Wrong argument count."); + return; + } + this.id = Integer.valueOf(args[0]); + this.table = new RoutingTable(this.id); + + if (args.length == 3) { + this.deadline = Integer.valueOf(args[2]).intValue(); + Msg.info("Hi, I'm going to join the network with the id " + id + "!"); + if (joinNetwork(Integer.valueOf(args[1]))) { + this.mainLoop(); + } + else { + Msg.info("I couldn't join the network :("); + } + } + else { + this.deadline = Integer.valueOf(args[1]).intValue(); + Msg.info("Hi, I'm going to create the network with the id " + id + "!"); + table.update(this.id); + this.mainLoop(); + } + Msg.debug("I'm leaving the network"); + Msg.debug("Here is my routing table:" + table); + } + + public void mainLoop() { + double next_lookup_time = Msg.getClock() + Common.RANDOM_LOOKUP_INTERVAL; + while (Msg.getClock() < this.deadline) { + try { + if (comm == null) { + comm = Task.irecv(Integer.toString(id)); + } + if (!comm.test()) { + if (Msg.getClock() >= next_lookup_time) { + randomLookup(); + next_lookup_time += Common.RANDOM_LOOKUP_INTERVAL; + } else { + waitFor(1); + } + } else { + Task task = comm.getTask(); + handleTask(task); + comm = null; + } + } + catch (Exception e) { + } + } + Msg.info(findNodeSuccedded + "/" + (findNodeSuccedded + findNodeFailed) + " FIND_NODE have succedded."); + } + + /** + * @brief Try to make the node join the network + * @param idKnown Id of someone we know in the system + */ + public boolean joinNetwork(int idKnown) { + boolean answerGot = false; + double timeBegin = Msg.getClock(); + Msg.debug("Joining the network knowing " + idKnown); + //Add ourselves and the node we know to our routing table + table.update(this.id); + table.update(idKnown); + //Send a "FIND_NODE" to the node we know. + sendFindNode(idKnown,this.id); + //Wait for the answer. + int trials = 0; + + do { + try { + if (comm == null) { + comm = Task.irecv(Integer.toString(id)); + } + if (comm != null) { + if (!comm.test()) { + waitFor(1); + } else { + Task task = comm.getTask(); + if (task instanceof FindNodeAnswerTask) { + answerGot = true; + //Retrieve the node list and ping them + FindNodeAnswerTask answerTask = (FindNodeAnswerTask)task; + Answer answer = answerTask.getAnswer(); + answerGot = true; + //answersGotten++; + if (answer.getDestinationId() == this.id) { + //Ping everyone in the list + for (Contact c : answer.getNodes()) { + table.update(c.getId()); + } + } + } else { + handleTask(task); + } + comm = null; + } + } + } + catch (Exception ex) { + trials++; + Msg.info("FIND_NODE failed"); + } + } while (!answerGot && trials < Common.MAX_JOIN_TRIALS); + /* Second step: Send a FIND_NODE in a node in each bucket */ + int bucketId = table.findBucket(idKnown).getId(); + for (int i = 0; ((bucketId - i) > 0 || + (bucketId + i) <= Common.IDENTIFIER_SIZE) && + i < Common.JOIN_BUCKETS_QUERIES; i++) { + if (bucketId - i > 0) { + int idInBucket = table.getIdInPrefix(this.id,bucketId - i); + this.findNode(idInBucket,false); + } + if (bucketId + i <= Common.IDENTIFIER_SIZE) { + int idInBucket = table.getIdInPrefix(this.id,bucketId + i); + findNode(idInBucket,false); + } + } + Msg.debug("Time spent:" + (Msg.getClock() - timeBegin)); + return answerGot; + } + + /* Send a request to find a node in the node's routing table. */ + public boolean findNode(int destination, boolean counts) { + int queries, answers; + int nodesAdded = 0; + boolean destinationFound = false; + int steps = 0; + double timeBeginReceive; + double timeout, globalTimeout = Msg.getClock() + Common.FIND_NODE_GLOBAL_TIMEOUT; + //Build a list of the closest nodes we already know. + Answer nodeList = table.findClosest(destination); + Msg.verb("Doing a FIND_NODE on " + destination); + do { + timeBeginReceive = Msg.getClock(); + answers = 0; + queries = this.sendFindNodeToBest(nodeList); + nodesAdded = 0; + timeout = Msg.getClock() + Common.FIND_NODE_TIMEOUT; + steps++; + do { + try { + if (comm == null) { + comm = Task.irecv(Integer.toString(id)); + } + if (!comm.test()) { + waitFor(1); + } else { + Task task = comm.getTask(); + if (task instanceof FindNodeAnswerTask) { + FindNodeAnswerTask answerTask = (FindNodeAnswerTask)task; + //Check if we received what we are looking for. + if (answerTask.getDestinationId() == destination) { + table.update(answerTask.getSenderId()); + //Add the answer to our routing table + for (Contact c: answerTask.getAnswer().getNodes()) { + table.update(c.getId()); + } + answers++; + + nodesAdded = nodeList.merge(answerTask.getAnswer()); + } else { + /* If it's not our answer, we answer to the node that has queried us anyway */ + handleTask(task); + //Update the timeout if it's not our answer. + timeout += Msg.getClock() - timeBeginReceive; + timeBeginReceive = Msg.getClock(); + } + } else { + handleTask(task); + timeout += Msg.getClock() - timeBeginReceive; + timeBeginReceive = Msg.getClock(); + } + comm = null; + } + } + catch (Exception e) { + comm = null; + } + } while (answers < queries && Msg.getClock() < timeout); + destinationFound = nodeList.destinationFound(); + } while (!destinationFound && (nodesAdded > 0 || answers == 0) && Msg.getClock() < globalTimeout + && steps < Common.MAX_STEPS); + + if (destinationFound) { + if (counts) { + findNodeSuccedded++; + } + Msg.debug("Find node on " + destination + " succedded"); + } else { + Msg.debug("Find node on " + destination + " failed"); + Msg.debug("Queried " + queries + " nodes to find " + destination); + Msg.debug(nodeList.toString()); + if (counts) { + findNodeFailed++; + } + } + return destinationFound; + } + + /** + * @brief Sends a "PING" request to a node + * @param destination Ping destination id. + */ + public void ping(int destination) { + boolean destinationFound = false; + double timeout = Msg.getClock() + Common.PING_TIMEOUT; + PingTask pingTask = new PingTask(this.id); + /* Sending the ping task */ + pingTask.dsend(Integer.toString(destination)); + do { + try { + Task task = Task.receive(Integer.toString(this.id),Common.PING_TIMEOUT); + if (task instanceof PingAnswerTask) { + PingAnswerTask answerTask = (PingAnswerTask)task; + if (answerTask.getSenderId() == destination) { + this.table.update(destination); + destinationFound = true; + } else { + handleTask(task); + } + } else { + handleTask(task); + } + waitFor(1); + } + catch (Exception ex) { + } + } while (Msg.getClock() < timeout && !destinationFound); + } + + /** + * @brief Sends a "FIND_NODE" request (task) to a node we know. + * @param id Id of the node we are querying + * @param destination id of the node we are trying to find. + */ + public void sendFindNode(int id, int destination) { + Msg.debug("Sending a FIND_NODE to " + Integer.toString(id) + " to find " + destination ); + FindNodeTask task = new FindNodeTask(this.id,destination); + task.dsend(Integer.toString(id)); + } + + /** Sends a "FIND_NODE" request to the best "alpha" nodes in a node list */ + public int sendFindNodeToBest(Answer nodeList) { + int destination = nodeList.getDestinationId(); + int i; + for (i = 0; i < Common.alpha && i < nodeList.size(); i++) { + Contact node = nodeList.getNodes().get(i); + if (node.getId() != this.id) { + this.sendFindNode(node.getId(),destination); + } + } + return i; + } + + public void randomLookup() { + findNode(0,true); + } - public Node(Host host, String name, String[]args) { - super(host,name,args); - } - - @Override - public void main(String[] args) throws MsgException { - //Check the number of arguments. - if (args.length != 2 && args.length != 3) { - Msg.info("Wrong argument count."); - return; - } - this.id = Integer.valueOf(args[0]); - this.table = new RoutingTable(this.id); - - if (args.length == 3) { - this.deadline = Integer.valueOf(args[2]).intValue(); - Msg.info("Hi, I'm going to join the network with the id " + id + "!"); - if (joinNetwork(Integer.valueOf(args[1]))) { - this.mainLoop(); - } - else { - Msg.info("I couldn't join the network :("); - } - } - else { - this.deadline = Integer.valueOf(args[1]).intValue(); - Msg.info("Hi, I'm going to create the network with the id " + id + "!"); - table.update(this.id); - this.mainLoop(); - } - Msg.debug("I'm leaving the network"); - Msg.debug("Here is my routing table:" + table); - } - /** - * Node main loop - */ - public void mainLoop() { - double next_lookup_time = Msg.getClock() + Common.RANDOM_LOOKUP_INTERVAL; - while (Msg.getClock() < this.deadline) { - try { - if (comm == null) { - comm = Task.irecv(Integer.toString(id)); - } - if (!comm.test()) { - if (Msg.getClock() >= next_lookup_time) { - randomLookup(); - next_lookup_time += Common.RANDOM_LOOKUP_INTERVAL; - } - else { - waitFor(1); - } - } - else { - Task task = comm.getTask(); - handleTask(task); - comm = null; - } - } - catch (Exception e) { - - } - } - Msg.info(findNodeSuccedded + "/" + (findNodeSuccedded + findNodeFailed) + " FIND_NODE have succedded."); - } - /** - * @brief Try to make the node join the network - * @param idKnown Id of someone we know in the system - */ - public boolean joinNetwork(int idKnown) { - boolean answerGot = false; - double timeBegin = Msg.getClock(); - Msg.debug("Joining the network knowing " + idKnown); - //Add ourselves and the node we know to our routing table - table.update(this.id); - table.update(idKnown); - //Send a "FIND_NODE" to the node we know. - sendFindNode(idKnown,this.id); - //Wait for the answer. - int trials = 0; + /** + * @brief Handles an incomming task + * @param task The task we need to handle + */ + public void handleTask(Task task) { + if (task instanceof KademliaTask) { + table.update(((KademliaTask) task).getSenderId()); + if (task instanceof FindNodeTask) { + handleFindNode((FindNodeTask)task); + } + else if (task instanceof PingTask) { + handlePing((PingTask)task); + } + } + } - do { - try { - if (comm == null) { - comm = Task.irecv(Integer.toString(id)); - } - if (comm != null) { - if (!comm.test()) { - waitFor(1); - } - else { - Task task = comm.getTask(); - if (task instanceof FindNodeAnswerTask) { - answerGot = true; - //Retrieve the node list and ping them - FindNodeAnswerTask answerTask = (FindNodeAnswerTask)task; - Answer answer = answerTask.getAnswer(); - answerGot = true; - //answersGotten++; - if (answer.getDestinationId() == this.id) { - //Ping everyone in the list - for (Contact c : answer.getNodes()) { - table.update(c.getId()); - } - } - } - else { - handleTask(task); - } - comm = null; - } - } + public void handleFindNode(FindNodeTask task) { + Msg.debug("Received a FIND_NODE from " + task.getSenderId()); + Answer answer = table.findClosest(task.getDestination()); + FindNodeAnswerTask taskToSend = new FindNodeAnswerTask(this.id,task.getDestination(),answer); + taskToSend.dsend(Integer.toString(task.getSenderId())); + } - } - catch (Exception ex) { - trials++; - Msg.info("FIND_NODE failed"); - } - } while (!answerGot && trials < Common.MAX_JOIN_TRIALS); - /* Second step: Send a FIND_NODE in a node in each bucket */ - int bucketId = table.findBucket(idKnown).getId(); - for (int i = 0; ((bucketId - i) > 0 || - (bucketId + i) <= Common.IDENTIFIER_SIZE) && - i < Common.JOIN_BUCKETS_QUERIES; i++) { - if (bucketId - i > 0) { - int idInBucket = table.getIdInPrefix(this.id,bucketId - i); - this.findNode(idInBucket,false); - } - if (bucketId + i <= Common.IDENTIFIER_SIZE) { - int idInBucket = table.getIdInPrefix(this.id,bucketId + i); - findNode(idInBucket,false); - } - } - Msg.debug("Time spent:" + (Msg.getClock() - timeBegin)); - return answerGot; - } - /** - * Send a request to find a node in the node's routing table. - */ - public boolean findNode(int destination, boolean counts) { - int queries, answers; - int nodesAdded = 0; - boolean destinationFound = false; - int steps = 0; - double timeBeginReceive; - double timeout, globalTimeout = Msg.getClock() + Common.FIND_NODE_GLOBAL_TIMEOUT; - //Build a list of the closest nodes we already know. - Answer nodeList = table.findClosest(destination); - Msg.verb("Doing a FIND_NODE on " + destination); - do { - timeBeginReceive = Msg.getClock(); - answers = 0; - queries = this.sendFindNodeToBest(nodeList); - nodesAdded = 0; - timeout = Msg.getClock() + Common.FIND_NODE_TIMEOUT; - steps++; - do { - try { - if (comm == null) { - comm = Task.irecv(Integer.toString(id)); - } - if (!comm.test()) { - waitFor(1); - } - else { - Task task = comm.getTask(); - if (task instanceof FindNodeAnswerTask) { - FindNodeAnswerTask answerTask = (FindNodeAnswerTask)task; - //Check if we received what we are looking for. - if (answerTask.getDestinationId() == destination) { - table.update(answerTask.getSenderId()); - //Add the answer to our routing table - for (Contact c: answerTask.getAnswer().getNodes()) { - table.update(c.getId()); - } - answers++; - - nodesAdded = nodeList.merge(answerTask.getAnswer()); - } - /* If it's not our answer, we answer to the node that - * has queried us anyway - */ - else { - handleTask(task); - //Update the timeout if it's not our answer. - timeout += Msg.getClock() - timeBeginReceive; - timeBeginReceive = Msg.getClock(); - } - } - else { - handleTask(task); - timeout += Msg.getClock() - timeBeginReceive; - timeBeginReceive = Msg.getClock(); - } - comm = null; - } - } - catch (Exception e) { - comm = null; - } - } while (answers < queries && Msg.getClock() < timeout); - destinationFound = nodeList.destinationFound(); - } while (!destinationFound && (nodesAdded > 0 || answers == 0) && Msg.getClock() < globalTimeout && steps < Common.MAX_STEPS); - - if (destinationFound) { - if (counts) { - findNodeSuccedded++; - } - Msg.debug("Find node on " + destination + " succedded"); - } - else { - Msg.debug("Find node on " + destination + " failed"); - Msg.debug("Queried " + queries + " nodes to find " + destination); - Msg.debug(nodeList.toString()); - if (counts) { - findNodeFailed++; - } - } - return destinationFound; - } - /** - * Sends a "PING" request to a node - * @param destination Ping destination id. - */ - public void ping(int destination) { - boolean destinationFound = false; - double timeout = Msg.getClock() + Common.PING_TIMEOUT; - PingTask pingTask = new PingTask(this.id); - /* Sending the ping task */ - pingTask.dsend(Integer.toString(destination)); - do - { - try { - Task task = Task.receive(Integer.toString(this.id),Common.PING_TIMEOUT); - if (task instanceof PingAnswerTask) { - PingAnswerTask answerTask = (PingAnswerTask)task; - if (answerTask.getSenderId() == destination) { - this.table.update(destination); - destinationFound = true; - } - else { - handleTask(task); - } - } - else { - handleTask(task); - } - waitFor(1); - } - catch (Exception ex) { - } - } while (Msg.getClock() < timeout && !destinationFound); - } - /** - * Sends a "FIND_NODE" request (task) to a node we know. - * @brief id Id of the node we are querying - * @brief destination id of the node we are trying to find. - */ - public void sendFindNode(int id, int destination) { - Msg.debug("Sending a FIND_NODE to " + Integer.toString(id) + " to find " + destination ); - FindNodeTask task = new FindNodeTask(this.id,destination); - task.dsend(Integer.toString(id)); - } - /** - * Sends a "FIND_NODE" request to the best "alpha" nodes in a node - * list - */ - public int sendFindNodeToBest(Answer nodeList) { - int destination = nodeList.getDestinationId(); - int i; - for (i = 0; i < Common.alpha && i < nodeList.size(); i++) { - Contact node = nodeList.getNodes().get(i); - if (node.getId() != this.id) { - this.sendFindNode(node.getId(),destination); - } - } - return i; - } - /** - * Does a random lookup - */ - public void randomLookup() { - findNode(0,true); - } - /** - * Handles an incomming task - * @param task The task we need to handle - */ - public void handleTask(Task task) { - if (task instanceof KademliaTask) { - table.update(((KademliaTask) task).getSenderId()); - if (task instanceof FindNodeTask) { - handleFindNode((FindNodeTask)task); - } - else if (task instanceof PingTask) { - handlePing((PingTask)task); - } - } - } - public void handleFindNode(FindNodeTask task) { - Msg.debug("Received a FIND_NODE from " + task.getSenderId()); - Answer answer = table.findClosest(task.getDestination()); - FindNodeAnswerTask taskToSend = new FindNodeAnswerTask(this.id,task.getDestination(),answer); - taskToSend.dsend(Integer.toString(task.getSenderId())); - } - public void handlePing(PingTask task) { - Msg.debug("Received a PING from " + task.getSenderId()); - PingAnswerTask taskToSend = new PingAnswerTask(this.id); - taskToSend.dsend(Integer.toString(task.getSenderId())); - } + public void handlePing(PingTask task) { + Msg.debug("Received a PING from " + task.getSenderId()); + PingAnswerTask taskToSend = new PingAnswerTask(this.id); + taskToSend.dsend(Integer.toString(task.getSenderId())); + } } diff --git a/examples/java/kademlia/PingAnswerTask.java b/examples/java/kademlia/PingAnswerTask.java index 46f2fd8556..d6dd4a0ed1 100644 --- a/examples/java/kademlia/PingAnswerTask.java +++ b/examples/java/kademlia/PingAnswerTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,10 +7,7 @@ package kademlia; public class PingAnswerTask extends KademliaTask { - /** - * Constructor - */ - public PingAnswerTask(int senderId) { - super(senderId); - } + public PingAnswerTask(int senderId) { + super(senderId); + } } diff --git a/examples/java/kademlia/PingTask.java b/examples/java/kademlia/PingTask.java index 3b08c93384..eacfb1d750 100644 --- a/examples/java/kademlia/PingTask.java +++ b/examples/java/kademlia/PingTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,14 +6,8 @@ package kademlia; -/** - * @brief "PING" task sent by a node to another to see if it is still alive - */ public class PingTask extends KademliaTask { - /** - * Constructor - */ - public PingTask(int senderId) { - super(senderId); - } + public PingTask(int senderId) { + super(senderId); + } } diff --git a/examples/java/kademlia/RoutingTable.java b/examples/java/kademlia/RoutingTable.java index ca136a0431..961d38fe35 100644 --- a/examples/java/kademlia/RoutingTable.java +++ b/examples/java/kademlia/RoutingTable.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -9,125 +9,105 @@ import java.util.Collections; import java.util.Vector; import org.simgrid.msg.Msg; -/** - * @brief Contains the various data of a routing table. - */ + public class RoutingTable { - /** - * Bucket list - */ - private Vector buckets; - /** - * Id of the routing table owner - */ - private int id; - /** - * Constructor - */ - public RoutingTable(int id) { - this.id = id; - buckets = new Vector(); - for (int i = 0; i < Common.IDENTIFIER_SIZE + 1; i++) { - buckets.add(new Bucket(i)); - } - } - /** - * Returns an identifier which is in a specific bucket of a routing table - * @brief id id of the routing table owner - * @brief prefix id of the bucket where we want that identifier to be - */ - public int getIdInPrefix(int id, int prefix) { - if (prefix == 0) { - return 0; - } - int identifier = 1; - identifier = identifier << (prefix - 1); - identifier = identifier ^ id; - return identifier; - } - /** - * Returns the corresponding node prefix for a given id - */ - public int getNodePrefix(int id) { - for (int j = 0; j < 32; j++) { - if ((id >> (32 - 1 - j) & 0x1) != 0) { - return 32 - j; - } - } - return 0; - } - /** - * Fins the corresponding bucket in a routing table for a given identifier - */ - public Bucket findBucket(int id) { - int xorNumber = id ^ this.id; -// Msg.info("Number:" + xorNumber.toString(16)); - int prefix = this.getNodePrefix(xorNumber); - - return buckets.get(prefix); - } - /** - * Updates the routing table with a new value. - */ - public void update(int id) { + /* Bucket list */ + private Vector buckets; + /* Id of the routing table owner */ + private int id; + + public RoutingTable(int id) { + this.id = id; + buckets = new Vector(); + for (int i = 0; i < Common.IDENTIFIER_SIZE + 1; i++) { + buckets.add(new Bucket(i)); + } + } + + /** + * @brief Returns an identifier which is in a specific bucket of a routing table + * @param id id of the routing table owner + * @param prefix id of the bucket where we want that identifier to be + */ + public int getIdInPrefix(int id, int prefix) { + if (prefix == 0) { + return 0; + } + int identifier = 1; + identifier = identifier << (prefix - 1); + identifier = identifier ^ id; + return identifier; + } + + /* Returns the corresponding node prefix for a given id */ + public int getNodePrefix(int id) { + for (int j = 0; j < 32; j++) { + if ((id >> (32 - 1 - j) & 0x1) != 0) { + return 32 - j; + } + } + return 0; + } + + /* Finds the corresponding bucket in a routing table for a given identifier */ + public Bucket findBucket(int id) { + int xorNumber = id ^ this.id; + int prefix = this.getNodePrefix(xorNumber); + return buckets.get(prefix); + } + + /* Updates the routing table with a new value. */ + public void update(int id) { + Bucket bucket = this.findBucket(id); + if (bucket.contains(id)) { + Msg.debug("Updating " + Integer.toString(id) + " in my routing table"); + //If the element is already in the bucket, we update it. + bucket.pushToFront(id); + } else { + Msg.debug("Adding " + id + " to my routing table"); + bucket.add(id); + if (bucket.size() > Common.BUCKET_SIZE) { + //TODO: Ping the least seen guy and remove him if he is offline. + } + } + } - Bucket bucket = this.findBucket(id); - if (bucket.contains(id)) { - Msg.debug("Updating " + Integer.toString(id) + " in my routing table"); - //If the element is already in the bucket, we update it. - bucket.pushToFront(id); - } - else { - Msg.debug("Adding " + id + " to my routing table"); - bucket.add(id); - if (bucket.size() > Common.BUCKET_SIZE) { - //TODO: Ping the least seen guy and remove him if he is offline. - } - } - } - /** - * Returns the closest notes we know to a given id - */ - public Answer findClosest(int destinationId) { - Answer answer = new Answer(destinationId); + /* Returns the closest notes we know to a given id */ + public Answer findClosest(int destinationId) { + Answer answer = new Answer(destinationId); + Bucket bucket = this.findBucket(destinationId); + bucket.addToAnswer(answer,destinationId); - - Bucket bucket = this.findBucket(destinationId); - bucket.addToAnswer(answer,destinationId); - - for (int i = 1; answer.size() < Common.BUCKET_SIZE && - ((bucket.getId() - i) >= 0 || - (bucket.getId() + i) <= Common.IDENTIFIER_SIZE); i++) { - //Check the previous buckets - if (bucket.getId() - i >= 0) { - Bucket bucketP = this.buckets.get(bucket.getId() - i); - bucketP.addToAnswer(answer,destinationId); - } - //Check the next buckets - if (bucket.getId() + i <= Common.IDENTIFIER_SIZE) { - Bucket bucketN = this.buckets.get(bucket.getId() + i); - bucketN.addToAnswer(answer, destinationId); - } - } - //We sort the list - Collections.sort(answer.getNodes()); - //We trim the list - while (answer.size() > Common.BUCKET_SIZE) { - answer.remove(answer.size() - 1); //TODO: Not the best thing. - } - - return answer; - } - - @Override - public String toString() { - String string = "RoutingTable [ id=" + id + " " ; - for (int i = 0; i < buckets.size(); i++) { - if (buckets.get(i).size() > 0) { - string += buckets.get(i) + " "; - } - } - return string; - } + for (int i = 1; answer.size() < Common.BUCKET_SIZE && ((bucket.getId() - i) >= 0 || + (bucket.getId() + i) <= Common.IDENTIFIER_SIZE); i++) { + //Check the previous buckets + if (bucket.getId() - i >= 0) { + Bucket bucketP = this.buckets.get(bucket.getId() - i); + bucketP.addToAnswer(answer,destinationId); + } + //Check the next buckets + if (bucket.getId() + i <= Common.IDENTIFIER_SIZE) { + Bucket bucketN = this.buckets.get(bucket.getId() + i); + bucketN.addToAnswer(answer, destinationId); + } + } + //We sort the list + Collections.sort(answer.getNodes()); + //We trim the list + while (answer.size() > Common.BUCKET_SIZE) { + answer.remove(answer.size() - 1); //TODO: Not the best thing. + } + return answer; + } + @Override + public String toString() { + String string = "RoutingTable [ id=" + id + " " ; + for (int i = 0; i < buckets.size(); i++) { + if (buckets.get(i).size() > 0) { + string += buckets.get(i) + " "; + } + } + return string; + } } diff --git a/examples/java/kademlia/kademlia.xml b/examples/java/kademlia/kademlia.xml index 7315a7e086..4ea655182d 100644 --- a/examples/java/kademlia/kademlia.xml +++ b/examples/java/kademlia/kademlia.xml @@ -1,28 +1,23 @@ - - + - - - + + - - - + + - - - + + - diff --git a/examples/java/migration/CMakeLists.txt b/examples/java/migration/CMakeLists.txt index 349c954bbf..27a2553671 100644 --- a/examples/java/migration/CMakeLists.txt +++ b/examples/java/migration/CMakeLists.txt @@ -30,9 +30,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/migration/Emigrant.java b/examples/java/migration/Emigrant.java index 5fda9f5bfc..194630675e 100644 --- a/examples/java/migration/Emigrant.java +++ b/examples/java/migration/Emigrant.java @@ -1,42 +1,42 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package migration; - -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Emigrant extends Process { - public Emigrant(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - Migration.mutex.acquire(); - - Msg.info("I'll look for a new job on another machine where the grass is greener."); - migrate(Host.getByName("Boivin")); - - Msg.info("Yeah, found something to do"); - Task task = new Task("job", 98095000, 0); - task.execute(); - waitFor(2); - - Msg.info("Moving back to home after work"); - migrate(Host.getByName("Jacquelin")); - migrate(Host.getByName("Boivin")); - waitFor(4); - - Migration.processToMigrate = this; - Migration.mutex.release(); - suspend(); - - Msg.info("I've been moved on this new host:" + getHost().getName()); - Msg.info("Uh, nothing to do here. Stopping now"); - } + public Emigrant(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Migration.mutex.acquire(); + + Msg.info("I'll look for a new job on another machine where the grass is greener."); + migrate(Host.getByName("Boivin")); + + Msg.info("Yeah, found something to do"); + Task task = new Task("job", 98095000, 0); + task.execute(); + waitFor(2); + + Msg.info("Moving back to home after work"); + migrate(Host.getByName("Jacquelin")); + migrate(Host.getByName("Boivin")); + waitFor(4); + + Migration.processToMigrate = this; + Migration.mutex.release(); + suspend(); + + Msg.info("I've been moved on this new host:" + getHost().getName()); + Msg.info("Uh, nothing to do here. Stopping now"); + } } \ No newline at end of file diff --git a/examples/java/migration/Migration.java b/examples/java/migration/Migration.java index 97aa53bf21..37509a07f7 100644 --- a/examples/java/migration/Migration.java +++ b/examples/java/migration/Migration.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,37 +7,28 @@ package migration; import org.simgrid.msg.Msg; import org.simgrid.msg.Mutex; -import org.simgrid.msg.NativeException; import org.simgrid.msg.Process; -/** - * Demonstrates the use of Task.setPriority to change - * the computation priority of a task - */ -public class Migration { - public static Mutex mutex; - public static Process processToMigrate = null; - - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : Priority platform_file deployment_file"); - Msg.info("example : Priority ping_pong_platform.xml ping_pong_deployment.xml"); - System.exit(1); - } - /* Create the mutex */ - mutex = new Mutex(); - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); +import org.simgrid.msg.NativeException; + +public class Migration { + public static Mutex mutex; + public static Process processToMigrate = null; + + public static void main(String[] args) throws NativeException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Migration platform_file deployment_file"); + Msg.info("example : Migration ../platforms/platform.xml migrationDeployment.xml"); + System.exit(1); } + /* Create the mutex */ + mutex = new Mutex(); + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/migration/Policeman.java b/examples/java/migration/Policeman.java index 664dd335ad..3d4cfb4650 100644 --- a/examples/java/migration/Policeman.java +++ b/examples/java/migration/Policeman.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,26 +6,26 @@ package migration; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Policeman extends Process { - public Policeman(Host host, String name, String[]args) { - super(host,name,args); - } + public Policeman(Host host, String name, String[]args) { + super(host,name,args); + } - @Override - public void main(String[] args) throws MsgException { - waitFor(1); - - Msg.info("Wait a bit before migrating the emigrant."); - - Migration.mutex.acquire(); - - Migration.processToMigrate.migrate(Host.getByName("Jacquelin")); - Msg.info("I moved the emigrant"); - Migration.processToMigrate.resume(); - } + @Override + public void main(String[] args) throws MsgException { + waitFor(1); + + Msg.info("Wait a bit before migrating the emigrant."); + + Migration.mutex.acquire(); + + Migration.processToMigrate.migrate(Host.getByName("Jacquelin")); + Msg.info("I moved the emigrant"); + Migration.processToMigrate.resume(); + } } \ No newline at end of file diff --git a/examples/java/mutualExclusion/CMakeLists.txt b/examples/java/mutualExclusion/CMakeLists.txt index 2c8c3d6437..02048a8bd6 100644 --- a/examples/java/mutualExclusion/CMakeLists.txt +++ b/examples/java/mutualExclusion/CMakeLists.txt @@ -33,9 +33,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/mutualExclusion/Coordinator.java b/examples/java/mutualExclusion/Coordinator.java index 7a0e0a679e..f605279144 100644 --- a/examples/java/mutualExclusion/Coordinator.java +++ b/examples/java/mutualExclusion/Coordinator.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,45 +7,44 @@ package mutualExclusion; import java.util.LinkedList; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +public class Coordinator extends Process { + public Coordinator(Host host, String name, String[]args) { + super(host,name,args); + } + LinkedList waitingQueue=new LinkedList(); + int CsToServe; -public class Coordinator extends Process { - public Coordinator(Host host, String name, String[]args) { - super(host,name,args); - } - LinkedList waitingQueue=new LinkedList(); - int CsToServe; - - public void main(String[] args) throws MsgException { - CsToServe = Integer.parseInt(args[0]); - Task task; - while (CsToServe >0) { - task = Task.receive("coordinator"); - if (task instanceof RequestTask) { - RequestTask t = (RequestTask) task; - if (waitingQueue.isEmpty()) { - Msg.info("Got a request from "+t.from+". Queue empty: grant it"); - GrantTask tosend = new GrantTask(); - tosend.send(t.from); - } else { - waitingQueue.addFirst(t); - } - } else if (task instanceof ReleaseTask) { - if (!waitingQueue.isEmpty()) { - RequestTask req = waitingQueue.removeLast(); - GrantTask tosend = new GrantTask(); - tosend.send(req.from); - } - CsToServe--; - if (waitingQueue.isEmpty() && CsToServe==0) { - Msg.info("we should shutdown the simulation now"); - } - } - } - } + public void main(String[] args) throws MsgException { + CsToServe = Integer.parseInt(args[0]); + Task task; + while (CsToServe >0) { + task = Task.receive("coordinator"); + if (task instanceof RequestTask) { + RequestTask t = (RequestTask) task; + if (waitingQueue.isEmpty()) { + Msg.info("Got a request from "+t.from+". Queue empty: grant it"); + GrantTask tosend = new GrantTask(); + tosend.send(t.from); + } else { + waitingQueue.addFirst(t); + } + } else if (task instanceof ReleaseTask) { + if (!waitingQueue.isEmpty()) { + RequestTask req = waitingQueue.removeLast(); + GrantTask tosend = new GrantTask(); + tosend.send(req.from); + } + CsToServe--; + if (waitingQueue.isEmpty() && CsToServe==0) { + Msg.info("we should shutdown the simulation now"); + } + } + } + } } diff --git a/examples/java/mutualExclusion/GrantTask.java b/examples/java/mutualExclusion/GrantTask.java index 79e19d0f0b..fb405a908d 100644 --- a/examples/java/mutualExclusion/GrantTask.java +++ b/examples/java/mutualExclusion/GrantTask.java @@ -1,12 +1,8 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package mutualExclusion; -import org.simgrid.msg.Task; - - -public class GrantTask extends Task { -} +public class GrantTask extends org.simgrid.msg.Task {} diff --git a/examples/java/mutualExclusion/MutexCentral.java b/examples/java/mutualExclusion/MutexCentral.java index d5da381303..ef1fc02dda 100644 --- a/examples/java/mutualExclusion/MutexCentral.java +++ b/examples/java/mutualExclusion/MutexCentral.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,29 +10,21 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class MutexCentral { - - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - - if(args.length < 2) { - Msg.info("Usage: Basic platform_file deployment_file"); - Msg.info("Fallback to default values"); - Msg.createEnvironment("../ring3.xml"); - Msg.deployApplication("mutex_centralized_deployment.xml"); - } else { - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - } - - /* execute the simulation. */ - Msg.run(); - } + public static void main(String[] args) throws NativeException { + Msg.init(args); + + if(args.length < 2) { + Msg.info("Usage: MutexCentral platform_file deployment_file"); + Msg.info("Fallback to default values"); + Msg.createEnvironment("../platform/small_platform.xml"); + Msg.deployApplication("mutex_centralized_deployment.xml"); + } else { + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + } + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/mutualExclusion/Node.java b/examples/java/mutualExclusion/Node.java index 55d91e3ffe..353dfd7947 100644 --- a/examples/java/mutualExclusion/Node.java +++ b/examples/java/mutualExclusion/Node.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,29 +6,29 @@ package mutualExclusion; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Node extends Process { - public Node(Host host, String name, String[]args) { - super(host,name,args); - } - public void request(double CStime) throws MsgException { - RequestTask req = new RequestTask(getName()); - Msg.info("Send a request to the coordinator"); - req.send("coordinator"); - Msg.info("Wait for a grant from the coordinator"); - Task.receive(getName()); // FIXME: ensure that this is a grant - Task compute = new Task("CS", CStime, 0); - compute.execute(); - ReleaseTask release = new ReleaseTask(); - release.send("coordinator"); - } - - public void main(String[] args) throws MsgException { - request(Double.parseDouble(args[1])); - } + public Node(Host host, String name, String[]args) { + super(host,name,args); + } + public void request(double CStime) throws MsgException { + RequestTask req = new RequestTask(getName()); + Msg.info("Send a request to the coordinator"); + req.send("coordinator"); + Msg.info("Wait for a grant from the coordinator"); + Task.receive(getName()); // FIXME: ensure that this is a grant + Task compute = new Task("CS", CStime, 0); + compute.execute(); + ReleaseTask release = new ReleaseTask(); + release.send("coordinator"); + } + + public void main(String[] args) throws MsgException { + request(Double.parseDouble(args[1])); + } } \ No newline at end of file diff --git a/examples/java/mutualExclusion/ReleaseTask.java b/examples/java/mutualExclusion/ReleaseTask.java index 6348116be2..2a0e020e33 100644 --- a/examples/java/mutualExclusion/ReleaseTask.java +++ b/examples/java/mutualExclusion/ReleaseTask.java @@ -1,9 +1,8 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package mutualExclusion; -public class ReleaseTask extends org.simgrid.msg.Task { -} +public class ReleaseTask extends org.simgrid.msg.Task {} diff --git a/examples/java/mutualExclusion/RequestTask.java b/examples/java/mutualExclusion/RequestTask.java index 225d16bf91..1b86e4b874 100644 --- a/examples/java/mutualExclusion/RequestTask.java +++ b/examples/java/mutualExclusion/RequestTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -8,9 +8,9 @@ package mutualExclusion; import org.simgrid.msg.Task; public class RequestTask extends Task { - String from; - public RequestTask(String name) { - super(); - from=name; - } + String from; + public RequestTask(String name) { + super(); + from=name; + } } diff --git a/examples/java/mutualExclusion/mutex_centralized_deployment.xml b/examples/java/mutualExclusion/mutex_centralized_deployment.xml index 4abc36c3a6..0f92c3053f 100644 --- a/examples/java/mutualExclusion/mutex_centralized_deployment.xml +++ b/examples/java/mutualExclusion/mutex_centralized_deployment.xml @@ -2,14 +2,14 @@ - + - - + + - - + + diff --git a/examples/java/pingPong/CMakeLists.txt b/examples/java/pingPong/CMakeLists.txt index 001a23bce1..1132494726 100644 --- a/examples/java/pingPong/CMakeLists.txt +++ b/examples/java/pingPong/CMakeLists.txt @@ -31,10 +31,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - ${CMAKE_CURRENT_SOURCE_DIR}/README - PARENT_SCOPE) diff --git a/examples/java/pingPong/PingPongTask.java b/examples/java/pingPong/PingPongTask.java index 76f7fff75e..17f2bedcdf 100644 --- a/examples/java/pingPong/PingPongTask.java +++ b/examples/java/pingPong/PingPongTask.java @@ -1,31 +1,29 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package pingPong; -import org.simgrid.msg.NativeException; import org.simgrid.msg.Task; +import org.simgrid.msg.NativeException; public class PingPongTask extends Task { - - private double timeVal; - - public PingPongTask() throws NativeException { - this.timeVal = 0; - } - - public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException { - super(name,computeDuration,messageSize); - } - - public void setTime(double timeVal){ - this.timeVal = timeVal; - } - - public double getTime() { - return this.timeVal; - } + private double timeVal; + + public PingPongTask() throws NativeException { + this.timeVal = 0; + } + + public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException { + super(name,computeDuration,messageSize); + } + + public void setTime(double timeVal) { + this.timeVal = timeVal; + } + + public double getTime() { + return this.timeVal; + } } - \ No newline at end of file diff --git a/examples/java/pingPong/PingPongTest.java b/examples/java/pingPong/PingPongTest.java index 04f71d9431..cb7ef02b6b 100644 --- a/examples/java/pingPong/PingPongTest.java +++ b/examples/java/pingPong/PingPongTest.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -8,27 +8,20 @@ package pingPong; import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; -public class PingPongTest { +public class PingPongTest { + public static void main(String[] args) throws NativeException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : PingPongTest platform_file deployment_file"); + Msg.info("example : PingPongTest ../platforms/platform.xml pingPongDeployment.xml"); + System.exit(1); + } - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); - public static void main(String[] args) throws NativeException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : PingPong platform_file deployment_file"); - Msg.info("example : PingPong ping_pong_platform.xml ping_pong_deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); - } + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/pingPong/README b/examples/java/pingPong/README deleted file mode 100644 index aa16de9c89..0000000000 --- a/examples/java/pingPong/README +++ /dev/null @@ -1,2 +0,0 @@ -This is a stupid ping/pong example. The processes exchange a simple -task and time them. \ No newline at end of file diff --git a/examples/java/pingPong/Receiver.java b/examples/java/pingPong/Receiver.java index 57e69cfc43..0d6f1ced74 100644 --- a/examples/java/pingPong/Receiver.java +++ b/examples/java/pingPong/Receiver.java @@ -5,41 +5,38 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ package pingPong; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Receiver extends Process { - public Receiver(Host host, String name, String[]args) { - super(host,name,args); - } - final double commSizeLat = 1; - final double commSizeBw = 100000000; - - public void main(String[] args) throws MsgException { - - Msg.info("hello!"); - double communicationTime=0; - - double time = Msg.getClock(); - - Msg.info("try to get a task"); - - PingPongTask task = (PingPongTask)Task.receive(getHost().getName()); - double timeGot = Msg.getClock(); - double timeSent = task.getTime(); - - Msg.info("Got at time "+ timeGot); - Msg.info("Was sent at time "+timeSent); - time=timeSent; - - communicationTime=timeGot - time; - Msg.info("Communication time : " + communicationTime); - - Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); - - Msg.info("goodbye!"); - } + final double commSizeLat = 1; + final double commSizeBw = 100000000; + public Receiver(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("hello!"); + double communicationTime=0; + + double time = Msg.getClock(); + + Msg.info("try to get a task"); + + PingPongTask task = (PingPongTask)Task.receive(getHost().getName()); + double timeGot = Msg.getClock(); + double timeSent = task.getTime(); + + Msg.info("Got at time "+ timeGot); + Msg.info("Was sent at time "+timeSent); + time=timeSent; + + communicationTime=timeGot - time; + Msg.info("Communication time : " + communicationTime); + Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); + Msg.info("goodbye!"); + } } \ No newline at end of file diff --git a/examples/java/pingPong/Sender.java b/examples/java/pingPong/Sender.java index 52fbab1ff3..530b67a306 100644 --- a/examples/java/pingPong/Sender.java +++ b/examples/java/pingPong/Sender.java @@ -1,55 +1,55 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package pingPong; -import org.simgrid.msg.Host; -import org.simgrid.msg.HostNotFoundException; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.HostNotFoundException; public class Sender extends Process { - public Sender(Host host, String name, String[] args) { - super(host,name,args); - } - private final double commSizeLat = 1; - final double commSizeBw = 100000000; - - public void main(String[] args) throws MsgException { - - Msg.info("hello!"); - - int hostCount = args.length; - - Msg.info("host count: " + hostCount); - String mailboxes[] = new String[hostCount]; - double time; - double computeDuration = 0; - PingPongTask task; - - for(int pos = 0; pos < args.length ; pos++) { - try { - mailboxes[pos] = Host.getByName(args[pos]).getName(); - } catch (HostNotFoundException e) { - Msg.info("Invalid deployment file: " + e.toString()); - System.exit(1); - } - } - - for (int pos = 0; pos < hostCount; pos++) { - time = Msg.getClock(); - - Msg.info("sender time: " + time); - - task = new PingPongTask("no name",computeDuration,commSizeLat); - task.setTime(time); - - task.send(mailboxes[pos]); - } - - Msg.info("goodbye!"); + private final double commSizeLat = 1; + final double commSizeBw = 100000000; + + public Sender(Host host, String name, String[] args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("hello!"); + + int hostCount = args.length; + + Msg.info("host count: " + hostCount); + String mailboxes[] = new String[hostCount]; + double time; + double computeDuration = 0; + PingPongTask task; + + for(int pos = 0; pos < args.length ; pos++) { + try { + mailboxes[pos] = Host.getByName(args[pos]).getName(); + } catch (HostNotFoundException e) { + Msg.info("Invalid deployment file: " + e.toString()); + System.exit(1); + } + } + + for (int pos = 0; pos < hostCount; pos++) { + time = Msg.getClock(); + + Msg.info("sender time: " + time); + + task = new PingPongTask("no name",computeDuration,commSizeLat); + task.setTime(time); + + task.send(mailboxes[pos]); } + + Msg.info("goodbye!"); + } } \ No newline at end of file diff --git a/examples/java/pingPong/pingPongDeployment.xml b/examples/java/pingPong/pingPongDeployment.xml index 16f5860380..c7eec34aac 100644 --- a/examples/java/pingPong/pingPongDeployment.xml +++ b/examples/java/pingPong/pingPongDeployment.xml @@ -2,7 +2,7 @@ - + - + diff --git a/examples/java/priority/CMakeLists.txt b/examples/java/priority/CMakeLists.txt index b23c0c15e5..1eb9ee4142 100644 --- a/examples/java/priority/CMakeLists.txt +++ b/examples/java/priority/CMakeLists.txt @@ -29,9 +29,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/priority/Priority.java b/examples/java/priority/Priority.java index 2462ca031b..10fa76acb9 100644 --- a/examples/java/priority/Priority.java +++ b/examples/java/priority/Priority.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,31 +7,22 @@ package priority; import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; -/** - * Demonstrates the use of Task.setPriority to change - * the computation priority of a task - */ -public class Priority { - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : Priority platform_file deployment_file"); - Msg.info("example : Priority ping_pong_platform.xml ping_pong_deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); +/* Demonstrates the use of Task.setPriority to change the computation priority of a task */ +public class Priority { + public static void main(String[] args) throws NativeException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Priority platform_file deployment_file"); + Msg.info("example : Priority ../platforms/platform.xml priorityDeployment.xml"); + System.exit(1); } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/priority/Test.java b/examples/java/priority/Test.java index 14370f3e6d..8fb44d3a4c 100644 --- a/examples/java/priority/Test.java +++ b/examples/java/priority/Test.java @@ -1,34 +1,35 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package priority; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; public class Test extends Process { - public Test(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - double computationAmount = 1.0; - double priority = 1.0; - - computationAmount = Double.valueOf(args[0]); - priority = Double.valueOf(args[1]); - - Msg.info("Hello! Running a task of size " + computationAmount + " with priority " + priority); - - Task task = new Task("Task", computationAmount, 0); - task.setPriority(priority); - - task.execute(); - - Msg.info("Goodbye now!"); - } + public Test(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + double computationAmount = 1.0; + double priority = 1.0; + + computationAmount = Double.valueOf(args[0]); + priority = Double.valueOf(args[1]); + + Msg.info("Hello! Running a task of size " + computationAmount + " with priority " + priority); + + Task task = new Task("Task", computationAmount, 0); + task.setPriority(priority); + + task.execute(); + + Msg.info("Goodbye now!"); + } } diff --git a/examples/java/startKillTime/CMakeLists.txt b/examples/java/startKillTime/CMakeLists.txt index acfe44b344..1a1bdc5e75 100644 --- a/examples/java/startKillTime/CMakeLists.txt +++ b/examples/java/startKillTime/CMakeLists.txt @@ -24,18 +24,9 @@ set(tesh_files PARENT_SCOPE) set(xml_files ${xml_files} - ${CMAKE_CURRENT_SOURCE_DIR}/deployment.xml - ${CMAKE_CURRENT_SOURCE_DIR}/deployment_kill.xml - ${CMAKE_CURRENT_SOURCE_DIR}/deployment_start.xml ${CMAKE_CURRENT_SOURCE_DIR}/deployment_start_kill.xml PARENT_SCOPE) set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/startKillTime/Master.java b/examples/java/startKillTime/Master.java index 270c4a6724..593e39a12e 100644 --- a/examples/java/startKillTime/Master.java +++ b/examples/java/startKillTime/Master.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -14,13 +14,13 @@ import org.simgrid.msg.TransferFailureException; public class Master extends Process { - public Master(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { - Msg.info("Hello!"); - waitFor(10.0); - Msg.info("OK, goodbye now."); - + public Master(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { + Msg.info("Hello!"); + waitFor(10.0); + Msg.info("OK, goodbye now."); } } diff --git a/examples/java/startKillTime/Slave.java b/examples/java/startKillTime/Slave.java index 0018b6e446..d8feef4806 100644 --- a/examples/java/startKillTime/Slave.java +++ b/examples/java/startKillTime/Slave.java @@ -1,33 +1,28 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package startKillTime; -import org.simgrid.msg.Host; -import org.simgrid.msg.HostFailureException; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Process; -import org.simgrid.msg.TimeoutException; -import org.simgrid.msg.TransferFailureException; +import org.simgrid.msg.MsgException; -/** - * Lazy Guy Slave, suspends itself ASAP - */ +/* Lazy Guy Slave, suspends itself ASAP */ public class Slave extends Process { - public Slave(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { - Msg.info("Hello!"); - try { - waitFor(10.0); - Msg.info("OK, goodbye now."); - } catch (MsgException e) { - Msg.debug("Wait cancelled."); - } - + public Slave(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("Hello!"); + try { + waitFor(10.0); + Msg.info("OK, goodbye now."); + } catch (MsgException e) { + Msg.debug("Wait cancelled."); + } } } diff --git a/examples/java/startKillTime/StartKillTime.java b/examples/java/startKillTime/StartKillTime.java index 8daffbef05..b7240b36f4 100644 --- a/examples/java/startKillTime/StartKillTime.java +++ b/examples/java/startKillTime/StartKillTime.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,28 +7,20 @@ package startKillTime; import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; - -public class StartKillTime { - /* This only contains the launcher. If you do nothing more than than you can run - * java org.simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : StartKilltime platform_file deployment_file"); - Msg.info("example : StartKilltime platform.xml startKilltime.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); +public class StartKillTime { + public static void main(String[] args) throws NativeException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : StartKilltime platform_file deployment_file"); + Msg.info("example : StartKilltime ../platforms/platform.xml deployment_start_kill.xml"); + System.exit(1); } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/startKillTime/deployment.xml b/examples/java/startKillTime/deployment.xml deleted file mode 100644 index 0bbd65449b..0000000000 --- a/examples/java/startKillTime/deployment.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/examples/java/startKillTime/deployment_kill.xml b/examples/java/startKillTime/deployment_kill.xml deleted file mode 100644 index 4270dc076f..0000000000 --- a/examples/java/startKillTime/deployment_kill.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/examples/java/startKillTime/deployment_start.xml b/examples/java/startKillTime/deployment_start.xml deleted file mode 100644 index 7e330549f0..0000000000 --- a/examples/java/startKillTime/deployment_start.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/examples/java/startKillTime/deployment_start_kill.xml b/examples/java/startKillTime/deployment_start_kill.xml index 5f083d8f47..d449286f08 100644 --- a/examples/java/startKillTime/deployment_start_kill.xml +++ b/examples/java/startKillTime/deployment_start_kill.xml @@ -1,10 +1,10 @@ - + - - - - + + + + diff --git a/examples/java/suspend/CMakeLists.txt b/examples/java/suspend/CMakeLists.txt index 07088a487a..d978b49ffa 100644 --- a/examples/java/suspend/CMakeLists.txt +++ b/examples/java/suspend/CMakeLists.txt @@ -30,9 +30,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - PARENT_SCOPE) diff --git a/examples/java/suspend/DreamMaster.java b/examples/java/suspend/DreamMaster.java index 8dff985403..6469b5a0f9 100644 --- a/examples/java/suspend/DreamMaster.java +++ b/examples/java/suspend/DreamMaster.java @@ -5,23 +5,24 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ package suspend; - import org.simgrid.msg.Host; import org.simgrid.msg.Msg; import org.simgrid.msg.Process; import org.simgrid.msg.MsgException; + public class DreamMaster extends Process { - public DreamMaster(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - Msg.info("Let's create a lazy guy."); - Process lazyGuy = new LazyGuy(getHost(),"Lazy",null); - lazyGuy.start(); - Msg.info("Let's wait a little bit..."); - waitFor(10); - Msg.info("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!"); - lazyGuy.resume(); - Msg.info("OK, goodbye now."); - } + public DreamMaster(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("Let's create a lazy guy."); + Process lazyGuy = new LazyGuy(getHost(),"Lazy",null); + lazyGuy.start(); + Msg.info("Let's wait a little bit..."); + waitFor(10); + Msg.info("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!"); + lazyGuy.resume(); + Msg.info("OK, goodbye now."); + } } \ No newline at end of file diff --git a/examples/java/suspend/LazyGuy.java b/examples/java/suspend/LazyGuy.java index ffad084d17..74231fe6b7 100644 --- a/examples/java/suspend/LazyGuy.java +++ b/examples/java/suspend/LazyGuy.java @@ -1,23 +1,24 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package suspend; - import org.simgrid.msg.Host; import org.simgrid.msg.Msg; import org.simgrid.msg.Process; import org.simgrid.msg.MsgException; + public class LazyGuy extends Process { - public LazyGuy(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws MsgException { - Msg.info("Nobody's watching me ? Let's go to sleep."); - suspend(); - Msg.info("Uuuh ? Did somebody call me ?"); - Msg.info("Mmmh, goodbye now."); - } + public LazyGuy(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("Nobody's watching me ? Let's go to sleep."); + suspend(); + Msg.info("Uuuh ? Did somebody call me ?"); + Msg.info("Mmmh, goodbye now."); + } } \ No newline at end of file diff --git a/examples/java/suspend/Suspend.java b/examples/java/suspend/Suspend.java index 027ed8e9d6..f6c19e04ba 100644 --- a/examples/java/suspend/Suspend.java +++ b/examples/java/suspend/Suspend.java @@ -1,27 +1,25 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package suspend; - import org.simgrid.msg.Msg; public class Suspend { - public static void main(String[] args) { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : Suspend platform_file deployment_file"); - Msg.info("example : Suspend platform.xml deployment.xml"); - System.exit(1); - } - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* execute the simulation. */ - Msg.run(); - } + public static void main(String[] args) { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Suspend platform_file deployment_file"); + Msg.info("example : Suspend ../platforms/platform.xml suspendDeployment.xml"); + System.exit(1); + } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/tracing/CMakeLists.txt b/examples/java/tracing/CMakeLists.txt index 9dde98c460..e21c754263 100644 --- a/examples/java/tracing/CMakeLists.txt +++ b/examples/java/tracing/CMakeLists.txt @@ -31,10 +31,3 @@ set(examples_src ${examples_src} ${sources} PARENT_SCOPE) -set(bin_files - ${bin_files} - PARENT_SCOPE) -set(txt_files - ${txt_files} - ${CMAKE_CURRENT_SOURCE_DIR}/README - PARENT_SCOPE) diff --git a/examples/java/tracing/PingPongTask.java b/examples/java/tracing/PingPongTask.java index f43b69e67c..22ee817f0a 100644 --- a/examples/java/tracing/PingPongTask.java +++ b/examples/java/tracing/PingPongTask.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -9,23 +9,22 @@ import org.simgrid.msg.NativeException; import org.simgrid.msg.Task; public class PingPongTask extends Task { - - private double timeVal; - - public PingPongTask() throws NativeException { - this.timeVal = 0; - } - - public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException { - super(name,computeDuration,messageSize); - } - - public void setTime(double timeVal){ - this.timeVal = timeVal; - } - - public double getTime() { - return this.timeVal; - } + private double timeVal; + + public PingPongTask() throws NativeException { + this.timeVal = 0; + } + + public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException { + super(name,computeDuration,messageSize); + } + + public void setTime(double timeVal){ + this.timeVal = timeVal; + } + + public double getTime() { + return this.timeVal; + } } - + diff --git a/examples/java/tracing/README b/examples/java/tracing/README deleted file mode 100644 index aa16de9c89..0000000000 --- a/examples/java/tracing/README +++ /dev/null @@ -1,2 +0,0 @@ -This is a stupid ping/pong example. The processes exchange a simple -task and time them. \ No newline at end of file diff --git a/examples/java/tracing/Receiver.java b/examples/java/tracing/Receiver.java index 0cd91d4baa..d3d0a1a466 100644 --- a/examples/java/tracing/Receiver.java +++ b/examples/java/tracing/Receiver.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2007, 2012-2014. The SimGrid Team. +/* Copyright (c) 2006-2007, 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -13,49 +13,47 @@ import org.simgrid.msg.Process; import org.simgrid.trace.Trace; public class Receiver extends Process { - - private final double commSizeLat = 1; + private final double commSizeLat = 1; private final double commSizeBw = 100000000; - - public Receiver(Host host, String name, String[]args) { - super(host,name,args); - } - - public void main(String[] args) throws MsgException { - - Msg.info("hello!"); - Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPing"); - double communicationTime=0; - - double time = Msg.getClock(); - - /* Wait for the ping */ - Msg.info("try to get a task"); - - PingPongTask ping = (PingPongTask)Task.receive(getHost().getName()); - double timeGot = Msg.getClock(); - double timeSent = ping.getTime(); - - Msg.info("Got at time "+ timeGot); - Msg.info("Was sent at time "+timeSent); - time=timeSent; - - communicationTime=timeGot - time; - Msg.info("Communication time : " + communicationTime); - - Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); - - /* Send the pong */ - Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPong"); - double computeDuration = 0; - PingPongTask pong = new PingPongTask("no name",computeDuration,commSizeLat); - pong.setTime(time); - pong.send(ping.getSource().getName()); - - /* Pop the two states */ - Trace.hostPopState (getHost().getName(), "PM_STATE"); - Trace.hostPopState (getHost().getName(), "PM_STATE"); - - Msg.info("goodbye!"); - } + + public Receiver(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("hello!"); + Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPing"); + double communicationTime=0; + + double time = Msg.getClock(); + + /* Wait for the ping */ + Msg.info("try to get a task"); + + PingPongTask ping = (PingPongTask)Task.receive(getHost().getName()); + double timeGot = Msg.getClock(); + double timeSent = ping.getTime(); + + Msg.info("Got at time "+ timeGot); + Msg.info("Was sent at time "+timeSent); + time=timeSent; + + communicationTime=timeGot - time; + Msg.info("Communication time : " + communicationTime); + + Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); + + /* Send the pong */ + Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPong"); + double computeDuration = 0; + PingPongTask pong = new PingPongTask("no name",computeDuration,commSizeLat); + pong.setTime(time); + pong.send(ping.getSource().getName()); + + /* Pop the two states */ + Trace.hostPopState (getHost().getName(), "PM_STATE"); + Trace.hostPopState (getHost().getName(), "PM_STATE"); + + Msg.info("goodbye!"); + } } diff --git a/examples/java/tracing/Sender.java b/examples/java/tracing/Sender.java index 82930bdcb8..8d9206b023 100644 --- a/examples/java/tracing/Sender.java +++ b/examples/java/tracing/Sender.java @@ -1,77 +1,74 @@ -/* Sender of basic ping/pong example */ - -/* Copyright (c) 2006-2014. The SimGrid Team. +/* Copyright (c) 2006-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ package tracing; -import org.simgrid.msg.Host; -import org.simgrid.msg.HostNotFoundException; import org.simgrid.msg.Msg; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; -import org.simgrid.msg.MsgException; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.HostNotFoundException; import org.simgrid.trace.Trace; public class Sender extends Process { - - private final double commSizeLat = 1; - private final double commSizeBw = 100000000; + private final double commSizeLat = 1; + private final double commSizeBw = 100000000; + + public Sender(Host host, String name, String[] args) { + super(host,name,args); + } + + public void main(String[] args) throws MsgException { + Msg.info("hello !"); + Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPing"); + + int hostCount = args.length; + Msg.info("host count: " + hostCount); + String mailboxes[] = new String[hostCount]; + double time; + double computeDuration = 0; + PingPongTask ping, pong; + + for(int pos = 0; pos < args.length ; pos++) { + try { + mailboxes[pos] = Host.getByName(args[pos]).getName(); + } catch (HostNotFoundException e) { + Msg.info("Invalid deployment file: " + e.toString()); + System.exit(1); + } + } + + for (int pos = 0; pos < hostCount; pos++) { + time = Msg.getClock(); + Msg.info("sender time: " + time); + ping = new PingPongTask("no name",computeDuration,commSizeLat); + ping.setTime(time); + ping.send(mailboxes[pos]); + + Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPong"); + pong = (PingPongTask)Task.receive(getHost().getName()); + double timeGot = Msg.getClock(); + double timeSent = ping.getTime(); + double communicationTime=0; + + Msg.info("Got at time "+ timeGot); + Msg.info("Was sent at time "+timeSent); + time=timeSent; + + communicationTime=timeGot - time; + Msg.info("Communication time : " + communicationTime); + + Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); - public Sender(Host host, String name, String[] args) { - super(host,name,args); - } - - public void main(String[] args) throws MsgException { - Msg.info("hello !"); - Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPing"); - - int hostCount = args.length; - Msg.info("host count: " + hostCount); - String mailboxes[] = new String[hostCount]; - double time; - double computeDuration = 0; - PingPongTask ping, pong; - - for(int pos = 0; pos < args.length ; pos++) { - try { - mailboxes[pos] = Host.getByName(args[pos]).getName(); - } catch (HostNotFoundException e) { - Msg.info("Invalid deployment file: " + e.toString()); - System.exit(1); - } - } - - for (int pos = 0; pos < hostCount; pos++) { - time = Msg.getClock(); - Msg.info("sender time: " + time); - ping = new PingPongTask("no name",computeDuration,commSizeLat); - ping.setTime(time); - ping.send(mailboxes[pos]); - - Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPong"); - pong = (PingPongTask)Task.receive(getHost().getName()); - double timeGot = Msg.getClock(); - double timeSent = ping.getTime(); - double communicationTime=0; - - Msg.info("Got at time "+ timeGot); - Msg.info("Was sent at time "+timeSent); - time=timeSent; - - communicationTime=timeGot - time; - Msg.info("Communication time : " + communicationTime); - - Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); - - /* Pop the last state (going back to sending ping) */ - Trace.hostPopState (getHost().getName(), "PM_STATE"); + /* Pop the last state (going back to sending ping) */ + Trace.hostPopState (getHost().getName(), "PM_STATE"); + } - } - /* Pop the sendingPong state */ - Trace.hostPopState (getHost().getName(), "PM_STATE"); - Msg.info("goodbye!"); - } + /* Pop the sendingPong state */ + Trace.hostPopState (getHost().getName(), "PM_STATE"); + Msg.info("goodbye!"); + } } diff --git a/examples/java/tracing/TracingTest.java b/examples/java/tracing/TracingTest.java index b8453bd260..5a033e3386 100644 --- a/examples/java/tracing/TracingTest.java +++ b/examples/java/tracing/TracingTest.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2007, 2012-2014. The SimGrid Team. +/* Copyright (c) 2006-2007, 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -8,35 +8,28 @@ package tracing; import org.simgrid.msg.Msg; import org.simgrid.trace.Trace; import org.simgrid.msg.NativeException; - + public class TracingTest { + public static void main(String[] args) throws NativeException { + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : TracingTest platform_file deployment_file"); + Msg.info("example : TracingTest ../platforms/platform.xml tracingPingPongDeployment.xml"); + System.exit(1); + } - /* This only contains the launcher. If you do nothing more than than you can run - * java simgrid.msg.Msg - * which also contains such a launcher - */ - - public static void main(String[] args) throws NativeException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - if(args.length < 2) { - Msg.info("Usage : PingPong platform_file deployment_file"); - Msg.info("example : PingPong ping_pong_platform.xml ping_pong_deployment.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); - /* Initialize some state for the hosts */ - Trace.hostStateDeclare ("PM_STATE"); - Trace.hostStateDeclareValue ("PM_STATE", "waitingPing", "0 0 1"); - Trace.hostStateDeclareValue ("PM_STATE", "sendingPong", "0 1 0"); - Trace.hostStateDeclareValue ("PM_STATE", "sendingPing", "0 1 1"); - Trace.hostStateDeclareValue ("PM_STATE", "waitingPong", "1 0 0"); + /* Initialize some state for the hosts */ + Trace.hostStateDeclare ("PM_STATE"); + Trace.hostStateDeclareValue ("PM_STATE", "waitingPing", "0 0 1"); + Trace.hostStateDeclareValue ("PM_STATE", "sendingPong", "0 1 0"); + Trace.hostStateDeclareValue ("PM_STATE", "sendingPing", "0 1 1"); + Trace.hostStateDeclareValue ("PM_STATE", "waitingPong", "1 0 0"); - /* execute the simulation. */ - Msg.run(); - } + /* execute the simulation. */ + Msg.run(); + } } diff --git a/examples/java/tracing/tracingPingPongDeployment.xml b/examples/java/tracing/tracingPingPongDeployment.xml index fa2c473261..ed7db68c49 100644 --- a/examples/java/tracing/tracingPingPongDeployment.xml +++ b/examples/java/tracing/tracingPingPongDeployment.xml @@ -2,9 +2,9 @@ - - + + - - + + diff --git a/examples/msg/chord/chord.xml b/examples/msg/chord/chord.xml index 88d352cb36..e60fdce836 100644 --- a/examples/msg/chord/chord.xml +++ b/examples/msg/chord/chord.xml @@ -1,59 +1,50 @@ - - + - - + - - + - - + - - + - - + - - + - - + - diff --git a/examples/msg/parallel_task/parallel_task.tesh b/examples/msg/parallel_task/parallel_task.tesh index 1f60947e6d..096436582b 100644 --- a/examples/msg/parallel_task/parallel_task.tesh +++ b/examples/msg/parallel_task/parallel_task.tesh @@ -1,6 +1,7 @@ #! ./tesh $ $SG_TEST_EXENV parallel_task/parallel_task$EXEEXT ${srcdir:=.}/../platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'ptask_L07' > [ 0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks. > [ 0.000000] (1:test@Fafard) First, build a classical parallel task, with 1 Gflop to execute on each node, and 10MB to exchange between each pair > [ 20.625396] (1:test@Fafard) Then, build a parallel task involving only computations and no communication (1 Gflop per node) diff --git a/examples/platforms/bypassASroute.xml b/examples/platforms/bypassASroute.xml index 4f33d9c2bb..dacf416023 100644 --- a/examples/platforms/bypassASroute.xml +++ b/examples/platforms/bypassASroute.xml @@ -1,46 +1,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/bypassRoute.xml b/examples/platforms/bypassRoute.xml index ce6eca8f60..ae2a0e88b5 100644 --- a/examples/platforms/bypassRoute.xml +++ b/examples/platforms/bypassRoute.xml @@ -1,58 +1,57 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/cloud.xml b/examples/platforms/cloud.xml index b869da7444..972231a063 100644 --- a/examples/platforms/cloud.xml +++ b/examples/platforms/cloud.xml @@ -2,299 +2,387 @@ - + - - - - - - - + + + + + + + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + - - + + + + + + - - + + + + + + + + - - + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + - - + + + + - - + + + + + + + + - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/cluster.xml b/examples/platforms/cluster.xml index 4a8ad9f8e8..a67462865a 100644 --- a/examples/platforms/cluster.xml +++ b/examples/platforms/cluster.xml @@ -5,15 +5,12 @@ | | | router | ____________|__________|_____________ backbone - | | | | | | - l0| l1| l2| l97| l96 | | l99 + | | | | | | + l0| l1| l2| l97| l96 | | l99 | | | ........ | | | | | node-0.acme.org node-99.acme.org --> - diff --git a/examples/platforms/cluster_and_one_host.xml b/examples/platforms/cluster_and_one_host.xml index 3e1cd55e7c..73004fc3c5 100644 --- a/examples/platforms/cluster_and_one_host.xml +++ b/examples/platforms/cluster_and_one_host.xml @@ -2,8 +2,7 @@ - @@ -11,10 +10,7 @@ - - - - + + diff --git a/examples/platforms/cluster_no_backbone.xml b/examples/platforms/cluster_no_backbone.xml index d600a790c2..5ae99e445d 100644 --- a/examples/platforms/cluster_no_backbone.xml +++ b/examples/platforms/cluster_no_backbone.xml @@ -1,21 +1,18 @@ - - - - + + diff --git a/examples/platforms/clusters_routing_full.xml b/examples/platforms/clusters_routing_full.xml index 14e63bf86e..6e897bd44e 100644 --- a/examples/platforms/clusters_routing_full.xml +++ b/examples/platforms/clusters_routing_full.xml @@ -1,14 +1,13 @@ - + c-10.me c-19.me --> - + - + - + - - - + + + diff --git a/examples/platforms/config.xml b/examples/platforms/config.xml index 66622fa403..4dae60f6c8 100644 --- a/examples/platforms/config.xml +++ b/examples/platforms/config.xml @@ -1,28 +1,23 @@ - - - - - - - + + + + + + - + - + - - - - - - + + diff --git a/examples/platforms/config_tracing.xml b/examples/platforms/config_tracing.xml index 55d9a8b547..360bc57a26 100644 --- a/examples/platforms/config_tracing.xml +++ b/examples/platforms/config_tracing.xml @@ -1,7 +1,6 @@ - @@ -12,8 +11,7 @@ - - + @@ -33,41 +31,21 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - diff --git a/examples/platforms/crosstraffic.xml b/examples/platforms/crosstraffic.xml index 385b1ce3bd..ef00680108 100644 --- a/examples/platforms/crosstraffic.xml +++ b/examples/platforms/crosstraffic.xml @@ -1,25 +1,16 @@ - - + - - - - - - - - + + diff --git a/examples/platforms/data_center.xml b/examples/platforms/data_center.xml index 8c5dfe166d..2be1246c3e 100644 --- a/examples/platforms/data_center.xml +++ b/examples/platforms/data_center.xml @@ -2,19 +2,21 @@ - + - - - - + + - + + + + - - @@ -23,43 +25,46 @@ - + - + - + - + - - - - - - - - - - - - - - - - - - + + - - - + + + + + + + + + + + + + + + + diff --git a/examples/platforms/energy_platform.xml b/examples/platforms/energy_platform.xml index 7f7ddb024b..adc1353681 100644 --- a/examples/platforms/energy_platform.xml +++ b/examples/platforms/energy_platform.xml @@ -1,28 +1,29 @@ - + - + - - - - + + + + - - + + - - + + - diff --git a/examples/platforms/fat_tree_cluster.xml b/examples/platforms/fat_tree_cluster.xml index e15071f354..7ab17e7a1a 100644 --- a/examples/platforms/fat_tree_cluster.xml +++ b/examples/platforms/fat_tree_cluster.xml @@ -1,18 +1,14 @@ - +This is taken from figure 1/ b/ of the paper "D-Mod-K Routing Providing on-Blocking Traffic for Shift Permutations on +Real Life Fat Trees" available at webee.technion.ac.il/publication-link/index/id/574 +This defines a two levels fat-tree, with 4 leaf switches connected to 4 nodes each and 2 core switches connected to +each leaf switch by two cables --> - + diff --git a/examples/platforms/g5k.xml b/examples/platforms/g5k.xml index 3e0d3480cc..45dfdd3883 100644 --- a/examples/platforms/g5k.xml +++ b/examples/platforms/g5k.xml @@ -1,752 +1,752 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/griffon.xml b/examples/platforms/griffon.xml index 9ea724a776..2e947001ba 100644 --- a/examples/platforms/griffon.xml +++ b/examples/platforms/griffon.xml @@ -1,39 +1,34 @@ - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + diff --git a/examples/platforms/meta_cluster.xml b/examples/platforms/meta_cluster.xml index 67ddb05347..4e4e36ab70 100644 --- a/examples/platforms/meta_cluster.xml +++ b/examples/platforms/meta_cluster.xml @@ -1,40 +1,29 @@ - - - - - - + + + + - + - - - - + + + + - + - - + + - - + diff --git a/examples/platforms/multicore_machine.xml b/examples/platforms/multicore_machine.xml index e865d1d59e..93134dc42b 100644 --- a/examples/platforms/multicore_machine.xml +++ b/examples/platforms/multicore_machine.xml @@ -1,9 +1,7 @@ - - - - - - + + + + diff --git a/examples/platforms/prop.xml b/examples/platforms/prop.xml index 3eaa3d539a..645f7f38ae 100644 --- a/examples/platforms/prop.xml +++ b/examples/platforms/prop.xml @@ -1,57 +1,46 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - + + diff --git a/examples/platforms/routing_cluster.xml b/examples/platforms/routing_cluster.xml index 3c502a5a29..adc51cf214 100644 --- a/examples/platforms/routing_cluster.xml +++ b/examples/platforms/routing_cluster.xml @@ -1,7 +1,6 @@ - - - @@ -55,10 +52,8 @@ l1_up / / l1_down | l3 l2_up\ \ l2_down l4_up / / l4_down | l6 l5_up\ \ - + - + diff --git a/examples/platforms/routing_none.xml b/examples/platforms/routing_none.xml index 28193525fb..01da662b46 100644 --- a/examples/platforms/routing_none.xml +++ b/examples/platforms/routing_none.xml @@ -1,10 +1,7 @@ - - - + diff --git a/examples/platforms/simulacrum_7_hosts.xml b/examples/platforms/simulacrum_7_hosts.xml index 6276deaa85..6563df4ab4 100644 --- a/examples/platforms/simulacrum_7_hosts.xml +++ b/examples/platforms/simulacrum_7_hosts.xml @@ -1,9 +1,8 @@ - - @@ -14,15 +13,14 @@ - + - + @@ -37,70 +35,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/small_platform.xml b/examples/platforms/small_platform.xml index 038076f981..55f991c8e1 100644 --- a/examples/platforms/small_platform.xml +++ b/examples/platforms/small_platform.xml @@ -1,60 +1,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/small_platform_fatpipe.xml b/examples/platforms/small_platform_fatpipe.xml index 6b08c56446..c810aa9d8f 100644 --- a/examples/platforms/small_platform_fatpipe.xml +++ b/examples/platforms/small_platform_fatpipe.xml @@ -1,24 +1,20 @@ - - - - - - - - + + + + + - - - - + + + + - - - - - - - + + + + + + diff --git a/examples/platforms/small_platform_one_link_routes.xml b/examples/platforms/small_platform_one_link_routes.xml index 40d0bb820b..e1d93cb353 100644 --- a/examples/platforms/small_platform_one_link_routes.xml +++ b/examples/platforms/small_platform_one_link_routes.xml @@ -1,78 +1,44 @@ - - - + + + + + + + - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/small_platform_with_failures.xml b/examples/platforms/small_platform_with_failures.xml index f3fd3ca983..47b0cceda6 100644 --- a/examples/platforms/small_platform_with_failures.xml +++ b/examples/platforms/small_platform_with_failures.xml @@ -1,61 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/small_platform_with_routers.xml b/examples/platforms/small_platform_with_routers.xml index d62e954573..1310835706 100644 --- a/examples/platforms/small_platform_with_routers.xml +++ b/examples/platforms/small_platform_with_routers.xml @@ -1,79 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/examples/platforms/torus_cluster.xml b/examples/platforms/torus_cluster.xml index f8bcd8675e..a0bec806d4 100644 --- a/examples/platforms/torus_cluster.xml +++ b/examples/platforms/torus_cluster.xml @@ -2,8 +2,7 @@ - + diff --git a/examples/platforms/two_hosts_platform.xml b/examples/platforms/two_hosts_platform.xml index c5825e2d37..b78490919b 100644 --- a/examples/platforms/two_hosts_platform.xml +++ b/examples/platforms/two_hosts_platform.xml @@ -5,6 +5,6 @@ - + diff --git a/examples/platforms/two_hosts_platform_shared.xml b/examples/platforms/two_hosts_platform_shared.xml index f3bbd656a4..3d93800ed8 100644 --- a/examples/platforms/two_hosts_platform_shared.xml +++ b/examples/platforms/two_hosts_platform_shared.xml @@ -1,19 +1,14 @@ - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/examples/platforms/two_hosts_platform_with_availability.xml b/examples/platforms/two_hosts_platform_with_availability.xml index 3023615c4f..5012186bf8 100644 --- a/examples/platforms/two_hosts_platform_with_availability.xml +++ b/examples/platforms/two_hosts_platform_with_availability.xml @@ -1,12 +1,10 @@ - - - - - - - - - + + + + + + + diff --git a/examples/platforms/two_hosts_platform_with_availability_included.xml b/examples/platforms/two_hosts_platform_with_availability_included.xml index efa7973dfe..6a9dd8a9aa 100644 --- a/examples/platforms/two_hosts_platform_with_availability_included.xml +++ b/examples/platforms/two_hosts_platform_with_availability_included.xml @@ -1,7 +1,6 @@ - 0.0 1.0 11.0 0.5 @@ -16,13 +15,15 @@ 10.0 0.8 20.0 0.4 - - - - - - + + + + + + + + - + diff --git a/examples/platforms/two_peers.xml b/examples/platforms/two_peers.xml index 3da4b1862a..7bd805cf99 100644 --- a/examples/platforms/two_peers.xml +++ b/examples/platforms/two_peers.xml @@ -1,20 +1,8 @@ - - - - - + + + diff --git a/examples/platforms/vivaldi.xml b/examples/platforms/vivaldi.xml index 09b4c140a1..2f3a4fb14f 100644 --- a/examples/platforms/vivaldi.xml +++ b/examples/platforms/vivaldi.xml @@ -1,50 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/simdag/io/io.tesh b/examples/simdag/io/io.tesh index 7e17983f5c..b782cdc708 100644 --- a/examples/simdag/io/io.tesh +++ b/examples/simdag/io/io.tesh @@ -1,6 +1,7 @@ #! ./tesh $ ${bindir:=.}/io/sd_io ${srcdir:=.}/examples/platforms/storage/storage.xml +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'host/model' to 'default' > [0.000000] [sd_io/INFO] Workstation 'denise' mounts 'c:' > [0.000000] [sd_io/INFO] Workstation 'denise' mounts '/home' > [0.000000] [sd_io/INFO] Workstation 'alice' mounts 'c:' diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 1d6e2400b7..dba26b2996 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -238,7 +238,7 @@ Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, MSG_host_set_property_value(host, name, value, xbt_free_f); - env->ReleaseStringUTFChars((jstring) jvalue, value); + env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); } diff --git a/src/bindings/java/jmsg_storage.cpp b/src/bindings/java/jmsg_storage.cpp index cc3b39b7aa..1af9c1eff7 100644 --- a/src/bindings/java/jmsg_storage.cpp +++ b/src/bindings/java/jmsg_storage.cpp @@ -182,7 +182,7 @@ Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject MSG_storage_set_property_value(storage, name, value, xbt_free_f); - env->ReleaseStringUTFChars((jstring) jvalue, value); + env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); } diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 1979185e3f..2f47778443 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -856,10 +856,6 @@ set(DOC_SOURCES doc/triva-time_interval.png doc/triva-time_interval.svg - doc/HelloWorld/CMakeLists.txt - doc/HelloWorld/HelloWorld.c - doc/HelloWorld/README - doc/doxygen/FAQ.doc doc/doxygen/advanced.doc doc/doxygen/bindings.doc @@ -1180,12 +1176,8 @@ set(CMAKE_SOURCE_FILES tools/cmake/scripts/IPC/Run/Win32IO.pm tools/cmake/scripts/IPC/Run/Win32Pump.pm tools/cmake/scripts/Diff.pm - tools/cmake/scripts/Makefile.default - tools/cmake/scripts/SimGrid.packproj tools/cmake/scripts/generate_memcheck_tests.pl tools/cmake/scripts/my_valgrind.pl - tools/cmake/scripts/postinstall.sh - tools/cmake/scripts/preinstall.sh tools/cmake/scripts/update_tesh.pl tools/cmake/UnitTesting.cmake tools/cmake/src/internal_config.h.in diff --git a/tools/cmake/Distrib.cmake b/tools/cmake/Distrib.cmake index 5e4d31dcd4..8f5338d9cc 100644 --- a/tools/cmake/Distrib.cmake +++ b/tools/cmake/Distrib.cmake @@ -6,8 +6,6 @@ file(MAKE_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/html/) install(DIRECTORY "${CMAKE_HOME_DIRECTORY}/doc/html/" DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/doc/simgrid/html/) -install(DIRECTORY "${CMAKE_HOME_DIRECTORY}/doc/HelloWorld/" - DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/doc/simgrid/HelloWorld/) # binaries if(enable_smpi) @@ -229,7 +227,6 @@ endforeach(file ${source_to_pack}) add_custom_command( TARGET dist-dir - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/tools/cmake/scripts/Makefile.default ${PROJECT_NAME}-${release_version}/Makefile COMMAND ${CMAKE_COMMAND} -E echo "${GIT_VERSION}" > ${PROJECT_NAME}-${release_version}/.gitversion ) diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 7d582cd123..d3d6c0a872 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -505,6 +505,7 @@ IF(NOT enable_memcheck) ADD_TESH(java-cloud-migration --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/cloud/migration/migration.tesh) ADD_TESH(java-commTime --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/commTime/commtime.tesh) ADD_TESH(java-energy --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/energy/energy.tesh) + ADD_TESH(java-storage --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/io/storage.tesh) ADD_TESH(java-kademlia --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/kademlia/kademlia.tesh) ADD_TESH(java-kill --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/master_slave_kill/kill.tesh) ADD_TESH(java-masterslave --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/masterslave/masterslave.tesh) diff --git a/tools/cmake/scripts/Makefile.default b/tools/cmake/scripts/Makefile.default deleted file mode 100644 index a7d7400fca..0000000000 --- a/tools/cmake/scripts/Makefile.default +++ /dev/null @@ -1,8 +0,0 @@ -#THIS Makefile should be erase by Cmake when use command "cmake." - -all : - @echo "THIS COMMAND IS NOT AVAILABLE!" - @echo "Since v3.4 we use Cmake. Now use:" - @echo "\tcmake -DCMAKE_INSTALL_PREFIX= .\n\tmake\n\tmake install" - -clean : all diff --git a/tools/cmake/scripts/SimGrid.packproj b/tools/cmake/scripts/SimGrid.packproj deleted file mode 100644 index 4bdcc1ed2c..0000000000 --- a/tools/cmake/scripts/SimGrid.packproj +++ /dev/null @@ -1,565 +0,0 @@ - - - - - Hierarchy - - Attributes - - Documents - - Background Image - - IFPkgFlagBackgroundAlignment - 6 - IFPkgFlagBackgroundScaling - 2 - Mode - 1 - Path - ../../doc/webcruft/simgrid_logo_2011.gif - Path Type - 2 - - License - - International - - Mode - 0 - Path - ../../LICENSE-LGPL-2.1 - Path Type - 2 - - - ReadMe - - International - - Mode - 0 - Path - ../../README - Path Type - 2 - - - Welcome - - International - - Mode - 0 - Path - - Path Type - 2 - - - - Files - - Compress - - Hierarchy - - Children - - - Children - - - Children - - GID - 80 - Path - SimGrid - Path Type - 1 - Privileges - 509 - Type - 2 - UID - 0 - - - Children - - GID - 80 - Path - Utilities - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - GID - 80 - Path - Applications - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - - Children - - GID - 80 - Path - Application Support - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Documentation - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Filesystems - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Frameworks - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Internet Plug-Ins - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - PreferencePanes - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Preferences - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Printers - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - QuickTime - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - Children - - GID - 80 - Path - Scripts - Path Type - 1 - Privileges - 509 - Type - 1 - UID - 0 - - - GID - 80 - Path - Library - Path Type - 1 - Privileges - 1021 - Type - 1 - UID - 0 - - - Children - - - Children - - - Children - - GID - 0 - Path - Extensions - Path Type - 1 - Privileges - 493 - Type - 1 - UID - 0 - - - GID - 0 - Path - Library - Path Type - 1 - Privileges - 493 - Type - 1 - UID - 0 - - - GID - 0 - Path - System - Path Type - 1 - Privileges - 493 - Type - 1 - UID - 0 - - - GID - 80 - Path - / - Path Type - 1 - Privileges - 1021 - Type - 1 - UID - 0 - - IFPkgFlagDefaultLocation - /Applications/SimGrid - Imported Package - - Package Path - - Split Forks - - - Plugins - - PluginsList - - - Path - Introduction - Type - 0 - - - Path - ReadMe - Type - 0 - - - Path - License - Type - 0 - - - Path - Target - Type - 0 - - - Path - PackageSelection - Type - 0 - - - Path - Install - Type - 0 - - - Path - FinishUp - Type - 0 - - - - Scripts - - Additional Resources - - International - - - Installation Scripts - - IFInstallationScriptsPostflight - - Path - - Status - - - IFInstallationScriptsPostinstall - - Path - postinstall.sh - Path Type - 2 - Status - - - IFInstallationScriptsPostupgrade - - Path - - Status - - - IFInstallationScriptsPreflight - - Path - - Status - - - IFInstallationScriptsPreinstall - - Path - preinstall.sh - Path Type - 2 - Status - - - IFInstallationScriptsPreupgrade - - Path - - Status - - - - Requirements - - - Settings - - Description - - International - - IFPkgDescriptionDeleteWarning - - IFPkgDescriptionDescription - SimGrid is a toolkit that provides core functionalities for the simulation of distributed applications in heterogeneous distributed environments. The specific goal of the project is to facilitate research in the area of parallel and distributed large scale systems, such as Grids, P2P systems and clouds. Its use cases encompass heuristic evaluation, application prototyping or even real application development and tuning. - IFPkgDescriptionTitle - SimGrid - IFPkgDescriptionVersion - 3.8 - - - Display Information - - CFBundleGetInfoString - SimGrid 1.0 Copyrights © 2012 My Great Company - CFBundleIconFile - ../../doc/webcruft/SGicon.icns - CFBundleIconFile Path Type - 2 - CFBundleIdentifier - com.mygreatcompany.pkg.SimGrid - CFBundleName - SimGrid - CFBundleShortVersionString - 1.0 - - Options - - IFPkgFlagAllowBackRev - - IFPkgFlagAuthorizationAction - 0 - IFPkgFlagFollowLinks - - IFPkgFlagIsRequired - - IFPkgFlagOverwritePermissions - - IFPkgFlagRelocatable - - IFPkgFlagRestartAction - 0 - IFPkgFlagRootVolumeOnly - - IFPkgFlagUpdateInstalledLanguages - - - Version - - IFMajorVersion - 3 - IFMinorVersion - 8 - - - - IFPkgFlagPackageSelection - 0 - Name - SimGrid-3.8 - Status - 1 - Type - 1 - - Name - Project - Settings - - 10.1 Compatibility - - Build Path - build - Build Path Type - 2 - Comment - - Remove .DS_Store - - Remove .pbdevelopment - - Remove CVS - - - - diff --git a/tools/cmake/scripts/postinstall.sh b/tools/cmake/scripts/postinstall.sh deleted file mode 100755 index ef11450648..0000000000 --- a/tools/cmake/scripts/postinstall.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh -echo "export SIMGRID_ROOT=/Applications/SimGrid" >> ~/.profile -echo "export DYLD_LYBRARY_PATH=$DYLD_LYBRARY_PATH:$SIMGRID_ROOT/lib" >> ~/.profile \ No newline at end of file diff --git a/tools/cmake/scripts/preinstall.sh b/tools/cmake/scripts/preinstall.sh deleted file mode 100755 index f093e59ef3..0000000000 --- a/tools/cmake/scripts/preinstall.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash -echo "\n#SIMGRID ICEBERG" >> ~/.profile -return 0 \ No newline at end of file