| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1546 人关注过本帖
标题:[求助]使用后退n帧技术的滑动窗口协议的模拟程序调试
取消只看楼主 加入收藏
lostmemory
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-1-3
收藏
 问题点数:0 回复次数:0 
[求助]使用后退n帧技术的滑动窗口协议的模拟程序调试
这是一个使用后退n帧技术的滑动窗口协议的模拟程序,小弟也是从网上找来的.还不能运行请高手帮忙调试一下.(有附件可下载)
#define MAX_SEQ 7
typedef enum {frame_arrival, cksum_err, timeout, network_layer_ready} event_type;
#include "protocol.h"
static boolean between(seq_nr a, seq_nr b, seq_nr c)
{
if (((a <= b) && (b < c)) || ((c < a) && (a <= b)) || ((b < c) && (c < a)))
return(true);
else
return(false);
}
static void send_data(seq_nr frame_nr, seq_nr frame_expected, packet buffer[])
{
frame s;
s.info = buffer[frame_nr];
s.seq = frame_nr;
s.ack = frame_expected % (MAX_SEQ + 1);
to_physical_layer(&s);
start_timer(frame_nr);
void protocol4(void)
{seq_nr next_frame_to_send;
seq_nr ack_expected;
seq_nr frame_expected;
frame r;
packet buffer[MAX_SEQ ];
seq_nr nbuffered;
seq_nr i;
event_type event;
enable_network_layer();
ack_expected = 0;
next_frame_to_send = 0;
frame_expected = 0;
nbuffered = 0;
while (true)
{
wait_for_event(&event);
switch(event)
{
case network_layer_ready:
from_network_layer(&buffer[next_frame_to_send]);
nbuffered = nbuffered + 1;
send_data(next_frame_to_send, frame_expected, buffer);
inc(next_frame_to_send);
break;
case frame_arrival:
from_physical_layer(&r);
if (r.seq == frame_expected)
{
to_network_layer(&r.info);
inc(frame_expected);
}
while (between(ack_expected, r.ack-1, next_frame_to_send))
{
nbuffered = nbuffered - 1;
fered = nbuffered - 1;
stop_timer(ack_expected);
inc(ack_expected);
}
break;
case cksum_err: break;
case timeout:
next_frame_to_send = ack_expected;
for (i = 1; i <= nbuffered; i++)
{
send_data(next_frame_to_send, frame_expected, buffer);
inc(next_frame_to_send);
}
if (nbuffered < MAX_SEQ)
enable_network_layer();
else
disable_network_layer();
}
}
搜索更多相关主题的帖子: 模拟程序 协议 窗口 滑动 技术 
2006-04-14 20:10
快速回复:[求助]使用后退n帧技术的滑动窗口协议的模拟程序调试
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016650 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved