Download - UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

Transcript
Page 1: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

1

Networking

UDP: User Datagram Protocol• RFC 768 [Postel 1980]: about three

pages.

• provides no reliability– it sends the datagram to the IP layer, but

there is no guarantee that:• it will reach its destination

• it will reach unspoiled its destination

UDP encapsulation

IPheader

UDPheader

UDPdata

UDP datagram

IP datagram

UDP - checksum32-bit source IP address

32-bit destination IP address

zero 8-bitprotocol(17)

16-bit UDPlength

16-bit source portnumber

16-bitdestinationport number

16-bit UDP length16-bit UDPchecksum

data

pseudoheader*

header

(*) not transmitted, only used for checksum calculations

UDP fragmentation

20 bytes 8 bytes

UDP data (1473 bytes)IPheader

UDPheader

IP datagram

1472 bytesIPheader

UDPheader

20 bytes 8 bytes

packet

IPheader

1 byte20 bytes

packet

IP: Internet Protocol4-bit

version

4-bitheaderlength

8-bit type ofservice(TOS)

16-bit total length (in bytes)

16-bit identification 3-bitflags 13-bit fragment offset

8-bit time tolive

(TTL)8-bit protocol 16-bit header checksum

32-bit source IP address

32-bit destination IP address

options (if any)

data

20 bytes

IP Datagram

Page 2: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

2

TFTPTrivial File Transfer protocol

• uses UDP as its transport mechanism

• mainly used to bootstrap diskless systems

• RFC 1350[Sollins 1992] is the officialspec.– RFC 2347, 2348, 2349 specify newer

extensions.

• lock-step protocol

formatIP

headerUDP

header TFTP message

opcode(2 bytes)

01

02

03

05

04

filename 0 mode 0

block # data 0 to 512 bytes

block #

error #

null terminated string

octet: binary/rawascii: convert nl to cr/nl

readwrite

dataack

error

2 bytes

null terminated message

the protocol

some-file01 0 octet 0

readrequest

client server

03 data01data

04 01ack

03 data02

03 < block sizenn

04 nn

TFTP ...• is a stop and wait protocol

• each data-block has a block number

– used in the acknowledge response

• lost packets are detected with timeout andretransmission implemented on the sender side.

• has no checksum / data integrity check

– handled by the UDP layer

• has no security

why are protocols so difficult?

RRQdata 1

ACK 1data 2

ACK 1time out

data 2ACK 2

ACK 2data 3

data 3

The sorcerer's apprentice syndrometime out

•ignore duplicate ACKs

the Fix

Page 3: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

3

tftp extensions

IPheader

UDPheader TFTP message

opcode(2 bytes)1=RRQ2=WRQ filename 0 mode 0 option1 0 value1 0 option2 0 value2 0

6=OACK option1 0 value1 0 option2 0 value2 0

4=ACK 0

DNSThe Domain Name System

• Server

– manage a distributed data base

– process queries/requests

• Client:

– does queries

– uses the resolver library functions

• ie: gethostbyname(...), gethostbyaddr(...)

DNS basics

arpa comedu org il...

in-addr ac

huji

cse

.unnamed root

DNS Zones• a zone is a subtree of the DNS tree that is

administered separately.

• each zone needs at least one name-server.

• each zone needs at least oneadministrator.

Zones ...• Primary name server

– obtains its data locally

• Secondary name server– obtains its data from the primary

DNS Message Format

identification flags

# of questions # of answer RRs

# of authority RRs # of additional RRs

questions

answers

authority

additional information

0 15 16 31

12 bytes header

variablelengthfields

Page 4: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

4

•identification: set by the client andreturned by the server.

•flags:

format ...

QR opcode AA TC RD RA MBZ rcode4 43

DNS - Summary• essential when host is connected to the

internet.

• hierarchical tree that forms the DNS namespace.

• all DNS queries and responses have thesame message format.

#include <stdio.h>#include <syslog.h>#include <time.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>/* | daytime server - RFC 867 */main(int cc, char **vv){ struct sockaddr_in sin; char buf[BUFSIZ]; int sfd;

if((sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); exit(1);

} bzero(&sin, sizeof(struct sockaddr_in)); sin.sin_family = AF_INET; sin.sin_port = htons(13);

if(bind(sfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("bind"); exit(1);

}

while(1) { int len; time_t clock;

len = sizeof(sin); if(recvfrom(sfd, buf, 1, 0, (struct sockaddr *)&sin, &len)

< 0) { perror("recvfrom"); continue; } time(&clock); strcpy(buf, ctime(&clock)); if(sendto(sfd, buf, strlen(buf), 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("sendto"); }

}}

Clients & Servers• Client:

– in general, an application that initiates a peer-to-peercommunication.

– usually invoked by the 'end user'

• Server:

– waits for incoming requests from a client.

– performs necessary work and

– probably returns a result.

Concurrent Vs. Iterative• concurrent-server

– handles multiple requests at one time.

• iterative-server– process one request at a time.

Page 5: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

5

Connection [oriented|less]• connectionless:

– UDP - User Datagram Protocol

– the burden of the data integrity is on the application.

• connection-oriented:

– TCP - Transport Control Protocol

– the application is free to deal with higher things.

types of server/client

iterative

connectionless

iterative

connection-oriented

concurrent

connectionless

concurrent

connection-oriented

Server types• iterative, connectionless

– the most common

• usually stateless

• trivial amount of processing

• iterative, connection-oriented

– less common

• trivial amount of data but

• need relaible transport

server types ...• concurrent, connectionless

– very uncommon

• a process is created for each request

• tfptd is such a server

• concurrent, connection-oriented

– the most common

• reliable transport

• usually used by long living activities

TCP - Transmission Control Protocol

• connection oriented

– exactly two end points.

• no broadcast/multicast

– the two applications must establish a connection witheach other before data can be exchanged.

• reliable

• byte stream

– 8-bit bytes with no interpretation

– there is no record boundaries.

reliable• data is broken up into best size chunks

– the unit of information passed by TCP to IP is called a segment.

• each segment sent has a timer

– when the timer expires before an acknowledgment is received, thesegment is retransmitted.

• when data is received, an acknowledgment is sent

– but not immediately.

• the data and header have a checksum

– a segment with bad/invalid checksum is dropped, the sender timesout and retransmits

Page 6: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

6

reliable ...• preserves sequence

– IP datagrams can arrive out of order

– segments are resequenced if necessary

• drops duplicates

– since IP datagrams can get duplicated

• flow control

– each end of the connection has a finite amount of buffer space.

– the receiving side allows the other end to send as much data asit has buffer for.

TCP encapsulation

IPheader

TCPheader

TCPdata

TCP segment

IP datagram

TCP Header16-bit source port

number16-bit destination port

number

32-bit sequence number

32-bit acknowledgment number

4-bitheaderlength

6-bitflags

16-bit window size

16-bit TCP checksum 16-bit urgent pointer

options (if any)

data (if any)

20bytes

max60

bytes

TCP Header ...• each segment contains a source and

destination port number.

• together with the source and destinationIP number from the IP header we get anunique identification of each connection.

• socket: IP address + port number

• socket pair: source + destination sockets.

TCP Header ...

flags Description

URG the urgent pointer is valid

ACK the acknowledgment is valid

PSH the receiver should pass this data ASAP

RST Reset the connection

SYNSynchronous sequence number to initconnection

FIN the sender has finished sending data

connection establishment1. the client dials a #

2. the server answers, Hello?

3. who's calling?

Page 7: UDP: User Datagram Protocol Networking UDP encapsulation ... · –UDP - User Datagram Protocol –the burden of the data integrity is on the application. •connection-oriented:

7

Connection Establishmentthe three way handshake

1. the client sends a SYN segment specifying theport # of the server it wants to connect to, andits ISN - Initial Sequence Number

2. the server responds with its own SYN segmentcontaining its ISN. The server also ACKs theclient's SYN by ACKing the client's ISN+1

3. the client must ACK this SYN from the serverby ACKing the server's ISN+1.

segment 1 SYN - isn

segment 2

SYN - isn'

ack isn+1

segment 3 ack isn'+1

•isn: initial sequence number–incremented by 1 every 4microseconds - actually by64,000 every 1/2 sec.–incremented on eachconnection by 64,000

client server

Segments, Streams and Sequence numbers

data stream

ISN + 2 current window

ready to be sent

last byte that can be sentbefore an ack is received

last byte successfully sentacknowledged

sent but not acked

TCP - Interactive data flow

client server

ack of data byte

echo of data byte

ack of echoed byte

serverkeystroke data byte

echo

display