大学计算机网络实验6-Go-back-n协议
北京邮电大学2013-2014学年计算机网络期中考试题

北京邮电大学2013-2014年第一学期《计算机网络》期中考试试题一.判断题(共10分,每题1分)判断下面的每项陈述是否正确,正确的答√,错误的答×。
1.()数据链路层采用Go Back N 协议,发送方已经发送了编号为0-7的帧,当计时器超时时,发送方收到应答序号为1、3和5的确认帧,则发送方需要重发的帧数是2。
2.()双绞线和同轴电缆相比,双绞线有更高的带宽,而且价格便宜,所以在计算机通信领域双绞线比同轴电缆使用得更普遍。
3.()与调制解调器(MODEM)相比,使用ADSL技术不需要讲计算机输出的数字信号调制为模拟信号,所以,ADSL能提供比MODEM拨号上网快得多的传输速率。
4.()使用一个带宽8MHz的信道,由于各层包头的开销和成帧的开销,如果仅统计应用层的数据传输速率,速率必低于1M字节/秒。
5.()奈奎斯特(Nyquist)不仅适用于铜线,也适用于光纤。
6.()两站之间采用Go-Back-N协议传送数据,若序号的比特数为4,则发送窗口的最大值是3。
7.()虚电路网络不需要像数据报网络实现从任意源到任意目的地的路由选择的能力。
8.()传统10Mbps以太网的波特速率是5M波特。
9.()在HDLC协议中,当接收方检测到帧差错时,可以发送RNR帧,请求迅速重传该帧。
10.()ppp是面向连接的协议,但不是可靠传输的协议。
二.计算题(共25分)1.(5分)一个系统有n层协议的层次结构,应用程序产生的消息长度为m字节,每层需要加h字节的头,这些头需要占用的网络带宽的比例为多少?2.(5分)在点到点信道上,假设数据帧传输出错的概率是P,应答帧从不出错,求要成功发送一帧的平均传送次数。
1 / 4。
自考计算机网络原理典型题(卷子)

自考计算机网络原理典型题(卷子)《计算机网络原理》计算应用题一、数据通信技术(1)知识点1.数据传输速率(比特率)的定义及公式:每秒传输的二进制位数。
r=1/t*log2n(1)按nyquist定理最小管制的数据速率就是多少?(2)若信噪比为30db,按shannon定理最大限制的数据速率是多少?5.设立利用12mhz的取样频率对信号展开取样,若定量级为4,先行排序表面化并无噪声信道中的数据传输速率和所需的信道频宽。
(建议写下排序过程)对于带宽为4khz的语音信号,采用量化级为128的脉码调制编码,问所产生的二进制位起码要用多n如果在信道上发送一比特二进制信号所需时间位0.05ms,那么通信信道的数据传输速率为__________。
2、码元速率(信号传输速率、调制速率、波特率)的定义及公式:b=1/tr=b*log2信号传输速率为1200baud,每个码元可行4种线性状态,该信号的数据传输速率为__________。
3、奈奎斯特公式:b=2hc=2h*log2n每赫兹带宽的理想低通信道的最高码元传输速率为每秒__________个码元。
普通电话线路带宽约3khz,则码元速率极限值为_________。
4、香农公式:c=h*log2(1+s/n)分贝公式:10log10(s/n)10lgs/n5、取样定理:取样频率大于等同于信号频率的2倍。
6、数据编码的三过程:取样、定量、编码7、量化与编码位数的关系:量化级别=以2为底编码位数次幂8、调幅、调频、调相小传输速率的信道就可以传输?设信号的采样量化级为256,若要使数据传输速率达到64kbps,试计算出所需的无噪声信道的带宽和信号调制速率。
(要求写出计算过程)使用脉码调制方法对模拟信号展开编码,每次取样采用256个定量级展开定量,若数据传输速率为64kbps,那么每秒钟取样的次数就是多少次?6.采用8种相位,每种相位各有4种幅度的pam调制方法,问在2400波特的信号传输速率下,能达到的数据传输率是多少?某调制解调器同时采用幅移键控和相移键控,使用0、兀/2、兀和3/2兀四种增益,每种增益又都存有两个相同的幅值,反问在波特率为1200的情况下数据速率就是多少?设有一调制解调器波特率为9600baud,采用pam调制技术,共有6种相位,其中2种相位每个相位各有2个幅度,则数据传输速率为多少?当采用1位校验位、2位停止位、8位数据位的异步传输时,该调制解调器的有效速率为多少?第1页共9页(2)典型题1.对于频宽为6mhz的信道,若用8种相同的状态则表示数据,在不能考量热噪声的情况下,该信道每秒最多能传送的位数为多少?若电视信道的带宽为6mhz,假定无噪声并使用4电平的数字信号,每秒钟能发送的比特数不会超过多少?2.对于频宽为3khz的信道,若存有8种相同的物理状态去则表示数据,信噪比为20分贝,反问按奈斯特定理最大限制的数据速率是多少?3.若要在一条50khz的信道上传输1.544mbps的之下载波,信噪比至少为多少?4.对于带宽为3khz的信道,若有8种不同的物理状态来表示数据,请问:二、曼彻斯特与三种技术(1)知识点1、标准曼彻斯特:滑动在中间,0、1看看前半;差分曼彻斯特:翻转在中间,0、1看起点,有跳是0,无跳是12、三种调制技术:调频:0低频,1高频;调幅:0无幅,1有幅;皮斯基:00二者,1180°3、三种复用技术:频分多路复用、时分多路复用和波分多路复用技术的同时实现条件及工作原理。
计算机网络教程第五版课后答案

数据按序到达
分组可能失序
建立连接后通信过程中不再需要地址
所有分组都携带地址或相关控制信息
端到端时延确定
端到端时延不确定
适合大量实时数据的传输
适合突发数据的传输
1-4为什么说因特网是自印刷术以来人类通信方面最大的变革?
解答:因特网已成为仅次于全球电话网的世界第二大网络,缩小了人际交往的时间和空间,大大改变着我们工作和生活的各个方面。
客户:在计算机网络中进行通信的应用进程中的服务请求方。
服务器:在计算机网络中进行通信的应用进程中的服务提供方。
客户-服务器方式:通常指的是一种网络应用程序的工作方式。客户-服务器方式所描述的是进程之间服务和被服务的关系。客户是服务请求方,服务器是服务提供方。服务器总是一直运行并被动等待通信,而客户总是主动发起通信。服务器可以同时处理多个客户的请求,而客户程序之间不直接进行通信。
1-2试简述分组交换的要点。
解答:分组交换采用存储转发技术,当需要发送数据时无需在源和目的之间先建立一条物理的通路,而是将要发送的报文分割为较小的数据段,将控制信息作为首部加在每个数据段前面(构成分组)一起发送给分组交换机。每一个分组的首部都含有目的地址等控制信息。分组交换网中的分组交换机根据分组首部中的控制信息,把分组转发到下一个分组交换机。用这种存储转发方式将分组转发到达最终目的地。
解答:分组交换时延为: 。电路交换时延为: 。因此,分组交换时延较电路交换时延小的条件为:
1-11在上题的分组交换网中,设报文长度和分组长度分别为x和(ph)(bit),其中p为分组的数据部分的长度,而h为每个分组所带的控制信息固定长度,与p的大小无关。通信的两端共经过k段链路。链路的数据传输速率为b(bit/s),结点的排队时间可忽略不。若打算使总的时延为最小,问分组的数据部分长度p应取多大?
数据通信与计算机网络第五版(习题答案)——第三章数据链路层

数据通信与计算机网络第五版第三章数据链路层3-1 数据链路(即逻辑链路)与链路(即物理链路)有何区别?“电路接通了”与“数据链路接通了”的区别何在?解答:所谓链路就是从一个结点到相邻结点的一段物理线路,而中间没有任何其他的交换结点。
在进行数据通信时,两个计算机之间的通信路径往往要经过许多段这样的链路。
可见链路只是一条路径的组成部分。
数据链路则是另一个概念。
这是因为当需要在一条线路上传送数据时,除了必须有一条物理线路外,还必须有一些必要的通信协议来控制这些数据的传输(这将在后面几节讨论)。
若把实现这些协议的硬件和软件加到链路上,就构成了数据链路。
这样的数据链路就不再是简单的物理链路而是个逻辑链路了。
“电路接通了”仅仅是物理线路接通了通信双方可以在上面发送和接收0/1比特了,而“数据链路接通了”表明在该物理线路接通的基础上通信双方的数据链路层协议实体已达成了一致并做好了在该链路上发送和接收数据帧的准备(可能互相要协商某些数据链路层参数)。
3-2 数据链路层包括哪些主要功能?试讨论数据链路层做成可靠的链路层有哪些优点和缺点。
解答:数据链路层的链路控制的主要功能包括:封装成帧、透明传输和差错检测,可选功能包括可靠传输、流量控制等。
在数据链路层实现可靠传输的优点是通过点到点的差错检测和重传能及时纠正相邻结点间传输数据的差错。
若在数据链路层不实现可靠传输由高层如运输层通过端到端的差错检测和重传来纠正这些差错会产生很大的重传时延。
但是在数据链路层实现可靠传输并不能保证端到端数据传输的可靠,如由于网络拥塞导致路由器丢弃分组等。
因此,即使数据链路层是可靠的,在高层如运输层仍然有必要实现端到端可靠传输。
如果相邻结点间传输数据的差错率非常低,则在数据链路层重复实现可靠传输就会给各结点增加过多不必要的负担。
3-3 网络适配器的作用是什么?网络适配器工作在哪一层?解答:网络适配器的作用就是实现数据链路层和物理层的功能。
适配器接收和发送各种帧时不使用计算机的CPU 。
arq 名词解释(一)

arq 名词解释(一)ARQ 名词解释ARQ(Automatic Repeat reQuest)是一种通信协议,用于在数据传输过程中检测和纠正错误。
在计算机网络和通信领域中,ARQ被广泛使用以确保数据传输的可靠性和完整性。
以下是与ARQ相关的一些名词及其解释:1. Stop-and-Wait ARQStop-and-Wait ARQ是一种最简单的ARQ协议。
发送方在发送数据后等待接收方的确认,只有在收到确认后才发送下一个数据包。
这种协议的优点是简单易实现,缺点是效率低下,因为发送方必须等待确认才能发送下一个数据包。
例子:发送方发送一个数据包给接收方,然后等待来自接收方的确认消息。
接收方收到数据包后发送确认消息给发送方。
如果发送方在一定时间内未收到确认消息,则会认为数据包丢失,重新发送该数据包。
2. Go-Back-N ARQGo-Back-N ARQ是一种基于滑动窗口的ARQ协议。
发送方可以连续发送多个数据包而无需等待确认,接收方按序接收数据包并发送确认消息。
如果接收方检测到某个数据包有错误,它会丢弃该数据包以及后续的所有数据包,并要求发送方重新传输从丢失的数据包开始之后的所有数据包。
例子:发送方按顺序发送数据包0、1、2、3、4。
接收方按顺序接收数据包0、1,但数据包2出现错误,接收方发送确认消息请求发送方重新传输从数据包2开始的数据包。
发送方重新发送数据包2、3、4。
3. Selective Repeat ARQSelective Repeat ARQ也是基于滑动窗口的ARQ协议。
发送方可以连续发送多个数据包,接收方按序接收数据包并发送确认消息。
与Go-Back-N不同的是,接收方可以丢弃出错的数据包,而不需要重新传输之前的所有数据包。
例子:发送方按顺序发送数据包0、1、2、3、4。
接收方按顺序接收数据包0、1,但数据包2出现错误,接收方丢弃数据包2并发送确认消息请求发送方重新传输数据包2。
计算机网络之ARQ协议

计算机网络之ARQ协议ARQ协议,全称为Automatic Repeat Request(自动重传请求),是一种常用的计算机网络中用于可靠数据传输的协议。
它通过在发送端和接收端之间进行数据包的确认和重传,来确保数据的可靠传输。
ARQ协议是一种基于反馈机制的协议,它根据接收端对数据包的确认或否认进行相应的处理。
一般而言,ARQ协议分为停止-等待ARQ、连续ARQ(Go-Back-N ARQ和选择性重传ARQ)等不同类型。
1. 停止-等待ARQ停止-等待ARQ是一种最简单的ARQ协议。
发送端发送一个数据包后,会停止发送并等待接收端的确认。
接收端收到数据包后,会发送一个确认信息给发送端,表示该数据包已经成功接收。
如果发送端在一定时间内没有收到确认信息,就认为该数据包丢失,会进行重传。
停止-等待ARQ的特点是简单,但效率较低。
发送端必须等待确认信息才能发送下一个数据包,无法充分利用网络带宽。
2. 连续ARQ连续ARQ是相对于停止-等待ARQ而言的一种改进协议。
它允许发送端连续地发送多个数据包,而不需要等待每个数据包的确认。
2.1 Go-Back-N ARQGo-Back-N ARQ是一种基于滑动窗口的连续ARQ协议。
发送端维护一个发送窗口,其中包含了多个已发送但未收到确认的数据包。
接收端维护一个接收窗口,其中包含了多个按顺序到达的数据包。
发送端发送数据包后,不需要等待确认即可继续发送下一个数据包。
接收端在正确接收到数据包时,发送一个累积确认,表示已成功接收到所有数据包。
如果接收端检测到有数据包丢失或损坏,会要求发送端进行重传。
Go-Back-N ARQ的特点是简单有效,但可能会出现连续数据包被丢失而导致的重复传输。
2.2 选择性重传ARQ选择性重传ARQ是一种更加精细的连续ARQ协议。
发送端维护一个发送窗口,其中包含了多个已发送但未收到确认的数据包。
接收端维护一个接收窗口,其中包含了多个按顺序到达的数据包。
简述go-back-n策略的基本原理
简述go-back-n策略的基本原理
Go-Back-N(GBN)是一种常用的拥塞控制策略,它主要用于面向连接的网络
环境中,被广泛用于TCP协议,是一种可靠的数据传输策略。
它是由NICAMAC公司发明的,即网络有序报文中的”向后移动N“策略。
主要基本原理是:探查的数据
报文会以递增的方式发送,发现丢包后,则停止发送,让发送方重发编号小于出现丢包的号码的报文,这一策略不断重复下去,直至接收到即将报文确认后重新恢复发送,以此达到可靠传输的目的。
Go-Back-N策略首先由源端发送端发出数据报文,然后进行确认,当等待超时
或者接收端重新发送确认时,源端发送端就会重新发送丢失的数据报文。
这种策略的优点是发送端在未收到接收端的确认时可以继续发送,使传输效率大大提高,但是缺点是如果接收方失去了太多数据报文,那么重传可能会超出网络缓冲区的容量,最终导致系统堵塞。
Go-Back-N在高校和高等教育中也是一种被广泛使用的传输策略,例如学校隔
离系统、网络实验,以及智能教学和课堂特殊实验要求较高的地方。
可以应用Go-Back-N策略,使传输速度增快,并有效控制网络拥塞,但要注意避免数据报文的
完整性被破坏,以及丢包的频繁出现,有效的把握数据的传输,避免数据的安全加密被攻破。
Go-Back-N策略是一种拥塞控制技术,它在高校和高等教育中有广泛的应用,其优
点是发送端在未收到接收端的确认时可以继续发送,使传输效率大大提高,但同时也有一定的缺点,要提高网络传输的可靠性,就需要注意控制丢包率,并且要保持数据报文的完整性和加密安全性。
计算机网络--滑动窗口实验报告
计算机网络--滑动窗口实验报告计算机网络滑动窗口协议实验报告目录一、实验内容和实验环境描述(2)1.实验内容(2)2.实验目的(2)3.实验环境(2)二、协议设计(3)三、软件设计(4)Part A 选择重传协议1.数据结构(4)2.模块结构(6)3.算法流程(7)Part B gobackn协议 1.数据结构(8)2.模块结构(9)3.算法流程(10)四、实验结果分析(11)五、探究问题(13)六、实验总结与心得体会(14)一、实验内容和实验环境描述1.实验内容利用所学数据链路层原理,自己设计一个滑动窗口协议,在仿真环境下编程实现有噪音信道环境下两站点之间无差错双工通信。
信道模型为8000bps全双工卫星信道,信道传播时延270毫秒,信道误码率为10?5,信道提供字节流传输服务,网络层分组长度固定为 256 字节。
2.实验目的通过该实验,进一步巩固和深刻理解数据链路层误码检测的CRC校验技术,以及滑动窗口的工作机理。
滑动窗口机制的两个主要目的:(1)实现有噪音信道环境下的无差错传输;(2)充分利用传输信道的带宽。
在程序能够稳定运行并成功实现第一个目标之后,运行程序并检查在信道没有误码和存在误码两种情况下的信道利用率。
为实现第二个目标,提高滑动窗口协议信道利用率,需要根据信道实际情况合理地为协议配置工作参数,包括滑动窗口的大小和重传定时器时限以及 ACK 搭载定时器的时限。
3.实验环境Windows10环境PC机Microsoft Visual Studio 2017集成开发环境二、协议设计本次试验主要设计数据链路层,实验中分别设计了gobackn协议与选择重传协议。
主要涉及到的层次结构是物理层、数据链路层、网络层。
物理层:为数据链路层提供的服务为8000bps,270ms传播延时,10?5误码率的字节流传输通道。
数据链路层利用接口函数send_frame()和 recv_frame()从物理层发送和接收一帧。
Go-Back-N Java程序,真正的好东西
国外教材《计算机网络》Go-Back-N Java程序,形象生动,学习效果很好。
/** This Go Back N Applet was designed to be used in conjunction with * "Computer Networking: A Top Down Approach"* by James Kurose & Keith Ross.* Terminology and specifications are based upon their description of the* Go Back N protocol in chapter 3, section 4.** Original Applet coded by Shamiul Azom as project assigned by * Prof. Martin Reisslein, Arizona State University* Course No. EEE-459/591. Spring 2001** Applet significantly revised by Matthew Shatley and Chris Hoffman * for Professor Paul D. Amer (amer@)* University of Delaware (2008)** Applet updated Feb. 2012 by Chris Hoffman to fix GoBackN text output * to reflect the single timer implementation of Go Back N, as outlined * on pg 234 in the 5th edition of the aforementioned text.** A note on magic numbers: Magic numbers are horrible to have in your code in general.* However, the graphics components of this applet provided no good way to remove the* magic numbers from the code as locations for objects are specified in pixel coordinates.* We apologize in advance for any confusion this may cause in reading the code.*/import java.applet.Applet;import java.awt.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class GBN extends Applet implements ActionListener, Runnable {private static final int ADVANCE_PACKET = 5;// Default values of parameters for animation// sender_window_len_def the sender can have a maximum of 5 outstanding // un-acknowledged packetsfinal int sender_window_len_def = 5;// how many packets the receiver can hold in memory without delivering data// in the case of GBN we can hold 1(or the current packet) in memory // if another packet arrives the one in memory is discardedfinal int receiver_window_len = 1;// GUI components to describe how the Simulation should be drawn final int pack_width_def = 10;final int pack_height_def = 30;final int h_offset_def = 100;final int v_offset_def = 50;final int v_clearance_def = 300;//used for timeout values, thread.sleep() is specified in milliseconds //so we convert to seconds for timeout processing.(1000 milliseconds = 1 second)final int TIMEOUT_MULTIPLIER = 1000;final int MIN_FPS = 3;final int FPS_STEP = 2;final int DESELECTED = -1;final int DEFAULT_FPS = 5;//default to 20 packets if no value is suppliedfinal int total_packet_def = 20;// 25 sec default timeout for retransmissionsfinal int time_out_sec_def = 25;// Default colors of different packets// these have been matched as closely to the the text as possible // Order of color values Red, Green, Bluefinal Color unack_color = new Color(204, 230, 247);final Color ack_color = Color.yellow;final Color sel_color = Color.green;final Color roam_pack_color = new Color(204, 230, 247);final Color roam_ack_color = Color.yellow;final Color dest_color = Color.red;final Color received_ack = new Color(37, 135, 234);// base - our sending base - the next expected packet to be received // nextseq - the next sequence number that will be given to a newly created// packet// selected - the index of the currently selected packet in transmission// lastKnownSucPacket - LAST KNOWN SUCcessful PACKET received by receiving// nodeint base, receiver_base, nextseq, fps, selected = DESELECTED, timeout, timeoutPacket, lastKnownSucPacket;boolean timerFlag, timerSleep;// define our buttons for actions available to be taken by the user Button send, stop, fast, slow, kill, reset;/** 2 threads run for the applet gbnTread - runs to create our animation and* process packets timerThread - created and sleeps for a specified period* of time. On wake up performs timeout processing A timeout causes all of* the outstanding packets to be re-transmitted. NOTE: Thetext(Computer* Networking: A Top Down Approach) specified a per packet timer, however* this is rarely implemented as there is a significant overhead in using* that many timers. Logically, the only packet that would ever timeout is* the left most edge of the sending window as this has been in transmission* the longest. Since a per packet timer system is not implemented in * practice we have simulated per packet timers per the books description* while using only a single timer.*/Thread gbnThread, timerThread;TextArea output; // output variable used to write information in the text// boxDimension offDimension;Image offImage; // implements double buffering to proved a smoother // animationGraphics offGraphics; // graphics component used for drawingGoBackNPacket sender[]; // sender array - holds the packets being sent // Declaring properties of our windowint window_len, pack_width, pack_height, h_offset, v_offset,v_clearance,total_packet, time_out_sec;/*************************************************************************** Method init *************************************************************************** Purpose: init method to set up applet for running - first methodcalled* on loading the code. Attempts to load parameters passed from HTMLcode* contained in the website. If there is an error or no parametersare* provided then the default values(declared above) are used.* Global variables used: sender - array holding the packets and the* corresponding acks for the packets sent in the applet* output - console window for applet activities & messages**************************************************************************/public void init() {// prevents layout manager from adjusting components in the applet// The buttons made it easier to deal with pixel coordinates// than recode for layout managersetLayout(null);output = new TextArea(150, 150); // setup output box// create text area for console output boxoutput.setBounds(0, 400, 650, 250); // set bounds for output boxoutput.setEditable(false); // prevent user from editing outputwritten// to consoleadd(output); // tell applet to draw our output boxsetupSimulationParams();base = 0; // Defining our base to be 0 the first packet number// expectedreceiver_base = 0; // Set the receiver base number to 0, which is the// first index in the receiver arraynextseq = 0; // Defining next sequence number for next packet sent. fps = DEFAULT_FPS; // Defining default Frame per Second for our animation// create a shared array, used for both the sender and the receiver // nodes.// all packets will be created and processed from this arraysender = new GoBackNPacket[total_packet];// Defining the buttons - creates the button and text to go on the // buttonsend = new Button("Send New");// set the command to be performed when button is pressed this command// is used// to determine which button was pressed in the actionPerformed methodsend.setActionCommand("rdt");// on button pushed the actionPerformed method of this class is called// and appropriate action is taken depending on the button pressed send.addActionListener(this);// set the size and location of this button (of form (x, y, width, // length)// this is specified in pixel coordinatessend.setBounds(0, 0, 90, 20);// same structure as abovestop = new Button("Pause");stop.setActionCommand("stopanim");stop.addActionListener(this);stop.setBounds(90, 0, 90, 20);fast = new Button("Faster");fast.setActionCommand("fast");fast.addActionListener(this);fast.setBounds(180, 0, 90, 20);slow = new Button("Slower");slow.setActionCommand("slow");slow.addActionListener(this);slow.setBounds(270, 0, 90, 20);kill = new Button("Kill Packet/Ack");kill.setActionCommand("kl");kill.addActionListener(this);kill.setEnabled(false);kill.setBounds(360, 0, 90, 20);reset = new Button("Reset");reset.setActionCommand("rst");reset.addActionListener(this);reset.setBounds(450, 0, 90, 20);// Adding the buttons to our applet window so they can be renderedand// usedadd(send);add(stop);add(fast);add(slow);add(kill);add(reset);// print out message about the new authors of the codeoutput.append("- GoBackN Applet written by Matt Shatley & Chris Hoffman\n");output.append("- Advised by Professor Paul D. Amer (amer@),U of Delaware, 2008\n");output.append("- Updated by Chris Hoffman and Professor Amer,2012\n\n");// tell user we are ready to begin demonstrating Go Back Noutput.append("-Ready to run. Press 'Send New' button tostart.\n");}// End init() method/**************************************************************************** Method Start **************************************************************************** Purpose: Start method required for implementing multi-threading.Start is* the first method called by a thread after creation.* Procedures Calling: run* Procedures Called: run* Global Variables Used: gbnThread - creates new thread for first* execution and starts thread(calling run method of thread)***************************************************************************/public void start() {// Creating GBNThread and starting execution. After start methodis run// the run method of this class is calledif (gbnThread == null)gbnThread = new Thread(this);gbnThread.start();}// End start() method/**************************************************************************** Method run **************************************************************************** Purpose: Run method required for runnable interface. Determineswhich* thread is calling and begins animation processing accordingly. gbnThread* produces the animation for the applet. The timerThread sleeps until* timeout processing is needed to retransmit the sending window.* Procedures/Functions Called: check_upto_n,paint/update(indirectly)* Procedures/Functions Calling: main, start* Local variables: currentThread - holds the identifier for thecurrently* executing thread i - temporary variable used for loop control* Global variables used: sender - array holding the packets and the* corresponding acks for the packets sent in the applet output - console* window to display information about the applet activities* lastKnownSucPacket - holds the number of the last successful packet to* arrive gbnThread - thread to advance animation********************************************************************* *****/public void run() {// test if our simulation has completed. Prevents animation from looping// over// no inputs. Terminates threads and exits method.if (sender[total_packet - 1] != null)if (sender[total_packet - 1].acknowledged) {sender[total_packet - 1].packet_pos += ADVANCE_PACKET;gbnThread = null;output.append("Data Transferred - Simulation completed\n");return;}/** determine which thread called the run method since both the GBN * simulation thread and the timer thread call the same run method. */System.gc();Thread currenthread = Thread.currentThread();// while the gbnThread (Go Back N simulation thread) is calling // animation advance the animation accordingly.while (currenthread == gbnThread) {/** Explanation of the following if structure:* if any of the packets in the sender array are in* transit between nodes then the location variable is incremented by* ADVANCE_PACKET(5 pixels by default) for that packet. Once the packet* has reached the receiving node the variable reached_dest is set to true.* Processing and sending of ACKs will then takes place.*/if (onTheWay(sender)) {for (int i = 0; i < total_packet; i++)if (sender[i] != null) // if a packet has been created at this index in arrayif (sender[i].on_way) // If this packet is currently being transmitted// Test if the packet has reached the destination node// if the packet has not reached the destination then// advance the packet's location by ADVANCE_PACKETif (sender[i].packet_pos < (v_clearance -pack_height))sender[i].packet_pos += ADVANCE_PACKET; // and// If a packet is moving towards the destinationelse if (sender[i].packet_ack) {deliverPackets(i);} else if (!sender[i].packet_ack) {// check if the packet this acknowledges is our// next expected// sequence numberif (sender[i].ackFor != i) {// extract what packet this ack is forint location = sender[i].ackFor;// check to see if we have processed the ack// as the original ack for this packet may// have been lostif (!sender[location].acknowledged) {// print out confirmation message,// process packet, and perform GBN// processingoutput.append("(S) - Cumulative Ack received for Packet(s) up to and including Packet " + location + ". Timer for Packet(s) up to and including " + location + " stopped\n");sender[location].received = true;sender[location].on_way = false;sender[location].acknowledged = true;sender[i].packet_ack = false;sender[i].on_way = false;// do go back n processing for every// packet up to the location of this// packetsimGoBackN(location);} else {/** else this is a duplicate ack. Go Back* N performs no action on duplicate* acks received. process packet and* ignore*/output.append("(S) - Cumulative Ack for Packet(s) up to and including " + sender[i].ackFor + " received again (DUPACK)\n");sender[i].packet_pos = pack_height + ADVANCE_PACKET;sender[i].packet_ack = false;sender[i].on_way = false;}} else {// else this is an ack for our next expected// sequence numberoutput.append("(S) - Cumulative Ack received for Packet(s) up to and including " + i + "\n");output.append("(S) - Stop timer\n");// check to see if there is another packet in transit// in case we need to restart the timerif(i < total_packet_def && sender[i + 1] != null){output.append("(S) - Start timer (for Packet " + (i+1) + ")\n");}sender[i].received = true;sender[i].on_way = false;// perform go back n processing for all// packets up to index i in sender arraysimGoBackN(i);}}// update our displayrepaint();// sleep to display a reasonable fps for the animaition.// without this the animation would process faster than the user// can see.try {Thread.sleep(TIMEOUT_MULTIPLIER / fps);timeout = (TIMEOUT_MULTIPLIER / fps);// if we get interupted something outside of our control has// gone wrong.// this should only be interrupted by a browser error} catch (InterruptedException e) {output.append("-Help\n");}}// end ifelsegbnThread = null;}while (currenthread == timerThread) {// if timerSleep is true we have told the timerthread to wait a// specified period of time(time_out_sec*TIMEOUT_MULTIPLIER)// before checking to see if any packets are still outstanding.if (timerSleep) {timerSleep = false;try {Thread.sleep(time_out_sec * TIMEOUT_MULTIPLIER);timeout = (time_out_sec * TIMEOUT_MULTIPLIER);} catch (InterruptedException e) {output.append("-Timer interrupted.\n");return;}} elseretransmitOutstandingPackets();}// end while}// End run() method/******************************************************************** ** Method retransmitOutstandingPacket ********************************************************************** Purpose: handles transmission of packets when a timeout occurs* Procedure calling: run(called by timerThread)* Procedures called: none* Global variables used: sender[] - to set up params for retransmission* timerSleep - to reset timer value* GBNThread - set animation thread for retransmissio* output - output messages to user about retransmission* base - number of left-most packet in the sending window* Local variables: n - used as loop control variable*********************************************************************/private void retransmitOutstandingPackets() {// after the timerThread wakes up process the packets in sender // array from the base of our window (the leftmost edge)// up to the last packet sendfor (int n = (base == 0) ? 0 : base - 1; n < base + window_len; n++) {if (sender[n] != null)if (!sender[n].acknowledged) {sender[n].on_way = true;sender[n].packet_ack = true;sender[n].packet_pos = pack_height + ADVANCE_PACKET;sender[n].ackFor = n;}timerSleep = true;if (gbnThread == null) {gbnThread = new Thread(this);gbnThread.start();}}// end for//test for border case -- needs cleanupfor(int i = base; i < total_packet; i++)if(sender[i].acknowledged == false){output.append("(S) - Timeout occurred (for Packet " +(i) + ") \n");break;}output.append("(S) - All outstanding Packet(s) from " + base + "to " + (nextseq - 1) + " are retransmitted. Start timer (for Packet "+base +")\n");}/**************************************************************************** Method simGoBackN **************************************************************************** Purpose: Simulates the Go Back N protocol. The "heart" of the GoBack N* processing. Method handles the acknowledging up to the ack we just* received.* Procedures/Functions Calling: run* Local variables: i - the index in the array to check up to - comesfrom the* packet we just received* Global variables used: sender - array holding the packets and the* corresponding acks for the packets sent in the applet* output - console window to display information about the applet* activities* lastKnownSucPacket - holds the number of the last successfulpacket to* arrive gbnThread - thread to advance animation***************************************************************************/public void simGoBackN(int i) {// set all packets in the sender array up to index i (our ack thatjust// arrived) to acknowledged per go back n specs.for (int n = 0; n <= i; n++) {sender[n].acknowledged = true;}// if our packet was selected clear the selection bit.if (i == selected) {selected = DESELECTED;kill.setEnabled(false);}timerThread = null; // resetting timer thread// increment our base value to reflect the new ack we just received if (i + window_len < total_packet)base = i + 1;// if we have room in our window allow the user to send a new packet if (nextseq < base + window_len)send.setEnabled(true);if (base != nextseq) {timerThread = new Thread(this);timerSleep = true;timerThread.start();} else// set out of order to false in order to control the last known// packet receivedsender[i].out_of_order = false;}/******************************************************************** * Method deliverPackets ********************************************************************* Purpose: process incomming acknowledgments. handle incrementing the* window and informing user of ack arrival* Procedures Calling: run* Procedures Called: none* Local Variables: none* Global Variables: packetNumber -index into sender of arriving packet* sender[] - array of packets updated to reflect a new ack has arrived* output - display information to user about ack that just arrived * base - number of left most packet in sending window********************************************************************* *****/private void deliverPackets(int packetNumber) {sender[packetNumber].reached_dest = true;// if this packet is an acknowledgment for any// other packet than itself, it is a duplicate// ack. print out a message telling the user the// packet is a duplicateif (sender[packetNumber].ackFor != packetNumber) {output.append("(S) Cumulative Ack for Packets up to and including " + sender[packetNumber].ackFor + " received again (DUPACK)\n");sender[packetNumber].packet_pos = pack_height +ADVANCE_PACKET;sender[packetNumber].packet_ack = false;// if all packets have been received in// order, print confirmation message of// packet arrival and process ack normally// check for in-order delivery} else if (check_upto_n(packetNumber) && packetNumber >= receiver_base) {sender[packetNumber].packet_pos = pack_height +ADVANCE_PACKET;sender[packetNumber].packet_ack = false;lastKnownSucPacket = packetNumber;output.append("(R) - Packet " + packetNumber + " received. Cumulative Ack for Packets up to and including " + packetNumber + " sent. Packet " + packetNumber + " delivered to application\n");// advance the receivers next expected// packet window while// the base less than our max packetsif (receiver_base + 1 < total_packet && receiver_base <= lastKnownSucPacket)receiver_base = receiver_base + 1;}// Handle the out of order packets by// creating a duplicate ack for the last// in order packet receivedelse {// handles the special case where the first packet is lost - otherwise any packet// that arrives will acknowledge packet 0 even though packet 0 has been lostif (base == 0 && sender[0].packet_ack && receiver_base ==0) {output.append("(R) - Packet " + packetNumber + " received out of order - no Packets acknowledged. Special case - No Ack sent\n");sender[packetNumber].packet_pos = pack_height + ADVANCE_PACKET;sender[packetNumber].on_way = false;sender[packetNumber].reached_dest = false;}//for duplicate ackselse if(packetNumber < receiver_base){sender[packetNumber].packet_pos = pack_height + ADVANCE_PACKET;sender[packetNumber].packet_ack = false;// base is stored as the next expected packet number so our last in packet// received is 1 less than the current value of base when base is 0 we have not// received any packets but we can't signify this without having an array out// of bounds erroroutput.append("(R) - Packet " + packetNumber + " received out of order Dropping Packet " + packetNumber + ". Cumulative Ack for Packets up to and including " + (lastKnownSucPacket) + " sent\n");}// all other packet arrivals handled belowelse {sender[packetNumber].packet_pos = pack_height + ADVANCE_PACKET;sender[packetNumber].packet_ack = false;// base is stored as the next expected packet number so our last in packet// received is 1 less than the current value of base when base is 0 we have not// received any packets but we can't signify this without having an array out// of bounds errorsender[packetNumber].ackFor = lastKnownSucPacket;sender[packetNumber].reached_dest = false;sender[packetNumber].out_of_order = true;output.append("(R) - Packet " + packetNumber + " received out of order. Dropping Packet " + packetNumber + ". Cumulative Ack for Packets up to and including " + (lastKnownSucPacket) + " sent\n");if (packetNumber == selected) {selected = DESELECTED;kill.setEnabled(false);}}}}/********************************************************************** Method setupSimulationParams ********************************************************************** Purpose: Extract simulation parameters from the HTML page the applet * is being executed from. If the parameter is supplied convert to value * to integer and check for greater than 0(less than 0 will throw exceptions)* if the value supplied is in range, assign that value to the simulation* parameter* Global variables used: window_len,pack_widt, pack_height, h_offset, v_offset,* v_clearance, total_packet, time_out_sec**************************************************************************/private void setupSimulationParams() {String strWinLen, strPackWd, strPackHt, strHrOff, strVtOff, strVtClr, strTotPack, strTimeout;// Start collecting parameters from HTML the applet is called from strWinLen = getParameter("window_length");strPackWd = getParameter("packet_width");strPackHt = getParameter("packet_height");strHrOff = getParameter("horizontal_offset");strVtOff = getParameter("vertical_offset");strVtClr = getParameter("vertical_clearance");strTotPack = getParameter("total_packets");strTimeout = getParameter("timer_time_out");// try to retrieve the expected parameters we read in from above try {//check if current param was supplied in HTML pageif (strWinLen != null) {//if param was supplied convert value to integer valuewindow_len = Integer.parseInt(strWinLen);//check if value supplied is greater than 0 (negative or 0 will cause simulation errors)//conditional assignment - if window_leng is greater than 0, window_len keeps its current value otherwise the defaultvalue(sender_window_len_def) is uesdwindow_len = (window_len > 0) ? window_len :sender_window_len_def;} else//if param was not supplied use default valuewindow_len = sender_window_len_def;//same structure as aboveif (strPackWd != null) {pack_width = Integer.parseInt(strPackWd);pack_width = (pack_width > 0) ? pack_width : pack_width_def;} elsepack_width = pack_width_def;if (strPackHt != null) {pack_height = Integer.parseInt(strPackHt);pack_height = (pack_height > 0) ? pack_height :pack_height_def;} elsepack_height = pack_height_def;if (strHrOff != null) {h_offset = Integer.parseInt(strHrOff);h_offset = (h_offset > 0) ? h_offset : h_offset_def;} elseh_offset = h_offset_def;if (strVtOff != null) {v_offset = Integer.parseInt(strVtOff);v_offset = (v_offset > 0) ? v_offset : v_offset_def;} elsev_offset = v_offset_def;if (strVtClr != null) {v_clearance = Integer.parseInt(strVtClr);v_clearance = (v_clearance > 0) ? v_clearance :v_clearance_def;} elsev_clearance = v_clearance_def;if (strTotPack != null) {total_packet = Integer.parseInt(strTotPack);total_packet = (total_packet > 0) ? total_packet: total_packet_def;} elsetotal_packet = total_packet_def;if (strTimeout != null) {time_out_sec = Integer.parseInt(strTimeout);time_out_sec = (time_out_sec > 0) ? time_out_sec: time_out_sec_def;} elsetime_out_sec = (time_out_sec > 0) ? time_out_sec: time_out_sec_def;//exception converting to integer - if a non integer value is supplied conversion to an integer value will throw an exception //if an exception is thrown, keep supplied values(already checked) and use default values for rest of params.} catch (Exception e) {// if above fails use what values we have and defaults for the rest// should recover more gracefully than previous codewindow_len = (window_len > 0) ? window_len :sender_window_len_def;pack_width = (pack_width > 0) ? pack_width : pack_width_def;pack_height = (pack_height > 0) ? pack_height : pack_height_def;h_offset = (h_offset > 0) ? h_offset : h_offset_def;v_offset = (v_offset > 0) ? v_offset : v_offset_def;v_clearance = (v_clearance > 0) ? v_clearance : v_clearance_def;total_packet = (total_packet > 0) ? total_packet :total_packet_def;time_out_sec = (time_out_sec > 0) ? time_out_sec :time_out_sec_def;}。
(完整版)计算机网络协议总结
1.物理层(比特流)2.数据链路层 ( 帧)PPP(点对点协议):面向连结,不行靠,只支持全双工链路,成帧技术,PPP 帧是面向字节的,全部的 PPP 帧的长度都是整数字节的。
只检错不纠错,没有流量控制。
CSMA/CD (载波监听多点接入 /碰撞检测协议):截断二进制指数退避算法指数退避算法网桥的自学习算法3.网络层( IP 数据报或称分组、包)IP 协议:无连结、不行靠、全力而为型ARP (地点分析协议):IP 地点→物理地点( MAC 地点)RARP (逆地点分析协议):物理地点( MAC 地点)→ IP 地点分组转发算法:直接交托、间接交托ICMP (网际控制报文协议):ICMP 同意主机或路由器报告差错状况和供给相关异样状况的报告。
ICMP 报文封装在IP 包中。
( ICMP 报文是 IP 层数据报的数据)路由选择协议:内部网关协议 IGP:RIP,OSPF外面网关协议 EGP:BGPRIP (路由信息协议):鉴于距离向量的路由选择算法。
RIP 用 UDP 用户数据报传递。
合适于规模较小的网络,最大跳数不超出15。
弊端:“好信息流传得快,而坏信息流传得慢”。
OSPF(开放最短路径优先):鉴于链路状态协议LSOSPF 直接用IP 数据报传递BGP(界限网关协议):不一样 AS 之间的路由协议。
用路径向量( path vector)路由协议BGP 用 TCP 报文传递力争找寻一条可以抵达目的网络且比较好的路由。
并不是要找寻一条最正确路由。
IGMP (网际组管理协议):多播协议。
IGMP 使用 IP 数据报传达其报文 BOOTP (指引程序协议):需要人工进行协议配置,使用 UDP 报文封装,也是无盘系统用来获取 IP 地点的方法DHCP (动向主机配置协议):自动分派主机地点VPN (虚构专用网):利用公用的因特网作为本机构各专用网之间的通讯载体。
NAT (网络地点变换 ):①在企业内部,每台机器都有一个形如10.X.Y.Z 的地点。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1实验名称:
2实验目的:始日期:
2011-11-25
10:00
实验结束时间:
2011-11-25
11:00
实验地点:3603
实验人:liu_chun
实验条件
运行Windows 2002/2003Server/XP操作系统的PC机一台,相应的java小程序。
实验主要步骤
实验现象
1、一般情况下: 如图所示,点击发“送新的分组”9次,实验现象如下图所示:
2、出现报文丢失的情况下, 如图所示,点击发“送新的分组”9次,实验现象如下图所示:
5、实验结果分析:
1、
若一定时间内未收到应答信号,N个包同时重发(如图现象2)
1、理解:Go-Back_N协议:发送方在发完一个数据帧后,不停下来等待应答帧,而是连续发送若干个数据帧,即使在连续发送过程中收到了接收方发来的应答帧,也可以继续发送。且发送方在每发送完一个数据帧时都要设置超时定时器。只要在所设置的超时时间内仍收到确认帧,就要重发相应的数据帧。
2、了解实验环境,这个程序模拟了Go-Back-N协议,在该程序中,窗口限制了发送端最多为5个分组而不需等待确认。多次点击“发送新分组”六次至多次,观察现象。