欢迎来到课桌文档! | 帮助中心 课桌文档-建筑工程资料库
课桌文档
全部分类
  • 党建之窗>
  • 感悟体会>
  • 百家争鸣>
  • 教育整顿>
  • 文笔提升>
  • 热门分类>
  • 计划总结>
  • 致辞演讲>
  • 在线阅读>
  • ImageVerifierCode 换一换
    首页 课桌文档 > 资源分类 > DOCX文档下载  

    云南大学软件学院计算机网络原理实验六实验报告.docx

    • 资源ID:1672116       资源大小:78.12KB        全文页数:50页
    • 资源格式: DOCX        下载积分:5金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要5金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    云南大学软件学院计算机网络原理实验六实验报告.docx

    试验六、传输层牢靠传输协议GBN编程试验报告序号:一姓名:_学号:成果一指导老师:一、试验目的;1、通过编写实现一个简洁牢旅的数据传输协议GBN的发送和接收代码,模拟牢靠数据传输2、理解TCP协议牢轮传输的差错检测、重传、累计确认、定时器的牢拳传输策略。二、试验指导:参考教材。动画演示:三、试验要求:编程实现一个GBN传输协议的发送方和接收方两程序,采纳编程语言不限,要求能将发送一一接收流程以与处理方法表现出来.1.试验流程图如下:O''X选择由传2.试验截图与代码如下:截图:'GUtrfQiuD*cktopitHfi6GBN001DbugGBN001xe-StopandVaitNetworkSitnj1.atorVersion1.1Snterthenumberofmessagestosinu1.ate:56Enterpacket1.ossprobabi1.ityenterO.Oforno1.oss:3Enterpacketcorruptionprobabi1ityO.O£ornocorruption:OSnteraveragetimebetweenEfiSSaEeSfromsender's1.ayer5>O.0:1interTRACE:3A:IfeWJ119ssagarrives,sendWindWisfu1.1.,buffernewmessage!entity:0aaaaaaaaaaaaaaaaaaaafu1.1.buffernewmessage!entity:0bbbbbbbbbbbbbbbbbbbbfu1.1.,buffernewmessage!entity:0CeCCCCCCCCCCCCCCCCCCfu1.1.,buffernewmessage!WEbrrtime:O.000870,type:1,frondayer5MAIN1.COP:datagiventostudent:A:Kew11essagearrives,sendMdndoWisVENTticDio:0.000891,typo:1.£rondayer5BAIN1.COP:datagiventostudent:A:Kewmessagearrives,sendwindowis1.VEOTtime:0.000909.type:I1frondayer5三AIN1.CX)P:datagiventostudent:A:New11ssagearrives,sendWiCdWis:VENrti:0.000913,type:1,frondayer5entity:0MAIN1.COP:datagiventostudent:dddddddddddddddddddd,A:New11essagearrives,sendWindOWisfu1.1.,buffernew11essage!WENrtime:0.000928,type:I,fro11dayer5entity:0Siwj1.atorterminatedattime0.000928aftersending56®sgsfromIayer5correct1.ysentpkts:9resentpkts:0青按任意道继续代码与注样:一、GBN.hpragmaonceinc1.ude<stdio.h>基础功能模块的数据结构声明#defineBIDIRECTIONA1.1*changeto1ifyouredoingextracreditandwritearoutineca1.1.edB_output/a*msg*isthedataunitpassedfro三1.ayer5(teacherscode)to1.ayer4(students'code).Itcontainsthedata(characters)tobede1.iveredto1.ayer5viathestudentstransport1.eve1.protoco1.entities.*/structmsgchardata20;;/apacketisthedataunitpassedfrom1.ayer4(studentscode)to1.ayer3(teacherscode).Notethepre-definedpacketstructure,whicha1.1.studentsmustfo1.1.ow./structpkt(intseqnus;intacknun;intchecksum;charpay1.oad20;);#defineWINDOfSIZE8#defineMAXBUFSIZE50defineRTT15.0WefineNOTUSED0ffdefineNACK-1MefineTRUE1defineFA1.SE0#defineB1网络仿真部分数据结构声明structeventf1.oatevtine;*eventtine/intevtype;/eventtypecode*/inteventity;/entitywhereeventoccurs*/structpkt*pktptr;/ptrtopacket(ifany)assocw/thisevent/structevent*prev;structevent*nxt;);/possib1.eevents:/#defineT1.ME1.1.1.NTERRUpT0ffdefineFROi1.1.AYER51#defineFRoi1.1.AYER32defineOFF0基础功能模块的函数声明voidCoaDputeChecksuin(structpkt*packet);计算校殴和intCheckCorrupted(structpktPaCket);检查数据是否出错voidA_output(structmsgDeSSage);A蟠向外发送数据voidA_input(structpktPaCket);A嵋接收数据voidAjinerinterruptO;/A计时器超时voidA-i11itO;/A端初始化voidB_output(structmsgmessage);voidB_input(structpktpacket);voidB-tinerinterruptO;voidB_initO;网络仿真部分的函数声明voidinit;初始化仿真器f1.oatJiBSrandO;随机数发生器0,1处理事务列表部分的函数声明voidgenerate_next_arriva1.O;产生下一个到达的分组voidinsertevent(structevent*p);向事务列表中插入一条新的事务voidPrinteV1.iSt();打印事务列表/a«Vb/9K«91«Vkajj1.jK2Bb1.jjKj2BJf1.1.scjK2BZZB1.S1.jjKjKH1.?B1.SCJK3K2HjU1.2f1.1.MCJKjKZB1.B1.jBCjKKZ0ZB2H1.IHCjkjKZf1.31.Jf1.JKK*计时器模块voidStoPtimer(int);停止计时器voidStarttiBer(int,f1.oat);启动计时器/aaT"j1.jK2KS1.Jb1.jKijB1.k2HS1.jHjkjKjKJk1.BcjKjKjK2K2S1.jKjKJf1.1.XCJKjKjKJkB1.jCjKAIH网络各层之间传送模块voidto1.ayer3(intAorB,structpktPaCket);向第3层发送信voidto1.ayer5(intAorB,chardatasent20);向第5层发送信息二、GBN.cinc1.ude*GBN.h*ffinc1.ude<stdio.h>tfinc1.ude<string.h>inc1.ude<std1.ib.h>externintTRACE=1;/formydebugging/为我的调试externintnsin=0;/nunberofmessagesfro三5to4sofar*/目前为止信息的数字是从5到4externintnsinnax=0;/numberofmsgstogenerate,thenstop*/假如信息产生的数字为0,然后就停止externf1.oattime=0.000;f1.oatIossprob;*probabi1.itythatapacketisdropped*/数据包可能会丢失f1.oatcorruptprob;/probabi1.itythatonebitispacketisf1.ipped*/这一点的数据包可能会被弹出去f1.oat1.ambda:/arriva1.rateofnessagesfrom1.ayer5/第五层到达的信息的次序intnto1.ayer3;*numbersentinto1.ayer3/被传送到第三层的数据staticintn1.ost=0;*nunber1.ostinmedia*/在媒介中数据丢失staticintncorrupt=0;/nu)rcorruptedbymedia*/被媒介毁坏的数据staticintexpectedseqnun=O;*expectedsequencenumberatreceiverside/.在接收者这边接收到Bi期的序列数据staticintnextseqnum;*nextsequencenumbertouseinsenderside/.下一个序列数据运用在发送者这边staticintbase;*theheadofsenderwindow/发送者的头窗口structpktwinbufWINDOWSIZE;*windowpacketsbuffer/.数据包缓冲区窗口staticintwinfront,winrear;/frontandrearpointsofwindowbuffer/窗口缓冲区的前方点和后方点staticintPktnuI;/packetnumberofwindowbuffer/窗口缓冲区的数据包个数structmsgbufferMAXBUFSIZE;/senderessagebuffer/.发送消息缓冲区intbuffront,bufrear;/frontandrearpointersofbuffer/.缓冲区的前指针与后指针staticintmsgnum;*I1.eSSagenu三berofbuffer/信息数量的缓冲intpacket_1.ost=0;intpacket_corrupt=0;intpacket-sent=0:externintpacket_correct=0;externintpackt-resent=0;intpacket_ti三eout=0;externstructevent*ev1.ist=NU1.1.;*theevent1.ist/计算校验和voidComputeChecksuD(structpkt*packet)(intchecksum;inti;checksum=packet->seqnun;checksum=checksu+packet->acknun;for(i=0;i<20;i+)checksum=checksum+(int)(packt->pay1.oadi);CheCkSUm=0-chcksu三;packet->checksun=checksun;)检查是否出错intCheckCorrupted(structpktpacket)(intchecksum;inti;checksum=packet,seqnun;checksum=checksum+packet,acknm;for(i=0;i<20;i+)checksum=checksum+(int)(packet,pay1.oadi);if(packet,checksunr+checksua)=0)return(FA1.SE);e1.sereturn(TRUE);)/A端向外发送数据/ca1.1.edfrom1.ayer5,passedthedatatobesenttootherside/voidA_output(structmsgnessage)(inti;structpktsendpkt;/ifwindowisnotfu1.1./if(nextseqnum<base+WINDOWSIZE)(printf(*A:Newmessagearrives,sendWindO1.risnotfu1.1.,sendnewmessgeto1.ayer3!n*);/createpacket/sendpkt.seqnum=nextseqnum;sendpkt.acknum=NOTUSED;for(i=0;i<20;i+)sendpkt.pay1.oadi=nessage.datai:/c<M三puterchecksum/CoaputeChecksun(Isendpkt);/sendoutpacket/to1.ayer3(A,sendpkt);/copythepackettowindovpacketbuffer*/winrear=(winrar+1.)%WINDOWSIZE;pktnun+;vinbufwinrear=sendpkt;for(i=0;i<20;i+)winbufwinrear.pay1.oadi=sendpkt.pay1.oadi;/updatestatevariab1.es/nextseqnu=nextseqnum+1;starttimer(A,RTT);B_input(sendpkt);A-input(sendpkt);/ifwindowisfu1.1./e1.se(printf(*A:Newmessagearrives,sendVindoWisfu1.1.,9;/ifbufferfu1.1.,giveupandexit*/if(BSgnum=MAXBUFSIZE)(printf(*Error:Senderbufferisfu1.1.(n");exit(1);)/otherwise,bufferthemessage*/e1.se(printfCbuffernewnessage!n*);bufrar=(bufrear+1)%MAXBUFSIZE;for(i=0;i<20;i)bufferbufrear.datai=message,datai;nsgnun+;/B端向外发送数据/ca1.1.edfra1.ayer5,passedthedatatobesenttootherside»/voidB_output(structmsgnessage)(inti;structpktsendpkt;/ifIrindoVisnotfu1.1./if(nextseqnum<bas+WINDOWSIZE)(printf(*A:Newmessagearrives,sendWindOVisnotfu1.1.,sendnevmessgeto1.ayr3!n*);/createpacket/sendpkt.seqnum=nextseqnum;sendpkt.acknum=NOTUSED;for(i=0;i<20;i)sendpkt.pay1.oadi=nessage.datai;/c三putrCheCkSU1.n*/ConuteChecksun(Asendpkt);/sendoutpacket/to1.ayer3(A,sendpkt);A_input(sendpkt)/copythepackettowindowpacketbuffer*/winrear=(winrear+1)%WINDOWSIZE;pktnun+;winbufwinrear=sendpkt;for(i=0;i<20;i+)winbufwinrar.pay1.oadi三sendpkt.pay1.oadi;/ifitisthefirstpacketinvindovrstarttimeout/if(base=nextseqnun)/starttimer(A,RTT);/printfCA:startanewtimer!n*);/*updatestatevariab1.es/nextseqnum=nextseqnun+1:/ifwindowisfu1.1./e1.se(printf(A:Newmessagearrives,sendWindOVisfu1.1.,*)/ifbufferfu1.1.,giveupandexit*/if(asgnum=MAXBUFSIZE)(printf(*Error:Senderbufferisfu1.1.!n*);exit(1);)/otherwise,bufferthemessage/e1.se(printf(*buffernevmessage!n,);bufrear=(bufrear+1)%MAXBUFSIZE;for(i=0;i<20;i)bufferbufrear.datai=message,datai;msgnun+;1/A端接收数据voidA_input(structpktpacket)(structpktsendpkt;inti;/ifreceivedpacketisnotcorruptedandACKisreceived/if(CheckCorrupted(packet)=FA1.SE)&&(packet,acknum!=NACK)(printf(*A:ACK%discorrect1.yreceived,*,packet,acknun);PaCket.correct+/de1.etetheackedpacketsfromwindowbuffer*/winfront=(winfront+(packet,acknu三+1.-bas)%WINDOWSIZE;pktnun=pktnum-(packet,acknu三+1.-base);/BOVewindowbase/base=packet,acknun÷1.;Stoptimer(八);if(base<nextseqnum)(/starttimer(A,RTT);printf(*nnnsndnewpackets!*);/ifbufferisnotempty,sendnewpackets/whi1.e(USgnUiI!=0)(nextseqnum<base+VINDOVSIZE)(/createpacket/sendpkt.seqnum=nextseqnum;sendpkt.acknum=NOTUSED;buffront=(buffront+1)%MAXBUFSIZE;for(i=0;i<20;i+)sendpkt.pay1.oadi=bufferbuffront.datai;/cosputerchecksum*/CooqMJteChecksumC&sendpkt);/ifitisthefirstpacketinwindow,starttimeout*/if(base=nextseqnum)(/startti三er(A,RTT);printf(*sendnewpackets!n*);.)/sendoutpacket/to1.ayer3(Atsendpkt);/copythepackettowindowpacketbuffer/winrear=(winrar+1.)WINDOfSIZE;winbufwinrear=sendpkt;pktnum+;*updatestatevariab1.es/nextseqnum=nextseqnun+1.;*de1.etemessagefrombuffer/msgnum-:e1.seprintf("A:NACKisreceived,donothing!n*):/B端接收数据*肯定要调用这个*Notethatwithsi111.extransferfro®a-to-B,thereisnoB-output0/ca1.1.edfrcM1.ayer3,whenapacketarrivesfor1.ayer4atB*/voidB_input(structpktpacket)(structpktsendpkt;inti;/ifnotcorruptedandreceivedpacketisinorder/if(CheckCorrupted(packet)=FA1.SE)&A(packet,seqnu三=expectedseqnum)printf(>nB:packet%discorrect1.yreceived,sendACK!n*,packet,seqnun);/sendanACKforthereceivedpacket/*createpacket/sendpkt.seqnum=NOTUSED:sendpkt.acknum=expectedseqnum;for(i=0;i<20;i+)sendpkt.pay1.oadi='0'/c(xq)uterchecksum*/ComputeChecksuB(Asendpkt);/sendoutpacket/to1.ayr3(B,sendpkt);/updatestatevariab1.es/expectedseqnum=expectedseqnum÷1.;printf(*B:expectedseqnum=%dn*,expectedseqnum):/de1.iverreceivedpacketto1.ayer5/to1.ayr5(B,packet,pay1.oad);/otherwise,discardthepacketandsendaNACK/e1.seprintf(*B:packet%discorruptedornotIexpects,sendNACK!n*,packet,seqnu);/createpacket/sendpkt.seqnum=NOTUSED;sendpkt.acknum=NACK;for(i=0;i<20;i+)sendpkt.pay1.oadi='0'/coi三puterchecksum/CouteQecksuun(sendpkt);/sendoutpacket/to1.ayr3(B,sendpkt);)/A计时器超时/ca1.1.edwhenA,stimergoesoff/voidA-tinrinterrupt0inti;printf(*A:tineout,resendpackets!n*);/starttimer/Starttimer(A,RTT);/resenda1.1.packetsnotacked/for(i=1.;i<=pktnu三;i+)(packet_resent+;to1.ayer3(A,winbuf(winfront+i)%WINDOISIZE);)./B计时器超时/ca1.1.edwhenB,stimergoesoff/voidB-tinerinterrupt0(inti;printf(*B:timeout,resendpackets!n*);/starttimer/Starttimer(B,RTT);/resenda1.1.packetsnotacked/for(i=1.;i<=pktnum;i+)packet-rsent+;to1.ayer3(B,winbuf(winfront+i)%WINDOfSIZE):)/A端初始化*entityAroutinesareca1.1.ed.Youcanuseittodoanyinitia1.ization/voidA_init0(base=0;nextseqnum=0;buffront=0;bufrear=0;Bsgnum=0;winfront=O;winrar=O;pktnum=O;)/B蟠初始化/entityBroutinesareca1.1.ed.Youcanuseittodoanyinitia1.ization*/voidB_initO(expectedseqnum=0;1初始化仿真器voidinit/initia1.izethesimu1.ator/(inti;f1.oatsum,avg;f1.oatjimsrand();FI1.Etfp;fp=fopenCparaoeter.txt',<r*);printf(*StopandWaitNetworkSiaMi1.atorVersion1.111n*);printf(*Enterthenumberofmessagestosinu1.ate:");/fscanf(fp,*W*,AnSimaX);scanf(*%d*,nsimax);printf(*nEnterpacket1.ossprobabi1.ityenter0.0forno1.oss:*);/fscanf(fp,*%fr,1.ossprob);scanf(*%f*,1.ossprob);printf(*nEnterpacketcorruptionprobabi1.ity0.0fornocorruption:*);/fscanf(fp,*%f*,Acorruptprob);scanf(*%f*,Acorruptprob);printf(>nEnteraveragetimebetweenmessagesfrosender*s1.ayr5>0.0:");/fscanf(fp,*%f*,ft1.abda);Scanfd1.ambda);printf(*nEntrTRACE:*);/fscanf(fp,*%d*,4TRACE);scanf%d*,4TRACE);printf(*nn*);srand(9999);sum=0.0;/initrandonnunbergenerator/testrandomnumbergeneratorforstudents/for(i=0;i<1000;i+)sum=sun+jinsrand();*jinsrand()shou1.dbeuniformin0,1/avg=sum/1000.0;*if(avg<0.25Havg>0.75)(printfC1.tis1.ike1.ythatrandomnumbergenerationonyourmachinen*);printfCisdifferentfroawhatthisemu1.atorexpects.P1.easetaken*);printf(*a1.ookattheroutinejinsrand()intheeu1.atorcode.Sorry,n*);exit(0);/printf%f*,avg);nto1.ayer3=0:n1.ost=0;ncompt=0;time=0.0:/initia1.izetimeto0.0/generate_next_arriva1.0;/initia1.izeevent1.ist/随机数发生器f1.oatjimsrand()(doub1.enum=2147483647;/1.argestint-MACHINEDEPENDENT!I!H!/f1.oatx;/individua1.studentsmayneedtochangem三/x=randmmn;/xshou1.dbeuniformin0,1*/return(x):/'/事务处理部分voidgenerate_next_arriva1.0(doub1.ex,IogO,cei1.;structevent*evptr;f1.oatttine;intte三pint;/if(TRACE>2)/printfGENERATENEXTARRIVA1.:creatingnewarriva1.n*);x=Ianbda*jimsrand0*2;/Xisuniformon0,2*1.aabda/havingmeanof1.ambda/vptr=(structevent*)11a1.Ioc(sizeof(structevent);evptr->evti三e=time+x;evptr->evtype=FR0M_1.AYER5;if(jinsrand()<O.5)evptr->eventity=A;)e1.seevptr->eventity=B;insertevent(evptr);)向事务列表中插入一条新的事务voidinsertevent(structevent*p)(structevent*q,*qo1.d;if(TRACE>2)(tinewi1.1./printf(*INSERTEVENT:is%1.fn*,tine);/printf(*INSERTEVafr:futuretimebe%1.fn>,p->vtime);q=ev1.ist;/qpointstofrontof1.istinIdIiChpstructinserted/if(q=NU1.1.)/*1.istisempty/(ev1.ist=p;p->next=NU1.1.;p->prev=NU1.1.;.)e1.se(for(qo1.d=q;q!=NU1.1.&&p->evtine>q->evtime;q=q->nxt)qo1.d=q;if(q=NU1.1.)/*endof1.ist/(qo1.d->next=p;p->prev=qo1.d;p->next=NU1.1.;)e1.seif(q=ev1.ist)/*frontof1.ist/.p->next=ev1.ist;p->prev=NU1.1.;p->next->prev=p;ev1.ist=p;)e1.se/midd1.eof1.ist/(p->nxt=q;p->prev=q->prv;q->prev->next);q->prev=p;)打印事务列表voidprintv1.ist(structevent*q;inti;printf(,nEvnt1.istFo1.1.ows:n*);for(q=ev1.ist;q!=NU1.1.;q=q->next)(printf(*Eventtime:%f,type:%dentity:%dn*,q->evtime,q->evtype,q->evntity);)printf(*n*);)后动计时器voidStarttiner(intAo,f1.oatincrement)(structevent*q;structevent*evptr;if(TRACE>2)printf(*n:STARTTIMER:startingtiuerat%fn*,time);/benice:checktoseeiftimerisa1.readystarted,ifso,thenwarn/for(q=ev1.ist;q!=NU1.1.&&q->next!=NU1.1.;q=q->next)/for(q=ev1.ist;q!=NU1.1.;q=q->next)if(q->evtype=TIMER_INTERRUPT&&q->evntity=AorB)(/printf(Warning:attepttostartatimerthatisa1.readystartedn*);return;/createfutureeventforwhentimergoesoff/evptr=(structevent)11a1.1.oc(sizeof(structevent);evptr->evtie=time+increment;evptr->vtype=TIMER-INTERRUPT;evptr->ventity=AorB;insertevent(evptr);)停止计时器/ca1.1.edbystud

    注意事项

    本文(云南大学软件学院计算机网络原理实验六实验报告.docx)为本站会员(夺命阿水)主动上传,课桌文档仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知课桌文档(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-1

    经营许可证:宁B2-20210002

    宁公网安备 64010402000986号

    课桌文档
    收起
    展开