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 CS162 Operating Systems and Systems Programming Lecture 23 Network Communication Abstractions Remote Procedure Call 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 November 21 2007 Prof John Kubiatowicz http inst eecs berkeley edu cs162 Use sequence numbers and reorder at destination Reliable messages Use Acknowledgements Want a window larger than 1 in order to increase throughput 11 21 07 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 Sent not acked Lec 23 2 Goals for Today Finish discussion of TCP Messages Send receive One vs two way communication Distributed Decision Making Two phase commit Byzantine Commit Sender has three regions Sent acked Kubiatowicz CS162 UCB Fall 2007 Not yet sent Remote Procedure Call Sender Window colored region adjusted by sender Receiver has three regions Received Given to app Received 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 Note Some slides and or pictures in the following are adapted from slides 2005 Silberschatz Galvin and Gagne Gagne Many slides generated from my lecture notes by Kubiatowicz 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 4 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 190 Retransmit A 340 60 Seq 340 A 380 20 Seq 380 11 21 07 Kubiatowicz CS162 UCB Fall 2007 A 400 0 Lec 23 5 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 Header 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 11 21 07 Not widely in use although in Windows since Windows 98 Kubiatowicz CS162 UCB Fall 2007 Lec 23 6 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 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 Ack Number 190 IP Header 20 bytes 140 Sequence Number Ack Number 100 Selective Acknowledgement Option SACK IP Header 20 bytes Window Based Acknowledgements TCP Pseudo random increment to previous sequence number 11 21 07 Used by several protocol implementations Kubiatowicz CS162 UCB Fall 2007 Lec 23 8 Use of TCP Sockets Socket an abstraction of a network I O queue Socket Setup Con t Embodies one side of a communication channel tion nnec o C uest Req 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 On server set up server socket 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 Example Java client Makes socket binds addr port calls connect Socket sock new Socket 169 229 60 38 6018 BufferedReader bin new BufferedReader new InputStreamReader sock getInputStream String line while line bin readLine null System out println line sock close 11 21 07 Kubiatowicz CS162 UCB Fall 2007 Lec 23 11 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 Distributed Applications How do you actually program a distributed application Need to synchronize multiple threads running on different machines No shared memory so cannot use test set Network Receive pout println Here is data sent to client client close Client Send server Makes socket binds addr port calls listen ServerSocket sock new ServerSocket 6013 while true Socket client sock accept PrintWriter pout new PrintWriter client
View Full Document
Unlocking...