8. transport layer - Wellesley...

7
1 CS242 Computer Networks Department of Computer Science Wellesley College The transport layer An introduction to process to process communication Transport layer 8-2 Transport-layer services o Provides for logical communication* between application processes running on different hosts. o Transport-layer protocols are implemented in the end systems, not in the network routers. *By logical communication we mean that from an applications perspective, it is as if the hosts directly connected. Transport layer 8-3 In other words, o We are now working on the other side of the socket. o Questions on this side include o How does UDP find the right socket? o How does TCP make it appear to the application- layer that there is a direct virtual pipe from client and server sockets? o And how does it keep all those pipes straight? Transport layer 8-4 Transport layer runs on top of network layer o Transport-layer protocols provide logical communication between processes. o Network-layer protocols provides provide logical communication between hosts.

Transcript of 8. transport layer - Wellesley...

1

CS242 Computer Networks Department of Computer Science Wellesley College

The transport layer An introduction to process to

process communication

Transport layer 8-2

Transport-layer services o  Provides for logical

communication* between application processes running on different hosts.

o  Transport-layer protocols are implemented in the end systems, not in the network routers.

*By logical communication we mean that from an application’s perspective, it is as if the hosts directly connected.

Transport layer 8-3

In other words, o  We are now working on

the other side of the socket.

o  Questions on this side include

o  How does UDP find the right socket?

o  How does TCP make it appear to the application-layer that there is a direct virtual pipe from client and server sockets?

o  And how does it keep all those pipes straight?

Transport layer 8-4

Transport layer runs on top of network layer

o  Transport-layer protocols provide logical communication between processes.

o  Network-layer protocols provides provide logical communication between hosts.

2

Transport layer 8-5

Transport layer versus network layers

Application Letters in messages envelopes Processes People Hosts Houses Transport- Randy & layer protocol Marla Network- Postal layer protocol service

Transport layer 8-6

There are some important differences o  A network-layer protocol

may not guarantee delivery of the mail.

o  Even if the mail is delivered, it may come out of order or even damaged.

o  Marla or I may decide to do something about this (for example, resend lost letter), or we may not.

Transport layer 8-7

Internet protocol (IP) o  Logical connection

between hosts (the Internet’s network-layer service) is provided by IP.

o  The IP service model is best-effort delivery, but it makes no guarantees.

o  Packets may not arrive on time, may arrive out of order, damaged, or not at all.

The vacuous transport protocol o  Question: What's the

least we get can away with at the transport layer.

o  Answer: Do nothing, we simply pass messages from the application process directly to the network layer.

o  On the receiving side, we haul back whatever appears on our doorstep.

Transport layer 8-8

3

Transport layer 8-9

The problem with doing nothing o  Properly addressed, the

network protocol can get the message to the right host, ...

o  ... but we still need to get it to the proper process.

o  For example, suppose a segment containing mail arrives while the host is running STMP, FTP, DNP, and HTTP. How does the message find the proper process?

Sockets* o  Each process has a socket

through which data passes from the process to the network and back.

o  The transport layer in the receiving host does not deliver data directly to a process, but to a socket.

Transport layer 8-10 *Again

Transport layer 8-11

Sorting and gathering o  The task of gathering data chunks from different sockets,

packaging each chunk with header information, and passing it to the network is called multiplexing.

o  The task of unpacking and delivering the data to the correct socket is called demultiplexing.

Transport layer 8-12

Source and destination ports o  A socket is identified with

its port number.* o  Application data are

encapsulated into segments which are addressed to the socket they are to be delivered.

source port # dest port #

32 bits

application data

(message)

other header fields

*Port numbers range from 0 to 65535 with 0 to 1023 reserved for well-known applications.

4

UDP connectionless multiplexing o  A Python program creates a UDP

socket using either clientSocket = socket(AF_INET, SOCK_DGRAM) or serverSocket = socket(AF_INET, SOCK_DGRAM) serverSocket.bind(‘’, 12000)

o  Typically, the client side of the application lets the transport layer pick its port number, while the server side application assigns a specific port number.**

Transport layer 8-13 *Why?

Transport layer 8-14

Identifying a UDP socket from the other side

o  A UDP socket is fully identified by a two-tuple consisting of a destination IP address and a destination port number.

o  So why include a source port number?

Host A/UDP 19157 sends chunk to

host B/UDP 46428

Transport layer delivers segment

Host B/UDP 46428 responds by sending

segment to host A/UDP 19157

Important: This scheme works precisely because

UDP is connectionless

Transport layer 8-15

TCP connection-oriented multiplexing* o  A TCP server application establishes a “welcoming socket” and waits for a connection.

o  The TCP client generates a connection-establishment segment using serverName = ‘serverName’ serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect(serverName, serverPort)

o  When the server receives connection-request, it informs the server process, which creates a connection socket. connectionSocket, addr =

serverSocket.accept() *Things get a little more complicated. Transport layer 8-16

How does TCP keep all those connections straight?

source port # dest port #

Data

source IP dest. IP:

Headers

o  For starters, a TCP socket is identified by a 4-tuple:

o  Source IP; o  Source port number; o  Destination IP; o  Destination port number.

o  In particular, arriving TCP segments with different source IP addresses or source port numbers may go to different sockets.

5

Transport layer 8-17

Multiple virtual connections

Three segments are sent with

identical destination IPs

and port numbers ...

Transport layer 8-18

Multiple virtual connections

Web servers typically spawn either 1) a new process, or 2) a new thread for each new client connection. Preferences ...

Internet protocols: Two extremes o  The remainder of this

lecture is devoted to UDP.*

o  We'll need a bit more preparation to discuss TCP, starting with principles of reliable data transfer.

o  That's up next

Transport layer 8-19 *Frankly, there's not a whole lot more to say.

Transport layer 8-20

UDP does as little as possible o  Aside from multiplexing

and demultiplexing and some light error checking, UDP adds nothing to IP.

o  So why use it? o  No connection

establishment. o  No connection state. o  Small packet header

overhead. o  Finer application-level

control over what data is sent.

6

Transport layer 8-21

UDP is often the protocol of choice

*Actually, these days both UDP and TCP are used with multimedia applications.

* *

Transport layer 8-22

For example, DNS . . . o  DNS queries a name

server then waits for a reply.

o  If none within a given time, DNS either queries another name server or informs the invoking application of no reply.

o  Choice of DNS results in a considerable savings in RRTs.*

*As you calculated in ps2.

Transport layer 8-23

UDP segment structure

source port # dest port #

32 bits

Application data

(message)

UDP segment format

length checksum Length, in

bytes of UDP

segment, including

header

1’s complement of the sum of 16 bits in segment.

UDP segment goes into addressed envelope

Transport layer 8-24

from socket import * serverName = 'hostname' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) message = raw_input('Input lowercase sentence:') clientSocket.sendto(message,(serverName, serverPort))

Drop UDP segment into

Network Layer datagram

149.60.183.23

7

UDP checksum

1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1

wraparound

sum checksum

1.  Add the bits of all 16 bit words in segment (wrapping the overflow bit (if any).

2.  Take the one's complement of the result.

1.  Add bits of all 16 bit words in received segment (wrapping if necessary).

2.  Add result to checksum and compare with 1111111111111111.

Sending End:

Receiving End:

Transport layer 8-25