Reliable Networking Tom Roeder CS415 2005sp

advertisement
Reliable Networking
Tom Roeder
CS415 2005sp
Last minute questions on Part II?
Goals

Add a reliable transmission layer



write test code



you discussed why in lecture: UDP is insufficient
NB: TCP doesn’t interact well with ad hoc routing
demonstrate to us that your code satisfies spec
This will be the case for all future parts
Non goals


No nontrivial window (we use size 1)
thus trivial congestion control, no AIMD

Would this still be TCP-friendly?
What to implement

minisockets

A connection-oriented networking layer

new header




control packets


fragmentation
sequence numbers
control types
ACK, SYN, FIN
Reliability


duplicate detection
retransmissions
Layered Implementation

Implement sockets on top of miniports

Your code should just call send and receive

When a port is created, it only accepts UDP
When connected to a stream, it only accepts TCP


No changes needed to the header



Received packets on a miniport are always
passed up to the receiving “application”
Sometimes this is an app, sometimes TCP
This is a standard modular design
Stream Semantics


Packets larger than max size are fragmented
Two possible ways



We choose the latter



keep track of message size
treat the socket as a byte stream
can ignore packet boundaries at the receiver
assume that multiple threads know how to
reassemble if they get random pieces of the msg
Easier for you to implement
minisockets
minisocket_t minisocket_server_create(int port, minisocket_error *error);
minisocket_t minisocket_client_create(network_address_t addr, int port,
minisocket_error *error);
int minisocket_send(minisocket_t socket, minimsg_t msg, int len,
minisocket_error *error);
int minisocket_receive(minisocket_t socket, minimsg_t msg, int max_len,
minisocket_error *error);
void minisocket_close(minisocket_t socket);




A port can be taken either by TCP or UDP
We give you the error messages
The server is listening for a client to connect
Send and receive happen as streams
Reliability

Retransmissions



May need to resend packets to account for loss
Use an ACK to decide if need to resend
interval: 100ms. Try 7 times, doubling each time


thus will wait about 12.5 seconds
Duplicate detection



Because of retransmissions, may get duplicates
Need to keep track of old seq nums to supress
Don’t forget to do this for control packets, too
minisockets as a state machine

Think of the states for each side




The state transitions here are the messages and the
timers



server: waiting for a connection, connected, closing socket,
etc.
client: various stages of connecting
both: stages in sending a packet (which retransmission
stage, ACK’ed or not, etc.)
open request, packet received, ACK
timeout expired
see http://gmckinney.info/resources/TCPIP_State_Transition_Diagram.pdf
Implementation Issues

Multiple threads sending and receiving

only one minithreads client to one server




each may have many threads on each side of the port
thus need to coordinate ACKs and timeouts between
them
may want to have dedicated threads for this
Should interact well with your scheduler


Most should be blocked on I/O most of the time
Should cause them to remain high priority
Questions?
Download