计算机网络实验1

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

杭州电子科技大学实验报告学生姓名:韩民杨学号:12081420指导教师:吴端坡实验地点:1#108实验时间:2015-4-24一、实验室名称:1#108二、实验项目名称:计算机网络实验1Codingonerrordectectingalgorithms(C++)三、实验学时:四、实验原理:C++编程五、实验目的:利用C++编程CRC16校验及奇偶校验六、实验内容:Codingonerrordectectingalgorithms(C++)1.CyclicredundancycheckUsingthepolynomialsbelowtoencoderandomgenerateddatastream(40-100bits).ShowtheFEC,andencodeddataframe.CRC-4x4+x+1ITUG.704CRC-16x16+x15+x2+1IBMSDLCCRC-32x32+x26+x23+...+x2+x+1ZIP,RAR,IEEE802LAN/FDDI,IEEE1394,PPP-FCSFortheerrorpatterlistedbelow,whattheconclusiondoesthereceiverget?Canthereceiverfindtheerrors?CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001RandomerrorsRandomerrorpattern2.ParitycheckUsingevenoroddparitycheckonrandomgenerateddatastream(8-20bits).Showencodeddataframe.Fortheerrorpatterlistedbelow,whattheconclusiondoesthereceiverget?Canthereceiverfindtheerrors?CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001七、实验器材(设备、元器件):PC机一台,装有C++集成开发环境。八、实验步骤:#includestdio.h#includestdlib.h#includememory.h#includestring.h#includeconio.h#includetime.h#defineNO_ERROR1#defineONE_ERROR2#defineTWO_ERROR3#defineRANDOM_ERROR4#defineRESULT1#defineCRC0#defineParity0#definecheck1intflag_parity;//判断奇偶校验voidByteToBit(char*out,constchar*in,intbits);voidinput_message(char*message);intxor(char**p,char*d,intlen);char*crc_function(char*str_p,intlen,char*dividend,intlen_d,inttype,char*crc_p);charParity_check(char*message_output,intlength,intmode);voidmain(){intpattern=0;intchannel_way=0;charmessage[8]={NULL};//datathatproducedbychancecharmessage_output[1000]={NULL};charmessage_crc[]={NULL};//transportintlength;//message'slength/*这是固定了为4为的crc,当这里改变是就可以直接改变crc的长度了*/chardividend[]=10011;charmessage_input[1000]=;/*这里可以更改数值当时16为crc的时候,此时的len_d为15*/intlen_d=5;//被除数长度设置charflag;while(true){fflush(stdin);//任意输入数据printf(pleaseinputthemessage!\n);gets(message);printf(Aneedtosendthismessage:%s\n,message);length=strlen(message);ByteToBit(message_output,message,length*8);for(intk=0;klength*8;k++){printf(%d,message_output[k]);message_input[k]=message_output[k]+48;}pattern=0;channel_way=0;printf(\n);printf(Codingonerrordectectingalgorithms\n);printf(1.Cyclicredundancycheck\n);printf(2.Paritycheck\n);printf(pleasechicepattern:\n);/*选择进入的检错模式*/scanf(%d,&pattern);fflush(stdin);//清空缓存区if(pattern==1){printf(*************************************\n);printf(analogchannel\n);printf(pleasechoicethewayoferror\n);printf(****1.Noerror*****\n);printf(****2.Oneerror*****\n);printf(****3.Twoerrors*****\n);printf(****4.Randomerrors*****\n);scanf(%d,&channel_way);printf(\ncrc:);//进行crc检测intlen=length*8;//printf(%d\n,len);char*crc=NULL;crc=crc_function(message_input,len,dividend,len_d,CRC,NULL);for(inti=0;ilen_d;i++){printf(%c,*crc);message_input[length*8+i]=*crc;crc+=1;}printf(\n);/*模拟信道CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001RandomerrorsRandomerrorpattern*/if(channel_way==NO_ERROR){char*result=NULL;intflagg=0;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......\n);printf(检错结果:);fflush(stdin);result=crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(inti=0;ilen_d-1;i++){printf(%c,*result);if((*result)-48!=0){printf(\nerror!\n);flagg=1;break;}result+=1;}if(flagg==0)printf(\nnoerror!\n);}if(channel_way==ONE_ERROR){char*result=NULL;message_input[0]=((message_input[0]-48)^('1'-48))+48;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......);printf(检错结果:);result=crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(inti=0;ilen_d-1;i++){if(*result=='1'){printf(dataerror!\n);break;}else{continue;result+=1;}}}if(channel_way==TWO_ERROR){char*result=NULL;message_input[0]=((message_input[0]-48)^('1'-48))+48;message_input[length*8-1]=((message_input[length*8-1]-48)^('1'-48))+48;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......);printf(检错结果:);result=crc_function(message_input,len,dividend,len_d,RESULT,crc);for(inti=0;ilen_d-1;i++){if(*result!='0'){printf(dataerror!\n);break;}else{continue;result+=1;}}}if(channel_way==RANDOM_ERROR){char*result=NULL;intno;srand((unsigned)time(NULL));//初始化随机数no=rand()%length*8;message_input[no]=((message_input[0]-48)^('1'-48))+48;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......\n);printf(检错结果:);result=crc_function(message_input,len,dividend,len_d,RESULT,crc);for(inti=0;ilen_d-1;i++){if(*result!='0'){printf(dataerror!\n);break;}else{continue;result+=1;}}}printf(************************************\n);printf(\n);printf(\n);}else{printf(Pleaseselecttheparitymode\n);printf(1.Evenparity\n);printf(2.Oddparity\n);scanf(%d,&flag_parity);charm=Parity_check(message_input,length*8,Parity);printf(在信道中传输的message:);message_input[length*8]=m;for(intmessage_number=0;message_number=length*8;message_number++)printf(%c,message_input[message_number]);printf(\n);printf(**************

1 / 19
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功