亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? worker.c

?? ARQ協議的實現 從單工停等到滑動窗口協議的實現
?? C
?? 第 1 頁 / 共 2 頁
字號:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "common.h"

#define NR_TIMERS 8		/* number of timers */
#define MAX_QUEUE 100000	/* max number of buffered frames */
#define NO_EVENT -1		/* no event possible */
#define FRAME_SIZE (sizeof(frame))
#define BYTE 0377		/* byte mask */
#define UINT_MAX  0xFFFFFFFF	/* maximum value of an unsigned 32-bit int */
#define INTERVAL 100000		/* interval for periodic printing */
#define AUX 2			/* aux timeout is main timeout/AUX */

/* DEBUG MASKS */
#define SENDS        0x0001	/* frames sent */
#define RECEIVES     0x0002	/* frames received */
#define TIMEOUTS     0x0004	/* timeouts */
#define PERIODIC     0x0008	/* periodic printout for use with long runs */

/* Status variables used by the workers, M0 and M1. */
bigint ack_timer[NR_TIMERS];	/* ack timers */
unsigned int seqs[NR_TIMERS];	/* last sequence number sent per timer */
bigint lowest_timer;		/* lowest of the timers */
bigint aux_timer;		/* value of the auxiliary timer */
int network_layer_status;	/* 0 is disabled, 1 is enabled */
unsigned int next_net_pkt;	/* seq of next network packet to fetch */
unsigned int last_pkt_given= 0xFFFFFFFF;	/* seq of last pkt delivered*/
frame last_frame;		/* arrive frames are kept here */
int offset;			/* to prevent multiple timeouts on same tick*/
bigint tick;			/* current time */
int retransmitting;		/* flag that is set on a timeout */
int nseqs = -1;			/* must be MAX_SEQ + 1 after startup */
extern unsigned int oldest_frame;	/* tells protocol 6 which frame timed out */

char *badgood[] = {"bad ", "good"};
char *tag[] = {"Data", "Ack ", "Nak "};

/* Statistics */
int data_sent;			/* number of data frames sent */
int data_retransmitted;		/* number of data frames retransmitted */
int data_lost;			/* number of data frames lost */
int data_not_lost;		/* number of data frames not lost */
int good_data_recd;		/* number of data frames received */
int cksum_data_recd;		/* number of bad data frames received */

int acks_sent;			/* number of ack frames sent */
int acks_lost;			/* number of ack frames lost */
int acks_not_lost;		/* number of ack frames not lost */
int good_acks_recd;		/* number of ack frames received */
int cksum_acks_recd;		/* number of bad ack frames received */

int payloads_accepted;		/* number of pkts passed to network layer */
int timeouts;			/* number of timeouts */
int ack_timeouts;		/* number of ack timeouts */

/* Incoming frames are buffered here for later processing. */
frame queue[MAX_QUEUE];		/* buffered incoming frames */
frame *inp = &queue[0];		/* where to put the next frame */
frame *outp = &queue[0];	/* where to remove the next frame from */
int nframes;			/* number of queued frames */

/* Prototypes. */
void wait_for_event(event_type *event);
void queue_frames(void);
int pick_event(void);
event_type frametype(void);
void from_network_layer(packet *p);
void to_network_layer(packet *p);
void from_physical_layer(frame *r);
void to_physical_layer(frame *s);
void start_timer(seq_nr k);
void stop_timer(seq_nr k);
void start_ack_timer(void);
void stop_ack_timer(void);
void enable_network_layer(void);
void disable_network_layer(void);
int check_timers(void);
int check_ack_timer(void);
unsigned int pktnum(packet *p);
void fr(frame *f);
void recalc_timers(void);
void print_statistics(void);
void sim_error(char *s);


void wait_for_event(event_type *event)
{
/* Wait_for_event reads the pipe from main to get the time.  Then it
 * fstat's the pipe from the other worker to see if any
 * frames are there.  If so, if collects them all in the queue array.
 * Once the pipe is empty, it makes a decision about what to do next.
 */
 
 bigint ct, word = OK;

  if (nseqs < 0) nseqs = oldest_frame;	/* need MAX_SEQ+1 for protocol 6 */
  offset = 0;			/* prevents two timeouts at the same tick */
  retransmitting = 0;		/* counts retransmissions */
  while (true) {
	queue_frames();		/* go get any newly arrived frames */
	if (write(mwfd, &word, TICK_SIZE) != TICK_SIZE) print_statistics();
	if (read(mrfd, &ct, TICK_SIZE) != TICK_SIZE) print_statistics();
	if (ct == 0) print_statistics();
	tick = ct;		/* update time */
	if ((debug_flags & PERIODIC) && (tick%INTERVAL == 0))
		printf("Tick %u. Proc %d. Data sent=%d  Payloads accepted=%d  Timeouts=%d\n", tick/DELTA, id, data_sent, payloads_accepted, timeouts);

	/* Now pick event. */
	*event = pick_event();
	if (*event == NO_EVENT) {
		word = (lowest_timer == 0 ? NOTHING : OK);
		continue;
	}
	word = OK;
	if (*event == timeout) {
		timeouts++;
		retransmitting = 1;	/* enter retransmission mode */
		if (debug_flags & TIMEOUTS)
		      printf("Tick %u. Proc %d got timeout for frame %d\n",
					       tick/DELTA, id, oldest_frame);
	}

	if (*event == ack_timeout) {
		ack_timeouts++;
		if (debug_flags & TIMEOUTS)
		      printf("Tick %u. Proc %d got ack timeout\n",
					       tick/DELTA, id);
	}
	return;
  }
}


void queue_frames(void)
{
/* See if any frames from the peer have arrived; if so get and queue them.
 * Queue_frames() sucks frames out of the pipe into the circular buffer,
 * queue[]. It first fstats the pipe, to avoid reading from an empty pipe and
 * thus blocking.  If inp is near the top of queue[], a single call here
 * may read a few frames into the top of queue[] and then some more starting
 * at queue[0].  This is done in two read operations.
 */

  int prfd, frct, k;
  frame *top;
  struct stat statbuf;

  prfd = (id == 0 ? r2 : r1);	/* which file descriptor is pipe on */

  if (fstat(prfd, &statbuf) < 0) sim_error("Cannot fstat peer pipe");
  frct = statbuf.st_size/FRAME_SIZE;	/* number of arrived frames */

  if (nframes + frct >= MAX_QUEUE)	/* check for possible queue overflow*/
	sim_error("Out of queue space. Increase MAX_QUEUE and re-make.");  

  /* If frct is 0, the pipe is empty, so don't read from it. */
  if (frct > 0) {
	/* How many frames can be read consecutively? */
	top = (outp <= inp ? &queue[MAX_QUEUE] : outp);/* how far can we rd?*/
	k = top - inp;	/* number of frames that can be read consecutively */
	if (k > frct) k = frct;	/* how many frames to read from peer */
	if (read(prfd, inp, k * FRAME_SIZE) != k * FRAME_SIZE)
		sim_error("Error reading frames from peer");
	frct -= k;		/* residual frames not yet read */
	inp += k;
	if (inp == &queue[MAX_QUEUE]) inp = queue;
	nframes += k;

	/* If frct is still > 0, the queue has been filled to the upper
	 * limit, but there is still space at the bottom.  Continue reading
	 * there.  This mechanism makes queue a circular buffer.
	 */
	if (frct > 0) {
		if (read(prfd, queue, frct * FRAME_SIZE) != frct*FRAME_SIZE)
			sim_error("Error 2 reading frames from peer");
		nframes += frct;
		inp = &queue[frct];
	}
  }
}


int pick_event(void)
{
/* Pick a random event that is now possible for the process.
 * The set of legal events depends on the protocol number and system state.
 * A timeout is not possible, for example, if no frames are outstanding.
 * For each protocol, events from 0 to some protocol-dependent maximum
 * are potentially allowed.  The maximum is given by highest_event.  The
 * events that are theoretically possible are given below.
 *
 *  # Event		Protocols:  1 2 3 4 5 6
 *  0 frame_arrival                 x x x x x x
 *  1 chksum_err                        x x x x
 *  2 timeout                           x x x x
 *  3 network_layer_ready                   x x 
 *  4 ack_timeout                             x (e.g. only 6 gets ack_timeout)
 *
 * Note that the order in which the tests is made is critical, as it gives
 * priority to some events over others.  For example, for protocols 3 and 4
 * frames will be delivered before a timeout will be caused.  This is probably
 * a reasonable strategy, and more closely models how a real line works.
 */

  switch(protocol) {
    case 2:			/* {frame_arrival} */
	if (nframes == 0 && lowest_timer == 0) return(NO_EVENT);
	return(frametype());

    case 3:			/* {frame_arrival, cksum_err, timeout} */
    case 4:
	if (nframes > 0) return((int)frametype());
	if (check_timers() >= 0) return(timeout);	/* timer went off */
	return(NO_EVENT);

    case 5:	/* {frame_arrival, cksum_err, timeout, network_layer_ready} */
	if (nframes > 0) return((int)frametype());
	if (network_layer_status) return(network_layer_ready);
	if (check_timers() >= 0) return(timeout);	/* timer went off */
	return(NO_EVENT);

    case 6:	/* {frame_arrival, cksum_err, timeout, net_rdy, ack_timeout}*/
	if (check_ack_timer() > 0) return(ack_timeout);
	if (nframes > 0) return((int)frametype());
	if (network_layer_status) return(network_layer_ready);
	if (check_timers() >= 0) return(timeout);	/* timer went off */
	return(NO_EVENT);
  }
}


event_type frametype(void)
{
/* This function is called after it has been decided that a frame_arrival
 * event will occur.  The earliest frame is removed from queue[] and copied
 * to last_frame.  This copying is needed to avoid messing up the simulation
 * in the event that the protocol does not actually read the incoming frame.
 * In protocols 2 and 3, the senders do not call from_physical_layer() to
 * collect the incoming frame.  If frametype() did not remove incoming frames
 * from queue[], they never would be removed.  Of course, one could change
 * sender2() and sender3() to have them call from_physical_layer(), but doing
 * it this way is more robust.
 *
 * This function determines (stochastically) whether the arrived frame is good
 * or bad (contains a checksum error).
 */

  int n, i;
  event_type event;

  /* Remove one frame from the queue. */
  last_frame = *outp;		/* copy the first frame in the queue */
  outp++;
  if (outp == &queue[MAX_QUEUE]) outp = queue;
  nframes--;

  /* Generate frames with checksum errors at random. */
  n = rand() & 01777;
  if (n < garbled) {
	/* Checksum error.*/
	event = cksum_err;
	if (last_frame.kind == data) cksum_data_recd++;
	if (last_frame.kind == ack) cksum_acks_recd++;
	i = 0;
  } else {
	event = frame_arrival;
	if (last_frame.kind == data) good_data_recd++;
	if (last_frame.kind == ack) good_acks_recd++;
	i = 1;
  }

  if (debug_flags & RECEIVES) {
	printf("Tick %u. Proc %d got %s frame:  ",
						tick/DELTA,id,badgood[i]);
	fr(&last_frame);
  }
  return(event);
}


void from_network_layer(packet *p)
{
/* Fetch a packet from the network layer for transmission on the channel. */

  p->data[0] = (next_net_pkt >> 24) & BYTE;
  p->data[1] = (next_net_pkt >> 16) & BYTE;
  p->data[2] = (next_net_pkt >>  8) & BYTE;
  p->data[3] = (next_net_pkt      ) & BYTE;
  next_net_pkt++;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩欧美一卡二卡| 国产喷白浆一区二区三区| 91久久精品日日躁夜夜躁欧美| 色美美综合视频| 91精品国产一区二区三区香蕉| 日韩美女视频一区二区在线观看| 日韩美女一区二区三区四区| 国产欧美日韩亚州综合| 亚洲r级在线视频| 岛国精品在线观看| 欧美日韩美女一区二区| 欧美成人a∨高清免费观看| 国产情人综合久久777777| 亚洲精品你懂的| 久久精品理论片| 欧美综合一区二区| 精品国产凹凸成av人导航| 中文字幕一区二区三区乱码在线| 亚洲一区二区三区四区的 | 亚洲丶国产丶欧美一区二区三区| 青青草视频一区| 欧美主播一区二区三区| 精品理论电影在线观看| 91在线精品一区二区| 欧美一区二区三区影视| 国产精品一区二区在线观看网站| 91精品国产综合久久精品图片| 最新不卡av在线| 99精品视频在线免费观看| 中文字幕精品一区| 国产成人精品亚洲777人妖| 精品国产乱码久久久久久蜜臀| 日韩激情av在线| 91精品国产全国免费观看| 蜜桃精品在线观看| 日本美女一区二区三区| 国产一区二区影院| 国产视频在线观看一区二区三区| 欧美色偷偷大香| aaa欧美大片| 综合电影一区二区三区| 高清成人在线观看| 欧美成人性福生活免费看| 亚洲一区二区三区在线| 欧美影片第一页| 亚洲成av人片观看| 91精品黄色片免费大全| 久久av资源网| 337p日本欧洲亚洲大胆精品 | 激情欧美一区二区三区在线观看| 怡红院av一区二区三区| 91精品国产一区二区| 香蕉影视欧美成人| 欧美电影在哪看比较好| 国产综合成人久久大片91| 亚洲美腿欧美偷拍| 欧美成人精品福利| 99精品国产一区二区三区不卡| 亚洲一级不卡视频| 国产日韩欧美精品电影三级在线| 日本高清成人免费播放| 狠狠色丁香婷婷综合久久片| 日韩中文字幕av电影| 日韩一区在线看| 国产日韩欧美精品电影三级在线| 欧美电影一区二区| 欧美亚洲另类激情小说| 99国产精品久久久久久久久久 | 91丨porny丨户外露出| 日本成人超碰在线观看| 亚洲国产精品麻豆| 香蕉乱码成人久久天堂爱免费| 亚洲人成在线播放网站岛国| 久久一区二区视频| 久久精品欧美一区二区三区不卡| 3d成人h动漫网站入口| 欧美国产日本视频| 日韩欧美一级二级| 99re成人在线| 色偷偷久久一区二区三区| 成人综合婷婷国产精品久久免费| 精品视频在线看| 日本韩国欧美一区二区三区| www.66久久| 日本aⅴ免费视频一区二区三区| 亚洲乱码国产乱码精品精98午夜| 亚洲国产成人自拍| 亚洲日本va午夜在线影院| 一区二区三区精品| 五月开心婷婷久久| 久久99精品久久久久久| 国产在线不卡视频| 99久久综合精品| 欧美日本在线观看| 久久嫩草精品久久久精品一| 中文字幕亚洲区| 亚洲成人黄色小说| 色噜噜狠狠一区二区三区果冻| 日韩精品中文字幕在线一区| 亚洲激情图片一区| 成人黄色国产精品网站大全在线免费观看 | 色狠狠桃花综合| 欧美三级一区二区| 精品国产乱码久久| 亚洲人精品午夜| 国产传媒日韩欧美成人| 精品视频全国免费看| 国产欧美精品国产国产专区| 亚洲成精国产精品女| 99精品视频一区二区三区| 精品sm在线观看| 日韩av中文字幕一区二区三区| 国产成人啪午夜精品网站男同| 欧美日韩黄色影视| 亚洲成人自拍一区| 91电影在线观看| 亚洲人精品午夜| 欧美一区二区在线视频| 洋洋成人永久网站入口| 一本久久综合亚洲鲁鲁五月天| 久久久久久久网| 国内精品自线一区二区三区视频| 欧美日韩精品免费| 午夜久久久久久| 91精品国产欧美一区二区18| 亚州成人在线电影| 欧美午夜影院一区| 亚洲国产精品天堂| 日韩精品一区国产麻豆| 久久成人久久鬼色| 国产日韩精品一区二区三区在线| 国产成+人+日韩+欧美+亚洲| 夜夜嗨av一区二区三区网页 | 欧洲视频一区二区| 国产精品人妖ts系列视频| 成人激情免费网站| 亚洲免费大片在线观看| 欧洲亚洲国产日韩| 美日韩一区二区三区| 久久久99久久精品欧美| 91色婷婷久久久久合中文| 午夜精品福利久久久| 中文字幕不卡的av| 欧美日韩国产成人在线免费| 日本美女一区二区| 日韩理论电影院| 欧美一区二区久久| 免费在线观看精品| 国产精品污网站| 欧美sm美女调教| 91美女片黄在线观看| 9人人澡人人爽人人精品| 日日夜夜免费精品视频| 亚洲视频在线一区| 亚洲三级视频在线观看| 欧美久久一二三四区| 成人国产一区二区三区精品| 婷婷久久综合九色综合伊人色| 久久精品欧美日韩精品| 日韩一区二区在线观看| 91免费精品国自产拍在线不卡| 九九视频精品免费| 日韩黄色免费网站| 亚洲国产裸拍裸体视频在线观看乱了| 久久精品一区二区三区不卡| 日韩久久精品一区| 久久综合久色欧美综合狠狠| 精品国精品国产| 日韩一区二区在线看| 欧美性xxxxx极品少妇| 91老司机福利 在线| 一本大道久久a久久精品综合| 成人小视频免费在线观看| 国产乱人伦精品一区二区在线观看| 奇米影视一区二区三区小说| 亚洲成精国产精品女| 日韩综合小视频| 麻豆91精品91久久久的内涵| 久久草av在线| 国产suv一区二区三区88区| 不卡av免费在线观看| 欧美在线看片a免费观看| 欧美妇女性影城| 精品国产乱码久久久久久影片| 国产欧美日韩在线看| 一区二区三国产精华液| 久久99久久久久久久久久久| 国产在线精品一区二区不卡了| eeuss影院一区二区三区| 欧美久久久久久久久久| 国产精品伦理在线| 免费看精品久久片| 91免费看片在线观看| 欧美精品久久久久久久多人混战 | 黑人精品欧美一区二区蜜桃| 97精品电影院| 亚洲成人一二三| 91网站最新网址| 久久天堂av综合合色蜜桃网| 亚洲综合精品久久|