Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
peersimgrid release 1.0
[simgrid.git] / contrib / psg / src / peersim / transport / UniformRouterAssignment.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 import peersim.config.*;
22 import peersim.core.*;
23
24
25 /**
26  * Initializes {@link RouterInfo} protocols by assigning routers to them.
27  * The number of routers is defined by static singleton {@link E2ENetwork}.
28  *
29  * @author Alberto Montresor
30  * @version $Revision: 1.6 $
31  */
32 public class UniformRouterAssignment implements Control
33 {
34
35 //---------------------------------------------------------------------
36 //Parameters
37 //---------------------------------------------------------------------
38
39 /** 
40  * Parameter name used to configure the {@link RouterInfo} protocol
41  * that should be initialized.
42  * @config 
43  */
44 private static final String PAR_PROT = "protocol"; 
45         
46 //---------------------------------------------------------------------
47 //Methods
48 //---------------------------------------------------------------------
49
50 /** Protocol identifier */
51 private int pid;        
52         
53
54 //---------------------------------------------------------------------
55 //Initialization
56 //---------------------------------------------------------------------
57
58 /**
59  * Reads configuration parameters.
60  */
61 public UniformRouterAssignment(String prefix)
62 {
63         pid = Configuration.getPid(prefix+"."+PAR_PROT);
64 }
65
66 //---------------------------------------------------------------------
67 //Methods
68 //---------------------------------------------------------------------
69
70 /**
71  * Initializes given {@link RouterInfo} protocol layer by assigning
72  * routers randomly.
73  * The number of routers is defined by static singleton {@link E2ENetwork}.
74 * @return always false
75 */
76 public boolean execute()
77 {
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);
84                 t.setRouter(r);
85         }
86
87         return false;
88 }
89
90 }
91