cse 489/589 programming assignment 2 › ~lusu › cse4589 › fall2019 › recitation › ... ·...

40
CSE 489/589 Programming Assignment 2

Upload: others

Post on 03-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

CSE 489/589Programming Assignment 2

Page 2: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Programming Assignment 2

•Due Time• 11/01/2019 @ 23:59:59 EST

•Submission• Source code.• Analysis report.• Don’t forget the Academic integrity statement.• Use the packaging script.

•How to submit• submit_cse489 (CSE 489)• submit_cse589 (CSE 589)

2

Page 3: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

OutlinePart 0 – An Overview to Reliable Transport Protocols

Part 1 – How to implement your protocols• Programming environment• Code Structure• The Routines You Will Write• The Alternating-Bit Version

Part 2 – Analysis and Report

3

Page 4: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

An Overview to Reliable Transport Protocols

Part 0:

4

Page 5: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit (rdt 3.0)

5

Assumption: underlying channel can lose and corrupt packets (data or ACKs)◦ checksum, seq. #, ACKs,

retransmissions will be of help.

Approach: sender waits “reasonable” amount of time for ACK

● retransmits if no ACK received in this time

● if pkt (or ACK) just delayed (not lost):◦ retransmission will be

duplicate, but use of seq. #’salready handles this◦ receiver must specify seq #

of pkt being ACKed● requires countdown timer

Page 6: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Go-Back-NSender● “window” of up to N, consecutive unack’ed pkts allowed

❖ timer for oldest unacked pkt❖ timeout(n): retransmit pkt n and all higher seq # pkts in

window❖ may receive duplicate ACKs (see receiver)

6

Page 7: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Selective-Repeat● Receiver individually acknowledges all correctly

received pkts◦ buffers pkts, as needed, for eventual in-order delivery

to upper layer

● Sender only resends pkts for which ACK not received◦ sender timer for each unACKed pkt

● Sender window◦ N consecutive seq #’s◦ again limits seq #s of sent, unACK’ed pkts

7

Page 8: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

How to implement your protocolsPart 1:

8

Page 9: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Programming Environment● In a simulator close to an actual UNIX

environment

Sender -A

Receiver - B

Simulator

Simulator

9

Page 10: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Simulator vs. Real Environment

10

Page 11: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Real Environment (PA1)● Sending/receiving process run on different hosts

A and B● Hosts A and B communicate over the network◦ Set of routers/links with packet loss/corruption

characteristics◦ User has no control over them

● Application implemented in user space, transport/network layer implemented in the kernel◦ App/transport talk to each other through sockets

● Each host has its own local clock/time

11

Page 12: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Simulator (PA2)● Simulated hosts A and B run on single real

host● Hosts A and B “communicate” over simulated

network◦ User specifies packet loss/corruption

● All layers implemented in user space● Both simulated hosts have the same time

measured in “time units”◦ get_sim_time()◦ Simulated time different from real time!

12

Page 13: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Design Goals● To insure the data generated from sender A’s

application layer is delivered in-order and correctly to the receiver B’s application layer

Simulator

Data packets will get lost or corrupted at lower layers!

13

Page 14: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Code Structure● A Simulator for Transport and lower layers

14

Page 15: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Routines You Will Write● A_output(message);● A_input(packet);● A_timerinterrupt();● A_init();

● B_input(packet);● B_init();

15

Page 16: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit Version● Take a journey when there’s no packet loss/

corruption◦ No timer in this journey

16

Page 17: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit Version

A_output() tolayer3() SimulatorSimulator B_input()

tolayer5()

tolayer3()Simulator

Simulator

A_input()

data generated at A’s app layer

data received at B’s app layer

ACK received by A

17

Page 18: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Messages and packets structure

18

Page 19: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● A_output()◦ Called whenever the upper layer at sender A has a

message to send◦ Function parameters - message

19

Page 20: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● A_output()◦ Will call tolayer3() inside

A_output(message) {…tolayer3(0, packet);…

}

20

Page 21: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit Version

A_output() tolayer3() SimulatorSimulator B_input()

tolayer5()

tolayer3()Simulator

Simulator

A_input()

data generated at A’s app layer

data received at B’s app layer

ACK received by A

21

Page 22: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● tolayer3()◦ Function parameters – AorB, packet◦ AorB

int AorBAorB = 0 [when being called by A]AorB = 1 [when being called by B]

◦ packetstruct pkt packet

22

Page 23: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● struct msg message ➔ struct pkt packet◦ The only two types of data can be recognized by the

simulator.◦ Both data packets and ack packets are of struct pkt

type.◦ Both data packets and ack packets need checksum◦ Don’t change the definitions of struct msg or struct pkt

23

Page 24: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● Checksum◦ Any content - payload, seqnum, acknum or checksum

can be corrupted by the simulator’s lower layers.

◦ It should include the data, seqnum and acknum fields.

24

Page 25: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Question● If the data generating speed at A’s app layer is

higher than the speed at which lower layers send packets, what should we do?

Buffer!

25

Page 26: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit Version

A_output() tolayer3() SimulatorSimulator B_input()

tolayer5()

tolayer3()Simulator

Simulator

A_input()

data generated at A’s app layer

data received at B’s app layer

ACK received by A

26

Page 27: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● B_input()◦ Function parameters - packet◦ Validate the checksum first◦ May call tolayer3() and tolayer5() inside

B_input(packet) {// validate the checksum;…// if the checksum is correct// send ack to Atolayer3(1, ack);// deliver the data to upper layertolayer5(1, payload);…

}27

Page 28: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● tolayer5()◦ Function parameters – AorB, datasent◦ AorB

int AorBAorB = 0 // called by AAorB = 1 // called by B

◦ datasent // different from tolayer3() herechar datasent[20] // payload

28

Page 29: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit Version

A_output() tolayer3() SimulatorSimulator B_input()

tolayer5()

tolayer3()Simulator

Simulator

A_input()

data generated at A’s app layer

data received at B’s app layer

ACK received by A

29

Page 30: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Functions● A_input()◦ Function parameters - packet◦ Validate the ack’s checksum◦ No need to deliver the ack to upper layer

30

Page 31: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

The Alternating-Bit Version● The journey is complete! ☺

31

Page 32: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Packet corruption and Loss● If packet corruption and loss happen at the

lower layers, what should we do?◦ NAK is not allowed to be used in this assignment

Retransmit with timer!

32

Page 33: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Timer▪ starttimer()• Starts a timer.• Function parameters – AorB, increment• AorB✓int AorB✓AorB = 0 // called by A✓AorB = 1 // called by B• Increment✓float increment• Only ONE timer provided by the simulator!

Page 34: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Timer▪ stoptimer()• Its usage is similar to starttimer()• Stops the timer

▪ A_timerinterrupt()• No function parameter• Will be called when A’s timer expires

Page 35: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Questions▪ What value should we use in the timer?

Hint: A packet sent into the network takes an average of 5 time units to arrive at the other side when there are no other packets in the medium.

▪ Where should we start and stop the timer?This will be different in the 3 protocols

Page 36: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

About the Simulator▪ When will the simulation end?• The simulation is controlled by the number of

messages generated by A’s app layer – the number of packets you type in before the simulation start

• The simulator will stop as soon as that number of messages have been passed down from A’s app layer.

Page 37: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

About the Simulator▪ What is “the average time between messages

from sender’s layer 5”?• Controls the source data rate• Non zero, positive value• Smaller the value, faster the packets will be

arriving to the sender’s transport layer.• Be careful about the relationship between the

buffer size and this value – Sender A shouldn’t drop any message at the transport layer• Best is to use a buffer size of 1000

Page 38: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Analysis: Result ▪ Application_A

#Packets sent from the Application Layer of Sender A▪ Transport_A

#Packets sent from the Transport Layer of Sender A▪ Transport_B

#Packets received at the Transport Layer of Receiver B▪ Application_B

#Packets received at the Application Layer at Receiver B▪ Throughput

Application_B/Simulation_time

Page 39: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Analysis: Experiments▪ PA2 Analysis part carries significant points.

▪ PA2 handout lists out 2 experiments (see section 6).• We of course encourage you to do more!

▪ You NEED to use the run_experiments script, provided with the template.• Do NOT run the binaries manually for analysis.

▪ The script will give you 10 results (different seeds).• You may take average for reporting.

Page 40: CSE 489/589 Programming Assignment 2 › ~lusu › cse4589 › Fall2019 › Recitation › ... · 2019-10-23 · Programming Assignment 2 •Due Time •11/01/2019@ 23:59:59 EST •Submission

Questions ?