Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / transport / E2ENetwork.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  */
18
19 package peersim.transport;
20
21
22 /**
23  * This static singleton emulates an underlying router network
24  * of fixed size, and stores the latency measurements for all pairs
25  * of routers.
26  *
27  * @author Alberto Montresor
28  * @version $Revision: 1.6 $
29  */
30 public class E2ENetwork
31 {
32
33 //---------------------------------------------------------------------
34 //Fields
35 //---------------------------------------------------------------------
36
37 /**
38  * True if latency between nodes is considered symmetric. False otherwise.
39  */
40 private static boolean symm;    
41         
42 /**
43  * Size of the router network. 
44  */
45 private static int size;
46
47 /**
48  * Latency distances between nodes.
49  */
50 private static int[][] array;
51         
52 //---------------------------------------------------------------------
53 //Initialization
54 //---------------------------------------------------------------------
55
56 /** Disable instance construction */
57 private E2ENetwork() {}
58
59 //---------------------------------------------------------------------
60 //Methods
61 //---------------------------------------------------------------------
62
63 /**
64  * Resets the network, by creating a triangular (if symm is true) or
65  * a rectangular (if symm is false) array of integers. Initially all
66  * latencies between any pairs are set to be 0.
67  * @param size the number or routers
68  * @param symm if latency is symmetric between all pairs of routers
69  */
70 public static void reset(int size, boolean symm)
71 {
72         E2ENetwork.symm = symm;
73         E2ENetwork.size = size;
74         array = new int[size][];
75         for (int i=0; i < size; i++) {
76                 if (symm)
77                         array[i] = new int[i];
78                 else
79                         array[i] = new int[size];
80         }
81 }
82         
83 //---------------------------------------------------------------------
84
85 /**
86  * Returns the latency associated to the specified (sender, receiver)
87  * pair. Routers are indexed from 0.
88  * 
89  * @param sender the index of the sender
90  * @param receiver the index of the receiver
91  * @return the latency associated to the specified (sender, receiver)
92  * pair.
93  */
94 public static int getLatency(int sender, int receiver) 
95 {
96         if (sender == receiver)
97                 return 0;
98         // XXX There should be the possibility to fix the delay.
99         if (symm) {
100                 // Symmetric network
101                 if (sender < receiver) {
102                         int tmp = sender;
103                         sender = receiver;
104                         receiver = tmp;
105                 }
106         } 
107         return array[sender][receiver];
108 }
109
110 //---------------------------------------------------------------------
111
112 /**
113  * Sets the latency associated to the specified (sender, receiver)
114  * pair. Routers are indexed from 0.
115  * 
116  * @param sender the index of the sender
117  * @param receiver the index of the receiver
118  * @param latency the latency to be set
119  */
120 public static void setLatency(int sender, int receiver, int latency) 
121 {
122         if (symm) {
123                 // Symmetric network
124                 if (sender < receiver) {
125                         int tmp = sender;
126                         sender = receiver;
127                         receiver = tmp;
128                 }
129         } 
130         array[sender][receiver] = latency;
131 }
132
133 //---------------------------------------------------------------------
134
135 /**
136  * Returns the current size of the underlying network (i.e., the number of
137  * routers).
138  */
139 public static int getSize()
140 {
141         return size;
142 }
143
144 }