搜档网
当前位置:搜档网 › 有噪声信道的单工协议

有噪声信道的单工协议

有噪声信道的单工协议

实验内容:

有噪声信道的单工停等协议的实现。

实验目的:

了解数据链路层协议的基本原理;

掌握数据链路层的基本流量控制和差错控制的实现方法;

掌握有噪声信道的单工停等协议的工作过程。

实验要求:

选用任一编程工具和编程语言实现;

使用发送端程序和接收端程序实现数据的可靠传输。

实验原理:

在有噪声信道中的数据传输可能由于不确定的原因造成传输数据的丢失,包括发送方发出的信息和接受方返回的确认帧。而在有连接有确实的数据传输过程中要求数据正确无误的传送的接受方,所以在数据链路层的协议上对于各种数据的损坏或丢失都要进行更正。本实验演示了该协议在各种状况(数据丢失,确认丢失,数据延迟)下的处理方式。

原程序:

import java.awt.*;

import java.awt.event.*;

class Thread1 extends Thread{

int tim;

Button b;

Frame f;

Thread1(int t,Frame fra){

tim=t;

b=new Button("0");

b.setForeground(Color.blue);

b.setBounds(10,30,40,30);

f=fra;

f.add(b);

}

public void run(){

if(tim==10){

for(int j=0;j

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(10+5*j,30+20*j,40,30);

}

b.setLabel("丢失");

try{sleep(1000);

}catch(InterruptedException e){}

f.remove(b);

}

if(tim==20){

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(10+5*j,30+20*j,40,30);

}

b.setLabel("1");

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(100+5*j,400-20*j,40,30);

}

try{sleep(1000);

}catch(InterruptedException e){}

f.remove(b);

}

if(tim==40){

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(10+5*j,30+20*j,40,30);

}

b.setLabel("1");

for(int j=0;j<10;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(100+5*j,400-20*j,40,30);

}

b.setLabel("丢失");

try{sleep(1000);

}catch(InterruptedException e){}

f.remove(b);

}

if(tim==50){

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(10+5*j,30+20*j,40,30);

}

b.setLabel("等待");

try{sleep(2000);

}catch(InterruptedException e){}

b.setLabel("1");

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(100+5*j,400-20*j,40,30);

}

try{sleep(1000);

}catch(InterruptedException e){}

f.remove(b);

}

}

}

class Thread2 extends Thread{

int tim;

Button b;

Frame f;

Thread2(int n,Frame fra){

tim=n;

b=new Button("0");

b.setBounds(200,30,30,20);

b.setForeground(Color.blue);

f=fra;

}

public void run(){

try{sleep(40*100);

}catch(InterruptedException e){}

f.add(b);

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(200+5*j,30+20*j,40,30);

}

b.setLabel("1");

for(int j=0;j<20;j++){

try{sleep(100);

}catch(InterruptedException e){}

b.setBounds(300+5*j,400-20*j,40,30);

}

try{sleep(1000);

}catch(InterruptedException e){}

f.remove(b);

}

}

class Event1 implements ActionListener{

Button but[]=new Button[4];

Frame f;

Button head,but1;

Label t1,t2;

public Event1(){

f=new Frame("Event Example");

f.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e)

{System.exit(0);}});

initialize();

}

public void initialize(){

f.setSize(800,500);

f.setLayout(null);

but[0]=new Button("正常");

but[1]=new Button("数据丢失");

but[2]=new Button("确认丢失");

but[3]=new Button("延迟");

for(int i=0;i<4;i++){

but[i].setBounds(700,40+50*i,70,25);

but[i].addActionListener(this);

f.add(but[i]);

}

t1=new Label("发送方");

t1.setBounds(610,30,50,30);

t1.setForeground(Color.red);

f.add(t1);

t2=new Label("接受方");

t2.setBounds(610,400,50,30);

t2.setForeground(Color.red);

f.add(t2);

head=new Button();

head.setBounds(10,30,600,10);

head.setBackground(Color.blue);

f.add(head);

but1=new Button();

but1.setBounds(10,400,600,10);

but1.setBackground(Color.blue);

f.add(but1);

f.setVisible(true);

}

public void actionPerformed(ActionEvent e){

if(e.getSource()==but[0]){

Thread1 t1=new Thread1(20,f);

t1.start();

}

else if(e.getSource()==but[1]){

Thread1 t1=new Thread1(10,f);

Thread2 t2=new Thread2(10,f);

t1.start();

t2.start();

}

else if(e.getSource()==but[2]){

Thread1 t1=new Thread1(40,f);

Thread2 t2=new Thread2(40,f);

t1.start();

t2.start();

}

else if(e.getSource()==but[3]){

Thread1 t1=new Thread1(50,f);

Thread2 t2=new Thread2(50,f);

t1.start();

t2.start();

}

}

public static void main(String args[]){

new Event1();

}

}

运行结果:

(1)当选择“数据丢失”时,从发送方发出的数据在半途中丢失(如下图1),接受方没收到数据,不发送确认帧回去,发送方因为超时重发数据(如图2)。

图1

图2

(二)当选择“确认丢失”时,接受方接到发送方发来的数据并把确认帧发出去,但确认帧在途中丢失(如图3),发送方因为没有收到确认帧而超时重发。发送方接到同一个数据再发一个确认帧回复,并把

数据丢弃(如图4)。

图3

图4

(三)当选择“延迟”时,接受方接到数据并把确认帧发出,但数据或确认帧在途中延迟(如图5),使得发送方等待超时重发。当发送方接到超时的确认帧,与自己期待的确认帧不同则丢弃该帧;接受方接到发送方重发的数据,与之前的数据重复,也丢弃之。

图5

图6

第三章 信道与噪声

通信原理电子教案 第3章信道与噪声 学习目标: 信道的数学描述方法; 恒参信道/随参信道及其传输特性; 加性高斯白噪声; 信道容量的概念。 重点难点:调制信道模型;编码信道模型;恒参信道对信号传输的影响;加性高斯白噪声;Shannon信道容量公式。随参信道对信号传输的影响;起伏噪声;噪声等效带宽;连续信道的信道容量“三要素”。随参信道特性的改善。 课外作业: 3-5,3-11,3-16,3-19,3-20 本章共分4讲 《通信原理》第九讲 知识要点:信道等义、广义信道、狭义信道,调制信道和编码信道。 §3.1 信道定义与数学模型 1、信道定义 信道是指以传输媒质为基础的信号通道。信道即允许信号通过,又使信号受到限制和损害。 研究信道的目的:建立传播预测模型;为实现信道仿真器提供基础。 狭义信道仅指信号的传输媒质,这种信道称为狭义信道;广义信道不仅是传输媒质,而且包括通信系统中的一些转换装置,这种信道称为广义信道。狭义信道按照传输媒质的特性可分为有线信道和无

线信道两类。有线信道包括明线、对称电缆、同轴电缆及光纤等。 广义信道按照它包括的功能,可以分为调制信道、编码信道等。 图3-1 调制信道和编码信道 2、信道的数学模型 信道的数学模型用来表征实际物理信道的特性,它对通信系统的分析和设计是十分方便的。下面我们简要描述调制信道和编码信道这两种广义信道的数学模型。 1. 调制信道模型 图3-2 调制信道模型 二端口的调制信道模型其输出与输入的关系有 一般情况下,可表示为信道单位冲击响应与输入信号的卷积,即 或 其中,依赖于信道特性。对于信号来说,可看成是乘性干扰,而为加性干扰。 在实际使用的物理信道中,根据信道传输函数的时变特性的不同可以分为两大类: 一类是基本不随时间变化,即信道对信号的影响是固定的或变化极为缓慢的,这类信道称为恒定参量信道,简称恒参信道; 另一类信道是传输函数随时间随机快变化,这类信道称为随机参量信道,简称随参信道。 在常用物理信道中,的特性有三种典型形式。 是常数,或在信号频带范围之内是常数,即 在信号频带范围之内不是常数,但不随时间变化,即 。 在信号频带范围之内不是常数,且随时间变化,即 , 2. 编码信道模型

相关主题