CSE 489/589Programming Assignment 2
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
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
An Overview to Reliable Transport Protocols
Part 0:
4
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
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
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
How to implement your protocolsPart 1:
8
Programming Environment● In a simulator close to an actual UNIX
environment
Sender -A
Receiver - B
Simulator
Simulator
9
Simulator vs. Real Environment
10
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
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
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
Code Structure● A Simulator for Transport and lower layers
14
The Routines You Will Write● A_output(message);● A_input(packet);● A_timerinterrupt();● A_init();
● B_input(packet);● B_init();
15
The Alternating-Bit Version● Take a journey when there’s no packet loss/
corruption◦ No timer in this journey
16
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
Messages and packets structure
18
Functions● A_output()◦ Called whenever the upper layer at sender A has a
message to send◦ Function parameters - message
19
Functions● A_output()◦ Will call tolayer3() inside
A_output(message) {…tolayer3(0, packet);…
}
20
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
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
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
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
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
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
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
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
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
Functions● A_input()◦ Function parameters - packet◦ Validate the ack’s checksum◦ No need to deliver the ack to upper layer
30
The Alternating-Bit Version● The journey is complete! ☺
31
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
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!
Timer▪ stoptimer()• Its usage is similar to starttimer()• Stops the timer
▪ A_timerinterrupt()• No function parameter• Will be called when A’s timer expires
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
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.
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
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
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.
Questions ?