CS162 Operating Systems and Systems Programming Lecture 23 Network Communication Abstractions Remote Procedure Call November 21 2007 Prof John Kubiatowicz http inst eecs berkeley edu cs162 Review Reliable Networking Layering building complex services from simpler ones Datagram an independent self contained network message whose arrival arrival time and content are not guaranteed Performance metrics Overhead CPU time to put packet on wire Throughput Maximum number of bytes per second Latency time until first bit of packet arrives at receiver Arbitrary Sized messages Fragment into multiple packets reassemble at destination Ordered messages Use sequence numbers and reorder at destination Reliable messages Use Acknowledgements Want a window larger than 1 in order to increase throughput Kubiatowicz CS162 UCB Fall 2007 11 21 07 Lec 23 2 Review TCP Windows and Sequence Numbers TCP provides a stream abstraction Reliable byte stream between two processes on different machines over Internet read write flush Input is an unbounded stream of bytes Output is identical stream of bytes same order zyxwvuts Router Router gfedcba Sender has three regions Sent acked Sent not acked Not yet sent Sender Window colored region adjusted by sender Receiver has three regions Received Received Given to app Buffered Not yet received Receiver Maximum size of window advertised to sender at setup 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 3 Goals for Today Finish discussion of TCP Messages Send receive One vs two way communication Distributed Decision Making Two phase commit Byzantine Commit Remote Procedure Call Note Some slides and or pictures in the following are adapted from slides 2005 Silberschatz Galvin and 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 4 Gagne Many slides Gagne generated from my lecture notes Window Based Acknowledgements TCP 100 140 190 230 260 300 340 380 400 Seq 380 Size 20 Seq 340 Size 40 Seq 300 Size 40 Seq 260 Size 40 Seq 230 Size 30 Seq 190 Size 40 Seq 140 Size 50 Seq 100 Size 40 A 100 300 Seq 100 A 140 260 Seq 140 A 190 210 Seq 230 A 190 140 Seq 260 A 190 100 Seq 300 A 190 60 Seq 190Retransmit A 340 60 Seq 340 A 380 20 Seq 380 11 21 07 Kubiatowicz CS162 UCB Fall 2007 A 400 0 Lec 23 5 TCP Header Sequence Number Ack Number IP Header 20 bytes IP Header 20 bytes Sequence Number Ack Number Selective Acknowledgement Option SACK TCP Header Vanilla TCP Acknowledgement Every message encodes Sequence number and Ack Can include data for forward stream and or ack for reverse stream Selective Acknowledgement Acknowledgement information includes not just one number but rather ranges of received packets Must be specially negotiated at beginning of TCP setup Not widely in use although in Windows since Windows 98 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 6 Congestion Avoidance Congestion How long should timeout be for re sending messages Too long wastes time if message lost Too short retransmit even though ack will arrive shortly Stability problem more congestion ack is delayed unnecessary timeout more traffic more congestion Closely related to window size at sender too big means putting too much data into network How does the sender s window size get chosen Must be less than receiver s advertised buffer size Try to match the rate of sending packets with the rate that the slowest link can accommodate Sender uses an adaptive algorithm to decide size of N Goal fill network between sender and receiver Basic technique slowly increase size of window until acknowledgements start being delayed lost TCP solution slow start start sending slowly If no timeout slowly increase window size throughput by 1 for each ack received Timeout congestion so cut window size in half Additive Increase Multiplicative Decrease 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 7 Sequence Number Initialization How do you choose an initial sequence number When machine boots ok to start with sequence 0 No could send two messages with same sequence Receiver might end up discarding valid packets or duplicate ack from original transmission might hide lost packet Also if it is possible to predict sequence numbers might be possible for attacker to hijack TCP connection Some ways of choosing an initial sequence number Time to live each packet has a deadline If not delivered in X seconds then is dropped Thus can re use sequence numbers if wait for all packets in flight to be delivered or to expire Epoch uniquely identifies which set of sequence numbers are currently being used Epoch stored on disk Put in every message Epoch incremented on crash and or when run out of sequence Pseudo random increment to previous sequence number Used by several protocol implementations 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 8 Use of TCP Sockets Socket an abstraction of a network I O queue Embodies one side of a communication channel Same interface regardless of location of other end Could be local machine called UNIX socket or remote machine called network socket First introduced in 4 2 BSD UNIX big innovation at time Now most operating systems provide some notion of socket Using Sockets for Client Server C C interface On server set up server socket Create socket Bind to protocol TCP local address port Call listen tells server socket to accept incoming requests Perform multiple accept calls on socket to accept incoming connection request Each successful accept returns a new socket for a new connection can pass this off to handler thread On client Create socket Bind to protocol TCP remote address port Perform connect on socket to make connection If connect successful have socket connected to server 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 9 Socket Setup Con t ion t c e n n Co t s ue q e R socket connection Client Server Socket new socket socket Server Things to remember Connection requires 5 values Src Addr Src Port Dst Addr Dst Port Protocol Often Src Port randomly assigned Done by OS during client socket setup Dst Port often well known 80 web 443 secure web 25 sendmail etc Well known ports from 0 1023 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 10 Socket Example Java server Makes socket binds addr port calls listen ServerSocket sock new ServerSocket 6013 while true Socket client sock accept PrintWriter pout new PrintWriter client getOutputStream true pout println Here is data sent to client client close client Makes socket binds addr port calls connect Socket sock new Socket 169 229 60 38 6018 BufferedReader bin new
View Full Document
Unlocking...