91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 937KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2021-05-17
  • 語言: 其他
  • 標簽: GoBackN??源碼??

資源簡介

計算機網絡滑動窗口協議GoBackN C程序源碼

資源截圖

代碼片段和文件信息

#include?
#include?

#include?“protocol.h“
#include?“datalink.h“

typedef?struct{????????//frames結構定義?由5個域kind、seq、ack和info??padding
????unsigned?char?kind;???/*?frame_DATA?*/
????unsigned?char?ack;
????unsigned?char?seq;
????unsigned?char?info[PKT_LEN];?
unsigned?int??padding;
}?frame?;??

static?int?phl_ready?=?0;????//對物理層狀態記錄
bool?no_nak?=?true;??/*?no?nak?has?been?sent?yet?*/

static?bool?between?(seq_nr?a?seq_nr?b?seq_nr?c)??/*已接受的確認應答號應該小于下一個要發送的序列號*/
{
/*return?true?if?a?<=b? if?(((a?<=?b)&&(b? return?(true);
else
return?(false);
}

static?void?put_frame(unsigned?char?*frame?int?len)?????//生成CRC-32?校驗和,并且把這32?比特校驗和附其后?
{
????*(unsigned?int?*)(frame?+?len)?=?crc32(frame?len);??
????send_frame(frame?len?+?4);??//函數send_frame?()用于將內存frame?處長度為len的緩沖區塊向物理層發送為一幀
????phl_ready?=?0;??
}

static?void?send_data(seq_nr?frame_nrseq_nr?frame_expectedpacket?buffer[])
{
????/*Construct?and?send?a?data?frame.?*/
????frame?s;

????s.kind?=?frame_DATA;
????s.seq?=?frame_nr;
????s.ack?=?(frame_expected?+?MAX_SEQ)?%(MAX_SEQ?+?1);??/*將frame_expected-1,期望接受的是frame_expected,
???????????????????????????????????而現在已經接收到的幀序號是frame_expected,所以捎帶確認的ACK應該是frame_expected-1?*/
???
????memcpy(s.info?&buffer[frame_nr].info?PKT_LEN);?
????dbg_frame(“Send?DATA?%d?%d?ID?%d\n“?s.seq?s.ack?*(short?*)s.info);

????put_frame((unsigned?char?*)&s?3?+?PKT_LEN);??????
????start_timer(frame_nr?DATA_TIMER);????//啟動frame_nr號寄存器??時限DATA_TIMER
stop_ack_timer();
}

static?void?send_nak_frame(seq_nr?frame_expected)??/*發送NAK*/
{
????frame?s;

????s.kind?=?frame_NAK;?????
????s.ack?=?frame_expected;????/*發送NAK?攜帶的ACK應該就是當前frame_expected幀*/???//pay?attention!
no_nak?=?false;

????dbg_frame(“Send?NAK??%d\n“?s.ack);
????put_frame((unsigned?char?*)&s?2);
stop_ack_timer();
}

int?main(int?argc?char?**argv)
{
int?len=0?arg?event;

????seq_nr?next_frame_to_send; /*?MAX_SEQ?>?1;?used?for?outbound?stream?*/
seq_nr?ack_expected; /*?oldest?frame?as?yet?unacknowledged?*/
seq_nr?frame_expected; /*?next?frame?expected?on?inbound?stream?*/
frame?r; /*?scratch?variable?*/
packet?buffer[MAX_SEQ+1]; /*?buffers?for?the?outbound?stream?*/
seq_nr?nbuffered; /*?#?output?buffers?currently?in?use?*/
seq_nr?i; /*?used?to?index?into?the?buffer?array?*/

ack_expected?=?0; /*?next?ack?expected?inbound?*/
next_frame_to_send?=?0; /*?next?frame?going?out?*/
????frame_expected?=?0; /*?number?of?frame?expected?inbound?*/
nbuffered?=?0; /*?initially?no?packets?are?buffered?*/
???
protocol_init(argc?argv);
????disable_network_layer();??/*數據鏈路層在緩沖區滿等條件下無法發送分組時通過disable_network_layer()?通知網絡層;*/?
lprintf(“Designed?by?計科4班2組(楊培軍、吳科橋、宋瑞)程序1:GoBackNbuild:?“?__DATE__“??“__TIME__“\n“);

for(;;){
event?=?wait_for_event(&arg); /*?four?possibilities:?see?event_t

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-03-18?22:38??GoBackN\
?????文件?????????518??2010-11-30?19:02??GoBackN\datalink.h
?????文件???????10752??2010-12-08?23:16??GoBackN\datalink.suo
?????目錄???????????0??2012-03-18?22:38??GoBackN\Debug\
?????文件????????3581??2010-12-12?19:29??GoBackN\Debug\GoBackN-A.log
?????文件????????3621??2010-12-12?19:29??GoBackN\Debug\GoBackN-B.log
?????文件??????172108??2010-12-07?13:21??GoBackN\Debug\GoBackN.exe
?????文件??????197556??2010-12-07?13:21??GoBackN\Debug\GoBackN.ilk
?????文件???????10644??2010-12-07?13:21??GoBackN\Debug\GoBackN.obj
?????文件??????220580??2010-12-07?12:58??GoBackN\Debug\GoBackN.pch
?????文件??????443392??2010-12-07?13:21??GoBackN\Debug\GoBackN.pdb
?????文件???????94208??2010-11-30?14:11??GoBackN\Debug\Protocol.dll
?????文件?????1550624??2010-12-11?00:33??GoBackN\Debug\test5a.log
?????文件?????1547472??2010-12-11?00:33??GoBackN\Debug\test5b.log
?????文件???????41984??2010-12-12?19:28??GoBackN\Debug\vc60.idb
?????文件???????53248??2010-12-07?13:21??GoBackN\Debug\vc60.pdb
?????文件????????7260??2010-12-07?13:21??GoBackN\GoBackN.cpp
?????文件????????3604??2010-12-01?13:00??GoBackN\GoBackN.dsp
?????文件?????????522??2010-12-01?12:59??GoBackN\GoBackN.dsw
?????文件???????58368??2011-10-23?21:01??GoBackN\GoBackN.ncb
?????文件???????53760??2011-10-23?21:01??GoBackN\GoBackN.opt
?????文件????????1165??2010-12-07?13:21??GoBackN\GoBackN.plg
?????文件???????13312??2010-12-08?23:16??GoBackN\GoBackN.suo
?????文件???????94208??2010-11-30?14:11??GoBackN\Protocol.dll
?????文件????????2344??2010-12-12?19:28??GoBackN\protocol.h
?????文件????????5932??2010-11-30?14:12??GoBackN\Protocol.lib

評論

共有 條評論