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

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

?? sim.c

?? ARQ協議的實現 從單工停等到滑動窗口協議的實現
?? C
字號:
/* Simulator for the protocols in chapter 3 of 
 *    "Computer Networks, 3rd ed. by Andrew S. Tanenbaum.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include "common.h"

#define DEADLOCK (3 * timeout_interval)	/* defines what a deadlock is */
#define MAX_PROTOCOL 6		/* highest protocol being simulated */
#define MANY 256		/* big enough to clear pipe at the end */

bigint tick = 0;		/* the current time, measured in events */
bigint last_tick;		/* when to stop the simulation */
int exited[2];			/* set if exited (for each worker) */
int hanging[2];			/* # times a process has done nothing */
struct sigaction act, oact;

/* Prototypes. */
void main(int argc, char *argv[]);
int parse_args(int argc, char *argv[]);
void set_up_pipes(void);
void fork_off_workers(void);
void terminate(char *s);
void sender2(void);
void receiver2(void);
void sender3(void);
void receiver3(void);
void protocol4(void);
void protocol5(void);
void protocol6(void);

void main(int argc, char *argv[])
{
/* The simulator has three processes: main, M0, and M1, all of which run
 * independently.  Set them all up first.  Once set up, main maintains the
 * clock (tick), and picks a process to run.  Then it writes a 32-bit word
 * to that process to tell it to run.  The process sends back an answer
 * when it is done.  Main then picks another process, and the cycle repeats.
 */

  int process = 0;		/* whose turn is it */
  int rfd, wfd;			/* file descriptor for talking to workers */
  bigint word;			/* message from worker */

  act.sa_handler = SIG_IGN;
  setvbuf(stdout, (char *) 0, _IONBF, (size_t) 0);	/* disable buffering*/
  if (parse_args(argc, argv) < 0) exit(1);     /* check args; store in mem */
  set_up_pipes();		/* create five pipes */
  fork_off_workers();		/* fork off the worker processes */

  /* Main simulation loop. */
  while (tick <last_tick) {
	process = rand() & 1;		/* pick process to run: 0 or 1 */
	tick = tick + DELTA;
	rfd = (process == 0 ? r4 : r6);
	if (read(rfd, &word, TICK_SIZE) != TICK_SIZE) terminate("");
	if (word == OK) hanging[process] = 0;
	if (word == NOTHING) hanging[process] += DELTA;
	if (hanging[0] >= DEADLOCK && hanging[1] >= DEADLOCK)
		terminate("A deadlock has been detected");

	/* Write the time to the selected process to tell it to run. */
	wfd = (process == 0 ? w3 : w5);
	if (write(wfd, &tick, TICK_SIZE) != TICK_SIZE)
		terminate("Main could not write to worker");

  }

  /* Simulation run has finished. */
  terminate("End of simulation");
}


int parse_args(int argc, char *argv[])
{
/* Inspect args on the command line and save them. */
  if (argc != 7) {
	printf("Usage: sim protocol events timeout loss cksum debug\n");
	return(-1);
  }

  protocol = atoi(argv[1]);
  if (protocol < 2 || protocol > MAX_PROTOCOL) {
	printf("Protocol %d is not valid.\n", protocol);
	return(-1);
  }

  /* Each event uses DELTA ticks to make it possible for each timeout to
   * occur at a different tick.  For example, with DELTA = 10, ticks will
   * occur at 0, 10, 20, etc.  This makes it possible for a timeout in
   * protocol 5 to schedule multiple timeouts for the future, all at unique
   * times, e.g. 1070, 1071, 1072, 1073, etc.  This property is needed to
   * make sure timers go off in the order they were set.  As a consequence,
   * internally, the variable tick is bumped by DELTA on each event.  Thus
   * asking for a simulation run of 1000 events will give 1000 events, but
   * they internally they will be called 0 to 10,000.
   */
  last_tick = DELTA * atol(argv[2]);	/* each event uses DELTA ticks */
  if ((long) last_tick < 0) {
	printf("Number of simulation events must be positive\n");
	return(-1);
  }

  /* Convert from external units to internal units so the user does not see
   * the internal units at all.
   */
  timeout_interval = DELTA * atoi(argv[3]);
  if ((long)timeout_interval < 0 || (protocol > 2 && timeout_interval == 0) ){
	printf("Timeout interval must be positive\n");
	return(-1);
  }

  /* Packet loss takes place at the sender.  Packets selected for being lost
   * are not put on the wire at all.  Internally, pkt_loss and garbled are
   * from 0 to 990 so they can be compared to 10 bit random numbers.  The
   * inaccuracy here is about 2.4% because 1000 != 1024.  In effect, it is
   * not possible to say that all packets are lost.  The most that can be
   * be lost is 990/1024.
   */
  pkt_loss = atoi(argv[4]);	/* percent of sends that chuck pkt out */
  if (pkt_loss < 0 || pkt_loss > 99) {
	printf("Packet loss rate must be between 0 and 99\n");
	return(-1);
  }
  pkt_loss = 10 * pkt_loss;	/* for our purposes, 1000 == 1024 */

  /* This arg tells what fraction of arriving packets are garbled.  Thus if
   * pkt_loss is 50 and garbled is 50, half of all packets (actually,
   * 500/1024 of all packets) will not be sent at all, and of the ones that
   * are sent, 500/1024 will arrive garbled.
   */
  garbled = atoi(argv[5]);
  if (garbled < 0 || garbled > 99) {
	printf("Packet cksum rate must be between 0 and 99\n", garbled);
	return(-1);
  }
  garbled = 10 * garbled;	/* for our purposes, 1000 == 1024 */

  /* Turn tracing options on or off.  The bits are defined in worker.c. */
  debug_flags = atoi(argv[6]);
  if (debug_flags < 0) {
	printf("Debug flags may not be negative\n", debug_flags);
	return(-1);
  }
  printf("\n\nProtocol %d.   Events: %u    Parameters: %u %d %u\n", protocol,
      last_tick/DELTA, timeout_interval/DELTA, pkt_loss/10, garbled/10,
								debug_flags);
  return(0);			/* no errors in command line parameters */
}

void set_up_pipes(void)
{
/* Create six pipes so main, M0 and M1 can communicate pairwise. */

  int fd[2];

  pipe(fd);  r1 = fd[0];  w1 = fd[1];	/* M0 to M1 for frames */
  pipe(fd);  r2 = fd[0];  w2 = fd[1];	/* M1 to M0 for frames */
  pipe(fd);  r3 = fd[0];  w3 = fd[1];	/* main to M0 for go-ahead */
  pipe(fd);  r4 = fd[0];  w4 = fd[1];	/* M0 to main to signal readiness */
  pipe(fd);  r5 = fd[0];  w5 = fd[1];	/* main to M1 for go-ahead */
  pipe(fd);  r6 = fd[0];  w6 = fd[1];	/* M1 to main to signal readiness */
}

void fork_off_workers(void)
{
/* Fork off the two workers, M0 and M1. */

  if (fork() != 0) {
	/* This is the Parent.  It will become main, but first fork off M1. */
	if (fork() != 0) {
		/* This is main. */
		sigaction(SIGPIPE, &act, &oact);
	        setvbuf(stdout, (char *)0, _IONBF, (size_t)0);/*don't buffer*/
		close(r1);
		close(w1);
		close(r2);
		close(w2);
		close(r3);
		close(w4);
		close(r5);
		close(w6);
		return;
	} else {
		/* This is the code for M1. Run protocol. */
		sigaction(SIGPIPE, &act, &oact);
	        setvbuf(stdout, (char *)0, _IONBF, (size_t)0);/*don't buffer*/
		close(w1);
		close(r2);
		close(r3);
		close(w3);
		close(r4);
		close(w4);
		close(w5);
		close(r6);
	
		id = 1;		/* M1 gets id 1 */
		mrfd = r5;	/* fd for reading time from main */
		mwfd = w6;	/* fd for writing reply to main */
		prfd = r1;	/* fd for reading frames from worker 0 */
		switch(protocol) {
			case 2:	receiver2();	break;
			case 3:	receiver3();	break;
			case 4: protocol4();	break;
			case 5: protocol5();	break;
			case 6: protocol6();	break;
		}
		terminate("Impossible.  Protocol terminated");
	}
  } else {
	/* This is the code for M0. Run protocol. */
	sigaction(SIGPIPE, &act, &oact);
        setvbuf(stdout, (char *)0, _IONBF, (size_t)0);/*don't buffer*/
	close(r1);
	close(w2);
	close(w3);
	close(r4);
	close(r5);
	close(w5);
	close(r6);

	id = 0;		/* M0 gets id 0 */
	mrfd = r3;	/* fd for reading time from main */
	mwfd = w4;	/* fd for writing reply to main */
	prfd = r2;	/* fd for reading frames from worker 1 */

	switch(protocol) {
		case 2:	sender2();	break;
		case 3:	sender3();	break;
		case 4: protocol4();	break;
		case 5: protocol5();	break;
		case 6: protocol6();	break;
	}
	terminate("Impossible. protocol terminated");
  }
}

void terminate(char *s)
{
/* End the simulation run by sending each worker a 32-bit zero command. */

  int n, k1, k2, res1[MANY], res2[MANY], eff, acc, sent;

  for (n = 0; n < MANY; n++) {res1[n] = 0; res2[n] = 0;}
  write(w3, &zero, TICK_SIZE);
  write(w5, &zero, TICK_SIZE);
  sleep(2);

  /* Clean out the pipe.  The zero word indicates start of statistics. */
  n = read(r4, res1, MANY*sizeof(int));
  k1 = 0;
  while (res1[k1] != 0) k1++;
  k1++;				/* res1[k1] = accepted, res1[k1+1] = sent */

  /* Clean out the other pipe and look for statistics. */
  n = read(r6, res2, MANY*sizeof(int));
  k2 = 0;
  while (res1[k2] != 0) k2++;
  k2++;				/* res1[k2] = accepted, res1[k2+1] = sent */

  if (strlen(s) > 0) {
	acc = res1[k1] + res2[k2];
	sent = res1[k1+1] + res2[k2+1];
	if (sent > 0) {
		eff = (100 * acc)/sent;
 	        printf("\nEfficiency (payloads accepted/data pkts sent) = %d%c\n", eff, '%');
	}
	printf("%s.  Time=%u\n",s, tick/DELTA);
  }
  exit(1);
 }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲综合一区在线| 五月天视频一区| 欧美一区二区三区色| 成人一区在线看| 蜜桃av一区二区三区电影| 国产成人午夜高潮毛片| 亚洲一二三四在线| 国产精品久久久久久久久久久免费看| 欧美三级在线视频| 91在线视频播放地址| 国产毛片一区二区| 蜜臀av一级做a爰片久久| 亚洲资源中文字幕| 亚洲欧美日本韩国| 中文成人av在线| 亚洲精品在线一区二区| 欧美人体做爰大胆视频| 色成年激情久久综合| 波多野洁衣一区| 国产精品99久久久久久似苏梦涵 | 97久久精品人人做人人爽| 老司机免费视频一区二区| 亚洲国产精品综合小说图片区| 亚洲欧洲美洲综合色网| 国产农村妇女毛片精品久久麻豆| 久久综合色综合88| 欧美成人三级在线| 欧美一区二区三区视频在线| 91精品视频网| 欧美人与性动xxxx| 91精品国产综合久久精品| 欧美日韩中文另类| 欧美天天综合网| 欧美性猛片aaaaaaa做受| 91福利国产成人精品照片| 91黄色免费网站| 欧美日免费三级在线| 欧美色爱综合网| 欧美午夜片在线看| 欧美日韩亚洲综合在线| 欧美日韩高清一区| 91精品国产入口在线| 欧美一级黄色片| 精品日本一线二线三线不卡| 欧美电视剧在线观看完整版| 久久综合999| 国产欧美日韩视频一区二区| 欧美高清在线视频| 中文字幕在线不卡一区二区三区 | 中文字幕在线不卡国产视频| 亚洲国产精品99久久久久久久久| 欧美激情综合网| 亚洲日本中文字幕区| 樱花草国产18久久久久| 亚洲h动漫在线| 另类的小说在线视频另类成人小视频在线| 麻豆精品一区二区三区| 欧美午夜不卡在线观看免费| 在线播放/欧美激情| 精品久久久久久久久久久久久久久 | 香港成人在线视频| 日本亚洲天堂网| 国产一区二区三区美女| 99久久精品国产一区二区三区| 在线视频一区二区三区| 91麻豆精品91久久久久久清纯| 2014亚洲片线观看视频免费| 国产精品免费久久| 亚洲成在人线在线播放| 久久精品国产第一区二区三区| 国产成a人无v码亚洲福利| 色婷婷狠狠综合| 91精品国产综合久久久久久久久久 | 国产成人在线免费观看| 一本大道久久a久久综合| 69堂国产成人免费视频| 国产精品三级电影| 爽爽淫人综合网网站| 国产精品影视在线观看| 在线视频一区二区三区| 久久亚洲二区三区| 亚洲午夜一二三区视频| 国产在线国偷精品产拍免费yy| 色综合久久久久综合| 日韩三级免费观看| 亚洲男女一区二区三区| 国产在线一区二区| 欧美美女bb生活片| 国产精品久久久久久久久免费桃花 | 99精品久久99久久久久| 日韩欧美成人一区二区| 中文字幕不卡在线观看| 亚洲一区在线电影| 经典三级视频一区| 91国偷自产一区二区开放时间| 欧美一区二区高清| 亚洲国产精品久久久久婷婷884 | 免费人成精品欧美精品| 成人午夜在线播放| 日韩你懂的在线播放| 日韩美女视频一区| 成人视屏免费看| 欧美成人女星排行榜| 亚洲欧美日韩国产一区二区三区 | 色噜噜狠狠成人中文综合| 精品国产在天天线2019| 婷婷亚洲久悠悠色悠在线播放| 成人免费视频视频| 欧美r级在线观看| 狠狠色狠狠色综合日日91app| 日本久久电影网| √…a在线天堂一区| 国产成人一级电影| 国产亚洲欧美日韩俺去了| 国产一区二区影院| 久久久久久久久久久99999| 午夜精品久久久久久久99樱桃| 国产iv一区二区三区| 26uuu国产一区二区三区| 国产精品亚洲视频| 色婷婷精品大在线视频| 欧美日韩成人激情| 亚洲蜜臀av乱码久久精品蜜桃| 99免费精品视频| 亚洲线精品一区二区三区 | 2020国产精品自拍| 亚洲毛片av在线| 成人高清在线视频| 中文字幕高清不卡| 国产高清视频一区| 久久久另类综合| 国产精品自拍在线| 久久网这里都是精品| 精品无人码麻豆乱码1区2区 | 欧美在线免费视屏| 亚洲综合色视频| 欧美特级限制片免费在线观看| 亚洲综合免费观看高清在线观看| 91国内精品野花午夜精品| 亚洲香蕉伊在人在线观| 欧美日韩一区二区三区四区| 日韩精品一卡二卡三卡四卡无卡| 欧美日韩另类一区| 青青青伊人色综合久久| 日韩精品一区二区三区中文不卡 | 欧洲一区在线电影| 国产a视频精品免费观看| 国产三级一区二区| 91一区二区三区在线观看| 亚洲少妇最新在线视频| 欧美性生活一区| 奇米影视7777精品一区二区| 亚洲精品在线三区| a亚洲天堂av| 亚洲国产一区二区在线播放| 911精品产国品一二三产区| 精品一区二区三区影院在线午夜| 国产嫩草影院久久久久| 91欧美一区二区| 日韩精品三区四区| 亚洲精品一区二区三区香蕉| 成人动漫一区二区| 亚洲一区二区欧美日韩 | 国产精品毛片a∨一区二区三区| 色视频一区二区| 麻豆精品视频在线观看免费| 国产日韩精品一区| 色欧美日韩亚洲| 蜜臀精品久久久久久蜜臀| 欧美国产97人人爽人人喊| 欧美日韩另类一区| 国产成人在线视频网址| 亚洲在线视频一区| 久久精子c满五个校花| 在线观看亚洲一区| 欧美一区二区黄色| 日韩欧美一区中文| 中文字幕不卡一区| 三级久久三级久久| 午夜欧美电影在线观看| 五月婷婷久久丁香| 日本美女一区二区三区视频| 老司机免费视频一区二区三区| 久久99国内精品| 欧美日韩一区在线观看| 欧美日韩亚洲另类| 欧美mv日韩mv| 一区二区理论电影在线观看| 蜜桃精品视频在线观看| 国产乱码字幕精品高清av| 欧美日韩国产一区二区三区地区| 国内精品久久久久影院薰衣草| 亚洲青青青在线视频| 久久亚洲综合色| 欧美日韩综合在线| 99久久精品一区| 国产精品一级二级三级| 日本欧洲一区二区| 亚洲在线视频网站| 亚洲色图欧洲色图婷婷|