資源簡介
實驗內(nèi)容
設(shè)計一個滑動窗口協(xié)議,在仿真環(huán)境下編程實現(xiàn)有噪音信道兩站點間無差錯雙工通信
信道模型
8000bps全雙工衛(wèi)星信道
單向傳播時延270毫秒
信道誤碼率為10-5
物理層接口:提供幀傳輸服務(wù),幀間有1ms幀邊界
網(wǎng)絡(luò)層屬性:分組長度固定256字節(jié)
實現(xiàn)Go BackN協(xié)議
代碼片段和文件信息
/***GO-BACK-N協(xié)議,確認幀為捎帶確認***/
#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);?
評論
共有 條評論