0% found this document useful (0 votes)
126 views80 pages

Advanced Computer Networks - CoSc-6111-Lecture-4

This document describes a course on Advanced Computer Networks. It provides details about the course title, code, credits, delivery methodology, and a list of chapter topics including Transport Layer, Socket Programming, TCP, and UDP. The chapters cover objectives, key concepts, and examples related to each topic. Labs are included to provide hands-on exercises for students.

Uploaded by

Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views80 pages

Advanced Computer Networks - CoSc-6111-Lecture-4

This document describes a course on Advanced Computer Networks. It provides details about the course title, code, credits, delivery methodology, and a list of chapter topics including Transport Layer, Socket Programming, TCP, and UDP. The chapters cover objectives, key concepts, and examples related to each topic. Labs are included to provide hands-on exercises for students.

Uploaded by

Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

CoSc-6111

Advanced Computer Networks

Dr. Shahnawaz Husain


Ph.D(CS&E), M.Tech(CS&E), B.E(CS&E)
Department CS,CET,Samara Univeristy, Samara, Ethiopia
Email:[email protected]
Ph: 00251967161370

1
Course Title EtCTS Lect. Lab Credit Hr.

Code

CoSc-6111 Advance Computer 6 3 3 4

Networks

2
Course Delivery Methodology

Theory

N/W Simulation

Programming

3
Chapter-4
Transport Layer

4
Objectives of the Chapter
Introduction

Socket

TCP

UDP

TCP over Wireless


5
Services Provided to the Upper Layers

The ultimate goal of the transport layer is to provide


efficient, reliable, and cost-effective service to its
users (normally processes) in the application layer.
To achieve this goal, the transport layer makes use of
the services provided by the network layer.
The hardware and/or software within the transport
layer that does the work is called the transport entity.

6
Part A: Introduction
● The transport layer is an end-to-end layer – this means
that nodes within the subnet do not participate in
transport layer protocols – only the end hosts.

● As with other layers, transport layer protocols send data


as a sequence of packets (segments).
Multiplexing in Transport Layer (1)
● The network layer provides communication between two
hosts.

● The transport layer provides communication between


two processes running on different hosts.

● A process is an instance of a program that is running on a


host.

● There may be multiple processes communicating between


two hosts – for example, there could be a FTP session
and a Telnet session between the same two hosts.
Multiplexing (2)
● The transport layer provides a way to multiplex / de-
multiplex communication between various processes.

● To provide multiplexing, the transport layer adds an


address to each segment indicating the source and
destination processes.
● In TCP/IP these transport layer addresses are called
port-numbers.

● Note these addresses need only be unique locally on


a given host.
Multiplexing (3)

The 5-tuple: (sending port, sending IP address, destination


port, destination IP address, transport layer protocol) uniquely
identifies a process-to-process connection in the Internet.
TPDU
Nesting of Transport Protocol Data Unit (TPDU)
{Segment}, packets, and frames.
Connection Establishment
How a user process in host 1 establishes a
connection with a time-of-day server in
host 2.
Transport Service Primitives

• The primitives for a simple transport service.


Node
Application 9. Protocol Stacks
AP Creates a new end point; allocates
table space for it within the transport
layer
Socket
interface
Identification of application (port #)

Transport
Network Identifies the node
Data Link Frames

NA

NIC card; identified by NIC card address(MAC address)


PART B: SOCKET

• Software interface designed to communicate between the


user program and TCP/IP protocol stack
• Implemented by a set of library function calls.
• Socket is a data structure inside the program.
• Both client and server programs communicate via a pair of
sockets.
Socket Framework
Application Program User Space

Socket Layer Kernel Space

TCP UDP

IP

Physical Network
(driver)
Socket Families
There are several significant socket
domain families:
⇨Internet Domain Sockets (AF_INET)
- implemented via IP addresses and
port numbers
⇨Unix Domain Sockets (AF_UNIX)
- implemented via filenames (think
“named pipe”)
⇨Novell IPX (AF_IPX)
⇨AppleTalk DDS (AF_APPLETALK)
Type of Socket

• Stream (SOCK_STREAM) Uses TCP protocol. Connection-


oriented service

• Datagram (SOCK_DGRAM) Uses UDP protocol.


Connectionless service

• Raw (SOCK_RAW) Used for testing


Creating a Socket
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);

• domain is one of the Protocol Families (PF_INET,


PF_UNIX, etc.)

• type defines the communication protocol semantics,


usually defines either:
– SOCK_STREAM: connection-oriented stream (TCP)
– SOCK_DGRAM: connectionless, unreliable (UDP)

• protocol specifies a particular protocol, just set this to 0 to


accept the default
TCP Client/Server
TCP Server
• Sequence of calls

sock_init() Create the socket

bind() Register port with the system

listen() Establish client connection

accept() Accept client connection

read/write read/write data

close() shutdown
TCP Client

• Sequence of calls

sock_init () Create socket

connect() Set up connection

write/read write/read data

close() Shutdown
Server Side Socket Details
Client Side Socket Details
UDP Clients and Servers Socket

• Connectionless clients and servers create a socket using SOCK_DGRAM


instead of SOCK_STREAM

• Connectionless servers do not call listen() or accept(), and usually do not call
connect()

• Since connectionless communications lack a sustained connection, several


methods are available that allow you to specify a destination address with
every call:
– sendto(sock, buffer, buflen, flags, to_addr, tolen);
– recvfrom(sock, buffer, buflen, flags, from_addr, fromlen);
UDP Server Socket
• Sequence of calls
sock_init() Create socket

bind() Register port with the system

recfrom/sendto Receive/send data

close() Shutdown
UDP Client Socket

• Sequence of calls

socket_init() Create socket

sendto/recfrom send/receive data

close() Shutdown
Socket
Programming
Example:
Internet File Server

6-6-1

• Client code using


sockets.
Socket
Programming
Example:
Internet File Server
(2)

• Server code using


sockets.
Lab Exercise: Connect two systems in LAN create
sockets for client and server and try to send some
data.

30
PART C: TCP
2. Introduction

• connection oriented.
• full duplex.

TCP Services:
• Reliable transport
• Flow control
• Congestion control

❑ UDP does not provide any of these services 


3. Flow of TCP Segments
4. TCP Services (1)
TCP converts the unreliable, best effort service of IP into a
reliable service, i.e., it ensures that each segment is
delivered correctly, only once, and in order.

Converting an unreliable connection into a reliable connection is basically


the same problem we have considered at the data link layer, and essentially the
same solution is used:

🡪TCP numbers each segment and uses an ARQ protocol to recover lost
segments.

🡪Some versions of TCP implement Go Back N and other versions implement


Selective Repeat.
5. TCP Services (2)
However, there are a few important differences between the transport layer and
the data link layer.

🡪 At the data link layer, we viewed an ARQ protocol as being operated between
two nodes (segment / hop by hop) connected by a point-to-point link.

🡪 At the transport layer, this protocol is implemented between two hosts


connected over network.

For Transport layer:-


🡪 Packets can arrive out-of-order, and packets may also be stored in
buffers within the network and then arrive at much later times.

🡪 The round-trip time will change with different connections and connection
establishment is more complicated.
6. TCP Header
• The Sequence number and Acknowledgement number fields perform
their usual functions. Note that the latter specifies the next byte
expected, not the last byte correctly received. Both are 32 bits long
because every byte of data is numbered in a TCP stream.
• The TCP header length tells how many 32-bit words are contained in
the TCP header. This information is needed because the Options field
is of variable length, so the header is, too. Technically, this field really
indicates the start of the data within the segment, measured in 32-bit
words, but that number is just the header length in words, so the effect
is the same.

37
• Next comes a 6-bit field that is not used. The fact that this field has
survived intact for over a quarter of a century is testimony to how well
thought out TCP is. Lesser protocols would have needed it to fix bugs
in the original design.
• Now come six 1-bit flags. URG is set to 1 if the Urgent pointer is in
use. The Urgent pointer is used to indicate a byte offset from the
current sequence number at which urgent data are to be found. This
facility is in lieu of interrupt messages. As we mentioned above, this
facility is a bare-bones way of allowing the sender to signal the
receiver without getting TCP itself involved in the reason for the
interrupt.

38
• The ACK bit is set to 1 to indicate that the Acknowledgement number
is valid. If ACK is 0, the segment does not contain an
acknowledgement so the Acknowledgement number field is ignored.
• The PSH bit indicates PUSHed data. The receiver is hereby kindly
requested to deliver the data to the application upon arrival and not
buffer it until a full buffer has been received (which it might otherwise
do for efficiency).
• The RST bit is used to reset a connection that has become confused
due to a host crash or some other reason. It is also used to reject an
invalid segment or refuse an attempt to open a connection. In general,
if you get a segment with the RST bit on, you have a problem on your
hands.

39
• The PSH bit indicates PUSHed data. The receiver is hereby kindly
requested to deliver the data to the application upon arrival and not
buffer it until a full buffer has been received (which it might otherwise
do for efficiency).
• The RST bit is used to reset a connection that has become confused
due to a host crash or some other reason. It is also used to reject an
invalid segment or refuse an attempt to open a connection. In general,
if you get a segment with the RST bit on, you have a problem on your
hands.

40
• The SYN bit is used to establish connections. The connection request
has SYN = 1 and ACK = 0 to indicate that the piggyback
acknowledgement field is not in use. The connection reply does bear
an acknowledgement, so it has SYN = 1 and ACK = 1. In essence the
SYN bit is used to denote CONNECTION REQUEST and
CONNECTION ACCEPTED, with the ACK bit used to distinguish
between those two possibilities.
• The FIN bit is used to release a connection. It specifies that the sender
has no more data to transmit. However, after closing a connection, the
closing process may continue to receive data indefinitely. Both SYN
and FIN segments have sequence numbers and are thus guaranteed to
be processed in the correct order.

41
7. Sample TCP Packet
8. TCP Connection Establishment
Active Passive
participant
(client participant
(serve
) SYN, r)
Sequ
en ceNu
m =
x
u m =y,
nce N
q u e
A CK , Se ent
YN + d g m
S
ckn owle
A
1
ACK, =x+
Ackno
=y+1 wledg
ment
9. Closing a TCP Connection (1)

client server
• client closes socket:
clientSocket.close(); clo FIN
se
• Step 1: client end system
sends TCP FIN control segment ACK
to server
clo
FIN
se
• Step 2: server receives FIN,
replies with ACK. Closes ACK

timed
wait
connection, sends FIN.

clos
ed
10. Closing a TCP Connection (2)

• Step 3: client receives FIN, replies


with ACK. client server
– Enters “timed wait” - will
respond with ACK to
closi FIN

received FINs ng
• Step 4: server, receives ACK. ACK
Connection closed. closi
FIN
• Note: with small modification, can
ng
handle simultaneous FINs.
ACK

timed
wait
clos
ed
clos
ed
11. TCP Transmission Policy

• Window management in TCP.


Explanation:
Suppose the receiver has a 4096-byte buffer. If the sender transmits a
2048-byte segment that is correctly received, the receiver will
acknowledge the segment. However, since it now has only 2048 bytes of
buffer space (until the application removes some data from the buffer), it
will advertise a window of 2048 starting at the next byte expected.
Now the sender transmits another 2048 bytes, which are acknowledged,
but the advertised window is 0. The sender must stop until the application
process on the receiving host has removed some data from the buffer, at
which time TCP can advertise a larger window.

47
Flow Control and Congestion Control

In a network, it is often desirable to limit the rate at which a source


can send traffic into the subnet.

If this is not done and sources send at too high of a rate, then
buffers within the network will fill-up resulting in long delays and
eventually packets being dropped.

Moreover as packets gets dropped, retransmission may occur,


leading to even more traffic.

We need to regulate the sources otherwise this can lead to


congestion collapse of the network, where very little traffic is
delivered to the destination.
49
Congestion Collapse
Notice, as the offered load increase, the number of packets delivered at
first increases, but at high enough loads, this rapidly decreases.
Flow Control and Congestion Control
(How to do)
Two different factors can limit the rate at which a source
sends data.

🡪 the inability of the destination to accept new data.


Techniques that address this are referred to as flow control.

🡪 the number of packets within the subnet.


Techniques that address this are referred to as
congestion control.
Flow Control and Congestion Control
(Who will control?)

Flow control and congestion control can be addressed at the


transport layer, but may also be addressed at other layers.

For example, some DLL protocols perform flow control on each


link. And some congestion control approaches are done at the
network layer.

In Transport layer both flow control and congestion control are


part of TCP (not the UDP).
Approaches to Congestion Control
(Congestion Avoidance)
Congestion control may be addressed at both the network
level and the transport layer.

Network Layer Approaches


Packet dropping 🡪 when a buffer becomes full a router can drop waiting
packets - if not coupled with some other technique, this can lead to
greater congestion through retransmissions.

Packet scheduling 🡪 certain scheduling policies may help in avoiding


congestion - in particular scheduling can help to isolate users that are
transmitting at a high rate.
Dynamic routing 🡪 when a link becomes congested,
change the routing to avoid this link - this only
helps up to a point (eventually all links become
congested) and can lead to instabilities

Admission control/Traffic policing - Only allow


connections in if the network can handle them and
make sure that admitted sessions do not send at too
high of a rate - only useful for connection-
oriented
networks.
An approach that can be used at either the network or
transport layers is

Rate control 🡪 this refers to techniques where the source


rate is explicitly controlled based on feedback from either the
network and/or the receiver.
{We have already discussed in Chapter-3}
For example, routers in the network may send a source a
"choke packet" upon becoming congested. When receiving
such a packet, the source should lower it rate.
Different networks have used various combinations of all these
approaches.

Traditionally, rate control at the transport layer has been


used in the Internet, but new approaches are beginning to be
used that incorporate some of the network layer techniques
discussed above.
Congestion Control in TCP Protocol

TCP implements end-to-end congestion control.


TCP detects congestion via the ACK's from the sliding-window
ARQ algorithm used for providing reliable service.

When the source times out before receiving an ACK, the


most likely reason is because a link became congested.
TCP uses this as an indication of congestion. In this case,
TCP will slow down the transmission rate.

TCP controls the transmission rate of a source by varying the


window size used in the sliding window protocol.
Two Scenarios for Congestion
(a)A fast network feeding a low-capacity receiver.
(b) A slow network feeding a high-capacity receiver
TCP - Slow Start
• Initial CW = 1. sender receiver
• After each ACK, CW += 1;
• Continue until: one segm
ent
– Loss occurs OR

T
T
R
– CW > slow start threshold two segm
ents
• Then switch to congestion
avoidance
• If we detect loss, cut CW in half four segm
ents
• Exponential increase in window size
per RTT

time
25. How are losses recovered?
• Say packet is lost (data or ACK!)
sende receiver
r
• Coarse-grained Timeout:
– Sender does not receive ACK after some Seq=9
2, 8 b
period of time data
ytes
– Event is called a retransmission time-out
(RTO)

timeout
=1 0
– RTO value is based on estimated round- ACK
0
trip time (RTT) X
– RTT is adjusted over time using los
exponential weighted moving average:
Seqs=9
RTT = (1-x)*RTT + (x)*sample 2, 8 b
yt e
data s
(x is typically 0.1)

First done in TCP Tahoe 0


= 10
ACK

tim
lost ACK e
scenario
26. Fast Retransmit
• Receiver expects N, gets N+1:

– Immediately sends ACK(N) sende receiver


– This is called a duplicate ACK r
– ACK
Does NOT delay ACKs here!
3000
– Continue sending dup ACKs for each
subsequent packet (not N) SEQ=300
0,
size=1000
SEQ=400 X
• Sender gets 3 duplicate ACKs:
SEQ0=500
– Infers N is lost and resends
– 3 chosen so out-of-order packets don’t SEQ0=600
trigger Fast Retransmit accidentally 0
– Called “fast” since we don’t need to wait ACK 3000
for a full RTT ACK 3000
ACK 3000
SEQ=300
0,
size=1000

tim
Introduced in TCP Reno e
TCP Connection Management Modeling
• The states used in the TCP connection management
finite state machine.
TCP Connection Management Modeling (2)
PART D: UDP
• UDP (User Datagram Protocol) 🡪 unreliable,
connectionless; No TCP’s flow control;
applications where prompt delivery more
important than accurate delivery (speech,
video, …)
• (Metaphor: postal service)
2. UDP
Datagram protocol 🡪 it does not have to establish a
connection to another machine before sending data.

1. Takes the data an application provides,


2. Packs it into a UDP packet
3. Hands it to the IP layer.
4. The packet is then put on the wire, and
that is where it ends.

There is no way to guarantee that


the packet will reach its destination.
3. UDP Packet
Basically all UDP provides is a multiplexing capability on top of IP.

The length field gives the length of the entire packet including the header.

The checksum is calculated on the entire packet


(and also on part of the IP header).

Calculating the checksum is optional, and if an error is detected the packet


may be discarded or may be passed on to the application with an error flag.
Lab Exercise:
Use different versions of TCP Protocols and check
their performance under low load, medium load and
heavy load.

67
The Application Layer
Example: The World Wide Web
Summary
(1) Architecture
(2) The Client Side
(3) The Server Side
(4) URL
(5) HTTP
(6) HTML
1. Architectural Overview (2)

• The parts of the Web model.


2. The Client Side

• (a) A browser plug-in. (b) A helper


application.
3. The Server Side (1)

• A multithreaded Web server with a front end and


processing modules.
4. URLs – Uniform Resource
Locaters
• Some common URLs.
5. HTTP Methods (1)
• The built-in HTTP request methods.
5. HTTP Methods (2)
• The status code response groups.
5. HTTP Message Headers (3)

• Some HTTP message headers.


5. Example
HTTP Usage (4)

• The start of the output


of
www.ietf.org/rfc.html.
6. HTML – HyperText Markup
Language (1)

(b)

• (a) The HTML for a sample Web page. (b) The formatted page.
6. HTML (2)

• A selection of common HTML tags. some


can have additional parameters.
Assignment:
Study the Protocols defined in Application
layer

80

You might also like