CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

19

Click here to load reader

description

What is STCP? TCP lite –Simplified connection setup Two-way handshake –No piggybacking of data with acknowledgement packets –No congestion control –No slow-start, fast retransmissions, delayed ACKs, etc. Still provides reliable, connection-based, byte- oriented transport between two endpoints –Flow control (sliding sender/receiver window) –Go-back N –Retransmissions

Transcript of CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

Page 1: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

CS492B project #2tutorial

2003. 9. 17Jin Hyun Ju

## This material is from Stanford cs244A ##

Page 2: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

Assignment overview• Client/server (client.c,

server.c)– File download application

• “Mysocket” layer (mysock.c)– Replacement for socket API

(myopen, myread, etc.)• STCP (transport.c)

– Transport layer: You fill this in!

• Network layer (network.c)– Simulates random packet loss,

delay, duplication– network_send(),

network_recv()—datagram service used by STCP

client

mysocket

transport

network

server

mysocket

transport

network

Page 3: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

What is STCP?• TCP lite

– Simplified connection setup• Two-way handshake

– No piggybacking of data with acknowledgement packets– No congestion control– No slow-start, fast retransmissions, delayed ACKs, etc.

• Still provides reliable, connection-based, byte-oriented transport between two endpoints– Flow control (sliding sender/receiver window)– Go-back N– Retransmissions

Page 4: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP packets• Simplified version of TCP segments

– SYN packet: start a connection– ACK packet: acknowledge reception of data (next seq)

• No data payload permitted in STCP• SYN-ACK: passive side completes connection

– FIN packet: end a connection• FIN-ACK: passive side closed connection

– Data packet: Any packet without these flags set– SYN/data packets: sequence numbers– No advertised window

Page 5: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP model• Each side of connection: two processes

– Parent (application/mysocket layer)– Child (your STCP implementation/network layer)

• Why this model?– Simulates real O/S implementation

• User-level socket library interfaces to kernel functionality• Network data arrival is asynchronous

– STCP implementation can sleep until an “interesting” event happens

• Timeout, packet arrival, etc.

Page 6: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP model

transportimplementation

network

transportinterface

mysocket

client

transportimplementation

network

transportinterface

mysocket

serverParent

Child

Page 7: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

Function calls• one STCP connection

– socket() ~ close() in server and client• mysocket(), mybind()

– wrapper function• myconnect(), myaccept() -> transport_inite() • mywrite(), myread()

-> write(), read() -> control_loop()• myclose()

Page 8: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

transport initiationparent process

0 1 0 1syn_sd[]

data_sd[]bind()

connect() fork()

childprocess

comm_sd

Page 9: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP transport layer initiation

• transport_init() creates two socket pairs, forks; parent blocks until connected– In STCP, a SYN received from

peer by child• Parent/child communicate

via local sockets (a la pipe)– syn_sd[]—notify parent of

connection completion– data_sd[]—pass data between

app/transport layer

myconnect(), myaccept()

transport_init()

Parent (app)

Child (transport)

syn_sd[0] (syn pipe)data_sd[0] (data pipe)syn_sd[1]data_sd[1]

syn_sd[0]data_sd[0]syn_sd[1] (syn pipe)data_sd[1] (data pipe)comm_sd (peer socket)

fork

IPCDatapipe

Synpipe

Page 10: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP IPC details• Forking, IPC is provided already in transport.c

– You shouldn’t need to touch much of transport_init(), except to

• Add your SYN/SYN-ACK handling• Change/add the transport layer state setup as needed

– Sockets created in transport_init() (using localsocketpair()) before forking

• Descriptors valid in both parent/child processes• Syn_sd[] used only for connection setup• Data_sd[] used for all data sent between application and

transport layer• Only one of each socket is used in parent/child to

communicate, a la pipe/FIFO– transport_init() closes unneeded sockets in parent and child

Page 11: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP/application interaction• Connection establishment (myconnect,

myaccept)– Application blocks until SYN received

• STCP wakes up blocked parent process using “syn pipe”

• syn_sd is finished with at this point• Data read/write (myread, mywrite)

– Application reads from/writes to its end of the “data pipe” – STCP writes to/reads from its end of the “data pipe”

• Whenever data is available (from app or peer) and you have space in your window

• Just assume data written to application has been read

Page 12: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP main control loop

transportimplementation

network

transportinterface

mysocket

client

transportimplementation

network

transportinterface

mysocket

server

local_data_sd= data_sd[1]

comm_sd

local_data_sd= data_sd[1]

Page 13: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP main control loop• Main loop repeatedly waits for event on

application socket (local_data_sd), peer socket (comm_sd), timeout (in part B onwards)– Select to see which event happened

Page 14: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP/application interaction• Connection teardown (myclose)

– Application closes stream socket returned by transport_init()– Pay attention to delivery semantics in assignment handout

• Multiple connections– A unique child process is forked by transport_init(), so you

don’t have to worry about session demultiplexing

Page 15: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

Select• Online information

– man –s 3c select• Looks in section 3c of manual (C library)• Also useful: section 2 (system calls), 3socket (socket

calls)

Page 16: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

context_t ctx• global variable• you can add new variable• see struct tcpcb

Page 17: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP in reliable mode• Network layer is reliable• All packets delivered in sequence, no

losses• You implement connection

setup/teardown, acknowledgements, send/receive windows

• Client/server pair should be able to download files after you’ve finished this

Page 18: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

STCP in unreliable mode• Network layer becomes obnoxious

– Packets reordered, dropped, duplicated– See network_send() in network.c

• You must handle retransmissions, timeouts, Go-back N, buffering of data, …– Minimum RTT estimate is 20 ms– Five retransmissions of any segment– Careful about packets crossing ends of receive window

• Client, server pair should now work with –U flags• Your modified transport.c is the only file needed

(and accepted) for testing and the final submission

Page 19: CS492B project #2 tutorial 2003. 9. 17 Jin Hyun Ju ## This material is from Stanford cs244A ##

General comments• See TCP FSM diagram (R. Stevens)

– Keep track of SYN_SENT, SYN_WAITING, etc.– STCP state machine is simpler

• Network layer uses UDP datagrams– Treat it like an IP implementation– Packet-oriented rather than byte-oriented service– Be sure to read the maximum length datagram!

• Unread bytes in a datagram are discarded by recv()• Portability

– Don’t forget to use htonX()/ntohX() as appropriate in STCP header fields