云南大学软件学院计算机网络原理实验六实验报告.docx
《云南大学软件学院计算机网络原理实验六实验报告.docx》由会员分享,可在线阅读,更多相关《云南大学软件学院计算机网络原理实验六实验报告.docx(50页珍藏版)》请在课桌文档上搜索。
1、试验六、传输层牢靠传输协议GBN编程试验报告序号:一姓名:_学号:成果一指导老师:一、试验目的;1、通过编写实现一个简洁牢旅的数据传输协议GBN的发送和接收代码,模拟牢靠数据传输2、理解TCP协议牢轮传输的差错检测、重传、累计确认、定时器的牢拳传输策略。二、试验指导:参考教材。动画演示:三、试验要求:编程实现一个GBN传输协议的发送方和接收方两程序,采纳编程语言不限,要求能将发送一一接收流程以与处理方法表现出来.1.试验流程图如下:OX选择由传2.试验截图与代码如下:截图:GUtrfQiuD*cktopitHfi6GBN001DbugGBN001xe-StopandVaitNetworkSit
2、nj1.atorVersion1.1Snterthenumberofmessagestosinu1.ate:56Enterpacket1.ossprobabi1.ityenterO.Oforno1.oss:3Enterpacketcorruptionprobabi1ityO.Oornocorruption:OSnteraveragetimebetweenEfiSSaEeSfromsenders1.ayer5O.0:1interTRACE:3A:IfeWJ119ssagarrives,sendWindWisfu1.1.,buffernewmessage!entity:0aaaaaaaaaaaaa
3、aaaaaaafu1.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:K
4、ewmessagearrives,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:
5、I,fro11dayer5entity:0Siwj1.atorterminatedattime0.000928aftersending56sgsfromIayer5correct1.ysentpkts:9resentpkts:0青按任意道继续代码与注样:一、GBN.hpragmaonceinc1.ude基础功能模块的数据结构声明#defineBIDIRECTIONA1.1*changeto1ifyouredoingextracreditandwritearoutineca1.1.edB_output/a*msg*isthedataunitpassedfro三1.ayer5(teachersco
6、de)to1.ayer4(studentscode).Itcontainsthedata(characters)tobede1.iveredto1.ayer5viathestudentstransport1.eve1.protoco1.entities.*/structmsgchardata20;;/apacketisthedataunitpassedfrom1.ayer4(studentscode)to1.ayer3(teacherscode).Notethepre-definedpacketstructure,whicha1.1.studentsmustfo1.1.ow./structpk
7、t(intseqnus;intacknun;intchecksum;charpay1.oad20;);#defineWINDOfSIZE8#defineMAXBUFSIZE50defineRTT15.0WefineNOTUSED0ffdefineNACK-1MefineTRUE1defineFA1.SE0#defineB1网络仿真部分数据结构声明structeventf1.oatevtine;*eventtine/intevtype;/eventtypecode*/inteventity;/entitywhereeventoccurs*/structpkt*pktptr;/ptrtopacke
8、t(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蟠向外发送数据void
9、A_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(structeven
10、t*p);向事务列表中插入一条新的事务voidPrinteV1.iSt();打印事务列表/aVb/9K91Vkajj1.jK2Bb1.jjKj2BJf1.1.scjK2BZZB1.S1.jjKjKH1.?B1.SCJK3K2HjU1.2f1.1.MCJKjKZB1.B1.jBCjKKZ0ZB2H1.IHCjkjKZf1.31.Jf1.JKK*计时器模块voidStoPtimer(int);停止计时器voidStarttiBer(int,f1.oat);启动计时器/aaTj1.jK2KS1.Jb1.jKijB1.k2HS1.jHjkjKjKJk1.BcjKjKjK2K2S1.jKjKJf1.1.
11、XCJKjKjKJkB1.jCjKAIH网络各层之间传送模块voidto1.ayer3(intAorB,structpktPaCket);向第3层发送信voidto1.ayer5(intAorB,chardatasent20);向第5层发送信息二、GBN.cinc1.ude*GBN.h*ffinc1.udetfinc1.udeinc1.udeexternintTRACE=1;/formydebugging/为我的调试externintnsin=0;/nunberofmessagesfro三5to4sofar*/目前为止信息的数字是从5到4externintnsinnax=0;/numberof
12、msgstogenerate,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/被传送到第
13、三层的数据staticintn1.ost=0;*nunber1.ostinmedia*/在媒介中数据丢失staticintncorrupt=0;/nu)rcorruptedbymedia*/被媒介毁坏的数据staticintexpectedseqnun=O;*expectedsequencenumberatreceiverside/.在接收者这边接收到Bi期的序列数据staticintnextseqnum;*nextsequencenumbertouseinsenderside/.下一个序列数据运用在发送者这边staticintbase;*theheadofsenderwindow/发送者的头
14、窗口structpktwinbufWINDOWSIZE;*windowpacketsbuffer/.数据包缓冲区窗口staticintwinfront,winrear;/frontandrearpointsofwindowbuffer/窗口缓冲区的前方点和后方点staticintPktnuI;/packetnumberofwindowbuffer/窗口缓冲区的数据包个数structmsgbufferMAXBUFSIZE;/senderessagebuffer/.发送消息缓冲区intbuffront,bufrear;/frontandrearpointersofbuffer/.缓冲区的前指针与后
15、指针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-s
16、eqnun;checksum=checksu+packet-acknun;for(i=0;ipay1.oadi);CheCkSUm=0-chcksu三;packet-checksun=checksun;)检查是否出错intCheckCorrupted(structpktpacket)(intchecksum;inti;checksum=packet,seqnun;checksum=checksum+packet,acknm;for(i=0;i20;i+)checksum=checksum+(int)(packet,pay1.oadi);if(packet,checksunr+checksua)
17、=0)return(FA1.SE);e1.sereturn(TRUE);)/A端向外发送数据/ca1.1.edfrom1.ayer5,passedthedatatobesenttootherside/voidA_output(structmsgnessage)(inti;structpktsendpkt;/ifwindowisnotfu1.1./if(nextseqnumbase+WINDOWSIZE)(printf(*A:Newmessagearrives,sendWindO1.risnotfu1.1.,sendnewmessgeto1.ayer3!n*);/createpacket/sen
18、dpkt.seqnum=nextseqnum;sendpkt.acknum=NOTUSED;for(i=0;i20;i+)sendpkt.pay1.oadi=nessage.datai:/cM三puterchecksum/CoaputeChecksun(Isendpkt);/sendoutpacket/to1.ayer3(A,sendpkt);/copythepackettowindovpacketbuffer*/winrear=(winrar+1.)%WINDOWSIZE;pktnun+;vinbufwinrear=sendpkt;for(i=0;i20;i+)winbufwinrear.p
19、ay1.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);)/o
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 云南大学 软件 学院 计算机网络 原理 实验 报告
链接地址:https://www.desk33.com/p-1672116.html