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.*;
23 import peersim.edsim.*;
27 * This transport protocol is based on the {@link E2ENetwork} class.
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.
34 * @author Alberto Montresor
35 * @version $Revision: 1.11 $
37 public class E2ETransport implements Transport, RouterInfo
40 //---------------------------------------------------------------------
42 //---------------------------------------------------------------------
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.
51 private static final String PAR_LOCAL = "local";
53 //---------------------------------------------------------------------
55 //---------------------------------------------------------------------
57 /** Identifier of this transport protocol */
58 private static int tid;
60 /** Local component of latency */
61 private static long local;
63 //---------------------------------------------------------------------
65 //---------------------------------------------------------------------
67 /** Identifier of the internal node */
68 private int router = -1;
70 //---------------------------------------------------------------------
72 //---------------------------------------------------------------------
75 * Reads configuration parameters.
77 public E2ETransport(String prefix)
79 tid = CommonState.getPid();
80 local = Configuration.getLong(prefix + "." + PAR_LOCAL, 0);
83 //---------------------------------------------------------------------
90 E2ETransport e2e=null;
91 try { e2e=(E2ETransport)super.clone(); }
92 catch( CloneNotSupportedException e ) {} // never happens
96 //---------------------------------------------------------------------
97 //Methods inherited by Transport
98 //---------------------------------------------------------------------
101 * Delivers the message reliably, with the latency calculated by
102 * {@link #getLatency}.
104 public void send(Node src, Node dest, Object msg, int pid)
106 /* Assuming that the sender corresponds to the source node */
107 E2ETransport sender = (E2ETransport) src.getProtocol(tid);
108 E2ETransport receiver = (E2ETransport) dest.getProtocol(tid);
110 E2ENetwork.getLatency(sender.router, receiver.router) + local*2;
111 EDSimulator.add(latency, msg, dest, pid);
114 //---------------------------------------------------------------------
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}.
122 public long getLatency(Node src, Node dest)
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;
131 //---------------------------------------------------------------------
132 //Methods inherited by RouterInfo
133 //---------------------------------------------------------------------
136 * Associates the node hosting this transport protocol instance with
137 * a router in the router network.
139 * @param router the numeric index of the router
141 public void setRouter(int router)
143 this.router = router;
146 //---------------------------------------------------------------------
149 * @return the router associated to this transport protocol.
151 public int getRouter()