public class Simulator
extends java.lang.Object
The main class of a simple simulator for TCP congestion
control.
Check also the
design
documentation for this simulator.
The simulator provides the system clock ticks for time
progression and orchestrates the work of the network nodes.
The simulated network consists of the network elements of sender-host,
router, and receiver-host, connected in a chain as follows:
The sender host sends only data segments and the receiver host only replies with acknowledgments. In other words, for simplicity we assume unidirectional transmission.SENDER <-> NETWORK/ROUTER <-> RECEIVER
By default, the simulator reports the values of the congestion control parameters for every iteration:
You can turn ON or OFF different levels of reporting by modifying
the variable currentReportingLevel
.
Only a few parameters can be controlled in this simulator. Rather than have a flexible, multifunctional network simulator that takes long time to understand and use, this simulator is simple for an undergraduate student to understand and use during a semester-long course. The students can modify it with modest effort and study several interesting simulation scenarios described in the design documentation.
Modifier and Type | Field and Description |
---|---|
static int |
currentReportingLevel
This field specifies the current reporting level(s)
for this simulator.
The minimum possible reporting is obtained by setting the zero value. |
private double |
currentTime
Simulation iterations represent the clock ticks for the simulation.
|
private Link |
link1
The communication link that connects
senderEndpt to router . |
private Link |
link2
The communication link that connects
receiverEndpt to router . |
private Endpoint |
receiverEndpt |
static int |
REPORTING_LINKS
Simulator's reporting flag:
Reports the activities of communicaTtion links ( Link ). |
static int |
REPORTING_RECEIVERS
Simulator's reporting flag:
Reports the activities of Receiver . |
static int |
REPORTING_ROUTERS
Simulator's reporting flag:
Reports the activities of Router . |
static int |
REPORTING_RTO_ESTIMATE
Simulator's reporting flag:
Reports the activities of RTOEstimator . |
static int |
REPORTING_SENDERS
|
static int |
REPORTING_SIMULATOR
Simulator's reporting flag:
Reports the activities of the simulator runtime environment. |
private Router |
router
The router that intermediated between the TCP endpoints.
|
private Endpoint |
senderEndpt
Two endpoints of the TCP connection that will be simulated.
|
private java.util.ArrayList<TimerSimulated> |
timers
An array of timers that the simulator has currently registered,
which are associated with
TimedComponent .To deal with concurrent events, it is recommended that timers are fired (if expired) after the component's functional operation is called. |
static int |
TOTAL_DATA_LENGTH
Total data length to send (in bytes).
|
Constructor and Description |
---|
Simulator(java.lang.String tcpSenderVersion_,
int bufferSize_,
int rcvWindow_)
Constructor of the simple TCP congestion control simulator.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelTimeout(TimerSimulated timer_)
Allows a component to cancel a running timer.
|
void |
checkExpiredTimers(TimedComponent component_)
The simulator checks if any running timers
expired because the simulation clock has ticked.
|
double |
getCurrentTime()
Returns the current "time" since the start of the simulation.
|
double |
getTimeIncrement()
Time increment ("tick") for the simulation clock.
|
static void |
main(java.lang.String[] argv_)
The main method.
|
void |
run(java.nio.ByteBuffer inputBuffer_,
int num_iter_)
Runs the simulator for the given number of transmission rounds
(iterations), starting with the current iteration stored in
the parameter
currentTime .Reports the outcomes of the individual transmissions. |
TimerSimulated |
setTimeoutAt(TimerSimulated timer_)
Allows a component to start a timer running.
|
public static int currentReportingLevel
private double currentTime
private Link link1
senderEndpt
to router
.private Link link2
receiverEndpt
to router
.private Endpoint receiverEndpt
public static final int REPORTING_LINKS
Link
).public static final int REPORTING_RECEIVERS
Receiver
.public static final int REPORTING_ROUTERS
Router
.public static final int REPORTING_RTO_ESTIMATE
RTOEstimator
.public static final int REPORTING_SENDERS
public static final int REPORTING_SIMULATOR
private Router router
private Endpoint senderEndpt
private java.util.ArrayList<TimerSimulated> timers
TimedComponent
.TimedComponent
public static final int TOTAL_DATA_LENGTH
public Simulator(java.lang.String tcpSenderVersion_, int bufferSize_, int rcvWindow_)
public void cancelTimeout(TimerSimulated timer_) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
timer_
- a running timer to be cancelled.java.lang.NullPointerException
java.lang.IllegalArgumentException
public void checkExpiredTimers(TimedComponent component_)
Note that to deal with with synchronization between concurrent events,
the caller decides which timers will be checked when. It is just to expect
the caller to know such information. In the current implementation,
this method is called from Endpoint.send(NetworkElement, Packet)
and Endpoint.handle(NetworkElement, Packet)
.
component_
- the timed component for which to check the expired timerspublic double getCurrentTime()
public double getTimeIncrement()
public static void main(java.lang.String[] argv_)
TCP-sender-version (one of Tahoe/Reno/NewReno) AND number-of-iterations
argv_
- Input argument(s) should contain the version of the
TCP sender (Tahoe/Reno/NewReno) and the number of iterations to run.public void run(java.nio.ByteBuffer inputBuffer_, int num_iter_)
currentTime
.Note: The router is invoked to relay only the packets (and it may drop some of them). For the sake of simplicity, the acknowledgment segments simply bypass the router, so they are never dropped.
inputBuffer_
- the input bytestream to be transported to the receiving endpointnum_iter_
- the number of iterations (transmission rounds) to run the simulatorpublic TimerSimulated setTimeoutAt(TimerSimulated timer_) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
cancelTimeout(TimerSimulated)
.
Note that the timer object is cloned here,
because the caller may keep reusing the original timer object,
as is done in, e.g., Sender.startRTOtimer()
.
timer_
- a timer to start counting down on the simulated time.java.lang.NullPointerException
java.lang.IllegalArgumentException