Showing posts with label TCP. Show all posts
Showing posts with label TCP. Show all posts

Saturday, August 17, 2013

TCP- Close wait simulation - Part 3

Lets try to do some dirty way of coding to produce close_wait!

Check out my server code! I am opening up new socket and waiting for request from client!
Once request is received, writing out a message to client and closing the connection then and there!
Server Code


In Client code I am creating new connection with Server and puting the clinet into sleep mode with out closing the connection.
Client Code


This will results as bellow!


Tuesday, August 13, 2013

TCP- Close wait simulation - Part 2

In my last blog , I gave a brief idea about TCP and TCP states, Lets check how its work in real network by simulating the TCP connection using NS2 simulator.

So what is NS2?

NS2 is a discrete event network simulator. It is aimed at network research, and supports simulation of various facets of networking, including TCP, multicast, and routing protocols.

You can easly install NS2 in Ubunutu using "Ubunutu Software Center", as usual make use of your terminal and install. sudo apt-get install ns2 nam xgraph.

Below NS2 Script contain TCP - TCP compare.


Below NS2 Script contain TCP-UDP compare

you can run these codes using ns .tcl

Above NS2 scripts help you to simulate how TCP's functionality in the real network.
Lets see what has happened!

As shown in Figure 1, the network model was configured with two TCP (TransmissionControl Protocol) flows for two milliseconds and recorded observation in trace files.

Figure 1
Trace files were plotted using “xgraph” utility and it has been shown in figure 2
Figure 2
According to the results given by the experiment, TCP flows fairly shared the network bandwidth.

As shown in Figure 3, additional another experiment was conducted in respect to model the TCP flow and UDP (User Datagram Protocol) flow in shared network environment, which experiment was inspected for two milliseconds. Furthermore, observations were recorded in the trace file as previous experiment.
Figure 3 
Second experiment’s trace files were plotted using “xgraph” utility and it has been shown in Figure 4.

In accordance with the second experimental result given in the Figure 4, UPD flow was taken over the shared network resource from TCP flow and it did not moderately shared the band with it .

Figure 4

According to Figure 5, in first experiment; first TCP flow was shared the bandwidth with second TCP flow. In second experiment; TCP flow was trampled by UDP flow.Hence, as a conclusion of those two experiments, TCP Shares the network resource fairly.Nevertheless, UPD does not share the network resource.

Even though this is irrelevant to this topic, this help us to understand the behavior of the TCP connections.

Sunday, August 11, 2013

TCP - Close wait simulation - Part 1


In this blog series i will try to explain how to simulate CLOSE_WAIT state of TCP in java . In order to do that as a prerequisite you have to understand the TCP. Therefore i refer to refer to "Computer Network" by Anrew Tanenbaum [1] in this first part of this series. In my next blog post i will simulated the behavior of the TCP using NS2 network simulation tool.Thereafter, I will be show simple code snippet  to demonstrate the CLOSE_WAIT.

So lets start with TCP.......

TCP

Transmission Control Protocol (TCP) is designed to be a bidirectional, ordered, and reliable data transmission protocol between two end points (programs). In this context, the term reliable means that it will retransmit the packets if it gets lost in the middle. TCP guarantees the reliability by sending back Acknowledgment (ACK) packets back for a single or a range of packets received from the peer.

This goes same for the control signals such as termination request/response. RFC 793 defines the TIME-WAIT state to be as follows:

TIME-WAIT - represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.

See the following TCP state diagram: 

alt text

TCP is a bidirectional communication protocol, so when the connection is established, there is not a difference between the client and the server. Also, either one can call quits, and both peers needs to agree on closing to fully close an established TCP connection.

Let's call the first one to call the quits as the active closer, and the other peer the passive closer. When the active closer sends FIN, the state goes to FIN-WAIT-1. Then it receives an ACK for the sent FIN and the state goes to FIN-WAIT-2. Once it receives FIN also from the passive closer, the active closer sends the ACK to the FIN and the state goes to TIME-WAIT. In case the passive closer did not received the ACK to the second FIN, it will retransmit the FIN packet.

RFC 793 sets the TIME-OUT to be twice the Maximum Segment Lifetime, or 2MSL. Since MSL, the maximum time a packet can wander around Internet, is set to 2 minutes, 2MSL is 4 minutes. Since there is no ACK to an ACK, the active closer can't do anything but to wait 4 minutes if it adheres to the TCP/IP protocol correctly, just in case the passive sender has not received the ACK to its FIN (theoretically).

References


[1]Tanenbaum, A. 1996. Computer networks. Upper Saddle River, N.J.: Prentice Hall PTR.