SlideShare a Scribd company logo
IP and Applications – Project
Implementation of a TFTP Client
Design and implementation of trivial file transfer
protocol client using finite state machine
Supervisor
Proff. Dr. Rudolf Jäger
Christopher Köhnen, cand. PhD
The goal of this small project is to implement a simple protocol in order to
foster the theoretical background offered during the lecture

Author
Udaykumar Sharma
Matrikelnummer : 997168
11/20/2013
Version 0.1
IP and Applications – Project Implementation of a TFTP Client

Table of Contents
Table of Contents .................................................................................................................................... 2
1.

Introduction .................................................................................................................................... 3

2.

Overview of protocol ...................................................................................................................... 4
2.1 TFTP READ Request ....................................................................................................................... 5
2.1.1 How to Client Send read Request to server? ............................................................................. 5
2.1.2 How server send data to Client? ................................................................................................ 5
2.1.3 How client send acknowledge to server? .................................................................................. 5
2.2 TFTP WRITE Request ..................................................................................................................... 6
2.2.1 How to make DatagramSocket? ................................................................................................ 6
2.2.2How to send WRITE request? ..................................................................................................... 6
2.2.3 How server send acknowledgement to client?.......................................................................... 6
2.2.4 How client send data to server? ................................................................................................ 7
2.2.5 How Server send acknowledgement for data? .......................................................................... 7
2.3 TFTP Data Flow Diagram ............................................................................................................... 8

3 TFTP Finite State Machine ................................................................................................................... 9
3.1 FSM for the Client ......................................................................................................................... 9
3.2 FSM Infinite Loop ........................................................................................................................ 10
4 Project UML diagram ......................................................................................................................... 11
4.1 Project work packages ................................................................................................................ 12
IP and Applications – Project Implementation of a TFTP Client

1. Introduction
TFTP is a short form of trivial file transfer protocol and is a forerunner protocol of FTP (file
transfer protocol). Basic use of TFTP is to transfer information from client to server or vice
versa.
TFTP protocol builds on top of UDP protocol. TFTP utilize functionality of UDP to transferring
information but advantage of TFTP is providing acknowledgement. TFTP has modes namely
octet, netascii and etc. and has operations such as READ, WRITE, DATA, ACKNODGEMENT
and ERROR. TFTP data packet is 512 byte. As described in requirement this project has build
on the bases of TFTP 1350 standard and also has facility of finite state machine.
IP and Applications – Project Implementation of a TFTP Client

2. Overview of protocol
In terms of networking there are client and server send request and response to eachother.
This request and response is in the form of read and write for data and acknowledgement.
Below table describe protocol stack of TFTP 1350.
Order of header

Local Medium

Internet

2 bytes
TFTP Opcode

Datagram

TFTP Formats

Type

Opcode #

Format without header

2 bytes

String

1byte

String

1 byte

01/02

Filename

0

Mode

0

2 bytes

2 bytes

N byte

Data

O3

Block #

Data

ACK

2 bytes
04

2 bytes
Block #

Error

2 bytes
05

2 bytes
ErrorCode

RRQ/WRQ

String
ErrMsg

Table 1 TFTP Formats

Above stack has contain 5 operation such as

Opcodes#
1
2
3
4
5

Operations
Read (RRQ)
Write (WRQ)
Data (DATA)
Acknowledgement (ACK)
Error (ERROR)

Let’s see all the operations in brief.

1 byte
0
IP and Applications – Project Implementation of a TFTP Client

2.1 TFTP READ Request
2.1.1 How to Client Send read Request to server?

0

#OPCODE
READ[1]

FILENAME
BINARY FORM

0

MODE (NETASCII)
BINARY FORM

0

/*To sending read request to server with #0#Opcode #Filename#0#Mode
*Opcode for read request is 01
*FileName is in Binary Form
*0 : Devide Filename and Mode
*Mode : (NETASCII, OCTET or MAIL) in Binary Form*/
DatagramPacket _readpacket = new DatagramPacket(packet,IP,Port);
socket.send(_readpacket);

2.1.2 How server send data to Client?

0

#OPCODE
DATA[3]

0

#BLOCK
NUMBER[1...]

#DATA BINARY
FORM

/**
*When client send read request to Server in reply server will send #Opcode (3) #Block Number (1---]
*and Binary Data */
DatagramPacket _datapacket = new DatagramPacket(byteArray,byteArray.length);
socket.recieve( _datapacket);

2.1.3 How client send acknowledge to server?

0

#OPCODE
DATA[4]

0

#BLOCK
NUMBER[1...]

0

0

/**When client send acknowledge response to Server #Opcode (4) #Block Number (1---] */
byteArra[0]=0
byteArra[0]=4
byteArra[0]=0
byteArra[0]=1
DatagramPacket _acknoledgepacket = new DatagramPacket(byteArray,byteArray.length);
socket.recieve( _acknoledge);
IP and Applications – Project Implementation of a TFTP Client

2.2 TFTP WRITE Request
2.2.1 How to make DatagramSocket?
/*When we know we have server available already then we can directly make datagram socket*/
DatagramSocket socket = new DatagramSocket()

2.2.2How to send WRITE request?
#OPCODE
WRITE[2]

0

FILENAME
BINARY FORM

0

MODE (NETASCII)
BINARY FORM

0

/**To sending Write request to server we required #Opcode #Filename#0#Mode
*Opcode for write request is 02
*FileName is in Binary Form
*0 : Devide Filename and Mode
*Mode : (NETASCII, OCTET or MAIL) in Binary Form*/
DatagramPacket _writepacket = new DatagramPacket(packet,IP,Port);
socket.send(_writepacket);

2.2.3 How server send acknowledgement to client?

0

#OPCODE ACK[4]

0 0

0

/**After getting Write request server will send Acknowledgement packet to client
*Opcode for ACK request is 04 following with 0’s */
DatagramPacket _acknowledgement packet = new DatagramPacket(ackpacket[],ackpacket.length);
socket.recieve(_acknowledgementpacket);
IP and Applications – Project Implementation of a TFTP Client
2.2.4 How client send data to server?

0

#OPCODE
DATA[3]

0

#BLOCK
NUMBER[1...]

#DATA BINARY
FORM

/**After getting acknowledgement response from the server, client will send “3” opcode follows
with “1 or 2 or 3…….” Block number and Data to the server */
byteArray[0]
byteArray[3]
byteArray[0]
byteArray[1]
DatagramPacket _datapacket = new DatagramPacket(byteArray,byteArray.length, ServerIP,
localport);
socket.send( _datapacket);

2.2.5 How Server send acknowledgement for data?

0

#OPCODE
DATA[4]

0

#BLOCK
NUMBER[1...]

0

0

/**After getting Data from the client, server will send “4” acknowledgement opcode follows with
“1 *or 2 or 3…….” Block number to the client */
byteArray[0]
byteArray[4]
byteArray[0]
byteArray[1]
DatagramPacket _acknowledgement = new DatagramPacket(byteArray,byteArray.length, ServerIP,
localport);
socket.recieve( _datapacket);
IP and Applications – Project Implementation of a TFTP Client
2.3 TFTP Data Flow Diagram
NOTE : Each request has Message size 512 byte including 2 byte for opcode and 2 byte for
block number so if total message size is 1024 byte then Message divided in 2 block and each
block data size is 512 byte.

File Size 1024 byte

512 Byte

512 Byte

Block 01

Block 02

Block 1

0

#OPCODE
DATA[3]

Block 2

0

#BLOCK
NUMBER[1...]

4 Byte TFTP Channel

After dividing File size in block its goes to TFTP channel
where it gets 4 more byte so each block has contain 516
byte of data
IP and Applications – Project Implementation of a TFTP Client

3 TFTP Finite State Machine
Finite state machine is useful to describe interactive network application. FSM describe TFTP
states more preciously it has 6 tuple:
FSM = <S, E, A, F, g, q0>
Where S, E and A are finite sets of states, events and actions. Respectively q0 is a initial
state of FSM.

3.1 FSM for the Client
State INIT is belongs to the User Interface it is not a part of FSM.

(R)
/RRQ

INIT
(W)
/WRQ

Read
Connection
Op(1)/Filename
/Mode(ascii)

Write
Error

Connection

Connection
Op(2)/Filename
/Mode(ascii)

Connection

Data (1)/ACK(1)

ACK (0)/Data(1)

Ack_sent

Data_sent

Data_RCV

ACK_RCV

Figure 3.1 TFTP FSM State diagram
IP and Applications – Project Implementation of a TFTP Client
As described in state diagram TFTP has two main states called Read and Write (Get and Put).
It follows with connection to the server which accepts first packet in the form of Opcode,
filename and mode. After establish connection with server client start sending data and
receiving acknowledgement from the server in the form of read and write packet.

3.2 FSM Infinite Loop
FSM has infinite loop to receive and send acknowledge and data from client to server.
do {
if (lastpacketprocess) {
dataprocess = false;
lastpacket = true;
}
if (!lastpacketprocess) {
// encode block number
encodeIntoTwoByete(blocknumber, spaceData,
OPCODE_SIZE);
// create data and reply UDP packet
dataPacket = new DatagramPacket( spaceData,
spaceData.length,
this.serverIpAddress, serverPortNum);
replyACK = new DatagramPacket( spaceAck,
spaceAck.length);
// send and receive data and acknowledgement
connection.dataSendRCV(dataPacket, replyACK);
filelength = filelength - onepacket;
blocknumber++;
readnumbyte = readnumbyte + 512;
// if not receive expected block number or opcode. resend
// packet again
while (!((checkAction(replyACK.getData(),blocknumber,
OPCODE_SIZE)) | (checkAction(replyACK.getData(), TFTP_ACK,
0))))
{
connection.dataSendRCV(dataPacket, replyACK);
}
if (filelength <= 512) {
lastpacketprocess = true;
}
}
// if final packet available send it and exit from loop
if (lastpacket) {
byte[] lastdata = new byte[ MESSAGE_HEADER_LENGTH
+ filelength];
dataPacket = new DatagramPacket(lastdata,lastdata.length,
this.serverIpAddress, serverPortNum);
replyACK = new DatagramPacket( spaceAck, paceAck.length);
connection.dataSendRCV(dataPacket, replyACK);
}
} while (dataprocess);
IP and Applications – Project Implementation of a TFTP Client
Above source code describe how infinite loop passes data and acknowledgement to the
server and in reply server provides a appropriate result to the client.

4 Project UML diagram
IP and Applications – Project Implementation of a TFTP Client
4.1 Project work packages

TFTP Main

TFTP
Constant
TFTP_State

TFTP Write

TFTP Read

Connection

Data_ACK_Send_
Receive







TFTP Main : This class belongs to User interface. This class calls the state classes.
TFTP Sate: This is a super class for the states. It generates socket and inetaddress of the
server
Write_Request : This class inherits from the TFTP_State class and perfoms the write
request.
Read_Request: This class is state class of TFTP_State it also inherited. This class perfoms
the read request.
Connection: This class make connection between Client and Server and get first packet
from the server in the form of acknowledgement or data.
Data_ACK_Send_Receive: This class responsible to gather data and its
acknowledgement from the server or receive and send bunch of data packet or
acknowledgement packet.
IP and Applications – Project Implementation of a TFTP Client
Bibliography
Nugues, P. (n.d.). WebProtocols. Retrieved November 19, 2013, from http://fileadmin.cs.lth.se/:
http://fileadmin.cs.lth.se/cs/Education/EDA095/2011/lectures/WebProtocols/Web_2011_4.pdf
State Pattern. (n.d.). Retrieved November 19, 2013, from Tutorial Point:
http://www.tutorialspoint.com/design_pattern/state_pattern.htm

More Related Content

What's hot

Kernel (OS)
Kernel (OS)Kernel (OS)
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating SystemsRohit Joshi
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
Pawandeep Kaur
 
Internet technology unit 5
Internet technology unit 5Internet technology unit 5
Internet technology unit 5
WE-IT TUTORIALS
 
INTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMSINTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMS
Ashita Agrawal
 
Volte originating-call
Volte originating-callVolte originating-call
Volte originating-call
Ashok Dwivedi
 
Application Layer
Application Layer Application Layer
Application Layer
Dr Shashikant Athawale
 
Chapter 7 - Data Link Control Protocols 9e
Chapter 7 - Data Link Control Protocols 9eChapter 7 - Data Link Control Protocols 9e
Chapter 7 - Data Link Control Protocols 9eadpeer
 
Difference between OSI Layer & TCP/IP Layer
Difference between OSI Layer & TCP/IP LayerDifference between OSI Layer & TCP/IP Layer
Difference between OSI Layer & TCP/IP Layer
Netwax Lab
 
Chapter 1: Introduction to Unix / Linux Kernel
Chapter 1: Introduction to Unix / Linux KernelChapter 1: Introduction to Unix / Linux Kernel
Chapter 1: Introduction to Unix / Linux Kernel
Dr.Ashvini Chaudhari Bhongade
 
IPC
IPCIPC
Rtos Concepts
Rtos ConceptsRtos Concepts
Rtos Concepts
Sundaresan Sundar
 
Sequence diagram- UML diagram
Sequence diagram- UML diagramSequence diagram- UML diagram
Sequence diagram- UML diagram
Ramakant Soni
 
Tr 069
Tr 069Tr 069
Tr 069
boyboy1234
 
Extract from TEMS Investigation 17.0 Help
Extract from TEMS Investigation 17.0 HelpExtract from TEMS Investigation 17.0 Help
Extract from TEMS Investigation 17.0 HelpPeter Eriksson
 
Lte epc kp is and signalling (sf)
Lte epc kp is and signalling (sf)Lte epc kp is and signalling (sf)
Lte epc kp is and signalling (sf)
Cesar Cardozo Barrios
 
TLA+ and PlusCal / An engineer's perspective
TLA+ and PlusCal / An engineer's perspectiveTLA+ and PlusCal / An engineer's perspective
TLA+ and PlusCal / An engineer's perspective
Torao Takami
 

What's hot (20)

Ip addressing classless
Ip addressing classlessIp addressing classless
Ip addressing classless
 
Kernel (OS)
Kernel (OS)Kernel (OS)
Kernel (OS)
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Internet technology unit 5
Internet technology unit 5Internet technology unit 5
Internet technology unit 5
 
INTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMSINTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMS
 
Volte originating-call
Volte originating-callVolte originating-call
Volte originating-call
 
Application Layer
Application Layer Application Layer
Application Layer
 
Chapter 7 - Data Link Control Protocols 9e
Chapter 7 - Data Link Control Protocols 9eChapter 7 - Data Link Control Protocols 9e
Chapter 7 - Data Link Control Protocols 9e
 
Difference between OSI Layer & TCP/IP Layer
Difference between OSI Layer & TCP/IP LayerDifference between OSI Layer & TCP/IP Layer
Difference between OSI Layer & TCP/IP Layer
 
Chapter 1: Introduction to Unix / Linux Kernel
Chapter 1: Introduction to Unix / Linux KernelChapter 1: Introduction to Unix / Linux Kernel
Chapter 1: Introduction to Unix / Linux Kernel
 
IPC
IPCIPC
IPC
 
RTP.ppt
RTP.pptRTP.ppt
RTP.ppt
 
Rtos Concepts
Rtos ConceptsRtos Concepts
Rtos Concepts
 
Wml
WmlWml
Wml
 
Sequence diagram- UML diagram
Sequence diagram- UML diagramSequence diagram- UML diagram
Sequence diagram- UML diagram
 
Tr 069
Tr 069Tr 069
Tr 069
 
Extract from TEMS Investigation 17.0 Help
Extract from TEMS Investigation 17.0 HelpExtract from TEMS Investigation 17.0 Help
Extract from TEMS Investigation 17.0 Help
 
Lte epc kp is and signalling (sf)
Lte epc kp is and signalling (sf)Lte epc kp is and signalling (sf)
Lte epc kp is and signalling (sf)
 
TLA+ and PlusCal / An engineer's perspective
TLA+ and PlusCal / An engineer's perspectiveTLA+ and PlusCal / An engineer's perspective
TLA+ and PlusCal / An engineer's perspective
 

Viewers also liked

Intelligent Weather Service
Intelligent Weather Service Intelligent Weather Service
Intelligent Weather Service
Uday Sharma
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2Uday Sharma
 
Java tutor oo ps introduction-version 1
Java tutor  oo ps introduction-version 1Java tutor  oo ps introduction-version 1
Java tutor oo ps introduction-version 1Uday Sharma
 
India presentation
India presentationIndia presentation
India presentation
Uday Sharma
 
Trivial file transfer protocol (tftp)
Trivial file transfer protocol (tftp)Trivial file transfer protocol (tftp)
Trivial file transfer protocol (tftp)Yunan MaOng
 
FTP - File Transfer Protocol
FTP - File Transfer ProtocolFTP - File Transfer Protocol
FTP - File Transfer Protocol
Peter R. Egli
 
File Transfer Protocol
File Transfer ProtocolFile Transfer Protocol
File Transfer Protocol
guest029bcd
 
Chap 18 telnet
Chap 18 telnetChap 18 telnet
Chap 18 telnet
Noctorous Jamal
 
Projet sur transfert de fichiers
Projet sur transfert de fichiersProjet sur transfert de fichiers
Projet sur transfert de fichiersjosepkap
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Socketselliando dias
 
Chap 20 smtp, pop, imap
Chap 20 smtp, pop, imapChap 20 smtp, pop, imap
Chap 20 smtp, pop, imap
Noctorous Jamal
 
Java rmi
Java rmiJava rmi
Java rmi
kamal kotecha
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
Mime
MimeMime
Mime
pullel
 

Viewers also liked (18)

Intelligent Weather Service
Intelligent Weather Service Intelligent Weather Service
Intelligent Weather Service
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2
 
Core java
Core javaCore java
Core java
 
Java tutor oo ps introduction-version 1
Java tutor  oo ps introduction-version 1Java tutor  oo ps introduction-version 1
Java tutor oo ps introduction-version 1
 
India presentation
India presentationIndia presentation
India presentation
 
Trivial file transfer protocol (tftp)
Trivial file transfer protocol (tftp)Trivial file transfer protocol (tftp)
Trivial file transfer protocol (tftp)
 
FTP - File Transfer Protocol
FTP - File Transfer ProtocolFTP - File Transfer Protocol
FTP - File Transfer Protocol
 
File Transfer Protocol
File Transfer ProtocolFile Transfer Protocol
File Transfer Protocol
 
Chap 18 telnet
Chap 18 telnetChap 18 telnet
Chap 18 telnet
 
Projet sur transfert de fichiers
Projet sur transfert de fichiersProjet sur transfert de fichiers
Projet sur transfert de fichiers
 
Ch21
Ch21Ch21
Ch21
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Sockets
 
Chap 20 smtp, pop, imap
Chap 20 smtp, pop, imapChap 20 smtp, pop, imap
Chap 20 smtp, pop, imap
 
Java rmi
Java rmiJava rmi
Java rmi
 
Ftp
FtpFtp
Ftp
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
 
Mime
MimeMime
Mime
 

Similar to Tftp client server communication

Multi Process Message Formats
Multi Process Message FormatsMulti Process Message Formats
Multi Process Message Formats
Pathfinder Solutions
 
TekTape Manual
TekTape ManualTekTape Manual
TekTape Manual
Yasin KAPLAN
 
Basic to advance protocols
Basic to advance protocolsBasic to advance protocols
Basic to advance protocols
Varinder Singh Walia
 
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
IRJET Journal
 
ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3John Mathias
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
RockyBhai46825
 
Networking Fundamentals
Networking Fundamentals Networking Fundamentals
Networking Fundamentals
Vikas Gupta
 
Interprocess Message Formats
Interprocess Message FormatsInterprocess Message Formats
Interprocess Message Formats
Pathfinder Solutions
 
07 - TCP_IP and the DoD Model.ppt
07 - TCP_IP and the DoD Model.ppt07 - TCP_IP and the DoD Model.ppt
07 - TCP_IP and the DoD Model.ppt
ssuserf7cd2b
 
Cisco discovery d homesb module 6 - v.4 in english.
Cisco discovery   d homesb module 6 - v.4 in english.Cisco discovery   d homesb module 6 - v.4 in english.
Cisco discovery d homesb module 6 - v.4 in english.igede tirtanata
 
Design an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing SoftwareDesign an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing Software
nilabarai
 
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPKrzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
PROIDEA
 
Networking based ppt
Networking based pptNetworking based ppt
Networking based ppt
IMEI
 
Custom_IP_Network_Protocol_and_Router
Custom_IP_Network_Protocol_and_RouterCustom_IP_Network_Protocol_and_Router
Custom_IP_Network_Protocol_and_RouterVishal Vasudev
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manualJaya Prasanna
 
R43019698
R43019698R43019698
R43019698
IJERA Editor
 
Unit 3 Assignment 1 Osi Model
Unit 3 Assignment 1 Osi ModelUnit 3 Assignment 1 Osi Model
Unit 3 Assignment 1 Osi Model
Jacqueline Thomas
 
Bc0055, tcpip
Bc0055, tcpipBc0055, tcpip
Bc0055, tcpip
smumbahelp
 
Module 1 slides
Module 1 slidesModule 1 slides
Module 1 slides
AnaniaKapala
 
ETE405-lec7.pptx
ETE405-lec7.pptxETE405-lec7.pptx
ETE405-lec7.pptxmashiur
 

Similar to Tftp client server communication (20)

Multi Process Message Formats
Multi Process Message FormatsMulti Process Message Formats
Multi Process Message Formats
 
TekTape Manual
TekTape ManualTekTape Manual
TekTape Manual
 
Basic to advance protocols
Basic to advance protocolsBasic to advance protocols
Basic to advance protocols
 
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
 
ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Networking Fundamentals
Networking Fundamentals Networking Fundamentals
Networking Fundamentals
 
Interprocess Message Formats
Interprocess Message FormatsInterprocess Message Formats
Interprocess Message Formats
 
07 - TCP_IP and the DoD Model.ppt
07 - TCP_IP and the DoD Model.ppt07 - TCP_IP and the DoD Model.ppt
07 - TCP_IP and the DoD Model.ppt
 
Cisco discovery d homesb module 6 - v.4 in english.
Cisco discovery   d homesb module 6 - v.4 in english.Cisco discovery   d homesb module 6 - v.4 in english.
Cisco discovery d homesb module 6 - v.4 in english.
 
Design an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing SoftwareDesign an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing Software
 
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPKrzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
 
Networking based ppt
Networking based pptNetworking based ppt
Networking based ppt
 
Custom_IP_Network_Protocol_and_Router
Custom_IP_Network_Protocol_and_RouterCustom_IP_Network_Protocol_and_Router
Custom_IP_Network_Protocol_and_Router
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manual
 
R43019698
R43019698R43019698
R43019698
 
Unit 3 Assignment 1 Osi Model
Unit 3 Assignment 1 Osi ModelUnit 3 Assignment 1 Osi Model
Unit 3 Assignment 1 Osi Model
 
Bc0055, tcpip
Bc0055, tcpipBc0055, tcpip
Bc0055, tcpip
 
Module 1 slides
Module 1 slidesModule 1 slides
Module 1 slides
 
ETE405-lec7.pptx
ETE405-lec7.pptxETE405-lec7.pptx
ETE405-lec7.pptx
 

More from Uday Sharma

Wat question papers
Wat question papersWat question papers
Wat question papersUday Sharma
 
Exercises of java tutoring -version1
Exercises of java tutoring -version1Exercises of java tutoring -version1
Exercises of java tutoring -version1Uday Sharma
 
Logistics final prefinal
Logistics final prefinalLogistics final prefinal
Logistics final prefinalUday Sharma
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel ProgrammingUday Sharma
 
Making Rules Project Management
Making Rules  Project ManagementMaking Rules  Project Management
Making Rules Project ManagementUday Sharma
 

More from Uday Sharma (6)

Wat question papers
Wat question papersWat question papers
Wat question papers
 
Exercises of java tutoring -version1
Exercises of java tutoring -version1Exercises of java tutoring -version1
Exercises of java tutoring -version1
 
Logistics final prefinal
Logistics final prefinalLogistics final prefinal
Logistics final prefinal
 
Presentation1
Presentation1Presentation1
Presentation1
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Making Rules Project Management
Making Rules  Project ManagementMaking Rules  Project Management
Making Rules Project Management
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 

Tftp client server communication

  • 1. IP and Applications – Project Implementation of a TFTP Client Design and implementation of trivial file transfer protocol client using finite state machine Supervisor Proff. Dr. Rudolf Jäger Christopher Köhnen, cand. PhD The goal of this small project is to implement a simple protocol in order to foster the theoretical background offered during the lecture Author Udaykumar Sharma Matrikelnummer : 997168 11/20/2013 Version 0.1
  • 2. IP and Applications – Project Implementation of a TFTP Client Table of Contents Table of Contents .................................................................................................................................... 2 1. Introduction .................................................................................................................................... 3 2. Overview of protocol ...................................................................................................................... 4 2.1 TFTP READ Request ....................................................................................................................... 5 2.1.1 How to Client Send read Request to server? ............................................................................. 5 2.1.2 How server send data to Client? ................................................................................................ 5 2.1.3 How client send acknowledge to server? .................................................................................. 5 2.2 TFTP WRITE Request ..................................................................................................................... 6 2.2.1 How to make DatagramSocket? ................................................................................................ 6 2.2.2How to send WRITE request? ..................................................................................................... 6 2.2.3 How server send acknowledgement to client?.......................................................................... 6 2.2.4 How client send data to server? ................................................................................................ 7 2.2.5 How Server send acknowledgement for data? .......................................................................... 7 2.3 TFTP Data Flow Diagram ............................................................................................................... 8 3 TFTP Finite State Machine ................................................................................................................... 9 3.1 FSM for the Client ......................................................................................................................... 9 3.2 FSM Infinite Loop ........................................................................................................................ 10 4 Project UML diagram ......................................................................................................................... 11 4.1 Project work packages ................................................................................................................ 12
  • 3. IP and Applications – Project Implementation of a TFTP Client 1. Introduction TFTP is a short form of trivial file transfer protocol and is a forerunner protocol of FTP (file transfer protocol). Basic use of TFTP is to transfer information from client to server or vice versa. TFTP protocol builds on top of UDP protocol. TFTP utilize functionality of UDP to transferring information but advantage of TFTP is providing acknowledgement. TFTP has modes namely octet, netascii and etc. and has operations such as READ, WRITE, DATA, ACKNODGEMENT and ERROR. TFTP data packet is 512 byte. As described in requirement this project has build on the bases of TFTP 1350 standard and also has facility of finite state machine.
  • 4. IP and Applications – Project Implementation of a TFTP Client 2. Overview of protocol In terms of networking there are client and server send request and response to eachother. This request and response is in the form of read and write for data and acknowledgement. Below table describe protocol stack of TFTP 1350. Order of header Local Medium Internet 2 bytes TFTP Opcode Datagram TFTP Formats Type Opcode # Format without header 2 bytes String 1byte String 1 byte 01/02 Filename 0 Mode 0 2 bytes 2 bytes N byte Data O3 Block # Data ACK 2 bytes 04 2 bytes Block # Error 2 bytes 05 2 bytes ErrorCode RRQ/WRQ String ErrMsg Table 1 TFTP Formats Above stack has contain 5 operation such as Opcodes# 1 2 3 4 5 Operations Read (RRQ) Write (WRQ) Data (DATA) Acknowledgement (ACK) Error (ERROR) Let’s see all the operations in brief. 1 byte 0
  • 5. IP and Applications – Project Implementation of a TFTP Client 2.1 TFTP READ Request 2.1.1 How to Client Send read Request to server? 0 #OPCODE READ[1] FILENAME BINARY FORM 0 MODE (NETASCII) BINARY FORM 0 /*To sending read request to server with #0#Opcode #Filename#0#Mode *Opcode for read request is 01 *FileName is in Binary Form *0 : Devide Filename and Mode *Mode : (NETASCII, OCTET or MAIL) in Binary Form*/ DatagramPacket _readpacket = new DatagramPacket(packet,IP,Port); socket.send(_readpacket); 2.1.2 How server send data to Client? 0 #OPCODE DATA[3] 0 #BLOCK NUMBER[1...] #DATA BINARY FORM /** *When client send read request to Server in reply server will send #Opcode (3) #Block Number (1---] *and Binary Data */ DatagramPacket _datapacket = new DatagramPacket(byteArray,byteArray.length); socket.recieve( _datapacket); 2.1.3 How client send acknowledge to server? 0 #OPCODE DATA[4] 0 #BLOCK NUMBER[1...] 0 0 /**When client send acknowledge response to Server #Opcode (4) #Block Number (1---] */ byteArra[0]=0 byteArra[0]=4 byteArra[0]=0 byteArra[0]=1 DatagramPacket _acknoledgepacket = new DatagramPacket(byteArray,byteArray.length); socket.recieve( _acknoledge);
  • 6. IP and Applications – Project Implementation of a TFTP Client 2.2 TFTP WRITE Request 2.2.1 How to make DatagramSocket? /*When we know we have server available already then we can directly make datagram socket*/ DatagramSocket socket = new DatagramSocket() 2.2.2How to send WRITE request? #OPCODE WRITE[2] 0 FILENAME BINARY FORM 0 MODE (NETASCII) BINARY FORM 0 /**To sending Write request to server we required #Opcode #Filename#0#Mode *Opcode for write request is 02 *FileName is in Binary Form *0 : Devide Filename and Mode *Mode : (NETASCII, OCTET or MAIL) in Binary Form*/ DatagramPacket _writepacket = new DatagramPacket(packet,IP,Port); socket.send(_writepacket); 2.2.3 How server send acknowledgement to client? 0 #OPCODE ACK[4] 0 0 0 /**After getting Write request server will send Acknowledgement packet to client *Opcode for ACK request is 04 following with 0’s */ DatagramPacket _acknowledgement packet = new DatagramPacket(ackpacket[],ackpacket.length); socket.recieve(_acknowledgementpacket);
  • 7. IP and Applications – Project Implementation of a TFTP Client 2.2.4 How client send data to server? 0 #OPCODE DATA[3] 0 #BLOCK NUMBER[1...] #DATA BINARY FORM /**After getting acknowledgement response from the server, client will send “3” opcode follows with “1 or 2 or 3…….” Block number and Data to the server */ byteArray[0] byteArray[3] byteArray[0] byteArray[1] DatagramPacket _datapacket = new DatagramPacket(byteArray,byteArray.length, ServerIP, localport); socket.send( _datapacket); 2.2.5 How Server send acknowledgement for data? 0 #OPCODE DATA[4] 0 #BLOCK NUMBER[1...] 0 0 /**After getting Data from the client, server will send “4” acknowledgement opcode follows with “1 *or 2 or 3…….” Block number to the client */ byteArray[0] byteArray[4] byteArray[0] byteArray[1] DatagramPacket _acknowledgement = new DatagramPacket(byteArray,byteArray.length, ServerIP, localport); socket.recieve( _datapacket);
  • 8. IP and Applications – Project Implementation of a TFTP Client 2.3 TFTP Data Flow Diagram NOTE : Each request has Message size 512 byte including 2 byte for opcode and 2 byte for block number so if total message size is 1024 byte then Message divided in 2 block and each block data size is 512 byte. File Size 1024 byte 512 Byte 512 Byte Block 01 Block 02 Block 1 0 #OPCODE DATA[3] Block 2 0 #BLOCK NUMBER[1...] 4 Byte TFTP Channel After dividing File size in block its goes to TFTP channel where it gets 4 more byte so each block has contain 516 byte of data
  • 9. IP and Applications – Project Implementation of a TFTP Client 3 TFTP Finite State Machine Finite state machine is useful to describe interactive network application. FSM describe TFTP states more preciously it has 6 tuple: FSM = <S, E, A, F, g, q0> Where S, E and A are finite sets of states, events and actions. Respectively q0 is a initial state of FSM. 3.1 FSM for the Client State INIT is belongs to the User Interface it is not a part of FSM. (R) /RRQ INIT (W) /WRQ Read Connection Op(1)/Filename /Mode(ascii) Write Error Connection Connection Op(2)/Filename /Mode(ascii) Connection Data (1)/ACK(1) ACK (0)/Data(1) Ack_sent Data_sent Data_RCV ACK_RCV Figure 3.1 TFTP FSM State diagram
  • 10. IP and Applications – Project Implementation of a TFTP Client As described in state diagram TFTP has two main states called Read and Write (Get and Put). It follows with connection to the server which accepts first packet in the form of Opcode, filename and mode. After establish connection with server client start sending data and receiving acknowledgement from the server in the form of read and write packet. 3.2 FSM Infinite Loop FSM has infinite loop to receive and send acknowledge and data from client to server. do { if (lastpacketprocess) { dataprocess = false; lastpacket = true; } if (!lastpacketprocess) { // encode block number encodeIntoTwoByete(blocknumber, spaceData, OPCODE_SIZE); // create data and reply UDP packet dataPacket = new DatagramPacket( spaceData, spaceData.length, this.serverIpAddress, serverPortNum); replyACK = new DatagramPacket( spaceAck, spaceAck.length); // send and receive data and acknowledgement connection.dataSendRCV(dataPacket, replyACK); filelength = filelength - onepacket; blocknumber++; readnumbyte = readnumbyte + 512; // if not receive expected block number or opcode. resend // packet again while (!((checkAction(replyACK.getData(),blocknumber, OPCODE_SIZE)) | (checkAction(replyACK.getData(), TFTP_ACK, 0)))) { connection.dataSendRCV(dataPacket, replyACK); } if (filelength <= 512) { lastpacketprocess = true; } } // if final packet available send it and exit from loop if (lastpacket) { byte[] lastdata = new byte[ MESSAGE_HEADER_LENGTH + filelength]; dataPacket = new DatagramPacket(lastdata,lastdata.length, this.serverIpAddress, serverPortNum); replyACK = new DatagramPacket( spaceAck, paceAck.length); connection.dataSendRCV(dataPacket, replyACK); } } while (dataprocess);
  • 11. IP and Applications – Project Implementation of a TFTP Client Above source code describe how infinite loop passes data and acknowledgement to the server and in reply server provides a appropriate result to the client. 4 Project UML diagram
  • 12. IP and Applications – Project Implementation of a TFTP Client 4.1 Project work packages TFTP Main TFTP Constant TFTP_State TFTP Write TFTP Read Connection Data_ACK_Send_ Receive       TFTP Main : This class belongs to User interface. This class calls the state classes. TFTP Sate: This is a super class for the states. It generates socket and inetaddress of the server Write_Request : This class inherits from the TFTP_State class and perfoms the write request. Read_Request: This class is state class of TFTP_State it also inherited. This class perfoms the read request. Connection: This class make connection between Client and Server and get first packet from the server in the form of acknowledgement or data. Data_ACK_Send_Receive: This class responsible to gather data and its acknowledgement from the server or receive and send bunch of data packet or acknowledgement packet.
  • 13. IP and Applications – Project Implementation of a TFTP Client Bibliography Nugues, P. (n.d.). WebProtocols. Retrieved November 19, 2013, from http://fileadmin.cs.lth.se/: http://fileadmin.cs.lth.se/cs/Education/EDA095/2011/lectures/WebProtocols/Web_2011_4.pdf State Pattern. (n.d.). Retrieved November 19, 2013, from Tutorial Point: http://www.tutorialspoint.com/design_pattern/state_pattern.htm