University Question Answers Chap 5
University Question Answers Chap 5
Congestion Control:
Too many packets present in (a part of) the network causes packet delay and loss that degrades
performance. This situation is called congestion. In other words, congestion in a network may
occur if the load on the network, the number of packets sent to the network, is greater than the
capacity of the network (the number of packets a network can handle).
The network and transport layers share the responsibility for handling congestion. Since
congestion occurs within the network, it is the network layer that directly experiences it and
must ultimately determine what to do with the excess packets. However, the most effective way
to control congestion is to reduce the load that the transport layer is placing on the network.
Congestion control refers to the mechanisms and techniques to control the congestion and keep
the load below the capacity.
Effects of Congestion:
As delay increases, performance decreases.
If delay increases, retransmission occurs, making situation even worse
Congestion control refers to techniques and mechanisms that can either prevent congestion,
before it happens, or remove congestion, after it has happened.
The General Principles of Congestion Control are as follows: Open Loop Principle:
attempt to prevent congestion from happening
after system is running, no corrections made Closed Loop Principle:
monitor system to detect congestion
The receiver should send acknowledgement for N packets rather than sending
acknowledgement for a single packet. The receiver should send an acknowledgment only if it
has to send a packet or a timer expires.
Discarding Policy
A good discarding policy adopted by the routers is that the routers may prevent congestion and
at the same time partially discards the corrupted or less sensitive package and also able to
maintain the quality of a message.
In case of audio file transmission, routers can discard fewer sensitive packets to prevent
congestion and also maintain the quality of the audio file.
Admission Policy
In admission policy a mechanism should be used to prevent congestion. Switches in a flow
should first check the resource requirement of a network flow before transmitting it further. If
there is a chance of a congestion or there is a congestion in the network, router should deny
establishing a virtual network connection to prevent further congestion.
Closed Loop Congestion Control
Closed-Loop congestion control mechanisms try to reduce effects of congestion after it
happens. Back Pressure:
Backpressure is a technique in which a congested node stops receiving packet from upstream
node. This may cause the upstream node or nodes to become congested and rejects receiving
data from above nodes. Backpressure is a node-to-node congestion control technique that
propagate in the opposite direction of data flow. The backpressure technique can be applied
only to virtual circuit where each node has information of its above upstream node.
In above diagram the 3rd node is congested and stops receiving packets as a result 2nd node
may be get congested due to slowing down of the output data flow. Similarly, 1st node may get
congested and informs the source to slow down.
Choke Packet:
Choke packet technique is applicable to both virtual networks as well as datagram subnets. A
choke packet is a packet sent by a node to the source to inform it of congestion. Each router
monitors its resources and the utilization at each of its output lines. whenever the resource
utilization exceeds the threshold value which is set by the administrator, the router directly
sends a choke packet to the source giving it a feedback to reduce the traffic. The intermediate
nodes through which the packets have traveled are not warned about congestion.
Implicit Signaling:
In this method, there is no communication between congested node or nodes and the source.
The source guesses that there is congestion somewhere in the network from other symptoms.
For example, when source sends several packets and there is no acknowledgment for a while,
one assumption is that network is congested and source should slow down.
Explicit Signaling:
In explicit signaling, if a node experiences congestion it can explicitly sends a packet to the
source or destination to inform about congestion. The difference between choke packet and
explicit signaling is that the signal is included in the packets that carry data rather than creating
different packet as in case of choke packet technique.
Explicit signaling can occur in either forward or backward direction.
Forward Signaling: In forward signaling signal is sent in the direction of the congestion. The
destination is warned about congestion. The receiver in this case adopts policies to prevent
further congestion.
Backward Signaling: In backward signaling signal is sent in the opposite direction of the
congestion. The source is warned about congestion and it needs to slow down.
TCP Connection
TCP is connection-oriented. a connection-oriented transport protocol establishes a logical path
between the source and destination.
In TCP, connection-oriented transmission requires three phases: connection establishment, data
transfer, and connection termination.
Connection Establishment
TCP transmits data in full-duplex mode. When two TCPs in two machines are connected, they
are
able to send segments to each other simultaneously.
Three-Way Handshaking: The connection establishment in TCP is called three-way
handshaking. The process starts with the server. The server program tells its TCP that it is
ready to accept a connection. This request is called a passive open. Although the server TCP is
ready to accept a connection from any machine in the world, it cannot make the connection
itself.
The client program issues a request for an active open. A client that wishes to connect to an
open server tells its TCP to connect to a particular server. TCP can now start the three-way
handshaking process.
1. The client sends the first segment, a SYN segment, in which only the SYN flag is set. This
segment is for synchronization of sequence numbers. The client in our example chooses a
random number as the first sequence number and sends this number to the server. This
sequence number is called the initial sequence number (ISN).
A SYN segment cannot carry data, but it consumes one sequence number.
2. The server sends the second segment, a SYN + ACK segment with two flag bits set as:
SYN and ACK. This segment has a dual purpose.A SYN + ACK segment cannot carry data,
but it does consume one sequence number.
3. The client sends the third segment. This is just an ACK segment. It acknowledges the
receipt of the second segment with the ACK flag and acknowledgment number field. An
ACK segment, if carrying no data, consumes no sequence number.
Connection Termination:
Using Three-Way Handshaking:
Half Close:
There is no sequencing of
Sequencing of data is a feature of
data in UDP. If the order is
Transmission Control Protocol (TCP).
Sequence required, it has to be
this means that packets arrive in order
managed by the
at the receiver.
application layer.
There is no retransmission
Retransmission of lost packets is
Retransmission of lost packets in the User
possible in TCP, but not in UDP.
Datagram Protocol (UDP).
TCP has a (20-60) bytes variable length UDP has an 8 bytes fixed-
Header Length
header. length header.
UDP supports
Broadcasting TCP doesn’t support Broadcasting.
Broadcasting.
UDP is used
TCP is used by HTTP, by DNS , DHCP ,
Protocols
HTTPs , FTP , SMTP and Telnet . TFTP, SNMP , RIP ,
and VoIP .
UDP connection is a
Stream Type The TCP connection is a byte stream.
message stream.
The slow-start algorithm is based on the idea that the size of the congestion window (cwnd)
starts with one maximum segment size (MSS), but it increases one MSS each time an
acknowledgment arrives.
Socket Programming:
A typical network application consists of a pair of programs—a client program and a server
program— residing in two different end systems. When these two programs are executed, a
client process and a server process are created, and these processes communicate with each
other by reading from, and writing to, sockets. When creating a network application, the
developer’s main task is therefore to write the code for both the client and server programs,
called socket programming.
There are two types of network applications. One type is an implementation whose operation
is specified in a protocol standard, such as an RFC or some other standards document; such an
application is sometimes referred to as “open,” since the rules specifying its operation are
known to all. For such an implementation, the client and server programs must conform to the
rules dictated by the RFC.
The other type of network application is a proprietary network application. In this case the
client and server programs employ an application-layer protocol that has not been openly
published in an RFC or elsewhere. A single developer (or development team) creates both the
client and server programs, and the developer has complete control over what goes in the code.
But because the code does not implement an open protocol, other independent developers will
not be able to develop code that interoperates with the application.
During the development phase, one of the first decisions the developer must make is whether
the application is to run over TCP or over UDP.
When a web page is opened, automatically a socket program is initialized to receive/send to
the process. The socket program at the source communicates with the socket program at the
destination machine with the associated source port/destination port numbers. When a web
page is terminated, automatically the socket programs will be terminated.
1 . server.c
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<sys/socket.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<sys/types.h>
#define MAXLINE 20
#define SERV_PORT 5777 main(int argc,char *argv) {
int i,j;
ssize_t n;
char line[MAXLINE],revline[MAXLINE];
int listenfd,connfd,clilen;
struct sockaddr_in servaddr,cliaddr;
listenfd=socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(SERV_PORT);
bind(listenfd,(struct sockaddr*)&servaddr,sizeof(servaddr));
listen(listenfd,1);
for(;;)
{
clilen=sizeof(cliaddr);
connfd=accept(listenfd,(struct sockaddr*)&cliaddr,&clilen);
printf("CONNECT TO CLIENT\n");
while(1)
{ if((n=read(connfd,line,MAXLINE))==0)
break;
line[n-1]='\0';
j=0;
for(i=n-2;i>=0;i--)
revline[j++]=line[i];
revline[j]='\0';
write(connfd,revline,n);}
}
}
2. client.c
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<sys/socket.h>
#include<stdlib.h>
#include<netinet/in.h> #include<sys/types.h>
#define MAXLINE 20
#define SERV_PORT 5777
main(int argc,char *argv)
{ char sendline[MAXLINE],revline[MAXLINE]; int sockfd;
struct sockaddr_in servaddr; sockfd=socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;servaddr.sin_port=ntohs(SERV_PORT);
connect(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr));
printf("Enter the data to be sent\n");
while(fgets(sendline,MAXLINE,stdin)!=NULL)
{
write(sockfd,sendline,strlen(sendline));
printf("\n Line sent");
read(sockfd,revline,MAXLINE);
printf("\nReverse of the given sentence is %s",revline);
printf("\n");
}
exit(0); }
Q. Draw and Explain TCP and UDP header and also write its function.
User Datagram
UDP packets, called user datagrams, have a fixed-size header of 8 bytes made of four fields,
each of 2 bytes (16 bits). The first two fields define the source and destination port numbers.
The third field defines the total length of the user datagram, header plus data. The 16 bits can
define a total length of 0 to 65,535 bytes. However, the total length needs to be less because a
UDP user datagram is stored in an IP datagram with the total length of 65,535 bytes. The last
field can carry the optional checksum.
UDP Services:
Process-to-Process Communication
UDP provides process-to-process communication using socket addresses, a combination of IP
addresses and port numbers.
Connectionless Services
UDP provides a connectionless service. This means that each user datagram sent by UDP is an
independent datagram. There is no relationship between the different user datagrams even if
they are coming from the same source process and going to the same destination program. The
user datagrams are not numbered. Also, unlike TCP, there is no connection establishment and
no connection termination. This means that each user datagram can travel on a different path.
Flow Control
UDP is a very simple protocol. There is no flow control, and hence no window mechanism.
The receiver may overflow with incoming messages. The lack of flow control means that the
process using UDP should provide for this service, if needed.
Error Control
There is no error control mechanism in UDP except for the checksum. This means that the
sender does not know if a message has been lost or duplicated. When the receiver detects an
error through the checksum, the user datagram is silently discarded. The lack of error control
means that the process using UDP should provide for this service, if needed.
Congestion Control
Since UDP is a connectionless protocol, it does not provide congestion control. UDP assumes
that the packets sent are small and sporadic and cannot create congestion in the network.
Encapsulation and Decapsulation
To send a message from one process to another, the UDP protocol encapsulates and
decapsulates messages.
Window size. This field defines the window size of the sending TCP in bytes. Note that the
length
of this field is 16 bits, which means that the maximum size of the window is 65,535 bytes. This
value is normally referred to as the receiving window (rwnd) and is determined by the receiver.
The sender must obey the dictation of the receiver in this case.
Checksum. This 16-bit field contains the checksum. The calculation of the checksum for TCP
follows the same procedure as the one described for UDP
Urgent pointer. This 16-bit field, which is valid only if the urgent flag is set, is used when the
segment contains urgent data.
Options. There can be up to 40 bytes of optional information in the TCP header.