2 * Copyright (c) 2003-2005 The BISON Project
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.
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.
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.
19 package peersim.transport;
23 * This static singleton emulates an underlying router network
24 * of fixed size, and stores the latency measurements for all pairs
27 * @author Alberto Montresor
28 * @version $Revision: 1.6 $
30 public class E2ENetwork
33 //---------------------------------------------------------------------
35 //---------------------------------------------------------------------
38 * True if latency between nodes is considered symmetric. False otherwise.
40 private static boolean symm;
43 * Size of the router network.
45 private static int size;
48 * Latency distances between nodes.
50 private static int[][] array;
52 //---------------------------------------------------------------------
54 //---------------------------------------------------------------------
56 /** Disable instance construction */
57 private E2ENetwork() {}
59 //---------------------------------------------------------------------
61 //---------------------------------------------------------------------
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
70 public static void reset(int size, boolean symm)
72 E2ENetwork.symm = symm;
73 E2ENetwork.size = size;
74 array = new int[size][];
75 for (int i=0; i < size; i++) {
77 array[i] = new int[i];
79 array[i] = new int[size];
83 //---------------------------------------------------------------------
86 * Returns the latency associated to the specified (sender, receiver)
87 * pair. Routers are indexed from 0.
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)
94 public static int getLatency(int sender, int receiver)
96 if (sender == receiver)
98 // XXX There should be the possibility to fix the delay.
101 if (sender < receiver) {
107 return array[sender][receiver];
110 //---------------------------------------------------------------------
113 * Sets the latency associated to the specified (sender, receiver)
114 * pair. Routers are indexed from 0.
116 * @param sender the index of the sender
117 * @param receiver the index of the receiver
118 * @param latency the latency to be set
120 public static void setLatency(int sender, int receiver, int latency)
124 if (sender < receiver) {
130 array[sender][receiver] = latency;
133 //---------------------------------------------------------------------
136 * Returns the current size of the underlying network (i.e., the number of
139 public static int getSize()