# Jasper Protocol Simulator (Java Simulation of Protocols for Education and Research)
Keywords: communication communications protocol network interactive graphical visual visualisation simulation simulator ABP Alternating Bit Protocol ABRA Abracadabra Protocol BOOTP Boot Protocol HTTP HyperText Transfer Protocol IP Internet Protocol SMTP Simple Mail Transfer Protocol SWP Sliding Window Protocol TCP Transmission Control Protocol TFTP Trivial File Transfer Protocol UDP User Datagram Protocol

# Jasper Protocol Simulator
(Java Simulation of Protocols for Education and Research)

## Description

This protocol simulator provides:

- the capability for interactively and graphically simulating a wide variety of communications protocols
- a framework for creating new protocol simulations
- pre-defined simulations of various well-known protocols:

- ABP (Alternating Bit Protocol)
- ABRA (Abracadabra Protocol)
- BOOTP (Boot Protocol)
- HTTP (HyperText Transfer Protocol)
- IP (Internet Protocol)
- SMTP (Simple Mail Transfer Protocol)
- SWP (Sliding Window Protocol, 3 and 5 column layout)
- TCP (Transmission Control Protocol)
- TFTP (Trivial File Transfer Protocol)
- UDP (User Datagram Protocol)

The simulator is written in Java, and so can be used on many platforms with a web browser (subject to applet security) and/or a Java environment. To compile or extend the simulator requires a Java development environment such as the Oracle JDK (and ideally also Apache Ant). To run simulations requires a Java runtime environment such as the Oracle JRE. The code has been pre-built using JDK 1.8. However, it should compile and run using Java 5 onwards.

(A Serbo-Croat version of this page was produced by Anja Skrba.)

## Installation

The simulator is provided as a Zip archive. The simulator unpacks to a directory called jasper-N.N according to version number. You might rename this to jasper for simplicity. The distribution contains:

build.xml
  Ant build file to manage the code
docs
  basic documentation
html
  directory for protocol simulation pages and simulator JAR archive
scenarios
  example scenario files
source
  directories for Java code (protocol, simulator, support)

## Simulation as an Applet

The simulator can be used on various protocols by opening html/index.html in a web browser. This assumes you renamed the distribution folder as jasper. This will bring up the main page, with general instructions and a list of protocols that can be simulated. Your web browser will need to be configured to run Java applets and (ideally) JavaScript. Due to Java security restrictions you must authorise running of the pre-compiled code created by the University of Stirling. Alternatively, use an applet viewer on the files (though the JavaScript to set protocol parameters will not work).

Most simulations are in three-column format: two protocol entities (sender/receiver or A/B) and a communications medium (link or network). A few simulations add the sending and receiving users (applications) in outer columns. This format is useful for showing what the user sees; typically this is only part of what is happening in the protocol.

In a web browser, select an action by clicking on the list at the bottom right of the diagram. Actions are things like a user sending a data message or the medium delivering a protocol message. You are completely in control of the simulation. For example you may decide when to send messages, whether to acknowledge messages, and whether to deliver or lose messages in the medium. Since the simulation does not run in real-time, a timeout is possible as soon as a message has been sent.

The last action in the diagram is shown in red. Various protocol comments may also be noted in green the diagram, e.g. that a timeout occurred or that a message was ignored.

If you make a mistake, or just want to backtrack in the simulation, then click Undo. You can undo as many steps as you like, right up to the beginning of the simulation. Clicking on Redo will perform again the last undone step. Clear will restart the simulation with the current protocol parameters. If you click on Run the simulator will run automatically, making random choices for you. If you are not sure what to experiment with, this is an easy way of seeing the protocol in action. While this is happening, the Run button changes to Stop. Click on Stop to return the simulator to user control. You can continue at this point as if you had made all the automatic choices yourself.

The Print, Load and Save buttons are disabled since the simulations are running as applets. If you wish hard copy of the simulation, position the scroll bar in the simulation pane at an interesting point and print out the whole web page.

Some simulations have associated protocol parameters. To change the defaults that are shown, enter new values and click Change Values. In some cases, this will force the simulation to restart. The following is a screen-shot of a TCP client-server simulation, showing the protocol parameters and the main simulation controls.

## Simulation as an Application

Running a protocol simulation as an application gives access to the Print, Load and Save buttons.

Print produces a hard copy of the whole simulation scenario. Note that individual pages cannot be selected for printing. The width of the printout is determined by the width of the on-screen window. Constants winWidth and winHeight in ProtocolSimulator define the initial window size. Constant maxHeight in TimeSequenceDiagram defines the vertical size of printed pages. The current sizes are appropriate for A4 paper. If necessary, change them for (say) US letter.

Load loads a simulation scenario file (with a name ending in .scn); this must be for the same protocol as you are currently simulating. It replaces the current simulation scenario (if any). Save saves the current simulation as a scenario file (with a name ending in .scn). If you are adventurous, you can create and edit your own scenarios using a text editor.

When the simulator is run as an application, a mandatory protocol name follows the main simulator class. Protocol parameters may then be given if required; protocols have defaults for these. Assume that the simulator has been built and is to be started from the top level of Jasper. The following (split here across two lines) will run TCP in client-server mode, with message window sizes other than the default:

        java -cp html/ProtocolSimulator.jar simulator.ProtocolSimulator
          TCP/cs windowSizeA=500 windowSizeB=300

## Development

The complete source of the simulator is provided. (Most files have Unix end-of-line.) The code should preferably be rebuilt using the Ant build.xml build file. ant -p will print help information about build targets. ant simulator will rebuild ProtocolSimulator.jar in the html directory. ant clean will remove all compiled class files and backup files, but preserving the JAR file. ant spotless will remove even this.

If you do not have Ant you will need to compile the Java source files manually and create a JAR file from the result.

To modify an existing protocol simulation or to write a new one will need a knowledge of the simulation framework. See the article An Interactive Visual Protocol Simulator for details of this and an extended example of how to develop a simulation. Once the framework is understood, a simple simulation can be developed in a day; complex protocols could take a week or two to develop.

Suppose that you want to develop a new simulation of the protocol EXP ('Example Protocol'). You would need to write EXP.java to instantiate the various entities in the protocol. For a simple protocol, you would then write EXPSender.java and EXPReceiver.java to define the behaviour of a sending or receiving protocol entity. More complex protocols could involve defining separate entities to handle the service interface and the protocol entity. It might also be necessary to define the formats of protocol messages and a variation on the underlying Medium to match these.

Due to increased Java security, applets need to be signed by a proper certificate. This has been done for the pre-compiled code. If you need to rebuild the code you will need your own keystore and digital certificate. See the Ant build file for how to use these.

Bear in mind that much of the development work was undertaken by students, so the level of comments in the code is somewhat limited in places. The ABP simulation is the simplest of the protocols and is a good place to start. The TFTP simulation is the best commented and best explained of the protocols. It illustrates nearly all the key points in simulation development.

## Licence

This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation - either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful but without any warranty, without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.

## Acknowledgements

The protocol simulator was developed by Computing Science and Mathematics at the University of Stirling. Iain A. Robin undertook most of the development for his Master's project under Ken Turner's supervision. Paul Johnson and Kenneth A. Whyte contributed to the development of some of the simulations for their Master's projects. Dr. Peter J. B. King, Heriot-Watt University, provided helpful ideas and suggestions.

## History

- Version 1.0: Private internal version, Iain Robin, 1st September 1999

- Version 1.1: Private internal version, Ken Turner, 22nd December 2000

- Version 1.2: Private internal version, Ken Turner, 5th March 2001

- Version 1.3: First public release, Ken Turner 6th June 2001

- Version 1.4: General updating, Ken Turner, 9th March 2006:

- HTML files updated to be XHTML-compliant.
- Source updated for JDK 1.5, and Swing graphics used. Note that JDK 1.5 or later is now required to re-compile the source or to run the code.
- Top-level directory structure revised to have source, build and docs directories.
- Makefile replaced by Ant build file. Only build and clean batch files retained. (Thanks to Dr. Peter J. B. King, Heriot-Watt University, for contributing to this.)
- Blank lines ignored in scenario files.
- ABP and SWP3 medium control is now offered through a parameter (delivery/loss, delivery only, automatic). It would be possible in principle use this with other protocols, but makes sense in only some cases. (Thanks to Dr. Peter J. B. King, Heriot-Watt University, for contributing to this.)
- SMTP protocol messages have been slightly renamed for consistency with the RFC.
- TCP default window size restored on restart. Acknowledgements now sent on receipt of data, and not when receiving window becomes full. Some complex changes caused by this. Data pending delivery now sent to user prior to Closed. Open while still Closing now leads to Closed when fully closed rather than immediately. Duplicate SYN plus ACK now cancels any retransmissions while Established.

- Version 1.5: Extensions for new protocols, Ken Turner, 11th February 2011

- Major new work has been undertaken for Pearson Education on new simulations (CSMA/CD, Multicast, Multiplexing, Protocol Stack, TCP Slow Start) to accompany the ninth edition of "Data and Computer Communications" by William Stallings.
- More comments, particularly JavaDoc, have been added to many files (which have also been reformatted).
- More thorough checks of values have been added to the JavaScript in HTML files. In addition, the HTML files have been revised and reformatted.
- The TimeSequenceDiagram class has been modified. Vertical space is now added before a DELIVER protocol event, and also before a COMMENT (even if it is not the first). A TRAVERSE protocol event has been added to deal with the situation that a dashed arrow crosses multiple columns. A corresponding TraverseTransmission class has been added.
- The Medium class has been extended with two isEmpty methods: one to check if the medium is completely empty of messages, and one to check if the medium is empty of messages from a particular source.
- All TCP classes have been extended to support the slow-start variant (TCP/ss). In addition, some problems with TCP have been corrected (obscure situations in which the protocol did not recover when trying to close). The TIME_WAIT state is now used to cope with these situations, including more abrupt termination when FIN is received in unusual situations.
- A Protocol can now now implement the methods getRandNumbers and setRandomNumbers (by default these do nothing useful). If these methods are implemented, a list of the random numbers is appended to the scenario header line when the scenario is saved, and is restored when the scenario is loaded. This is for protocols such as CSMA that generate their own random numbers (as opposed to media that do so as per previous releases). The header line is now in a format such as "Jasper CSMA 0.3,0.01,0.891". If no random numbers are present following the protocol type (as is the case with previous scenario files) then no action is taken.

- Version 1.6: Distribution via SourceForge, Ken Turner, 18th December 2014

- The simulator has been packaged and made available via SourceForge.

- Version 1.7: Update for Java 7u51 onwards, Ken Turner, 28th September 2015

- The build file now sets the "Caller-Allowable-Codebase" attribute in the simulator JAR manifest. This is so that more recent Java versions will allow JavaScript access to the simulator applet. The user will be asked to grant access to the applet from any file URL.
- The pre-built simulator JAR has been signed with a later University of Stirling certificate valid up to August 2018.