Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add java-bittorrent example (still not working).
[simgrid.git] / examples / lua / SimSplay / sim_splay.lua
index 401c17d..6202cb3 100644 (file)
@@ -1,38 +1,43 @@
 require "simgrid"
+
 -- Splay global modules
 rpc = {}
 log = {}
 job = {}
-event = {}
+events = {}
 os = {}
 start = {}
+misc = {}
+
 -- Splay global variables
-job.me ={}
+job.me = {}
 job.nodes = {}
 job.list_type = "random"
 
---Init nodes tables
+-- Init nodes tables
 function init_nodes()
-       for i= 1,simgrid.Host.number() do               
-               job.nodes[i] = simgrid.Host.getPropValue(simgrid.Host.at(i),"ip")..":"..simgrid.Host.getPropValue(simgrid.Host.at(i),"port");
-       end     
+  for i = 1, simgrid.host.number() do          
+    job.nodes[i] = { ip = simgrid.host.get_prop_value(simgrid.host.at(i), "ip"),
+                     port = simgrid.host.get_prop_value(simgrid.host.at(i), "port") }
+  end  
 end
 
 function init_jobs()
-   init_nodes()
+  init_nodes()
 end
 
 -- Job methods
 function job.me.ip()
-     return simgrid.Host.getPropValue(simgrid.Host.self(),"ip");
+  return simgrid.host.get_prop_value(simgrid.host.self(), "ip")
 end
 
 function job.me.port()
- return simgrid.Host.getPropValue(simgrid.Host.self(),"port");
+  return simgrid.host.get_prop_value(simgrid.host.self(), "port")
 end
 
+
 function job.position()
-  return simgrid.Host.getPropValue(simgrid.Host.self(),"position");
+  return simgrid.host.get_prop_value(simgrid.host.self(), "position")
 end
 
 -- log Methods
@@ -41,51 +46,71 @@ function log:print(msg)
 end
 
 -- rpc Methods
-function rpc.call(node,call)
- --init_nodes();
- func = "empty"
- arg = "empty"
- mailbox = node
-
- if type(call) == "table" then
-       func = call[1]
-       arg = call[2]
- end
- task_call = simgrid.Task.new("splay_task",10000,10000);
- task_call['func_call_name'] = func;
- task_call['func_call_arg'] = arg;
- --log:print("Sending Task to mailbox "..mailbox.." to call "..func.." with arg "..arg);
- simgrid.Task.iSend(task_call,mailbox);
- call_function(func,arg)
-end 
+function rpc.call(node, call)
+  --init_nodes();
+  func = "empty"
+  arg = "empty"
+  mailbox = node
+
+  if type(node) == "table" then
+    mailbox = node.ip..":"..node.port
+  end
+
+  if type(call) == "table" then
+    func = call[1]
+    arg = call[2]
+  end
+  task_call = simgrid.task.new("splay_task", 10000, 10000)
+  task_call['func_call_name'] = func
+  task_call['func_call_arg'] = arg
+  log:print("Sending Task to mailbox "..mailbox.." to call '"..func.."' with arg '"..arg.."'")
+  simgrid.task.send(task_call, mailbox)
+
+end
+
+function rpc.server(port)
+  -- nothing really to do : no need to open Socket since it's a Simulation
+end
 
 -- event Methods
-function event.sleep(time)
+function events.sleep(time)
   my_mailbox = job.me.ip()..":"..job.me.port()
-  task = simgrid.Task.splay_recv(my_mailbox, time)
+  task = simgrid.task.recv(my_mailbox, time)
+
+  if task ~= nil then
+    -- an RPC call just woke me up
+    call_function(task['func_call_name'], task['func_call_arg'])
+  end
 end
 
--- main func for each process, this is equivalent to the Deploiment file 
-function event.thread(main_func)
-  dofile("platform_script.lua");
- init_jobs()
+-- main function for each process, this is equivalent to the deployment file 
+function events.thread(main_func)
+  dofile("platform_script.lua")
 init_jobs()
 end
 
 -- OS methods
 function os.exit()
- simgrid.Host.destroy(simgrid.Host.self());
+  simgrid.host.destroy(simgrid.host.self())
 end
 
 -- Start Methods
 function start.loop()
- simgrid.run()
- simgrid.clean()
 simgrid.run()
 --simgrid.clean()
 end
+
+-- Misc Methods
+function misc.between(a, b)
+  return a
+end
+
 -- useful functions
-function call_function(fct,arg)
-    _G[fct](arg)
+function call_function(fct, arg)
+  _G[fct](arg)
 end
 
-function SPLAYschool()
simgrid.info("Calling me...")
+function SPLAYschool(arg)
 simgrid.info("Calling me..."..arg)
 end
+