“I’d tell you a UDP joke, but I’m not sure you’d get it”

TCP and UDP

  • Note: “datagram” is transport layer name for packet
  • TCP is part of the Transport Layer
    • TCP: Transport control protocol
    • Adds port #, sequence #, ack #, etc
    • Sockets: enable more than one connection per machine
    • Connections:
      • enables guarantees of order given delivery
      • almost guarantees delivery
  • Simpler alternative: UDP (User Datagram Protocol)
    • No retries, no acknowledgements, no ordering
    • It’s just a port number and a checksum
    • Less overhead; less resource-intensive due to no ACKs
    • Good for audio and video
  • UDP header (32 bits): source port, dest port, length, checksum
  • Checksum:
    • Break data into 16-bit integers
    • Add the integers, wrapping carries
    • Invert the result for easier bitwise comparison
  • TCP adds a number of features to provide
    • Ordering: data is broken up, transmitted, and reassembled in order
    • Acknowledgment
    • Pacing: transmission rate is modulated to reduce packet loss

Acknowledgment

  • Naive approach: wait for an ACK in response for every packet
    • Need a timeout to avoid deadlock
    • Can be orders of magnitude slower than without ACK
    • System is idle almost all of the time
  • Pipelining: allow multiple in-flight packets
    • Introduces need for buffering
    • Set a window size to limit buffering and regulate load
  • Simple pipeline strategy: “Go back N
    • Discard out-of-order packets and send ACK up to last in-order packet
    • Sender goes back to last in-order packet if not most recent
    • Sender goes back to last ACK if no ACK is received by timeout
    • Single delayed packet blocks entire pipeline
    • One packet near the beginning wastes everything after
  • Selective repeat pipeline strategy
    • Sender and receiver each maintain sliding windows
    • Sender must track timeout for each packet
      • Resends unacknowledged packets
    • Receiver drops OOO packets that are outside window
    • Sender advances window when lowest packet is ACK’ed
    • Receiver advances window when lowest packet is received
  • Sequence numbers wrap around, so they can have collisions
    • Avoid with window size less than half as large as the max sequence number