Project 4: Reliable Networking Slide heritage: Previous TAs - - PowerPoint PPT Presentation

project 4 reliable networking
SMART_READER_LITE
LIVE PREVIEW

Project 4: Reliable Networking Slide heritage: Previous TAs - - PowerPoint PPT Presentation

Project 4: Reliable Networking Slide heritage: Previous TAs Announcements Project 4 has been released I assume youve read the project description Due Friday, April 14th This is a pretty complex project Startearly!


slide-1
SLIDE 1

Project 4: Reliable Networking

Slide heritage: Previous TAs

slide-2
SLIDE 2

Announcements

  • Project 4 has been released
  • I assume you’ve read the project description
  • Due Friday, April 14th
  • This is a pretty complex project ⇨ Startearly!
slide-3
SLIDE 3

UDP TCP Internet Protocol Ethernet (or similar) Host OS UDP Stack network.h minimsg minisocket Transport Layer Network Layer Link Layer

Our network stack vs. the real world

TCP/IP Stack PortOS Network Stack

slide-4
SLIDE 4

Minisocket is a simplified TCP

  • Protocol is connection oriented

○ You must find a way to establish a connection between two endpoints

  • Data is sent as a continuous stream of bytes

○ Messages are an application level concept ○ Minisocket must maintain correct ordering

  • No limit on message sizes

○ You must fragment and reassemble the data

slide-5
SLIDE 5

State Machine

Listening Connecting Fail

connection failed minisocket_client_create minisocket_server_create

Connected

received connection connection accepted

Sending

message sent minisocket_send

Receiving

minisocket_receive message received either side calls minisocket_close

Closed

  • ther party

doesn’t reply Other party sends FIN

slide-6
SLIDE 6

Of course, it’s much more complicated...

TCP State Machine Source: Wikipedia/Cube00 License: CC BY-SA 3.0

slide-7
SLIDE 7

W h a t can go wrong?

  • Any party can die
  • Messages can get lost
  • Data might be reordered
  • Network might be partitioned

Welcome to the fun world of distributed systems!

slide-8
SLIDE 8

Connecting: Three-Way Handshake

Client Server

MSG_SYN MSG_SYNACK MSG_ACK Non-blocking protocol

  • Any packet might be lost
  • Will be resent up to seven times
  • Timeout doubles every time

Initial Timeout: 100ms * Give up after 12.7s

slide-9
SLIDE 9

Messages can get lost

Client Server

MSG_SYNACK MSG_ACK Lost MSG_SYN MSG_SYN

Timeout

slide-10
SLIDE 10

Messages can get lost

Client Server

MSG_SYN

Timeout

MSG_SYNACK MSG_ACK MSG_SYNACK Lost Note: In this case both parties might retransmit

slide-11
SLIDE 11

Messages can get lost

Client Server

MSG_ACK MSG_SYN

Timeout

MSG_SYNACK Lost MSG_ACK MSG_SYNACK

slide-12
SLIDE 12

Messages can get lost multiple times

Server

MSG_SYNACK MSG_ACK Lost Lost

Client

MSG_SYN

Timeout

MSG_SYN MSG_SYN

Timeout

slide-13
SLIDE 13

Sending Data: SEQ and ACK Numbers

Sender Receiver

MSG_ACK with ack_number=34 MSG_ACK with seq_number=34 and“hodor” seq_number represents how many packets have been sent ⇨ is used to order messages ack_number shows total received packets ⇨ is used to resend lost messages Note: This is a symmetric channel. Both parties can send and receive.

slide-14
SLIDE 14

Again, messages can get lost

Sender Receiver

seq_number=34 with“hodor” Lost ack_number=34

Timeout

seq_number=34 with“hodor”

slide-15
SLIDE 15

Again, messages can get lost

Sender Receiver

seq_number=34 with“hodor” ack_number=34

Timeout

Lost seq_number=34 with“hodor” ack_number=34

slide-16
SLIDE 16

Either side can send and receive!

Participant 1 Participant 2

seq=34,ack=12 with“hodor” seq=12,ack=34 seq=13,ack=34 with“arya” seq=34,ack=13

slide-17
SLIDE 17

Closing connections

Client Server

MSG_FIN MSG_ACK Again, this is a symmetric protocol. Both sides can close the connection.

slide-18
SLIDE 18

Minisocket Header

Bytes 1 2 3 4 5 6 7 8 16 24

source_port destination_port source_address protocol destination_address

type

seq_number ack_number

The first 21 bytes are identical to minimsg_header! Use protocol field to multiplex protocols.

slide-19
SLIDE 19

Tricky Part: How to implement timeout?

Remember that:

  • Parties might never respond
  • Multiple threads can call minisocket_receive() on the sameport
  • At most one thread can call minisocket_send() on a port

Things you must avoid:

  • Putting threads on the run queue more thanonce
  • Thread keeps waiting after message is received
  • Thread blocks infinitely
slide-20
SLIDE 20

Tricky Part: How to implement timeout?

Waiting Setup alarm & Put thread on wait queue for port Alarm Fires Remove thread from port’s wait queue & wake up thread Deregister alarm & wake up thread ACK received

slide-21
SLIDE 21

To make it a little easier

  • You don’t have to implement congestion control
  • Sending one packet at a time issufficient
  • minimsg_send can block until corresponding ACK is received

But you can implement window sizes > 1 if you want to! (and have the time…)

slide-22
SLIDE 22

Where to start

  • Think about the state machine fromearlier!
  • Try to make connection setup and termination workfirst.
  • Test with no loss and single-thread access
slide-23
SLIDE 23

Test all the code!

  • What happens if you send very largemessages?
  • Can you handle a lot of messages?
  • What if there isloss?
  • If one party crashes the other oneshouldn’t.
  • What if multiple threads are sending/receiving from the sameport?
slide-24
SLIDE 24

Test all the code!

In network.c: double loss_rate = 0.0; double duplication_rate = 0.0; bool synthetic_network = false;

These change the behavior of the network You have to set this to true for the other values to have any effect!

slide-25
SLIDE 25

Updating your project

Your project has been merged with the latest

  • code. Make sure everything compiles and

nothing is missing New files: minisocket, conn-network[1-3]

slide-26
SLIDE 26

Good Luck

As always, if you need help, come to office hours

  • r post your questions on Piazza!

Questions?