New York University Computer Science Department Courant Institute of Mathematical Sciences
New York University Computer Science Department Courant Institute of Mathematical Sciences
Assignment #8
I. Due
II. Objectives
1. Get introduced to (or reacquainted with) a very neat computational model called a
finite state machine.
2. Build a finite state machine implementation of the TCP connection protocol (3-
way handshake) for the both the client (active) side and the server (passive) side
of a connection.
3. Leverage a JAVA package that implements a programmable finite state machine
to write a program that uses these classes to implement the TCP connection
protocol given in Figure 1 below.
4. Since you won’t really get events from a communications link, a sequence of
events will be simulated by reading and parsing commands from "standard input"
(System.in in Java)
PASSIVE / Λ ACTIVE / <syn>
CLOSED
CLOSE /
Λ
LISTEN CLOSE /
SEND / <syn>
Λ
SYN / <syn-ack>
SYN_RCVD SYN / <syn-ack> SYN_SENT
ACK / Λ
SYNACK/ <ack>
CLOSE / <fin>
FIN_WAIT_1
RDATA / SDATA / <n> CLOSE_WAIT
<n>
FIN / CLOSE / <fin>
ACK / Λ <ack>
FIN / ACK / Λ
ACK / Λ
<ack>
TIMEOUT / Λ
TIME_WAIT CLOSED
III. References
1. Microsoft Word.
2. Win Zip as necessary.
3. Java SE 6.0 and above
V. Assignment
1. States
2. Events
3. Transitions
4. Start State
The Start State is the state of the machine before is has received any
events.
Moore machines can do anything a Mealy machine can do (and vice versa).
The FSM that you will experiment with in this assignment is a Mealy
machine.
2. Understand your program inputs requirements:
Your program MUST accept as input (from standard input) the Strings for
events in the following table
Events in standard input will be separated by white space (note: EOL is also
white space!).
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:
On Windows, the command is the same, but the classpath command argument
is introduced by -cp rather than -classpath.
Your program should loop, reading ONE event from standard in and
processing that event completely, including display of any output, then
continuing to read and process the next event, until end of input stream (end of
file)
You MUST implement ALL of the states shown in the transition diagram.
You MUST Implement all of the transitions shown in the transition diagram
AND the transitions for RDATA and SDATA.
Notice that there are two transitions in the Established state to handle data
events. These are the SDATA (application request to send data) and the
RDATA (data received from the network) events that can occur while in the
ESTABLISHED State. You should handle these Events by writing an output
message:
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:
where xxx is the invalid event. Your program should then continue as if the
“bad” input did not occur.
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).
NOTE: Use ONLY the constructor that allows you to specify the
FSM name and starting state:
public FSM(String fsmName, State start)
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).
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 if you send my program an Event that is not defined for the
current State?
When you detect the end of the input stream on standard input, just exit.
1. Electronic:
Your assignment file must be emailed to the TA. The file must be created and
sent by the beginning of class. After the class period, the homework is late. The
email clock is the official clock.
Your assignment file should contain your program source code packaged as a JAR
file.
To create the JAR file containing your JAVA source code (please do not include
the class files), change your working directory to the directory where your JAVA
files are located and execute the command:
Include the jar file in your assignment zip file and send the zip file as an email
attachmentl to the grader.
The associated documentation provided in your zip file MUST include a readme
file containing the name of the class that contains the main() method.
2. Written:
NOTE:
The sequence of the hardcopy submission is:
1. Cover sheet
2. Assignment Answer Sheet(s)
Assignment 8
Assignment Layout (25%)
Assignment is neatly assembled on 8 1/2 by 11 paper.
Cover page with your name (last name first followed by a comma then first name),
username and section number with a signed statement of independent effort is
included.
Program and documentation submitted for Assignment #8 are satisfactory.
File name is correct.