亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
av成人动漫在线观看| 欧美怡红院视频| 日本一区二区成人在线| 色综合中文综合网| 欧美日韩中文国产| 国产福利一区在线| 一区二区三区在线观看动漫 | 粉嫩嫩av羞羞动漫久久久 | 国产欧美精品一区二区色综合| 欧美久久一二区| 99久久精品久久久久久清纯| 天天射综合影视| 亚洲免费三区一区二区| 国产日韩欧美激情| 日韩一级成人av| 69p69国产精品| 欧美日韩一区二区三区不卡| 99re视频这里只有精品| 国产在线不卡一卡二卡三卡四卡| 亚洲精品精品亚洲| 亚洲精品亚洲人成人网在线播放| 日韩精品最新网址| 欧美老年两性高潮| 3d动漫精品啪啪1区2区免费 | 日本欧美加勒比视频| 亚洲va韩国va欧美va| 亚洲三级免费观看| 日韩一区在线免费观看| 欧美国产日产图区| 国产精品高潮久久久久无| 中文字幕免费不卡| 亚洲欧洲一区二区在线播放| 国产精品国产三级国产普通话99| 中文字幕 久热精品 视频在线| 国产精品丝袜一区| 亚洲精品亚洲人成人网| 亚洲va在线va天堂| 国产福利电影一区二区三区| 福利一区二区在线| 96av麻豆蜜桃一区二区| 色婷婷综合久久久中文字幕| 色综合天天性综合| 精品日韩欧美在线| 亚洲国产一区二区三区| 水野朝阳av一区二区三区| 高清不卡一区二区在线| 欧美在线视频不卡| 亚洲欧美日韩国产综合| 免费观看91视频大全| 91麻豆文化传媒在线观看| 91麻豆精品国产综合久久久久久| 精品国产91亚洲一区二区三区婷婷| 国产精品欧美久久久久一区二区| 奇米综合一区二区三区精品视频| 成人免费观看av| 久久综合国产精品| 免费亚洲电影在线| 欧美精品久久久久久久多人混战| 国产亚洲一本大道中文在线| 日韩av中文在线观看| 91精彩视频在线| 亚洲欧美偷拍另类a∨色屁股| 国产精品伊人色| 国产日韩v精品一区二区| 美女视频黄 久久| 久久噜噜亚洲综合| 精品在线播放免费| 久久理论电影网| 成人免费视频一区| 国产区在线观看成人精品| 国产乱对白刺激视频不卡| wwwwww.欧美系列| 韩国v欧美v日本v亚洲v| 欧美va在线播放| 国产精品一区二区91| 国产欧美日产一区| 欧美中文字幕久久| 日本亚洲视频在线| 国产精品视频一区二区三区不卡 | 91丨国产丨九色丨pron| 亚洲精品写真福利| 欧美一级精品在线| 国产成人亚洲综合a∨婷婷| 一区二区在线观看视频在线观看| 日本道免费精品一区二区三区| 亚洲bt欧美bt精品| 欧美成人一区二区三区片免费 | 麻豆成人av在线| 一区二区三区鲁丝不卡| 亚洲精品乱码久久久久| 精品国产乱码久久久久久图片 | 午夜伊人狠狠久久| 中文天堂在线一区| 日韩精品中文字幕在线一区| 91麻豆精东视频| 国产一区二区在线电影| 日日夜夜一区二区| 亚洲私人黄色宅男| 亚洲视频免费在线| 中文一区二区在线观看| 欧美电影免费观看高清完整版| 99re视频精品| 色天使色偷偷av一区二区| 国产精品77777竹菊影视小说| 日本伊人精品一区二区三区观看方式 | 中文字幕中文字幕中文字幕亚洲无线| 欧美一区二区黄| 日韩欧美第一区| 欧美mv和日韩mv的网站| 欧美一区二区三区免费| 欧美日韩国产一二三| 欧美四级电影网| 日韩精品专区在线影院重磅| 日韩欧美二区三区| 国产午夜精品一区二区三区四区| 精品播放一区二区| 国产精品久久久久久久蜜臀| 国产精品久久久久久久久久久免费看 | 五月天欧美精品| 久久99国产乱子伦精品免费| 狠狠狠色丁香婷婷综合激情| 国产美女视频一区| 97久久精品人人爽人人爽蜜臀| 色综合亚洲欧洲| 日韩三级伦理片妻子的秘密按摩| 欧美mv和日韩mv国产网站| 久久色视频免费观看| 亚洲欧美另类久久久精品2019| 久久精品国产免费看久久精品| 国产精品系列在线播放| 色婷婷久久99综合精品jk白丝 | 91精品欧美综合在线观看最新| 久久久久久久久久久久久女国产乱| 国产精品午夜电影| 久99久精品视频免费观看| www.日韩精品| 精品日产卡一卡二卡麻豆| 18涩涩午夜精品.www| 国产一区二区三区日韩| 欧洲日韩一区二区三区| 国产亚洲欧洲997久久综合 | 一区二区三区国产精品| 成人免费三级在线| 久久综合九色欧美综合狠狠| 图片区小说区区亚洲影院| 色综合久久综合网97色综合| 国产日韩欧美电影| 黄色小说综合网站| 精品国产免费人成电影在线观看四季| 国产精品天干天干在线综合| 国产成人av电影在线| 国产人成一区二区三区影院| 精品一区二区三区免费视频| 日韩精品一区二区三区在线观看 | 亚洲综合色区另类av| 色综合天天综合色综合av| 亚洲欧美一区二区久久| 精品视频全国免费看| 美腿丝袜在线亚洲一区| 欧美一区二区成人| 精品一区二区三区不卡 | 欧洲一区二区三区在线| 亚洲电影欧美电影有声小说| 精品视频1区2区3区| 日韩黄色在线观看| 欧美va在线播放| 91丨九色丨黑人外教| 图片区日韩欧美亚洲| 精品国产91亚洲一区二区三区婷婷 | 欧美亚洲精品一区| 美女视频黄 久久| 1000部国产精品成人观看| 在线免费不卡电影| 国产一区二区美女| 一区二区三区成人| 国产亚洲一二三区| 9191精品国产综合久久久久久| 国产福利精品导航| 精品一区二区免费视频| 一区二区在线看| 国产精品久久久久久久久快鸭| 欧美午夜电影网| 在线视频你懂得一区二区三区| 久久精品国产亚洲a| 性欧美疯狂xxxxbbbb| 玉米视频成人免费看| 日本一区二区三区四区在线视频 | 欧美色网站导航| 欧美视频在线观看一区二区| av电影天堂一区二区在线 | 懂色av一区二区在线播放| 精品在线视频一区| 久久成人免费网| 国产一区在线精品| 国产麻豆成人传媒免费观看| 久久超级碰视频| 国产成人亚洲综合色影视 | 91精品国产色综合久久不卡电影| 欧美亚洲精品一区| 7777精品伊人久久久大香线蕉最新版 |