计算机网络实验1.doc

上传人:灯火****19 文档编号:137316919 上传时间:2020-07-07 格式:DOC 页数:19 大小:253KB
返回 下载 相关 举报
计算机网络实验1.doc_第1页
第1页 / 共19页
计算机网络实验1.doc_第2页
第2页 / 共19页
计算机网络实验1.doc_第3页
第3页 / 共19页
计算机网络实验1.doc_第4页
第4页 / 共19页
计算机网络实验1.doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《计算机网络实验1.doc》由会员分享,可在线阅读,更多相关《计算机网络实验1.doc(19页珍藏版)》请在金锄头文库上搜索。

1、杭 州 电 子 科 技 大 学实 验 报 告学生姓名:韩民杨 学 号:12081420 指导教师:吴端坡实验地点: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 enco

2、de 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 receiver fin

3、d 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 receiver

4、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 CRC

5、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_output,in

6、t 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,message_out

8、putk);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(*n);p

9、rintf( 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_input,

10、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;resul

12、t+=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,dividend,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)cha

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号