Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / transport / E2ETransport.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 import peersim.edsim.*;
24
25
26 /**
27  * This transport protocol is based on the {@link E2ENetwork} class.
28  * Each instance
29  * of this transport class is assigned to one of the routers contained in
30  * the (fully static singleton) {@link E2ENetwork},
31  * and subsequently the {@link E2ENetwork} class is used to obtain the
32  * latency for messages sending based on the router assignment.
33  *
34  * @author Alberto Montresor
35  * @version $Revision: 1.11 $
36  */
37 public class E2ETransport implements Transport, RouterInfo
38 {
39
40 //---------------------------------------------------------------------
41 //Parameters
42 //---------------------------------------------------------------------
43
44 /**
45  * The delay that corresponds to the time spent on the source (and destination)
46  * nodes. In other words, full latency is calculated by fetching the latency
47  * that belongs to communicating between two routers, incremented by
48  * twice this delay. Defaults to 0.
49  * @config
50  */
51 private static final String PAR_LOCAL = "local";
52         
53 //---------------------------------------------------------------------
54 //Static fields
55 //---------------------------------------------------------------------
56
57 /** Identifier of this transport protocol */
58 private static int tid;
59         
60 /** Local component of latency */
61 private static long local;
62
63 //---------------------------------------------------------------------
64 //Fields
65 //---------------------------------------------------------------------
66
67 /** Identifier of the internal node */
68 private int router = -1;
69         
70 //---------------------------------------------------------------------
71 //Initialization
72 //---------------------------------------------------------------------
73
74 /**
75  * Reads configuration parameters.
76  */
77 public E2ETransport(String prefix)
78 {
79         tid = CommonState.getPid();
80         local = Configuration.getLong(prefix + "." + PAR_LOCAL, 0);
81 }
82
83 //---------------------------------------------------------------------
84
85 /**
86  * Clones the object.
87  */
88 public Object clone()
89 {
90         E2ETransport e2e=null;
91         try { e2e=(E2ETransport)super.clone(); }
92         catch( CloneNotSupportedException e ) {} // never happens
93         return e2e;
94 }
95
96 //---------------------------------------------------------------------
97 //Methods inherited by Transport
98 //---------------------------------------------------------------------
99
100 /**
101 * Delivers the message reliably, with the latency calculated by
102 * {@link #getLatency}.
103 */
104 public void send(Node src, Node dest, Object msg, int pid)
105 {
106         /* Assuming that the sender corresponds to the source node */
107         E2ETransport sender = (E2ETransport) src.getProtocol(tid);
108         E2ETransport receiver = (E2ETransport) dest.getProtocol(tid);
109         long latency =
110            E2ENetwork.getLatency(sender.router, receiver.router) + local*2;
111         EDSimulator.add(latency, msg, dest, pid);
112 }
113
114 //---------------------------------------------------------------------
115
116 /**
117 * Calculates latency using the static singleton {@link E2ENetwork}.
118 * It looks up which routers the given nodes are assigned to, then
119 * looks up the corresponding latency. Finally it increments this value
120 * by adding twice the local delay configured by {@value #PAR_LOCAL}.
121 */
122 public long getLatency(Node src, Node dest)
123 {
124         /* Assuming that the sender corresponds to the source node */
125         E2ETransport sender = (E2ETransport) src.getProtocol(tid);
126         E2ETransport receiver = (E2ETransport) dest.getProtocol(tid);
127         return E2ENetwork.getLatency(sender.router, receiver.router) + local*2;
128 }
129
130
131 //---------------------------------------------------------------------
132 //Methods inherited by RouterInfo
133 //---------------------------------------------------------------------
134
135 /**
136  * Associates the node hosting this transport protocol instance with
137  * a router in the router network.
138  * 
139  * @param router the numeric index of the router 
140  */
141 public void setRouter(int router)
142 {
143         this.router = router;
144 }
145
146 //---------------------------------------------------------------------
147
148 /**
149  * @return the router associated to this transport protocol.
150  */
151 public int getRouter()
152 {
153         return router;
154 }
155
156 }