计算机网络实验(共19页).doc
《计算机网络实验(共19页).doc》由会员分享,可在线阅读,更多相关《计算机网络实验(共19页).doc(19页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上杭 州 电 子 科 技 大 学实 验 报 告学生姓名:韩民杨 学 号: 指导教师:吴端坡实验地点:1#108 实验时间:2015-4-24一、实验室名称:1#108二、实验项目名称:计算机网络实验1Coding on error dectecting algorithms(C+)三、实验学时:四、实验原理:C+编程五、实验目的:利用C+编程CRC16校验及奇偶校验六、实验内容:Coding on error dectecting algorithms(C+)1. Cyclic redundancy checkUsing the polynomials below to
2、 encode random generated data stream (40-100bits). Show the FEC, and encoded data frame.CRC-4x4+x+1ITU G.704CRC-16x16+x15+x2+1IBM SDLCCRC-32x32+x26+x23+.+x2+x+1ZIP, RAR, IEEE 802 LAN/FDDI, IEEE 1394, PPP-FCSFor the error patter listed below, what the conclusion does the receiver get? Can the receive
3、r find the errors?CaseError patternNo error00000000One error1000.000Two errors100.001Random errorsRandom error pattern2. Parity check Using even or odd parity check on random generated data stream (8-20bits).Show encoded data frame.For the error patter listed below, what the conclusion does the rece
4、iver get? Can the receiver find the errors?CaseError patternNo error00000000One error1000.000Two errors100.001七、实验器材(设备、元器件):PC机一台,装有C+集成开发环境。八、实验步骤:#include#include#include#include#include #include #define NO_ERROR 1#define ONE_ERROR 2#define TWO_ERROR 3#define RANDOM_ERROR 4#define RESULT 1#define
5、 CRC 0#define Parity 0#define check 1int flag_parity;/判断奇偶校验void ByteToBit(char* out,const char* in,int bits);void input_message(char*message);int xor(char *p, char *d,int len);char *crc_function(char *str_p,int len,char *dividend,int len_d,int type,char *crc_p );char Parity_check(char *message_outp
6、ut,int length,int mode);void main()int pattern = 0;int channel_way =0;char message8=NULL;/ data that produced by chance char message_output1000 = NULL;char message_crc = NULL;/transportint length; /messages length/*这是固定了为4为的crc,当这里改变是就可以直接改变crc的长度了*/char dividend=10011;char message_input1000=;/*这里可以
7、更改数值当时16为crc的时候,此时的len_d为15*/int len_d=5;/被除数长度设置char flag;while (true)fflush(stdin);/任意输入数据printf(please input the message!n);gets(message);printf(A need to send this message:%sn,message);length = strlen(message);ByteToBit(message_output,message,length*8);for(int k = 0;klength*8;k+)printf(%d,messag
8、e_outputk);message_inputk = message_outputk+48;pattern = 0;channel_way =0;printf(n);printf(Coding on error dectecting algorithmsn);printf( 1.Cyclic redundancy checkn);printf( 2.Parity check n);printf( please chice pattern: n);/*选择进入的检错模式*/scanf(%d,&pattern);fflush(stdin);/清空缓存区if(pattern = 1)printf(
9、*n);printf( analog channeln);printf( please choice the way of errorn);printf(* 1.No error *n);printf(* 2.One error *n);printf(* 3.Two errors *n);printf(* 4.Random errors *n);scanf(%d,&channel_way);printf(ncrc:);/进行crc检测int len = length*8;/printf(%dn,len);char *crc = NULL;crc = crc_function(message_i
10、nput,len,dividend,len_d,CRC,NULL);for(int i = 0;i len_d;i+)printf(%c,*crc);message_inputlength*8+i = *crc;crc+=1;printf(n);/*模拟信道Case Error patternNo error 00000000One error 1000.000Two errors 100.001Random errorsRandom error pattern*/if(channel_way = NO_ERROR)char *result = NULL;int flagg=0;printf(
11、信道中传输数据:);for(int f =0;flength*8+len_d-1 ;f+)printf(%c,message_inputf);printf(n);printf(正在检错中.n);printf(检错结果:);fflush(stdin);result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(int i = 0;i len_d-1;i+)printf(%c,*result);if(*result) - 48 != 0)printf(n error! n);flagg =1;break;
12、result+=1;if(flagg = 0)printf(n no error! n);if(channel_way = ONE_ERROR)char *result = NULL;message_input0 = (message_input0 - 48)(1-48) + 48;printf(信道中传输数据:);for(int f =0;flength*8+len_d-1 ;f+)printf(%c,message_inputf);printf(n);printf(正在检错中.);printf(检错结果:);result = crc_function(message_input,len,d
13、ividend,len_d,RESULT,crc-len_d);for(int i = 0;i len_d-1;i+)if(*result = 1)printf(data error! n);break;elsecontinue;result+=1;if(channel_way = TWO_ERROR)char *result = NULL;message_input0 = (message_input0 - 48)(1-48) + 48;message_inputlength*8-1 = (message_inputlength*8-1 - 48)(1-48) + 48;printf(信道中
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机网络 实验 19
限制150内