Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC 3407: Operating Systems Lecture 21: Network Protocols.

Similar presentations


Presentation on theme: "COSC 3407: Operating Systems Lecture 21: Network Protocols."— Presentation transcript:

1 COSC 3407: Operating Systems Lecture 21: Network Protocols

2 Network Protocols u Protocol: agreement between two parties as to how information is to be transmitted. u Example: system calls are the protocol between the operating system and applications NFS WWWE-mail ssh RPC TCP UDP IP Packet radio ATM Ethernet Physical/Link Layer Network Layer Transport Layer

3 Network Protocols u Networking examples: many levels – Physical level: mechanical and electrical network (e.g. how are 0 and 1 represented) – Link level: packet formats/error control (for instance, the CSMA/CD protocol) – Network level: network routing, addressing – Transport Level: reliable message delivery u Layering – build complex services from simpler services

4 Protocols u Our goal in the following is to show how to construct a secure, ordered, message service routed to anywhere Physical Reality: packetsAbstraction: messages Limited sizeArbitrary size Unordered (sometimes)Ordered UnreliableReliable Machine-to-machineProcess-to-process Only on local area netRouted anywhere AsynchronousSynchronous InsecureSecure

5 Basic Networking Limitations u The physical/link layer is pretty limited – Packets are of limited size (called the “Maximum Transfer Unit or MTU: often 200-1500 bytes in size) – Routing is limited to within a physical link (wire) or perhaps through a switch – Packets can get lost or garbled – Physical routers crash/links get damaged u Datagram: an independent, self-contained network message whose arrival, arrival time, and content are not guaranteed u Need resilient routing algorithms to send messages on wide area – Multi-hop routing mechanisms – Redundant links/Ability to route around failed links

6 Arbitrary size messages u Arbitrary size messages on top of limited size ones u Send N little messages – split up message into fixed size packets – abcdefgh -> 1 of 3/abc 2 of 3/def 3 of 3/gh u Checksum can be computed on each fragment, or on whole message

7 IP – Internet Protocol u Deliver messages unreliably (“Best effort”) from one machine in internet to another. a. Routes packets from one machine through internet to another b. Some intermediate links may have limited size. – Fragments on demand, re-assembles at destination c. Unreliable, unordered, machine->machine u Includes 256 different “sub-protocols” built on top of IP – Examples: ICMP(1), TCP(6), UDP (17), IPSEC(50,51)

8 IP Packet Format 16-bit identification ToS4 13-bit frag off Total length(16-bits) protocolTTL16-bit header checksum 32-bit source IP address 32-bit destination IP address IHL flags options (if any) Data 0151631 IP Ver4 IP Header Length Size of datagram (header+data) Flags & Fragmentation to split large messages Time to Live (hops) Type of transport protocol IP header 20 bytes

9 Process-process communication u User process communication on top of machine to machine communication u What we really want is routing from process  process – Example: ssh, email, ftp, web browsing u Mailbox (or “port”) address – include in each message, the destination mailbox. u Allows you to direct each message to correct process u A “port” is a 16-bit identifier used in addition to IP address – A communication channel (connection) defined by 4 items: [source address, source port, dest address, dest port]

10 UDP – Unreliable Datagram Protocol u Unreliable, unordered, user-to-user communication u Built on top of IP (IP Protocol 17) u Important aspect: low overhead! – Often used for high-bandwidth video streams UDP Data 16-bit UDP length16-bit UDP checksum 16-bit source port 16-bit destination port IP Header (20 bytes)

11 Ordered messages u Ordered messages on top of unordered ones u IP can re-order packets – send A, B arrives: B, A u How do we fix this? Assign sequence numbers to successive packets – – 0, 1, 2, 3,... u If arrive out of order, don’t deliver #3 to user application until get #2. u Sequence numbers specific to a connection – for example, the machine-machine (or mailbox-mailbox) pair. u This means put “source” as well as “destination” in each header.

12 Performance considerations u Overhead – CPU time to put packet on wire u Latency – how long before first bit of packet arrives at receiver – Raw transfer time + overhead at each routing hop u Throughput – maximum bytes per second – Depends on “wire speed”, but also limited by slowest router (routing delay) or by congestion at routers u Contributions to Latency – Wire latency: depends on speed of light on wire » about 1.5 ns/foot – Router latency: depends on internals of router » Could be < 1 ms (for a good router) » Question: can router handle full wire throughput?

13 Example u How long to send 4KB packet over various networks? Typical overhead to send a packet: 1 ms. u Ethernet (10 – 10,000Mb/s) within Parker: – Latency: speed of light = 1.5 ns / foot, implies < 1 microsecond (if no routers in path). – Throughput delay: packet doesn’t arrive until all its bits get there! So 4KB/10 Mb/s = 3 milliseconds (roughly as long as a disk!) u ATM (155 Mb/s) within Parker: – Latency same. – Throughput delay: 4KB/ 155 Mb/s = 200 microseconds. u ATM cross-country? – Latency: 3000 miles * 5000 ft/mile => 15 milliseconds. – Throughput delay: same as above. u How many bits are in transit at the same time? – 15 ms * 155 Mb/s => 280 KB u Key to good performance: in local area, minimize overhead, improve bandwidth. In wide area, keep pipeline full.

14 Reliable message delivery u Reliable message delivery on top of unreliable delivery u All of these networks can garble, drop messages. 1. Physical media – if transmit close to maximum rate, get more throughput, even if some messages get lost 2. Congestion – what if no place to put incoming message (no buffer space)? – Point-to-point network: no space at each switch/router – Broadcast network: two hosts try to use same link? – In any network: no buffer space at destination – Rate mismatch: what if sender sends faster than receiver can process?

15 Reliable message delivery 1. Detect garbling at receiver via checksum, discard if incorrect 2. Receiver ack’s if received properly 3. Timeout at sender. If no ack, retransmit

16 Reliable message delivery u Some questions: u If the sender doesn’t get an ack, does that mean the receiver didn’t get the original message? – No. u What if ack gets dropped? Or if message gets delayed. – Sender doesn’t get ack; retransmits. Receiver gets message twice, ack’s each. u Solution: put sequence number in message to identify re- transmitted packets. Receiver checks for duplicate sequence #’s. If so, discards. 1. Sender must keep copy of every message that has not been ack’ed yet (easy) 2. Receiver must keep track of every message that could be a duplicate (hard! How does receiver know when it’s ok to forget about received messages?)

17 Reliable message delivery u Several approaches to maintaining state at sender/receiver: a. Alternating bit protocol. One bit sequence number. – Send one message at a time; – don’t send next message until ack received. – Sender only keeps copy of last message; – receiver keeps track of sequence # of last message received. u Pros: – Simple, Small overhead u Cons – Poor performance » Wire can hold multiple messages; want to fill up at (wire latency  throughput) – doesn’t work if network can delay or duplicate messages arbitrarily A B msg,#0 ack,#0 msg,#0 msg,#1 ack,#1 ack,#0

18 Reliable message delivery b. Window-based protocol (TCP). – Send up to N messages at a time, without waiting for ack. – “Window” reflects storage at receiver – sender shouldn’t overrun receiver’s buffer space. – Each message has sequence number. – Receiver can say, “I’ve ack’ed up to message #X -> any message below X is a duplicate. A B msg,#0 ack,#0

19 Reliable message delivery u Acks serve dual purpose: – Reliability: Confirming packet received – Flow Control: Receiver ready for packet » Remaining space in queue at receiver can be returned with ACK u What if message gets garbled/dropped? Receiver will get messages out of order! – Discard any messages that arrive out of order? » Simple, worse performance – Keep copy until sender fills in the missing piece? » Reduces # of retransmits, more complex u What if ack gets dropped? – Timeout and resend just the un-acknowledged message.

20 TCP: transmission control protocol u Reliable byte stream between two processes on different machines over Internet (read, write, flush). u Fragments byte stream into packets, hands packets to IP. u Uses window-based protocol (to minimize state at sender and receiver): send up to N messages at a time, without waiting for ack. u “Window” reflects storage at receiver – sender shouldn’t overrun receiver’s buffer space. u Sender has three regions: sent and ack’ed, sent and not ack’ed, not yet sent

21 TCP: transmission control protocol u Receiver has three regions: received and ack’ed (given to application), received and buffered, not yet received (or received and discarded because out of order) u Each ack says: “got all messages up to #”. What happens if ack is delayed, arrives out of order? OK in this scheme. Just discard. Sequence numbers Sender messages Sent, ack’ed Sent, not ack’ed Not yet sent receiver messages Received, given to app Received, buffered Not yet received

22 Arbitrary Size Messages (revisited) u Face similar issues as in TCP when building big messages on small ones, when messages can get dropped. 1. Ack each fragment? Lots of acks 2. One ack for entire big message? Re-transmit all fragments, even if only one gets dropped 3. “Blast protocol” – send one ack, tells sender which pieces were missing. Selective retransmit.

23 Initialization u How do you know which sequence # to start with? – When machine boots, ok to start with #0? » No. Could send two separate messages with the same serial #! » 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 1. Time to live: each TCP packet has a deadline. If not delivered in X seconds, then dropped. – Thus, can re-use sequence numbers if wait for all packets in flight to be delivered or to expire. 2. Epoch # – uniquely identifies which set of sequence numbers are being used. – Put in every message, epoch # incremented on crash and/or when run out of sequence #’s, and stored on disk. 3. Pseudo-random increment to previous sequence number – Used by a number of implementations now

24 Congestion u How long should timeout be for re-sending messages? – Too long? Wastes time if message is dropped. – Too short? Retransmit even though ack will arrive shortly. u Stability problem: more congestion -> ack is delayed -> unnecessary timeout -> more traffic -> more congestion u TCP solution: “slow start”. Originally, window size = buffer space on remote end. u Now, window size = control on how much to add to congestion. u Start sending slowly. – If no timeout, slowly increase window size (throughput). – If a timeout occurs, it means there’s congestion, so cut window size (throughput) in half.

25 General’s Paradox u Can I use messages and retries over an unreliable network to synchronize two machines so that they are guaranteed to do some operation at the same time? u Remarkably, no, even if all messages get through. u General’s paradox: two generals, on separate mountains. – Can only communicate via messengers; the messengers can be captured. u Need to coordinate the attack – if they attack at different times, then they all die. – If they attack at the same time, they win.

26 General’s Paradox u Even if all messages are delivered, can’t coordinate! – Can’t simultaneously get two generals or two machines to agree to do something at the same time. u No solution to this – one of the few things in CS that’s just impossible. A B 11 am ok! Ok 11’s good for me So 11 it is? Yeah, but what if you don’t get this ack?...........

27 Two phase commit u Since we can’t solve the General’s Paradox (i.e., simultaneous action), let’s solve a related problem. u Abstraction: distributed transaction – two machines agree to do something, or not do it, atomically (but not necessarily at exactly the same time).

28 Two phase commit u Two phase commit protocol does this: – Use a persistent, stable log on each machine to keep track of whether commit has happened. » If a machine crashes, when it wakes up it first checks its log to see what state the world was in at the time of the crash. – Prepare Phase: » The global coordinator requests that all participants will promise to commit or rollback the transaction » Participants record promise in log, then acknowledge » If anyone votes to abort, coordinator writes “abort” in its log and tells everyone to abort; each records “abort” in log – Commit Phase: » After all participants respond that they are prepared, then the coordinator writes “commit” to its log » Then asks all nodes to commit; they respond with ack » After receive acks, coordinator writes “got commit” to log – Log can be used to complete this process such that all machines either commit or don’t commit

29 Two phase commit u First phase, ask if each can commit – for instance, transfer of funds from one bank to another. 1. A writes, “Begin transaction” to log 2. A -> B: OK to transfer funds to me? u Not enough cash: B-> A: transaction aborted A writes “Abort” to log u Enough cash: B: Write new X account balance to log B->A: OK, I can commit

30 Two phase commit u Second phase, A can decide for both, whether they will commit. 3. A: Write new Y account balance to log 4. Write commit to log 5. Send message to B that commit occurred 6. Write “Got commit” to log u What if: – B crashes at 1? Wakes up, does nothing. A will timeout, abort transaction, retry. – A crashes at 3? Wakes up, sees transaction in progress. What transaction, sends message to B, abort. – B crashes at 3? B will come back up, look at log, so that when A sends it “Commit” message, it will say, oh, ok, commit.

31 Two phase commit u One problem with 2PC is “Blocking”: That is, a site gets stuck in a situation where it cannot continue until some other site (usually the coordinator) recovers. u How could this happen? – Participant site B writes a “prepared to commit” record to its log, sends a “yes” vote to the coordinator (site A) and crashes. – Site A crashes – Site B wakes up, checks its log and realizes that it had voted “yes” on the update. » It sends a message to site A, asking what happened. » At this point, B cannot change its mind and decide to abort, because the update may have committed while it was crashed, thus it is blocked. » Note, B may be able to learn the fate of the update by asking some of the other participants.

32 Two phase commit u Blocking is problematic because a blocked site must hold resources (for example, locks on updated items, pages pinned in memory, etc.) until it learns the fate of the update. u Question: Can blocking be avoided? u Answer: yes! If you are willing to impose some constraints on the way that voting is done, an algorithm called “Three Phase Commit” can solve the problem. – 3PC is not generally used in practice, however, due to performance reasons and the low instance of blocking in practice.


Download ppt "COSC 3407: Operating Systems Lecture 21: Network Protocols."

Similar presentations


Ads by Google