Internet and Intranet Protocols and Applications

 

Programming Project 1.

Revision 0: Jan 28, 2002

Revision 1: Feb 05, 2002 (fixed  typing error – no content change)

 

Due Date: Feb 13

The purpose of this first assignment is twofold:

1.      I want to introduce you to (or reacquaint you with) a very neat computational model called a finite state machine.

2.      I want to give you a simple programming project to get you started with JAVA (in case you're not yet comfortable with JAVA).

Finite state machines (fsm) are used to implement simulations, compilers, and, of most interest to us, communications protocols.  You can learn about finite state machines from any text that covers Automata Theory or Theory of Switching Circuits, or from a myriad of sources on the World Wide Web.  For our purposes, this is what you need to know:

Machines are organisms (real or synthetic) that respond to a countable (finite) set of stimuli (events) by generating predictable responses (outputs) based on a history of prior events (current state).  I like to view any object that behaves according to this stimulus/response relationship as a machine.

How do we represent a machine as a computational model?  Well, we need:

1.      States

2.      Events

3.      Transitions

4.      Start State

States represent the particular configurations that our machine can assume.

Events define the various inputs that a machine will recognize

Transitions represent a change of state from a current state to another (possibly the same) state that is dependent upon a specific event.  In a Mealy machine, an FSM may generate an output upon a transition.

The Start State is the state of the machine before is has received any events

Generally, finite a state machine is classified as either a Mealy machine - one that generates an output for each transition, or a Moore machine - one that generates an output for each state.

Moore machines can do anything a Mealy machine can do (and vice versa).

In my experience, Mealy machines are more useful for implementing communications protocols.

The fsm that we will experiment with is a Mealy machine.

In this assignment you are asked to build a finite state machine implementation of the TCP connection protocol (3-way handshake) for the client (initiating) side.  To make your life easier, we will give you a JAVA package that is a programmable finite state machine.  Your job is to write a program that uses these classes to implement the client side TCP 3-way handshake (see the class text, section 3.5.8).

You MUST accept as input (from standard input) the events in the following table:

EVENT

Input string

Client initiates TCP connection

OPEN

SYN + ACK received

SYNACK

ACK received

ACK

Data is received

DATA

FIN received

FIN

Client initiates TCP disconnect

CLOSE

Timed wait ends

TIMEOUT

 

 

 

 

 

 

 

 

 

 

Events in standard input will be separated by white space (note: EOL is also white space!).

You MUST implement the following states (refer to figure 3.39 in the text)

CLOSED, SYN_SENT, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, TIME_WAIT.

Implement all of the transitions shown in figure 3.39.

Notice that I have added an event in the table above that does not appear in the transition diagram (fig. 3.39).  This is the DATA event.  The DATA Event represents the receipt of data while in the ESTABLISHED State.  You should handle this Event by writing an output message:

“DATA received n

Where n is a number representing the number of DATA Events received to date, including this DATA Event.  The transition for the DATA Event should leave the FSM in the ESTABLISHED State.

To simplify your task, you may treat ANY String that you read from standard input that is NOT one of the events defined here by writing:

"Error: unexpected Event: xxx"

where xxx is the invalid event.  Your program should then continue as if the “bad” input did not occur.

The classes in the FSM package are:

FSM

The finite state machine class.

State

An abstract class that you will use to define the states for your FSM.

Event

A class that you will use to define the events for your FSM

Transition

A class that you will use to define the transitions in your FSM

Action

An abstract class that you will use to define the actions that you take on each transition.

FsmException

A class used to generate detectable errors in package classes.

 

OK, so how do I use these classes to make an FSM?

1.      Create classes for your states (by extending State) and allocate your states.

2.      Allocate an FSM, giving it a name and a Start State (see the constructor)

3.      Create your events (by allocating instances of Event).

4.      Create classes for the actions to take on each transition (by extending Action) and allocate your actions.

5.      Allocate instances of the Transaction class using the allocated State, Event, and Action objects, and add these Transition objects to your FSM object (see the addTransition() method in FSM).

 

How to I "send" events into the FSM?

The FSM class has a "doEvent" method that takes a an Event object as its input.

 

What happens when I send an Event to the FSM?

Well, this is a Mealy machine, so the FSM will locate the Transition you defined that associates the Event with the current state of the FSM, then set the current state to the state defined in this Transition as the next state, then it will execute the action method you specified in this Transition's Action object.

 

What do I do in my "Action" methods?

For all Transitions EXCEPT those caused by the DATA Event, write the message:

 "Event eee received, current State is sss"

where eee is the Event and sss is the current State.

For the Action on the ESTABLISHED/DATA Transition, write the message:

 “DATA received n

Where n is a number representing the number of DATA Events received to date, including this DATA Event.

 

What do I do if you send my program an Event that is not defined for the current State?

The FSM.doEvent() method will throw an FsmException if you pass an Event that is not defined for the current State.  Make sure that you catch this exception and just display the exception (every Exception has a toString() method).  Your program should then continue as if the “bad” Event did not occur.

 

How does my program terminate?

When you detect the end of the input stream on standard input, just exit.

 

How to submit:

Create a JAR file containing the Your JAVA source code (DON’T include the class files)

To create the jar file, change your working directory to the directory where your JAVA files are located and execute the command:

jar cvf xxx.jar *.java

Where  xxx is YOUR STUDENT ID.

Send the jar file as an attachment in an email to your grader.

All emails MUST be dated prior to 5:00 PM on the due date.

You may send questions to the class mailing list ONLY.

The code for the FSM package is HERE. The package is in a jar file, so you will need to extract it or use the jar file in your classpath.

To use the classes, your JAVA program must import the classes in the Fsm package.  The easiest way to use the package is to include the jar file in your class path when you compile and execute.  For example, on Unix, you might try:

javac -cp .;./Fsm.jar myProgram.java            to compile myProgram.java, and

java  -cp .;./Fsm.jar myProgram           to run myProgram

On Windows, the command is the same, but the classpath command argument is introduced by -cp rather than -classpath.

The documentation for the FSM package is HERE.