48
Computer Networks 1 Lectured by: Nguyễn Lê Duy Lai 2/14/2011 HCM City University of Technology 1

Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Embed Size (px)

Citation preview

Page 1: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Computer Networks 1

Lectured by: Nguyễn Lê Duy Lai

2/14/2011HCM City University of Technology 1

Page 2: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Lecture 8: The Transport Layer

Reference: Chapter 6 - “Computer Networks”, Andrew S. Tanenbaum, 4th

Edition, Prentice Hall, 2003.

2/14/2011 HCM City University of Technology 2

Page 3: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The Transport Services Elements of Transport Protocols A Simple Transport Protocol The Internet Transport Protocols: UDP The Internet Transport Protocols: TCP Performance issues

Outline

2/14/2011HCM City University of Technology 3

Page 4: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Transport Layer task is to provide reliable, cost-effective data transport from the source machine to the destination machine, independently of the physical network or networks currently in use

Services Provided to the Upper Layers Transport Service Primitives Berkeley Sockets An Example of Socket Programming:

An Internet File Server

The Transport Services

2/14/2011HCM City University of Technology 4

Page 5: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The network, transport, and application layers

Services Provided to the Upper Layers

2/14/2011 5HCM City University of Technology

Page 6: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The connection-oriented transport service, connections have three phases: establishment, data transfer, and release

The connectionless transport service Why are there two distinct layers?

The transport code runs entirely on the users' machines

The network layer mostly runs on the routers (which are operated by the carrier)

Types of Transport Services

2/14/2011HCM City University of Technology 6

Page 7: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The transport layer must provide some operations to application programs

Each transport service has its own interface

The primitives for a simple transport service

Transport Service Primitives

2/14/2011 7HCM City University of Technology

Page 8: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

TPDU (Transport Protocol Data Unit): messages sent from transport entity to transport entity

The nesting of TPDUs, packets, and frames

Transport Protocol Data Unit

2/14/2011 8HCM City University of Technology

Page 9: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Transport Service State Diagram

A state diagram for a simple connection management scheme:

Italics: packet arrivals

Solid lines: client's state sequence

Dashed lines: server's state sequence.

2/14/2011 9HCM City University of Technology

Page 10: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The socket primitives used in Berkeley UNIXfor TCP (Internet programming)

Berkeley Sockets

2/14/2011 10HCM City University of Technology

Page 11: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Server code can be compiled and run on any UNIX system connected to the Internet

Client code can then be compiled and run on any other UNIX machine

SERVER_PORT BUF_SIZE Server: setsockopt, bind, listen, accept, send,

receive, close Client: socket, connect, send, receive, close

Ex: An Internet File Server

2/14/2011HCM City University of Technology 11

Page 12: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Addressing Connection Establishment Connection Release Flow Control and Buffering Multiplexing Crash Recovery

Elements of Transport Protocols

2/14/2011HCM City University of Technology 12

Page 13: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Transport protocols resemble the data link protocols?

Yes: Dealing with error control, sequencing, and flow control, among other issues

No: dissimilarities between the environments in which the two protocols operate (physical channel and the entire subnet)

Potential existence of storage capacity in the subnet

Buffering and flow control

A comparison needed...

2/14/2011HCM City University of Technology 13

Page 14: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Addressing Application

addresses on a host: Ports

TSAPs, NSAPs and transport connections

2/14/2011 14HCM City University of Technology

Page 15: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Initial Connection Protocol

2/14/2011HCM City University of Technology 15

Page 16: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Three-way handshake (a) Normal operation. (b) Old CONNECTION REQUEST

appearing out of nowhere. (c) Duplicate CONNECTION REQUEST and duplicate ACK

Connection Establishment

2/14/2011 16HCM City University of Technology

Page 17: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The problem occurs when the network can lose, store, and duplicate packets

The existence of delayed duplicates A machine losing all memory Guarantee not only that a packet is dead,

but also that all acknowledgements to it are also dead

Connection Establishment Issues

2/14/2011HCM City University of Technology 17

Page 18: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Asymmetric Connection Release

Asymmetric release is the way the telephone system works

Abrupt disconnection with loss of data

2/14/2011 18HCM City University of Technology

Page 19: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

If either blue army attacks by itself, it will be defeated, but if the two blue armies attack simultaneously, they will be victorious

In fact, it can be proven that no protocol exists that works

The Two-Army Problem

2/14/2011 20HCM City University of Technology

Page 20: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

(a) Normal case of a three-way handshake (b) final ACK lost

Symmetric Connection Release

2/14/2011HCM City University of Technology 21

Page 21: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

(c) Response lost. (d) Response lost and subsequent DRs lost

Continue...

2/14/2011 22HCM City University of Technology

Page 22: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

UDP – User Datagram Protocol Connection-less service Useful in client-server situations: Remote

Procedure Call, real-time AV streaming

TCP – Transmission Control Protocol Connection-oriented service Reliable byte stream services over unreliable

network Most widely used in Internet

The Internet Transport Protocols

2/14/2011HCM City University of Technology 24

Page 23: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

UDP transmits segments consisting of an 8-byte header followed by the payload

Two ports serve to identify the end points within the source and destination machines

UDP Header

2/14/2011 25HCM City University of Technology

Page 24: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Source port is primarily needed when a reply must be sent back to the source

When a UDP segment arrives, its payload is handed to the process attached to the destination port

The UDP length field includes the 8-byte header and the data

The UDP checksum is optional and stored as 0 if not computed

UDP Segment

2/14/2011HCM City University of Technology 26

Page 25: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Does: Providing an interface to the IP protocol Demultiplexing multiple processes using the

ports

Does Not: Flow control Error control Retransmission upon receipt of a bad

segment

UDP Does and Does Not Do...

2/14/2011HCM City University of Technology 27

Page 26: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

An internetwork differs from a single network: different topologies, bandwidths, delays, packet sizes, and other parameters

TCP was specifically designed to provide a reliable end-to-end byte stream over an unreliable internetwork

TCP transport entity, either a library procedure, a user process, or part of the kernel

TCP breaks user data stream up into pieces not exceeding 64 KB (in practice, 1460 data bytes)

Introduction to TCP

2/14/2011HCM City University of Technology 31

Page 27: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Sender and receiver need to create connection end-points first, called sockets

Each socket is addressed by the host IP address (32 bits) and a port number (16 bits)

A TCP connection must be explicitly established between sockets

Port numbers < 1024 are reserved (well-known ports)

TCP connections are full-duplex and point-to-point

Push and urgent data

TCP Service Model

2/14/2011HCM City University of Technology 32

Page 28: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

A single daemon, called inetd (Internet daemon) in UNIX, attach itself to multiple ports

When first incoming connection, inetd forks off a new process and executes the appropriate daemon in it, letting that daemon handle the request

Inetd learns which ports it is to use from a configuration file

The system administrator can set up the system to have permanent daemons

TCP Daemons

2/14/2011HCM City University of Technology 33

Page 29: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The sending and receiving TCP entities exchange data in the form of segments

Two limits restrict the segment size: 65,515-byte IP payload Maximum transfer unit (MTU): 1500 bytes

Basic protocol used by TCP entities is the sliding window

Segments can arrive out of order, delayed, timed out

Each byte in the stream has its own unique offset

TCP Segment

2/14/2011HCM City University of Technology 34

Page 30: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

The TCP Segment Header

2/14/2011HCM City University of Technology 35

Page 31: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Source port and Destination port: identify the local end points of the connection

Sequence number: every byte of data is numbered in a TCP stream

Acknowledgement number: specifies the next byte expected

TCP header length: tells how many 32-bit words are contained in the TCP header

URG bit: is set to 1 if the Urgent pointer is in use ACK bit: is set to 1 to indicate that the Acknowledgement

number is valid PSH bit: indicates PUSHed data

Explanation

2/14/2011HCM City University of Technology 36

Page 32: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

RST bit: is used to reset a connection SYN bit: is used to establish connections FIN bit: is used to release a connection Window size: field tells how many bytes

may be sent starting at the byte acknowledged

Checksum field: checksums the header, the data, and the conceptual pseudoheader

Options: provides a way to add extra facilities

Explanation (cont')

2/14/2011HCM City University of Technology 37

Page 33: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

(a) TCP connection establishment in the normal case.

(b) Call collision.

TCP Connection Establishment

2/14/2011 38HCM City University of Technology

Page 34: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Each simplex connection is released independently

Either party can send a TCP segment with the FIN bit set

To avoid the two-army problem, timers are used

If a response to a FIN is not forthcoming within two maximum packet lifetimes, the sender of the FIN releases the connection

TCP Connection Release

2/14/2011HCM City University of Technology 39

Page 35: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

TCP Connection Management Modeling

2/14/2011HCM City University of Technology 40

Page 36: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Window Management in TCP

2/14/2011HCM City University of Technology 41

Page 37: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Client operations Identify server IP and port Create UDP socket Send/receive data to server Close socket

Server operations Create socket and register with the system Read client messages and respond to client

Client-Server Application with UDP (1)

2/14/2011HCM City University of Technology 44

Page 38: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Client-Server Application with UDP (2)

2/14/2011HCM City University of Technology 45

Page 39: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Client operations Identify server IP and port Create UDP socket Setup connection to server Send/receive data Close connection

Client-Server Application with TCP (1)

2/14/2011HCM City University of Technology 46

Page 40: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Server operations Create and register socket Listen and wait for incoming connections Accept connection Send/receive data Close connection

Client-Server Application with TCP (2)

2/14/2011HCM City University of Technology 47

Page 41: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Concurrent server operations Create and register socket Listen and wait for incoming connections Accept connection and spawn new thread to

handle the connection Listen and wait for new connection Thread operations

Send/receive data through connection Close connection

Client-Server Application with TCP (3)

2/14/2011HCM City University of Technology 48

Page 42: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Client-Server Application with TCP (4)

2/14/2011HCM City University of Technology 49

Page 43: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

InetAddress ServerSocket Socket URL URLConnection DatagramSocket

Java API: java.net package

2/14/2011HCM City University of Technology 50

Page 44: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Class used for internet addresses (Internet Protocol)

Use methods: getLocalHost, getByName, or getAllByName to create an InetAddress instance:

public static InetAddess InetAddress.getByName(String hostname)

public static InetAddess [] InetAddress.getAllByName(String hostname)

public static InetAddess InetAddress.getLocalHost() To get the host IP address or host name:

getHostAddress() getHostName()

InetAddress class

2/14/2011HCM City University of Technology 51

Page 45: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

To describe a socket To create a socket

Socket(InetAddress address, int port) Socket(String host, int port) Socket(InetAddress address, int port,

InetAddress, localAddr, int localPort) Socket(String host, int port, InetAddress,

localAddr, int localPort) Socket()

Socket Class (1)

2/14/2011HCM City University of Technology 52

Page 46: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Get socket information InetAddress getInetAddress() int getPort() InetAddress getLocalAddress() int getLocalPort()

Using output and input Streams public OutputStream getOutputStream() throws IOException

public InputStream getInputStream() throws IOException

Socket Class (2)

2/14/2011HCM City University of Technology 53

Page 47: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Used for a server side socket Create a ServerSocket

ServerSocket(int port) throws IOException ServerSocket(int port, int backlog) throws IOException

ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException

ServerSocket Class (1)

2/14/2011HCM City University of Technology 54

Page 48: Lectured by: Nguyễn Lê Duy Lai 2/14/2011HCM City University of Technology1

Socket accept() throws IOException. void close() throws IOException InetAddress getInetAddress() int getLocalPort() void setSoTimeout(int timeout) throws SocketException

ServerSocket Class (2)

2/14/2011HCM City University of Technology 55