lab 2: admin details lab 2 is out! due: o november 4th, 12 noon o november 6th, 12 noon (90% cap)...
Post on 29-Mar-2015
216 Views
Preview:
TRANSCRIPT
Lab 2: Admin details
• Lab 2 is out!
• Due: o November 4th, 12 noon
o November 6th, 12 noon (90% cap)
• Assignment and starter code online
• Start early!On average, took students 14 hours to complete Lab 2 last
year
Functionality
Functionality
Write an application that:
• Takes in data from one host
Functionality
Write an application that:
• Takes in data from one host
• Turns those data into packets
Functionality
Write an application that:
• Takes in data from one host
• Turns those data into packets
• Transmits those packets reliably and in-order to the other host
Example
Beware the appearance of simplicity
Why the Internet isn't just "tubes"
• A packet can be corrupted
• A packet can be delayed
• A packet can be dropped
• A packet can be duplicated
corrupted delayed dropped duplicated
corrupted delayed dropped duplicated
Please transfer $100 from my bank account to Phil's
corrupted delayed dropped duplicated
Please transfer $100 from my bank account to Phil's
Please transfer $14837135 from my bank account to Phil's
corrupted delayed dropped duplicated
corrupted delayed dropped duplicated
Please deposit $100 into my account
Please transfer $100 from my bank account to Phil's
corrupted delayed dropped duplicated
Please deposit $100 into my account
Please transfer $100 from my bank account to Phil's
Please deposit $100 into my account
Please transfer $100 from my bank account to Phil's
corrupted delayed dropped duplicated
corrupted delayed dropped duplicated
Please transfer $100 from my bank account to Phil's
corrupted delayed dropped duplicated
Please transfer $100 from my bank account to Phil's
corrupted delayed dropped duplicated
corrupted delayed dropped duplicated
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Tools for ordered, reliable streams
• Checksums
• Sequence numbers
• Acknowledgments
• Timeouts
cksums seq nos acks timeouts
cksums seq nos acks timeouts
Hash:
cksum(data) integer
cksums seq nos acks timeouts
Hash:
cksum(data) integer
cksum("a") 1
cksums seq nos acks timeouts
Please transfer $100 from my bank account to Phil's
Please transfer $14837135 from my bank account to Phil's
cksums seq nos acks timeouts
Please transfer $100 from my bank account to Phil's
Please transfer $14837135 from my bank account to Phil's
Tag packet with checksum before sending
cksums seq nos acks timeouts
Please transfer $100 from my bank account to Phil's
Please transfer $14837135 from my bank account to Phil's
Tag packet with checksum before sending
Please transfer $100 from my bank account to Phil's
Please transfer $14837135 from my bank account to Phil's
cksum("Please ...") cksum("Please ...")
cksums seq nos acks timeouts
Note:
cksum("Please transfer ... $100 ...")
cksum("Please transfer ... $14837135 ...")
cksums seq nos acks timeouts
Note:
cksum("Please transfer ... $100 ...")
cksum("Please transfer ... $14837135 ...")
Please transfer $100 from my bank account to Phil's
Please transfer $14837135 from my bank account to Phil's
cksum("Please ...") cksum("Please ...")
cksums seq nos acks timeouts
Monotonically increasing number appended to packet
cksums seq nos acks timeouts
Monotonically increasing number appended to packet
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
cksums seq nos acks timeouts
Monotonically increasing number appended to packet
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Seq no: 152 Seq no: 152
Seq no: 152
cksums seq nos acks timeouts
Monotonically increasing number appended to packet
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Seq no: 152 Seq no: 152
Seq no: 152
cksums seq nos acks timeouts
Monotonically increasing number appended to packet
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Seq no: 152 Seq no: 152
Seq no: 152
cksums seq nos acks timeouts
Monotonically increasing number appended to packet
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Please transfer $100 from my bank account to Phil's
Seq no: 152 Seq no: 152
Seq no: 152Sender: Last sequence number sent (and last sequence number ack-d)
Receiver: Last sequence number received
cksums seq nos acks timeouts
Receiver acknowledges received packets
If sender does not receive ack, retransmits
cksums seq nos acks timeouts
Receiver acknowledges received packets
If sender does not receive ack, retransmits
Please transfer $100 from my bank account to Phil's
Seq no: 152
cksums seq nos acks timeouts
Receiver acknowledges received packets
If sender does not receive ack, retransmits
Please transfer $100 from my bank account to Phil's
Seq no: 152
Please transfer $100 from my bank account to Phil's
Seq no: 152
Please transfer $100 from my bank account to Phil's
Seq no: 152
cksums seq nos acks timeouts
Receiver acknowledges received packets
If sender does not receive ack, retransmits
Please transfer $100 from my bank account to Phil's
Seq no: 152
Please transfer $100 from my bank account to Phil's
Seq no: 152
Please transfer $100 from my bank account to Phil's
Seq no: 152
Ack no: 153
Duplicate
Corrupt
Delay
Drop
Checksums
Sequence numbers
Acknowledgments
Timeouts
Stop and wait
If you have a Sender and a Receiver:
• Sender sends a data message.
• Sender waits until receiver acknowledges receptiono If Sender receives ack, sends its next available
packeto If Sender does not receive ack, the Sender re-
transmits the data that had not been acknowledged
Beware the appearance of simplicity
Difficulties
• Conceptual
• The "little" things
Conceptual: Event-based code
Conceptual: Event-based code
• What are the events?
• What parts of code map to events?
• How to respond to events?
• How track state in? When transition between states?
Events
• Receive data packet
• Receive ack packet
• Input goes from empty to having data
• Output goes from full to having room
• Timer expires
• Create a new connection
------
• Receive shutdown from opposite end
• Receive shutdown from input
Conceptual: Event-based code
• What are the events?
• What parts of code map to events?
• How to respond to events?
• How track state in? When transition between states?
Events
• Create a new connection
rel_create
• Receive data packet
• Receive ack packet
rel_recvpkt
• Input goes from empty to having data
rel_read
• Output goes from full to having room
rel_output
• Timer expires
rel_timer
Conceptual: Event-based code
• What are the events?
• What parts of code map to events?
• How to respond to events?
• How track state in? When transition between states?
Events
• Create a new connection
rel_create
• Receive data packet
• Receive ack packet
rel_recvpkt
• Input goes from empty to having data
rel_read
• Output goes from full to having room
rel_output
• Timer expires
rel_timer
Timer expires
cksums seq nos acks timeouts
Receiver acknowledges received packets
If sender does not receive ack, retransmits
Please transfer $100 from my bank account to Phil's
Seq no: 152
Please transfer $100 from my bank account to Phil's
Seq no: 152
Please transfer $100 from my bank account to Phil's
Seq no: 152
Timer expires
Timer expiration maps to retransmits
When do we retransmit?
Timer expires
Timer expiration maps to retransmits
When do we retransmit?
• Have unack-ed packet outstanding
• We sent unack-ed packet > TIMEOUT ago
Receive data packet
Receive data packet
• Sanity checks
Receive data packet
• Sanity checkso Does its checksum match?o Are you expecting the sequence number?o Is it the right length?o Has the other end already closed its output stream?
Receive data packet
• Sanity checkso Does its checksum match?o Are you expecting the sequence number?o Is it the right length?o Has the other end already closed its output stream?
• Action takeno Should you send ack?o Should you pass payload to output?
Receive data packet
• Sanity checkso Does its checksum match?o Are you expecting the sequence number?o Is it the right length?o Has the other end already closed its output stream?
• Action takeno Should you send ack?o Should you pass payload to output?
Conceptual: Event-based code
• What are the events?
• What parts of code map to events?
• How to respond to events?
• How track state in? When transition between states?
Ticky-tacky bugs
Computing checksum
htons/htonl/ntohs/ntohlstrcpy
Receive data packet
• Sanity checkso Does its checksum match?o Are you expecting the sequence number?o Is it the right length?o Has the other end already closed its output stream?
• Action takeno Should you send ack?o Should you pass payload to output?
cksum
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno; /* Only valid if length > 8 */
char data[500];
};
typedef struct packet packet_t;
cksum
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno; /* Only valid if length > 8 */
char data[500];
};
typedef struct packet packet_t;
Provided a cksum function in code:
uint16 cksum(const void* data, int len)
cksum
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno;
char data[500];
};
typedef struct packet packet_t;
Provided a cksum function in code:
uint16 cksum(const void* data, int len)
cksum
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno;
char data[500];
};
typedef struct packet packet_t;
Provided a cksum function in code:
uint16 cksum(const void* data, int len)
How do you know what to fill in for cksum field before performing the cksum?
cksum
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno;
char data[500];
};
typedef struct packet packet_t;
Provided a cksum function in code:
uint16 cksum(const void* data, int len)
How do you know what to fill in for cksum field before performing the cksum?
Zero cksum field before performing cksum on packet
Ie: pkt.cksum = 0; pkt.cksum = cksum( <some cast> pkt, len);
Host order/network order
How do I write the number 512?
Host order/network order
How do I write the number 512?
Hint: 512 = 2^9
Host order/network order
How do I write the number 512?
Hint: 512 = 2^9
Binary: 1000000000
Hex: 200
Host order/network order
How do I write the number 512?
Hint: 512 = 2^9
Binary: 1000000000
Hex: 200
MSB LSB
Host order/network order
MSB LSB
Should a machine store this as or ?
How do I write the number 512?
Hint: 512 = 2^9
Binary: 1000000000
Hex: 200
How do I write the number 512?
Hint: 512 = 2^9
Binary: 1000000000
Hex: 200
Host order/network order
MSB LSB
Should a machine store this as or ?
Little-endian
Big-endianNetwork byte order
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno;
char data[500];
};
typedef struct packet packet_t;
Host order/network order
?
?
Host order/network order
struct packet {
uint16_t cksum;
uint16_t len;
uint32_t ackno;
uint32_t seqno;
char data[500];
};
typedef struct packet packet_t;
?
?
htons htonl ntohs ntohl
htons ntohs htonl ntohl
If your host is little-endian:
ntohs( ) htons( )
If your host is big-endian
ntohs( ) htons( )
Example
recvd_pkt.seqno = ntohl(recvd_pkt.seqno);
Example
recvd_pkt.seqno = ntohl(recvd_pkt.seqno);
Design goal:
Limit the places you use ntohl, ntohs, htons, htonl to as few places as possible.
Testing
● Test interoperability with reference solution● Test interoperability with classmates● use test options to simulate bad network connectivity
○ --drop○ --duplicate○ --corrupt○ --delay
Summary
What the network can do to packets
Primitives for reliability
• Checksums
• Sequence numbers
• Acknowledgments
• Timeouts
Event-based code
• What are events?
• How do they map to code?
• How do you respond to them?
• How do you transition between states?
Gotchas
• cksum
• nthos htons ntohl htonl
Words of advice
Start early!
Start by reading/thinking/desiging
Test your implementation thoroughly
Start early!
Figure out when to call conn_input
Start early!
top related