Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— Presentation transcript:

1 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

2 Functionality

3 Write an application that: Takes in data from one host

4 Functionality Write an application that: Takes in data from one host Turns those data into packets

5 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

6 Example

7 Beware the appearance of simplicity

8 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

9 corrupted delayed dropped duplicated

10 Please transfer $100 from my bank account to Phil's

11 corrupted delayed dropped duplicated Please transfer $100 from my bank account to Phil's Please transfer $14837135 from my bank account to Phil's

12 corrupted delayed dropped duplicated

13 Please deposit $100 into my account Please transfer $100 from my bank account to Phil's

14 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

15 corrupted delayed dropped duplicated

16 Please transfer $100 from my bank account to Phil's

17 corrupted delayed dropped duplicated Please transfer $100 from my bank account to Phil's

18 corrupted delayed dropped duplicated

19 Please transfer $100 from my bank account to Phil's

20 Tools for ordered, reliable streams Checksums Sequence numbers Acknowledgments Timeouts

21 cksums seq nos acks timeouts

22 Hash: cksum(data) integer

23 cksums seq nos acks timeouts Hash: cksum(data) integer cksum("a") 1

24 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

25 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

26 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...")

27 cksums seq nos acks timeouts Note: cksum("Please transfer... $100...") cksum("Please transfer... $14837135...")

28 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...")

29 cksums seq nos acks timeouts Monotonically increasing number appended to packet

30 cksums seq nos acks timeouts Monotonically increasing number appended to packet Please transfer $100 from my bank account to Phil's

31 cksums seq nos acks timeouts Monotonically increasing number appended to packet Please transfer $100 from my bank account to Phil's Seq no: 152

32 cksums seq nos acks timeouts Monotonically increasing number appended to packet Please transfer $100 from my bank account to Phil's Seq no: 152

33 cksums seq nos acks timeouts Monotonically increasing number appended to packet Please transfer $100 from my bank account to Phil's Seq no: 152

34 cksums seq nos acks timeouts Monotonically increasing number appended to packet Please transfer $100 from my bank account to Phil's Seq no: 152 Sender: Last sequence number sent (and last sequence number ack-d) Receiver: Last sequence number received

35 cksums seq nos acks timeouts Receiver acknowledges received packets If sender does not receive ack, retransmits

36 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

37 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

38 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

39 Duplicate Corrupt Delay Drop Checksums Sequence numbers Acknowledgments Timeouts

40 Stop and wait If you have a Sender and a Receiver: Sender sends a data message. Sender waits until receiver acknowledges reception o If Sender receives ack, sends its next available packet o If Sender does not receive ack, the Sender re- transmits the data that had not been acknowledged

41 Beware the appearance of simplicity

42 Difficulties Conceptual The "little" things

43 Conceptual: Event-based code

44 What are the events? What parts of code map to events? How to respond to events? How track state in? When transition between states?

45 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

46 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?

47 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

48 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?

49 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

50 Timer expires

51 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

52 Timer expires Timer expiration maps to retransmits When do we retransmit?

53 Timer expires Timer expiration maps to retransmits When do we retransmit? Have unack-ed packet outstanding We sent unack-ed packet > TIMEOUT ago

54 Receive data packet

55 Sanity checks

56 Receive data packet Sanity checks o 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?

57 Receive data packet Sanity checks o 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 taken o Should you send ack? o Should you pass payload to output?

58 Receive data packet Sanity checks o 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 taken o Should you send ack? o Should you pass payload to output?

59 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?

60 Ticky-tacky bugs Computing checksum htons / htonl / ntohs / ntohl strcpy

61 Receive data packet Sanity checks o 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 taken o Should you send ack? o Should you pass payload to output?

62 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;

63 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)

64 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)

65 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?

66 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( pkt, len);

67 Host order/network order How do I write the number 512?

68 Host order/network order How do I write the number 512? Hint: 512 = 2^9

69 Host order/network order How do I write the number 512? Hint: 512 = 2^9 Binary: 1000000000 Hex: 200

70 Host order/network order How do I write the number 512? Hint: 512 = 2^9 Binary: 1000000000 Hex: 200 MSBLSB

71 Host order/network order MSBLSB Should a machine store this as or ? How do I write the number 512? Hint: 512 = 2^9 Binary: 1000000000 Hex: 200

72 How do I write the number 512? Hint: 512 = 2^9 Binary: 1000000000 Hex: 200 Host order/network order MSBLSB Should a machine store this as or ? Little-endian Big-endian Network byte order

73 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 ? ?

74 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

75 htons ntohs htonl ntohl If your host is little-endian: ntohs( ) htons( ) If your host is big-endian ntohs( ) htons( )

76 Example recvd_pkt.seqno = ntohl(recvd_pkt.seqno);

77 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.

78 Testing Test interoperability with reference solution Test interoperability with classmates use test options to simulate bad network connectivity --drop --duplicate --corrupt --delay

79 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

80 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!


Download ppt "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,"

Similar presentations


Ads by Google