资源简介
实验内容
设计一个滑动窗口协议,在仿真环境下编程实现有噪音信道两站点间无差错双工通信
信道模型
8000bps全双工卫星信道
单向传播时延270毫秒
信道误码率为10-5
物理层接口:提供帧传输服务,帧间有1ms帧边界
网络层属性:分组长度固定256字节
实现Go BackN协议
代码片段和文件信息
/***GO-BACK-N协议,确认帧为捎带确认***/
#include
#include
#include “protocol.h“
#include “datalink.h“
#define inc(k) if(k #define DATA_TIMER 2800
#define MAX_SEQ 7
#pragma comment(lib“Protocol.lib“)
typedef struct{
unsigned char kind; /* frame_DATA */
unsigned char ack; //ACK number
unsigned char seq; //seq bumber
unsigned char data[PKT_LEN]; //净荷域
unsigned int padding; //存放CRC校验和
}frame;
static unsigned char frame_nr = 0buffer[MAX_SEQ+1][PKT_LEN] nbuffered=0;
static unsigned char frame_expected = 0ack_expected=0next_frame_to_send=0;
static int phl_ready = 0;
int between(unsigned char aunsigned char bunsigned char c) //判断帧有没有在当前窗口中
{
if(((a<=b)&&(b return 1;
else
return 0;
}
static void put_frame(unsigned char *frame int len)
{
*(unsigned int *)(frame + len) = crc32(frame len);
send_frame(frame len + 4);
phl_ready = 0;
}
static void send_data_frame(void) //将帧传递给物理层传送,并开始计时器计时
{
frame s;
s.kind = frame_DATA;
s.seq = next_frame_to_send;
s.ack = (frame_expected+MAX_SEQ)%(MAX_SEQ+1);
memcpy(s.databuffer[next_frame_to_send]PKT_LEN);
dbg_frame(“Send DATA %d %d ID %dwindows %d\n“ s.seq s.ack *(short *)s.datanbuffered);
put_frame((unsigned char *)&s 3 + PKT_LEN);
start_timer(next_frame_to_send DATA_TIMER);
}
int main(int argc char **argv)
{
int event arg;
frame f;
int len = 0;
int i;
protocol_init(argc argv);
- 上一篇:c++实现找出数组最大值函数
- 下一篇:文件读入与导出
评论
共有 条评论