CN - Module 4
CN - Module 4
IN
C
Faculty:
N
SY
BCS502 – COMPUTER NETWORKS Prof. Ashok Herur
U
ashok. herur @eastpoint. ac.
VT in
Module 4
.IN
C
N
Transport Layer
SY
U
VT
.IN
• Different transport layer protocols – TCP and UDP
C
N
• Flow control and Error control
SY
• Congestion control
U
VT
.IN
C
N
SY
U
VT
.IN
• Facilitates communication between host processes.
C
N
• Divides the message into data segments on the sending side, and reassembles
SY
them on the receiving side.
U
• Takes complete responsibility for a reliable, end-to-end transport of the
VT
message.
.IN
C
N
SY
U
VT
• The software and hardware within the Transport layer that does the work is
.IN
called the Transport entity.
C
• The Transport entity is generally located (when it comes to Internet) in the
N
SY
Operating System, or in a library package bound into network applications.
• It can also be in a separate user process or even in the Network Interface card.
U
VT
.IN
application process (on another host), it must specify it unambiguously.
C
• In the Internet, such addresses are called Ports. (in generic terms, an address
N
SY
is called TSAP – Transport Service Access Point).
U
Access Point).
VT
• However, note that a host could be running many applications simultaneously,
in which case a single IP address will lead to many Port addresses.
.IN
C
The Transport layer at the
N
destination host should
SY
know the port to which
the data is to be delivered.
U
VT Eg. shown is from TSAP
1208 on Host 1 to TSAP
1522 on Host 2.
• The Network layer too had Connectionless (Datagram Packet Switching) and
.IN
Connection-oriented (Virtual Circuit Packet Switching) transmissions.
C
• However, they were restricted to transmission from the transmitting router
N
(representing the transmitting host) to the terminal router (representing the
SY
destination host).
• Any deficiencies in the service has to be handled by the Transport layer.
U
VT
• Transport layer has two main protocols:
• TCP (Transport Control Protocol) – Connection-oriented
• UDP (User Datagram Protocol) – Connectionless.
.IN
internetwork.
C
N
SY
U
VT
• Is Connection-oriented
.IN
• Explicit set-up and tear-down of TCP session
C
• Offers Stream-of-bytes service
N
• Receives a stream of bytes from higher layers.
SY
• Passes them as Segments to the lower layers.
U
• Provides Reliable, in-order delivery
• Checksums to detect corrupted data
VT
• Acknowledgments & retransmissions for reliable delivery
• Sequence numbers to detect losses and reorder data
.IN
Source port Destination port
C
Sequence number
Flags: SYN
N
Acknowledgment
FIN
SY
RST HdrLen 0 Flags Advertised window
PSH
URG
U
Checksum Urgent pointer
ACK VT Options (variable)
Data
.IN
• A port number identifies the endpoint of a connection.
• A pair <IP address, port number> identifies one endpoint of a connection.
C
N
SY
U
VT
• Sequence Number:
.IN
• The range of the 32-bit SeqNo is
0 <= SeqNo <= 2 32 -1 ≈ 4.3 Giga
C
• Each sequence number identifies a byte in the byte stream.
N
SY
• Initial Sequence Number (ISN) of a connection is set during connection
establishment.
U
VT
.IN
C
N
SY
U
VT
• Acknowledgement Number:
.IN
• Acknowledgements are piggybacked.
• A segment from A -> B can contain an acknowledgement for a data sent in
C
the B -> A direction.
N
• If a host sends an AckNo in a segment it sets the “ACK flag”
SY
• The AckNo contains the SeqNo of the next byte that a host wants to
U
receive.
• Example: The acknowledgement for a segment with sequence numbers
VT
0-1500 is AckNo=1501.
• Header Length:
.IN
• Length of header in terms of 32-bit words (4 bytes)
• The TCP header has a variable length (with minimum 20 bytes)
C
• This 4-bit field can hold numbers from 5 (20 bytes) to 15 (60 bytes)
N
SY
• Flags:
• SYN: Synchronize sequence numbers
U
• Sent in the first packet when initiating a connection
VT
• FIN: Sender is finished with sending
• Used for closing a connection
• Both sides of a connection must send a FIN
.IN
• RST: Causes the receiver to Reset the connection
• Receiver terminates the connection and indicates higher layer
C
application about the reset
N
• ACK: Acknowledgement Number is valid
SY
• URG: Urgent pointer is valid
• If the bit is set, the following bytes, in the range given below,
U
contain an urgent message:VT
SeqNo <= urgent message <= SeqNo+urgent pointer
• PSH: PUSH flag is used to tell the receiver to pass all data (that it currently
has) to the application.
• Normally set by sender when the sender’s buffer is empty.
Computer Networks - Prof Ashok Herur 19
TCP Header fields
• Window Size:
.IN
• Each side advertises the size of its sliding window.
• Window size is the maximum number of bytes that a receiver can accept.
C
• Maximum window size is 216-1= 65535 bytes
N
SY
• TCP Checksum:
• TCP checksum covers over both TCP header and TCP data
U
• Urgent Pointer:
VT
• Only valid if URG flag is set
N
SY
U
VT
.IN
CK Each host tells its ISN (Initial
SYN A
C
sequence number) to the other host.
N
ACK
SY
Dat
aD
at
U
a
VT
• Three-way handshake to establish connection
• Host A sends a SYN (open) to the host B
• Host B returns a SYN acknowledgment (SYN ACK)
• Host A sends an ACK to acknowledge the SYN ACK
Computer Networks - Prof Ashok Herur 22
Step 1: A’s Initial SYN Packet
.IN
A’s port B’s port
C
Flags: SYN
Acknowledgment
N
FIN
SY
RST 20 0 Flags Advertised window
PSH
URG Checksum Urgent pointer
U
ACK
VT Options (variable)
.IN
B’s port A’s port
C
Flags: SYN
N
A’s ISN plus 1
FIN
SY
RST 20 0 Flags Advertised window
PSH
URG Checksum Urgent pointer
U
ACK VT Options (variable)
.IN
A’s port B’s port
Sequence number
C
Flags: SYN
N
B’s ISN plus 1
FIN
SY
RST 20 0 Flags Advertised window
PSH
URG Checksum Urgent pointer
U
ACK VT Options (variable)
A B
.IN
FI
N
C
CK
FIN A
N
At this time, B can still send
data to A
SY
FIN
FIN
ACK
U
VT
• Each end of the data flow must be shut down independently.
• If one end is done, it sends a FIN segment. This means that no
more data will be sent.
Computer Networks - Prof Ashok Herur 26
Error control in TCP
• The Data Link layer implements error control measures like using
.IN
a CRC Checksum and using some ARQ protocols.
C
• If every frame is verified, on EVERY link, at the Data Link layer, can
N
something be wrong, end-to-end, when the message reaches the
SY
destination host?
• While the Link layer checks take care of the errors that may occur
U
on the various links, they cannot take care of the errors that may
VT
occur INSIDE the routers.
• At every router, various fields (TTL, Fragment Offset, etc) will /
may change, leading to a change in the Packet Header checksum.
• The Data Link layer implements flow control measures like using
.IN
Sliding window protocols.
C
• What would be the optimum size of a window?
N
• At the Data Link layer (for a link between adjacent nodes), the
SY
window size can be pretty small (1, 2, 4,…) since the Bandwidth-
U
Delay product is low.
VT
• Bandwidth-Delay product broadly indicates how many bits
(segments) could have been transmitted by the time a sender
receives the acknowledgment of a message segment sent earlier.
.IN
Bandwidth-Delay product will be high because of the high delay
required to traverse the entire path to the destination.
C
N
• Therefore, the Window size here (at the Transport Layer) has to
SY
be much larger.
• The same logic applies to the Buffering at the transmitting host.
U
VT
• It has to be much larger than that used at an intermediate
router.
.IN
control should be independent of the underlying Network and
Data Link layer technologies.
C
N
• But, in practice, there are various issues with wireless links /
SY
networks.
• The main issue is that % packet loss is often used as a measure of
U
congestion. VT
• This % packet loss is normally high on wireless links / networks,
due to the higher rate of transmission error (due to noise).
.IN
connection is effectively stopped because of the throttling by the
congestion control mechanisms.
C
N
• One solution is to differentiate the packet losses due to
SY
transmission error and due to insufficient bandwidth.
• Things will be more complicated when the path contains a few
U
wired links and a few wireless links.
VT
N
SY
U
VT
.IN
• UDP implements a connectionless transfer.
• It does not require connection establishment prior to data transfer
C
• UDP service is unreliable
N
SY
• UDP does not guarantee the delivery of datagram to the destination
• It does not guarantee the correct order of the datagrams.
U
• UDP computes the checksum for the entire header plus data
VT
• UDP does not buffer the incoming datagrams.
• UDP does not have the feature to segment long messages.
.IN
forming a firm connection with the destination before transferring the data.
• User Datagram Protocol (UDP) is used for:
C
N
• Sending relatively small amounts of data, eliminating concerns regarding
SY
controlling errors or the flow of the packets
• Routing update protocols such as Routing Information Protocol (RIP) and
U
Network control protocols like SNMP. VT
• Multicasting because UDP works well with packet switching.
.IN
and smoothly.
• It is specifically chosen for time-sensitive applications like gaming, playing
C
videos, or Domain Name System (DNS) lookups (convert Domain names to IP
N
addresses).
SY
• For users, it is better to have the overall transmission arrive on time than wait
U
for it to get there in a near-perfect state.
VT
• For this reason, UDP is commonly used in Voice over Internet Protocol
(VoIP) applications as well.
.IN
0 15, 16
31
C
N
Source Port Number Destination Port Number
SY
U
UDP LengthVT Checksum
Data
.IN
assumed to be the port to reply to if needed.
C
• If not used, it should be zero.
N
• If the source host is the server, the port number is likely to be a well-known
SY
port number from 0 to 1023.
U
• If the source host is the client, the port number is likely to be an ephemeral
VT
(temporary, short-lived) port number.
• In networking, you might use well-known ports (0 to 1023), registered ports
(1024 to 49151), and dynamic or ephemeral ports (49152 to 65535), as
defined by the Internet Assigned Numbers Authority (IANA).
Computer Networks - Prof Ashok Herur 37
User Datagram Protocol (UDP)
• Destination port number identifies the receiver's port and is required.
.IN
• UDP Length field specifies the length in bytes of the UDP header and data.
C
• The minimum length is 8 bytes, the length of the header.
N
• The field size sets a theoretical limit of 65,535 bytes (8-byte header +
SY
65,527 bytes of data) for a UDP datagram.
• The Checksum field may be used for error-checking of the header and data (by
U
VT
the Application layer); The field carries all-zeros if unused.
N
SY
U
VT
.IN
offered by the hosts.
• It is a global issue, involving all hosts, all routers and all links in the
C
network.
N
SY
• When too many packets are present in a small part of the subnet, it leads to
congestion.
U
• Then, the data carrying capacity of the subnet reduces.
VT
• When the number of packets dumped onto the subnet by the hosts is within
the carrying capacity, they are all delivered (except the ones with
transmission errors)
• The number delivered is proportional to the number sent by the hosts
Computer Networks - Prof Ashok Herur 40
Congestion control
• As traffic increases beyond the capacity, the network cannot cope and
.IN
packets are lost.
C
N
SY
U
VT
.IN
• More traffic and low bandwidth lines
• Insufficient buffer at the routers
C
N
• Having a very large buffer is counter-productive (why?)
SY
• Slow processors at the routers
U
VT
.IN
• Average queue length at the routers
C
• Average packet delay
N
SY
• Standard deviation of the packet delay
U
• Number of packets that are timed-out and retransmitted
VT
In all the above cases, a rising number indicates growing congestion.
.IN
topology (adaptive routing), traffic can build up in a part of the network.
C
• The basic principle behind all the Congestion Control algorithms is: Reduce
N
load and / or Increase capacity.
SY
• Often, it is difficult to increase capacity temporarily and at short notice.
• Therefore, most of the algorithms concentrate on reducing (regulating)
U
the load. VT
.IN
• Admission Control techniques:
• Leaky bucket algorithm
C
N
• Token bucket algorithm
SY
• Traffic throttling techniques:
U
• Choke packet algorithm VT
• Explicit Congestion Notification
• Load shedding
.IN
C
N
SY
U
VT
.IN
network (on an average) is constant, regardless of the burstiness of the input;
It does nothing when input is idle or the rate is below the defined constant
C
rate.
N
• The host injects one packet per clock tick onto the network. This results in a
SY
uniform flow of packets, smoothing out bursts and reducing congestion.
U
• It is implemented as a single-server queue with constant service time.
VT
• If the bucket (buffer) overflows, then packets are discarded.
.IN
bytes per tick.
C
• The leaky bucket algorithm imposes the same restriction on all hosts (some
N
sending almost continuously and some sending occasionally).
SY
• In short, it does not allow any burstiness beyond the constant output rate
that has been defined.
U
VT
.IN
size of the burst.
• In the TB algorithm, the bucket holds tokens.
C
• Each token entitles the host to transmit a fixed number of bytes.
N
• To transmit a packet, the host must capture and destroy the required
SY
number of tokens (depending on the packet size).
U
• Tokens are generated by a clock at the rate of one token every Δt sec.
VT
• Idle hosts can capture and save up tokens (up to the max. size of the bucket)
in order to send larger bursts later.
• When the bucket fills up, new tokens are lost.
.IN
C
N
SY
U
VT
.IN
packets to the sources from where it received packets.
C
• A choke packet is a control packet generated at a congested node.
N
• The source, on receiving the choke packet must reduce its transmission rate
SY
by a certain percentage.
U
• This is a direct way of telling the sources to slow down temporarily.
VT
.IN
C
N
SY
U
VT
.IN
• A more efficient method is to send to choke packets hop-by-hop.
C
• This requires each hop to reduce its transmission even before the choke
N
packet arrive at the source.
SY
U
VT
.IN
• This technique will spread the
congestion backwards – To the routers
C
along the way.
N
SY
• It is better to have many routers ‘mildly’
congested than having one router
U
VT congested ‘heavily’
.IN
router can tag any packet it forwards (by setting a bit in the packet’s header)
to signal that it is experiencing congestion.
C
• When the packet is delivered, the destination notes that there is congestion
N
and informs the sender when it sends a Reply / Acknowledgement packet.
SY
• The sender can then throttle its transmissions, as before.
U
• This method is called Explicit Congestion Notification (ECN).
VT
.IN
earlier, are able to control congestion.
C
• Load shedding just means that the congested router will throw away packets
N
to reduce the load, when the buffer is filled up / or about to get filled up.
SY
• The key question here is about which packets to discard; The answer depends
on the type of application to which the packets belong.
U
• For a File Transfer, an old packet is worth more than a new one. Dropping packet 6 and
VT
keeping packets 7 to 10 (for example) will only force the receiver to do more work to
buffer the data that it cannot yet use.
• In contrast, in real-time applications, a new packet is worth more than an old one,
because packets become useless if they are delayed and miss the time when they must
be played out.
.IN
with it when it gets worse.
C
• Random Early Detection is a type of Load Shedding that discards packets
N
before the buffer space is filled up.
SY
• This idea stems from the fact that most hosts on the Internet do not get
congestion signals in the form of ECN.
U
• The only reliable indication of congestion that they get is Packet loss.
VT
• To determine when to start discarding, routers maintain a running average of
their queue length.
.IN
particular link is said to be congested, and a small fraction of the packets
(coming on that link) are dropped at random.
C
• Picking packets at random makes it more likely that the fastest senders will
N
see more packet drops.
SY
• This is the best option since a router cannot tell which of the sources
(sending packets on that link) is contributing more to the congestion.
U
VT
• The affected sender will notice the loss, and its Transport layer protocol will
slow down.
• The (higher-than-normal) lost packets are thus delivering the same
message as a choke packet, but implicitly.