UDP: User Datagram Protocol RFC 768 [Postel 1980]: about three - - PDF document

udp user datagram protocol
SMART_READER_LITE
LIVE PREVIEW

UDP: User Datagram Protocol RFC 768 [Postel 1980]: about three - - PDF document

UDP: User Datagram Protocol RFC 768 [Postel 1980]: about three pages. Networking 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


slide-1
SLIDE 1

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

IP header UDP header UDP data

UDP datagram IP datagram

UDP - checksum

32-bit source IP address 32-bit destination IP address zero

8-bit protocol(17)

16-bit UDP length

16-bit source port number 16-bit destination port number

16-bit UDP length 16-bit UDP checksum data

pseudo header* header

(*) not transmitted, only used for checksum calculations

UDP fragmentation

20 bytes 8 bytes

UDP data (1473 bytes) IP header UDP header

IP datagram

1472 bytes IP header UDP header

20 bytes 8 bytes

packet

IP header

1 byte 20 bytes

packet

IP: Internet Protocol

4-bit version 4-bit header length 8-bit type of service (TOS) 16-bit total length (in bytes) 16-bit identification 3-bit flags 13-bit fragment offset 8-bit time to live (TTL) 8-bit protocol 16-bit header checksum 32-bit source IP address 32-bit destination IP address

  • ptions (if any)

data

20 bytes IP Datagram

slide-2
SLIDE 2

2

TFTP

Trivial File Transfer protocol

  • uses UDP as its transport mechanism
  • mainly used to bootstrap diskless systems
  • RFC 1350[Sollins 1992] is the official

spec.

– RFC 2347, 2348, 2349 specify newer extensions.

  • lock-step protocol

format

IP header UDP header TFTP message

  • pcode

(2 bytes) 01 02 03 05 04 filename mode

block #

data 0 to 512 bytes

block # error #

null terminated string

  • ctet: binary/raw

ascii: convert nl to cr/nl read write data ack error

2 bytes null terminated message

the protocol

some-file 01

  • ctet

read request

client server

03 data 01 data 04 01 ack 03 data 02 03

< block size

nn 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 and

retransmission implemented on the sender side.

  • has no checksum / data integrity check

– handled by the UDP layer

  • has no security

why are protocols so difficult?

RRQ data 1 ACK 1 data 2 ACK 1

time out

data 2 ACK 2 ACK 2 data 3 data 3

The sorcerer's apprentice syndrome time out

  • ignore duplicate ACKs

the Fix

slide-3
SLIDE 3

3

tftp extensions

IP header UDP header TFTP message

  • pcode

(2 bytes) 1=RRQ 2=WRQ filename mode

  • ption1 0 value1

0 option2 0 value2 6=OACK

  • ption1 0 value1

0 option2 0 value2 4=ACK

DNS The 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 com edu

  • rg

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 one

administrator.

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 variable length fields

slide-4
SLIDE 4

4

  • identification: set by the client and

returned by the server.

  • flags:

format ...

QR opcode AA TC RD RA MBZ rcode 4 4 3

DNS - Summary

  • essential when host is connected to the

internet.

  • hierarchical tree that forms the DNS name

space.

  • all DNS queries and responses have the

same 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-peer communication. – 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.

slide-5
SLIDE 5

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-

  • riented

concurrent connectionless concurrent connection-

  • riented

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 with each 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, the segment 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 times

  • ut and retransmits
slide-6
SLIDE 6

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 as it has buffer for.

TCP encapsulation

IP header TCP header TCP data

TCP segment IP datagram

TCP Header

16-bit source port number 16-bit destination port number 32-bit sequence number 32-bit acknowledgment number 4-bit header length 6-bit flags 16-bit window size 16-bit TCP checksum 16-bit urgent pointer

  • ptions (if any)

data (if any) 20 bytes max 60 bytes

TCP Header ...

  • each segment contains a source and

destination port number.

  • together with the source and destination

IP number from the IP header we get an unique 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

SYN

Synchronous sequence number to init connection

FIN

the sender has finished sending data

connection establishment

  • 1. the client dials a #
  • 2. the server answers, Hello?
  • 3. who's calling?
slide-7
SLIDE 7

7 Connection Establishment the three way handshake

1. the client sends a SYN segment specifying the port # of the server it wants to connect to, and its ISN - Initial Sequence Number 2. the server responds with its own SYN segment containing its ISN. The server also ACKs the client's SYN by ACKing the client's ISN+1 3. the client must ACK this SYN from the server by 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 4 microseconds - actually by 64,000 every 1/2 sec. –incremented on each connection 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 sent before an ack is received last byte successfully sent acknowledged sent but not acked

TCP - Interactive data flow

client server ack of data byte echo of data byte ack of echoed byte server keystroke d a t a b y t e echo display