1 / 5

Tips on Programming Assignment 2: Reliable Data Transfer

Tips on Programming Assignment 2: Reliable Data Transfer. For the rdt3.0, refer its FSM for programming: Define five states for host A (sender) enum Astat e _type {waitAck0, waitAck1, waitData0, waitData1} Astat e ; Define two states for host B (receiver)

arwen
Download Presentation

Tips on Programming Assignment 2: Reliable Data Transfer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tips on Programming Assignment 2: Reliable Data Transfer • For the rdt3.0, refer its FSM for programming: • Define five states for host A (sender) enum Astate_type {waitAck0, waitAck1, waitData0, waitData1} Astate; • Define two states for host B (receiver) enum Bstate_type {waitSeq0, waitSeq1} Bstate; • Define subfunction for checksum • ComputChecksum(), CheckCorrupted()

  2. Wait for 0 from below Wait for 1 from below rdt3.0: receiver FSM udt_rcv(rcvpkt) && notcorrupt(rcvpkt) && has_seq0(rcvpkt) extract(rcvpkt,data) deliver_data(data) sndpkt = make_pkt(ACK0, chksum) udt_send(sndpkt) udt_rcv(rcvpkt) && (corrupt(rcvpkt) || has_seq0(rcvpkt)) udt_rcv(rcvpkt) && (corrupt(rcvpkt) || has_seq1(rcvpkt)) receiver FSM udt_send(sndpkt) udt_send(sndpkt) udt_rcv(rcvpkt) && notcorrupt(rcvpkt) && has_seq1(rcvpkt) extract(rcvpkt,data) deliver_data(data) sndpkt = make_pkt(ACK1, chksum) udt_send(sndpkt)

  3. Wait for ACK0 Wait for ACK1 Wait for call 1 from above Wait for call 0from above rdt3.0 sender FSM rdt_send(data) udt_rcv(rcvpkt) && ( corrupt(rcvpkt) || isACK(rcvpkt,1) ) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) start_timer L udt_rcv(rcvpkt) L timeout udt_send(sndpkt) start_timer udt_rcv(rcvpkt) && notcorrupt(rcvpkt) && isACK(rcvpkt,1) udt_rcv(rcvpkt) && notcorrupt(rcvpkt) && isACK(rcvpkt,0) stop_timer stop_timer timeout udt_send(sndpkt) start_timer udt_rcv(rcvpkt) L rdt_send(data) udt_rcv(rcvpkt) && ( corrupt(rcvpkt) || isACK(rcvpkt,0) ) sndpkt = make_pkt(1, data, checksum) udt_send(sndpkt) start_timer L

  4. Program each state transition in FSM • If state changes, remember to change Astate, Bstate accordingly • Some FSMcode mappings: • timeout  A_timerinterrupt() is called • udt_rcv(rcvpkt)  A_input(packet), B_input(packet) is called • udt_send(sndpkt)  tolayer3(0/1, packet) • rdt_send(data)  A_output(message) is called • deliver_data(data)  tolayer5(message) is called in host B • extract(rcvpkt,data)  copy packet.payload[] to message.data[] •  (do nothing)  exit a function immediately (e.g., return -1;)

  5. Programming Tips • Some definition for easy naming: • #define host_A 0 #define host_B 1 • #define TRUE 100 #define FALSE 200 • #define NOTUSED 300 #define TIMEOUT 15 (20) • Program the simplest scenario first: • No loss, no error scenario • Add your own “printf(“ #### …..\n”);” in all (or most) state transitions for debugging • The printf text should show the detail of each action. • This is the most important “run-time” debugging method!!! Don’t be lazy here! • Add “getchar();” in places where you want to stop the code temporally to see output results • Your code will enter infinite loop if it has some errors • tolayer5(hostB, message); BreceivedMsgNum ++; printf(" #### B correctly received the No. %d message\n", BreceivedMsgNum);

More Related