3 import org.simgrid.msg.Host;
4 import peersim.core.Network;
5 import peersim.core.Node;
7 import java.util.Comparator;
9 import java.util.TreeMap;
13 * NodeHost class used to make the mapping Node-Host.
15 * @author Khaled Baati 26/10/2014
16 * @version version 1.1
18 public class NodeHost {
21 * A collection of map contained the couple (host,node)
23 public static TreeMap<Node, Host> mapHostNode = new TreeMap<Node, Host>(
24 new Comparator<Node>() {
25 public int compare(Node n1, Node n2) {
26 return String.valueOf(n1.getID()).compareTo(
27 String.valueOf(n2.getID()));
32 * The main method to make the mapping Node to Host in the
33 * {@link #mapHostNode} field
35 public static void start() {
37 for (Integer i = 0; i < PSGSimulator.size; i++) {
38 host = PSGPlatform.hostList[i];
39 mapHostNode.put(Network.get(i), host);
44 * This static method gets a Node instance associated with a host of your
48 * The host associated in your platform.
49 * @return The node associated.
51 public static Node getNode(Host host) {
52 for (Map.Entry<Node, Host> element : mapHostNode.entrySet()) {
53 if (element.getValue() == host)
54 return element.getKey();
60 * This static method gets a host instance associated with the node of your
64 * The node associated in your platform.
65 * @return The host associated, else return null (host doesn't exist).
67 public static Host getHost(Node node) {
68 for (Map.Entry<Node, Host> element : mapHostNode.entrySet()) {
69 if (element.getKey() == node)
70 return element.getValue();