欢迎来到天天文库
浏览记录
ID:21330292
大小:39.00 KB
页数:14页
时间:2018-10-21
《三种arq协议c语言算法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、三种ARQ协议的C语言算法自己收藏的觉得很有用故上传到百度与大家一起分享!三种ARQ协议的C语言算法一、停止等待ARQ(stop-and-waitARQ)文件名p2.c/*Protocol2(stop-and-wait)alsoprovidesforaone-directionalflowofdatafromsendertoreceiver.Thecommunicationchannelisonceagainassumedtobeerrorfree,asinprotocol1.However,thistime,thereceiverhasonlyafinitebuffercapac
2、ityandafiniteprocesingspeed,sotheprotocolmustexplicitlypreventthesenderfromfloodingthereceiverwithdatafasterthanitcanbehandled.*/typedefenum{frame_arrival}event_type;#include"protocol.h"voidsender2(void){frames;/*bufferforanoutboundframe*/packetbuffer;/*bufferforanoutboundpacket*/event_typeeve
3、nt;/*frame_arrivalistheonlypossibility*/while(true){from_network_layer(&buffer);/*gogetsomethingtosend*/s.info=buffer;/*copyitintosfortransmission*/to_physical_layer(&s);/*byebyelittleframe*/wait_for_event(&event);/*donotproceeduntilgiventhegoahead*/}}voidreceiver2(void){framer,s;/*buffersforf
4、rames*/event_typeevent;/*frame_arrivalistheonlypossibility*/while(true){wait_for_event(&event);/*onlypossibilityisframe_arrival*/from_physical_layer(&r);/*gogettheinboundframe*/to_network_layer(&r.info);/*passthedatatothenetworklayer*/to_physical_layer(&s);/*sendadummyframetoawakensender*/}}二、
5、回退N帧ARQ(go-back-nARQ)文件名p5.c/*Protocol5(pipelining)allowsmultipleoutstandingframes.ThesendermaytransmituptoMAX_SEQframeswithoutwaitingforanack.Inaddition,unlikethepreviousprotocols,thenetworklayerisnotassumedtohaveanewpacketallthetime.Instead,thenetworklayercausesanetwork_layer_readyeventwhent
6、hereisapackettosend.*/#defineMAX_SEQ7/*shouldbe2^n-1*/typedefenum{frame_arrival,cksum_err,timeout,network_layer_ready}event_type;#include"protocol.h"staticbooleanbetween(seq_nra,seq_nrb,seq_nrc){/*Returntrueif(a<=b7、8、((c9、10、((b11、))return(true);elsereturn(false);}staticvoidsend_data(seq_nrframe_nr,seq_nrframe_expected,packetbuffer[]){/*Constructandsendadataframe.*/frames;/*scratchvariable*/s.info=buffer[frame_nr];/*insertpacketintoframe*/s.seq=frame_nr;/*inserts
7、
8、((c9、10、((b11、))return(true);elsereturn(false);}staticvoidsend_data(seq_nrframe_nr,seq_nrframe_expected,packetbuffer[]){/*Constructandsendadataframe.*/frames;/*scratchvariable*/s.info=buffer[frame_nr];/*insertpacketintoframe*/s.seq=frame_nr;/*inserts
9、
10、((b11、))return(true);elsereturn(false);}staticvoidsend_data(seq_nrframe_nr,seq_nrframe_expected,packetbuffer[]){/*Constructandsendadataframe.*/frames;/*scratchvariable*/s.info=buffer[frame_nr];/*insertpacketintoframe*/s.seq=frame_nr;/*inserts
11、))return(true);elsereturn(false);}staticvoidsend_data(seq_nrframe_nr,seq_nrframe_expected,packetbuffer[]){/*Constructandsendadataframe.*/frames;/*scratchvariable*/s.info=buffer[frame_nr];/*insertpacketintoframe*/s.seq=frame_nr;/*inserts
此文档下载收益归作者所有