CSE 331: Introduction to Networks and Security Slide Set 5 Fall 2000 Instructor: Carl A. Gunter
IPv4 Packet Format • IPv4 (Version field set to “4”) Version Hlen TOS Length Ident Flags Offset TTL Protocol Checksum SourceAddr DestinationAddr Options(variable length) Pad DATA
TCP and UDP packets • Protocols support O.S. “port numbers”: UDP TCP SrcPort DstPort SrcPort DstPort Checksum Length SequenceNum DATA Acknowledgment HL 0 Flags Advert.Wind. Checksum UrgPtr Options (variable) DATA
UDP packet format • IP enhancement for Demux and checksum 0 15 31 SrcPort DstPort Checksum Length DATA
UDP End-to-End Model • Multiplexing/Demultiplexing with Port number Application Application Application Application UDP Sender (Multiplexer) UDP Receiver (Demultiplexer)
Port Numbers • O.S. Independent way to specify sender and receiver applications • Limited to 16 bits, so <65536 (64K) • Question: per-host or per-IP address? • Usually UNIX does per-host • “Well-known” ports for certain services • Ports used for rendezvous
UDP also provides... • A simple checksum covering UDP header, data (message body), and pseudo-header (length, source IP, destination IP), using IP algorithm • Optional in IPv4, mandatory in IPv6 • No: flow control, reliability, ordering, etc. • Very little service enhancement over IP
TCP • Need reliable, ordered delivery of data • No duplicates • Data units called segments • Transmission Control Protocol • Connection-oriented (thus full-duplex) • Also provides flow and congestion control
TCP End-to-End Model • Buffering corrects errors but may introduce delays Application Application Application Application TCP Sender: Send Buffers TCP Receiver Receive Buffers segment segment segment segment
TCP Provides • Ordering using sequence numbers • Each byte has a sequence number • Risk of overflow increases • Reliability using: • acknowledgements • checksums • sequence numbers
Frame ACK Automatic Repeat Request Sender Receiver Timeout Time Timeout
Frame ACK ARQ Continued Sender Receiver Frame Timeout Time Timeout
Frame Frame ACK ARQ Continued Sender Receiver Timeout ACK Time Timeout
Frame Frame ACK ARQ Continued Sender Receiver Timeout Time ACK Timeout
Alternating Bit Protocol Sender Receiver Frame 0 Timeout ACK 0 Time Frame 1 Timeout ACK 1 Frame 0 Timeout ACK 0
Sliding Window Protocol Sender Receiver Time
SWP Endpoint States Send Window Size Sender Last Acknowledgement Received Last Frame Sent Receive Window Size Receiver Next Frame Expected Last Frame Acceptable
End-to-End Issues for TCP • New issues when link is not point to point • Setup required • Variable capabilities of connections • Packet Delay • Congestion control required • Compare: X.25 approach
Flags SYN FIN RESET PUSH URG ACK Fields 0 15 31 SrcPort DstPort SequenceNum Acknowledgment HL 0 Flags Advert.Wind. Checksum UrgPtr Options (variable) DATA Packet Format
TCP Receiver • Maintains a buffer from which application reads; advertises < buffer size as the window for sliding window • Responds with Acknowledge and AdvertisedWindow on each send; updates byte counts when data O.K. • Application blocked until read() O.K.
TCP Sender • Maintains a buffer; sending application is blocked until room in the buffer for its write • Holds data until acknowledged by receiver as successfully received • Implement window expansion and contraction; note difference between flow and congestion control
Flow vs. Congestion Control • Flow control protects the recipient from being overwhelmed. • Congestion control protects the network from being overwhelmed.
TCP Congestion Control • Additive Increase / Multiplicative Decrease • Slow Start • Fast Retransmit and Fast Recovery
Increase and Decrease • A value CongestionWindow is used to control the number of unacknowledged transmissions. • This value is increased linearly until timeouts for ACKs are missed. • When timeouts occur, CongestionWindow is decreased by half to reduce the pressure on the network quickly. • The strategy is called “additive increase / multiplicative decrease”.
Slow Start • Sending the entire window immediately could cause a traffic jam in the network. • Begin “slowly” by setting the congestion window to one packet. • When acknowledgements arrive, double the congestion window. • Continue until ACKs do not arrive or flow control dominates.
Retransmit and Recovery • Fast retransmit uses duplicate ACKs to anticipate dropped packets. • When an out-of-order packet arrives, the receiver sends the previous ACK a second time. • When the sender gets a repeat ACK three times, it anticipates that a packet was lost and retransmits. • Fast recovery exploits outstanding ACKs to avoid falling back into a full slow start after a timer expires.
Remote Procedure Call • Model of communication • support distributed programming • in fact tries to hide communication! • Interface between programming language and communications system • Adopts procedure-call interface • e.g., remote_foo(arg_1, arg_2);
RPC client and server • RPC client host must know how to reach server and what service is required • RPC server host must know who is requesting the service, what service is requested, and how to reply • Usually built over UDP; issues include argument marshalling, transport, binding, etc. Example: name resolution
Simple RPC Stack Dispatches request messages to the right process Synchronizes request and reply messages Fragments and reassembles large messages
The BSD “socket” API • Designed for UNIX, which had “pipes” • Socket provides a “handle” (descriptor) which can be used for system operations such as read() and write() • Other services must exist for rendezvous, synchronization, etc.
Making a Socket • int socket(int domain, int type, int protocol) • Domains: PF_INET, PF_UNIX • Types: SOCK_STREAM, SOCK_DGRAM • Example, TCP Socket: • socket(PF_INET, SOCK_STREAM, UNSPEC)
Passive Open /Active Connect • Server • int bind(int socket, struct sockaddr* address, int addr_len) • int listen(int socket,...) • int accept(int socket, struct sockaddr* address, ...) • Client • int connect(int socket, struct sockaddr* address, int addr_len)
Write and Read • int write(int socket, char* message, int msg_len) • int read(int socket, char* buffer, int buf_len)