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;
21 import peersim.config.*;
22 import peersim.core.*;
26 * Initializes {@link RouterInfo} protocols by assigning routers to them.
27 * The number of routers is defined by static singleton {@link E2ENetwork}.
29 * @author Alberto Montresor
30 * @version $Revision: 1.6 $
32 public class UniformRouterAssignment implements Control
35 //---------------------------------------------------------------------
37 //---------------------------------------------------------------------
40 * Parameter name used to configure the {@link RouterInfo} protocol
41 * that should be initialized.
44 private static final String PAR_PROT = "protocol";
46 //---------------------------------------------------------------------
48 //---------------------------------------------------------------------
50 /** Protocol identifier */
54 //---------------------------------------------------------------------
56 //---------------------------------------------------------------------
59 * Reads configuration parameters.
61 public UniformRouterAssignment(String prefix)
63 pid = Configuration.getPid(prefix+"."+PAR_PROT);
66 //---------------------------------------------------------------------
68 //---------------------------------------------------------------------
71 * Initializes given {@link RouterInfo} protocol layer by assigning
73 * The number of routers is defined by static singleton {@link E2ENetwork}.
74 * @return always false
76 public boolean execute()
78 int nsize = Network.size();
79 int nrouters = E2ENetwork.getSize();
80 for (int i=0; i < nsize; i++) {
81 Node node = Network.get(i);
82 RouterInfo t = (RouterInfo) node.getProtocol(pid);
83 int r = CommonState.r.nextInt(nrouters);