CS4516 Program 2 Help Session (C10)

Slides:



Advertisements
Similar presentations
Intermediate TCP/IP TCP Operation.
Advertisements

I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
1 Elementary TCP Sockets socket function connect function bind function listen function accept function fork and exec functions Concurrent servers close.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
CSCE 515: Computer Network Programming TCP Details Wenyuan Xu Department of Computer Science and Engineering.
Global Employee Location Server Jeff Zhou 3/19/2011 CS4516 HELP Session 1 Modified based on CS4514 B05 slides.
Client 1 Client 2 Server Child Process1 Child Process2 (1) (2) (3) serverbase.txt Note: each child process keeps a separate copy of the DB.
Client 1 Client 2 Server Child Process1 Child Process2 (1) (2) (3) serverbase.txt Note: each child process keeps a separate copy of the DB.
Reliable Networking Tom Roeder CS sp. Last minute questions on Part II?
CS4514-Help Session By Huahui Wu. Description In this project, you are supposed to implement a PAR (Positive Acknowledgement with Retransmission)
Cs4411 – Operating Systems Practicum November 4, 2011 Zhiyuan Teo Supplementary lecture 4.
CS4514 HELP Session 3 Concurrent Server Using Go-Back-N Song Wang 12/08/2003.
Concurrent Server Using Selective Repeat Data Link Layer Mingzhe Li 12/05/2005 CS4514 HELP Session 3.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
CS4514 Assignment 2 Help Session – Data Link Layer Client and Server Processes Speaker: Hao Shang Date: Nov. 11th, 2004.
CS4514 HELP Session 3 Concurrent Server Using Go-Back-N Song Wang 02/17/2004.
1 CS4514 – B03 Project 2 Help Session Choong-Soo Lee November 24, 2003.
1 CCNA 2 v3.1 Module Intermediate TCP/IP CCNA 2 Module 10.
Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework.
TCP. Learning objectives Reliable Transport in TCP TCP flow and Congestion Control.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
1 CS4514 Project 2 Help Session (B05) Mingzhe Li Nov 10, 2005.
Project 2: A P2P Chat Application Review Ananth Rao.
CS4516: Medical Examiner Client/Server Evan Frenn 1.
Elementary TCP Sockets
1 Semester 2 Module 10 Intermediate TCP/IP Yuda college of business James Chen
LWIP TCP/IP Stack 김백규.
1 CS3516 Project 3 Help Session (B14) Dongqing Xiao Dec 04, 2014.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
TCP1 Transmission Control Protocol (TCP). TCP2 Outline Transmission Control Protocol.
Elementary TCP Sockets
Programming with TCP – III 1. Zombie Processes 2. Cleaning Zombie Processes 3. Concurrent Servers Using Threads  pthread Library Functions 4. TCP Socket.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
I/O Multiplexing. What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors,
Today’s topic: UDP Reliable communication over UDP.
CMPT 471 Networking II Network Programming © Janice Regan,
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
Transport Layer: Sliding Window Reliability
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
1 CS3516 Project 3 Help Session (A15) Dongqing Xiao Sep 30th,2015.
© 2002, Cisco Systems, Inc. All rights reserved..
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Computer Networking Lecture 16 – Reliable Transport.
ECE 297 Concurrent Servers Process, fork & threads ECE 297.
Chapter 9: Transport Layer
Chapter 3 Transport Layer
I/O Multiplexing.
Instructor Materials Chapter 9: Transport Layer
Review: TCP Client-Server Interaction
Concurrent Server Using Go-Back-N
Introduction of Transport Protocols
Transport Layer Our goals:
Overview Jaringan Komputer (2)
Lecture 4 Socket Programming Issues
Chapter 5 (part 1) TCP Client /Server Example By: Lim Meng Hui.
Process-to-Process Delivery:
Chapter 5 Peer-to-Peer Protocols and Data Link Layer
CS4514 Project 2 Help Session (B07)
Advanced Network Programming spring 2007
CS4470 Computer Networking Protocols
TCP/IP Socket Programming in C
Concurrent Server (in APP) Using Go-Back-N (in DLL)
Simulation of Datalink Layer Communication Speaker: Jae Chung
Chapter 5 Peer-to-Peer Protocols and Data Link Layer
Lecture 4 Peer-to-Peer Protocols and Data Link Layer
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Presentation transcript:

CS4516 Program 2 Help Session (C10) Choong-Soo Lee and Rabin Karki Jan. 26, 2010

Description The goal is to implement a concurrent server with a Positive Acknowledgement with Retransmission (PAR) protocol on top of an emulated physical layer. The receiver acknowledges only the correctly received segments and the sender uses timeout to detect and send the lost segment. Physical layer is emulated by a TCP connection plus an error module. Your programs should compile and work on “cccwork[1-2].wpi.edu”

Framework Client Server Network Layer Network Layer Data Link Layer Physical Layer Physical Layer Do NOT attempt to put everything in one big main()

Network Layer Client Server Network Layer Network Layer photo[1-5].jpg photonew[id][1-5].jpg read (block) write (block) Network Layer Network Layer nwl_recv(pkt) nwl_recv(ack) Network layer ack Network layer ack pkt pkt Packet size: 128 bytes

Data Link Layer Client Server Network Layer Network Layer Network layer ack Network layer ack pkt dll_send(pkt) dll_send(pkt) Data Link Layer Data Link Layer dll_recv(frm) dll_recv(frm) ack/frm (Network Layer ack) frm frm ack/frm (Network Layer ack) Client link layer does not need to ACK “Network Layer ACK” frame!

Physical Layer Client Server Datalink Layer Datalink Layer ack frm phl_send() phl_send() Physical Layer Physical Layer phl_recv() phl_recv() TCP Connection

Client: dll_send(pkt, …) 1. Read a block and split into payloads phl_send(frm, …): Force bit error every 6-th Frame 2. For each payload 2.1 Create Frame (frm) 2.2.1 Timeout Handler: phl_send(frm, …) 2.2 Start a Timer 2.3 phl_send(frm, …) 2.4 phl_recv(ack/frm,…) ack/frm? 2.4.1 nwl_ack received frm ack ack ok? no yes client.log 3. Waiting for Network Layer ack: if (!nwl_ack) phl_recv(frm,…)

Create Frame Datafield 1. Compute Seq Number, Frame Type and End-Of-Packet (EOP) bytes Seq FT EOP Datafield 2. Error-Detection (ED) bytes (XOR on Seq + FT + EOP + Data) Seq FT EOP Datafield ED 2 Bytes 1 Byte 1 Byte <= 80 Bytes 2 Bytes EOP: End of Packet ED: Error Detection FT: Frame Type Seq: Sequence Num

Server: dll_recv(frm, …) 1. Compute ED byte phl_send(ack, …): Force bit error every 8-th Frame ED ok? Return no yes Dup? Drop frm yes no server.log 2. Create ACK Frame (ack) 3. phl_send(ack, …) no EOP? 4. Reassemble the packet yes 5. nwl_recv(pkt, …)

Create ACK Frame 1. Compute Seq Number and Frame Type Seq FT 2. Error-Detection (ED) bytes (ED = Seq) Seq FT ED 2 Bytes 1 Byte 2 Bytes EOP: End of Packet ED: Error Detection FT: Frame Type Seq: Sequence Num

Timers The client uses a timer to detect a frame loss. The client sets a timer when it transmits a frame. When the timer expires, the client retransmits the frame. Two kinds of timer Select : easier to use Signal and Timer : nicer implementation

Select: Monitor Given FDs (SDs) # include <sys/select.h> # include <sys/time.h> int select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout); struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ }

Example: Select fd_set bvfdRead; int readyNo; struct timeval timeout; int sockfd; while (1) { timeout.tv_sec = 0; timeout.tv_usec = 500; FD_ZERO(&bvfdRead); FD_SET(sockfd, &bvfdRead); readyNo = select(sockfd+1, &bvfdRead, 0, 0, &timeout); if(readyNo < 0) error_handler(); else if(readyNo == 0) timeout_handler(); else { FD_ZERO(&bvfdRead); receive_handler(); }

Signal and Timer: Soft Interrupt Head files #include <signal.h> #include <time.h> Register a function to TIMEOUT signal signal (SIGALRM, timeout); Create a timer and begin to run timer_create(); timer_settime(); Compile with option “-lrt” (link runtime library)

Example: Signal and Timer timer_t timer_id; void timeout(int signal_number){ printf("\n SIGNUM: %d\n", signal_number); exit(0); } void start_timer(){ struct itimerspec time_val; signal (SIGALRM, timeout); timer_create( CLOCK_REALTIME, NULL, &timer_id); /* set timeout to 1 second */ time_val.it_value.tv_sec = 1; time_val.it_value.tv_nsec = 0; time_val.it_interval.tv_sec = 0; time_val.it_interval.tv_nsec = 0; timer_settime(timer_id, 0, &time_val, NULL); } main(){ start_timer(); while(1);

System Overview Child Process1 Child Process2 serverbase.txt client1.log Server (1) Client1 (3) (2) fork() (4) fork() client2.log Child Process1 Client2 Child Process2 Note: each child process keeps a separate copy of the DB. we do not keep data consistency for the serverbase This is automatically done by using fork() 11/23/2018

Concurrent Photo Server Server will process requests in parallel (hence, concurrent server) There are several ways to achieve concurrency Using fork() Using multiple threads Using select()

fork() It splits current process into two processes: a parent and a child. How does the program determine whether it is the parent or the child after the split? The fork() command returns 0 if it is the child. So all we need to do is check the return value from fork(). Now you can program the child to handle the data transmission and the parent can continue on to accept other requests.

Example pid_t pid, id; int listenfd, connfd; /* 1. create a socket socket() */ if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ perror("Error creating socket"); exit(1); } /* 2. fill in sockaddr_in{ } with server's well-known port */ … /* 3. bind socket to a sockaddr_in structure bind() */ bind (listenfd, ...); /* 4. specify the backlog of incoming connection requests listen() */ listen (listenfd, 5); while(1){ connfd = accept(listenfd, ... ); if(( pid = fork()) == 0){ close(listenfd); /* child closes listening socket */ doit(connfd); /* process the request. this is where the work is done. */ close(connfd); /* done with this client */ exit(0); } close(listenfd); /* parent closes the socket */

Open a File Open a file for read: int rfile; if ((rfile = open(“filename1”, O_RDONLY)) < 0) { perror("Input File Open Error"); exit(1); } Open a file for write (create if not exist): int ofile; if ((ofile = open(“filename2”, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) < 0) perror("Output File Open Error");

File Read Read from file if (rd_size < 0) while ((rd_size = read(rfile, buf, 190)) > 0) { do something with “buf” here } if (rd_size < 0) perror("File Read Error"); exit(1); else printf ("Reach the end of the file\n");

File Write/Close Write to File Close files if ((wr_size = write(ofile, buf, rd_size)) < 0) { perror("Write Error:"); exit(1); } Close files close(rfile); close(ofile);

Display Image in Linux Make sure you have “X forwarding” with your ssh client And you need have an Xserver (X-Win32 or etc.) running on you windows computer. The image display is not required for the Project. These code tested on cccwork[1-2].wpi.edu if (fork() == 0) { execl("/usr/local/bin/xv", "xv", “image.jpg”, NULL); } else wait(NULL); printf("Done display! \n");

Questions?