Title: CSCI 5273 Computer Networks Stevens, Chapter 11
1CSCI 5273Computer NetworksStevens, Chapter 11
12UDP with supplemental informationon the
POSIX interfaceBroadcast Multicast
- Dirk GrunwaldAssoc. ProfessorDept. of Computer
ScienceUniversity of Colorado, Boulder
2Overview
- Basic UDP protocol
- IP Fragmentation reassembly
- Path MTU discovery
- ICMP Source Quench
- POSIX interface pragmatics
3UDP Protocol
IP Datagram
UDP Datagram
IPHeader
UDPHeader
UDPData
20 bytes
8 bytes
4UDP Header
16-bit Destination Port
16-bit Source Port
16-bit UDP Checksum (opt)
16-bit UDP Length
Data (if any)
5UDP Header
IPHeader
UDPHeader
UDPData
6UDP Checksum
IPHeader
UDPHeader
UDPData
IPPesudo-Header
7IP Pseudo-Header
32-bit Source IP address
32-bit Destination IP address
MBZ
Protocol
16-bit UDP Length
16-bit Destination Port
16-bit Source Port
16-bit UDP Checksum (opt)
16-bit UDP Length
Data (if any)
Possible odd byte
PAD
8UDP Checksum
- Checksum calculated like IP checksum, but use
pseudo-IP header to insure packet arrived at
proper host - If transmitted checksum field is zero, it means
sender didnt compute the checksum. - If the computed checksum would be zero, its
represented as 65535 - No packets with checksum errors are not reported
9IP Fragmentation
- When a router transits a packet that is too large
for the MTU of the outgoing link, the packet is
fragmented - Fragmented packets are not reassembled until they
reach their final destination - Fragments may also be fragmented
- Fragments are identified using the datagram
sequence - Typically, if any fragment is lost, a router will
discard all fragments. Routers usually only
discover fragment loss if they drop the fragment
themselves. - The endpoint assumes fragments are lost after
30-60 seconds
10Packets vs. Datagrams
- An IP datagram is the unit of end-to-end
transmission at the IP layer (before
fragmentation after reassembly) - A packet is the unit of data passed between the
IP layer and the link layer. - A packet can be a complete IP datagram or a
fragment
11IP Fragmentation
Payload
IP Header
Payload
IP Header
Payload
IP Header
More Fragementsis Set
Payload
IP Header
More Fragementsis NOT Set
12IP Fragmentation - Identifying Information
Payload
IP Header
Payload
IP Header
13IP Fragmentation
Payload
IP Header
Payload
IP Header
14IP Fragmentation Of Non-Final Fragments
Payload
IP Header
Payload
IP Header
Payload
IP Header
More Fragementsis Set
IP Header
Payload
Payload
IP Header
15IP Fragmentation Of Final Fragment
Payload
IP Header
Payload
IP Header
Payload
IP Header
Payload
IP Header
More Fragementsis Set
IP Header
More Fragementsis NOT Set
IP Header
16Dont Fragment
- Hosts must be able to receive packets of 576
bytes, which means a 512-byte datagram wont be
fragmented - One of the IPv4 header flags specifies that this
packet should be fragmented
16-bit Packet Identification
Fragment Offset
Reserved
Dont Fragment
MoreFragments
17ICMP Unreachable Error
- Attempting to fragment a fragment with dont
fragment set generates an ICMP error packet - ICMP type destination unreachable (type 3)
- code fragmentation required but dont fragment
set (code 4)
Type (3)
Code (4)
Checksum
MTU of next network hop
MBZ
IP Header (including options)and first 8 bytes
of original IP datagram data
18MTU Discovery UsingDont Fragment Packets
19ICMP Source Quench
- If a router / host discards datagrams due to
buffer overflows, it may send a ICMP source
quench message - I tried for 15 minutes to generate this on a slow
host was unable to do so - More likely to occur when e.g., routing to a
dialup, but even that failed. - Can be used by a protocol to slow down
transmission rate (e.g., TCP)
20UDP Pragmatics (review from code)
- UDP port and TCP ports are separate name spaces
- UDP port 80 doesnt mean the same thing as TCP
port 80 - UDP ports are unique to a specific interface
- port 80 on loopback is not the same as port 80 on
eth0 - Most POSIX/UNIX systems let you specify
wildcards - IPADDR_ANY is a special address (0.0.0.0) that is
a wild card interface address
21Using netstat to see ports
current-45 netstat -n -a Active Internet
connections (including servers) Proto Recv-Q
Send-Q Local Address Foreign Address
State tcp 0 0 128.138.202.9222
128.138.241.121813 ESTABLISHED tcp
0 0 0.0.0.06000 0.0.0.0
LISTEN tcp 0 0 0.0.0.022
0.0.0.0 LISTEN tcp
0 0 0.0.0.01024 0.0.0.0
LISTEN tcp 0 0 0.0.0.0758
0.0.0.0 LISTEN tcp
0 0 0.0.0.025 0.0.0.0
LISTEN tcp 0 0 0.0.0.0113
0.0.0.0 LISTEN tcp
0 0 0.0.0.079 0.0.0.0
LISTEN tcp 0 0 0.0.0.0512
0.0.0.0 LISTEN tcp
0 0 0.0.0.0513 0.0.0.0
LISTEN tcp 0 0 0.0.0.0514
0.0.0.0 LISTEN tcp
0 0 0.0.0.023 0.0.0.0
LISTEN tcp 0 0 0.0.0.021
0.0.0.0 LISTEN tcp
0 0 0.0.0.037 0.0.0.0
LISTEN tcp 0 0 0.0.0.013
0.0.0.0 LISTEN tcp
0 0 0.0.0.0111 0.0.0.0
LISTEN udp 0 0 0.0.0.08000
0.0.0.0 udp 0 0
0.0.0.0768 0.0.0.0 udp 0
0 0.0.0.0770 0.0.0.0 udp
0 0 0.0.0.0177 0.0.0.0
22Using netstat to see interfaces
current-45 netstat -n -a . udp 0
0 128.138.202.928000 0.0.0.0 udp 0
0 127.0.0.18000 0.0.0.0 udp
0 0 0.0.0.0769 0.0.0.0 udp
0 0 0.0.0.0768 0.0.0.0
23System Calls Used
- Socket
- Create an endpoint on the local system
- Bind
- Specify the local interface and port for the
endpoint - Connection
- Specify the remote interface and port for the
endpoint - setsockopt / getsockopt
- Modify various default properties
24Bound Connected Sockets
- Until bind is called, a socket is not bound
- Cant receive messages (havent specified port)
- When you send using an unbound socket, its
bound to an ephemeral port - Until connect is called, a socket is not
connected - Sending messages on an unconnected socket
requires that you specify the destination address
each time. - If you do call connect, you can only receive
messages on the connected socket from that the
specified remote endpoint
25POSIX socket interface
- send
- Send a message on a connected socket
- sendto
- Send a datagram to a specified IP address. The
socket can be unconnected. - recv
- Receive a datagram from a bound socket
- recvfrom
- Receive a datagram and record the source IP
address - recvmsg
- Essentially like recvfrom, but arguments packed
in a struct
26One Last POSIX call - select
- Select lets you wait on multiple file descriptors
to become available, or for a timeout to occur - include ltsys/time.hgt
- int select(
- int nfds,
- fd_set readfds,
- fd_set writefds,
- fd_set exceptfds,
- struct timeval timeout)
- Youll need this for next homework!
27Common UDP Server Pattern
socket
recvfrom
setsockopt
sendto
bind
28Common UDP Server Pattern
socket
sendto
setsockopt
recvfrom