Project 1: A Web Server Called Liso

Similar documents
COMP/ELEC 429/556 Introduction to Computer Networks

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

CS118 Discussion Week 2. Taqi

I/O Models. Kartik Gopalan

Version Control with Git and What is there in Project 1 PALLABI GHOSH COMPUTER NETWORKS RECITATION 1

CS118 Discussion 1A, Week 3. Zengwen Yuan Dodd Hall 78, Friday 10:00 11:50 a.m.

Ports under 1024 are often considered special, and usually require special OS privileges to use.

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

10. I/O System Library

CISC2200 Threads Spring 2015

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Introduction to Socket Programming

CSC209 Review. Yeah! We made it!

Any of the descriptors in the set {1, 4} have an exception condition pending

Εργαστήριο 9 I/O Multiplexing

CSE 43: Computer Networks Structure, Threading, and Blocking. Kevin Webb Swarthmore College September 14, 2017

Project 1. 1 Introduction. October 4, Spec version: 0.1 Due Date: Friday, November 1st, General Instructions

Group-A Assignment No. 6

Global Employee Location Server

Computer Networks CS3516 B Term, 2013

Networked Applications: Sockets. End System: Computer on the Net

2/13/2014. A protocol is an agreed-upon convention that defines how communication occurs between two (or more?) endpoints

BSD Sockets API. Mesut Ali ERGIN. Yeditepe University Information and Computer Science Department

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Internet Connectivity with

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

CSE 489/589 Recitation TCP Socket & Synchronous I/O Multiplexing

CS 3013 Operating Systems WPI, A Term Assigned: Friday, August 31, 2007 Due: Monday, September 17, 2007

HTTP Server Application

CSE 333 Lecture non-blocking I/O and select

Computer Networks - A Simple HTTP proxy -

COMP 321: Introduction to Computer Systems

SOCKET PROGRAMMING. What is a socket? Using sockets Types (Protocols) Associated functions Styles

The Specification of Project-1

9/13/2007. Motivations for Sockets What s in a Socket? Working g with Sockets Concurrent Network Applications Software Engineering for Project 1

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

CONCURRENT PROGRAMMING. Lecture 5

Program Assignment 2

Figure 1: Graphical representation of a client-server application

Project Introduction

Computer Networks Prof. Ashok K. Agrawala

Introduction to Lab 2 and Socket Programming. -Vengatanathan Krishnamoorthi

CPS 214: Computer Networks. Slides by Adolfo Rodriguez

Overview. Setup and Preparation. Exercise 0: Four-way handshake

Lecture 7b: HTTP. Feb. 24, Internet and Intranet Protocols and Applications

Lecture 2: Applications and Application Programming

Network Games Part II. Architecture of Network Game

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

ECE697AA Lecture 2. Today s lecture

Network programming(ii) Lenuta Alboaie

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations

Recitation 14: Proxy Lab Part 2

Programming Assignment Multi-Threading and Debugging 2

Types (Protocols) Associated functions Styles We will look at using sockets in C Java sockets are conceptually quite similar

CSE 333 Lecture fork, pthread_create, select

Redesde Computadores(RCOMP)

Programming Assignment 1

What s an API? Do we need standardization?

Recitation: Cache Lab & C

Communication Networks ( ) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University. Allon Wagner

CS631 - Advanced Programming in the UNIX Environment Interprocess Communication II

Question Score 1 / 19 2 / 19 3 / 16 4 / 29 5 / 17 Total / 100

Lab 09 - Virtual Memory

15-441: Computer Networks, Fall 2012 Project 2: Distributed HTTP

December 8, epoll: asynchronous I/O on Linux. Pierre-Marie de Rodat. Synchronous/asynch. epoll vs select and poll

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

ISA 563: Fundamentals of Systems Programming

Josh Primero, Tessa Eng are the lead TAs for this lab.

Project #1: Tracing, System Calls, and Processes

CSE 333 Lecture HTTP

Redes de Computadores (RCOMP)

Key Points for the Review

Programming Assignment 1

Communication Networks ( ) / Fall 2013 The Blavatnik School of Computer Science, Tel-Aviv University

Christian Tschudin (basierend auf einem Foliensatz von C. Jelger und T. Meyer) Departement Mathematik und Informatik, Universität Basel

Martin Brunner, Jonas Pfoh Sept. 6, Sept. 24, 2010

ECE 650 Systems Programming & Engineering. Spring 2018

CS 118 Project Phase 2 P2P Networking

PROGRAMMING ASSIGNMENTS 3 & 4 TAO

Chapter 3: Client-Server Paradigm and Middleware

REALIZATION CONCEPT Version: 1.02

Tutorial on Socket Programming

WEB SECURITY p.1

CS 428, Easter 2017 Proxy Lab: Writing a Proxy Server Due: Wed, May 3, 11:59 PM

G Honors Operating Systems

A Client-Server Exchange

Rudy: a small web server. Johan Montelius. October 2, 2016

Internet applications

EECS122 Communications Networks Socket Programming. Jörn Altmann

CSc 450/550 Computer Networks Network Architectures & Client-Server Model

Peer to Peer Instant Messaging

Decaf PP2: Syntax Analysis

EE 422C HW 6 Multithreaded Programming

Programming Assignment 0

Concurrent Programming. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Socket Programming for TCP and UDP

Transcription:

Project 1: A Web Server Called Liso 15-441/641 Computer Networks Kenneth Yang Viswesh Narayanan

"What happens when you type google.com into your browser's address box and press enter?"... Establish a TCP connection - Checkpoint 1 TLS handshake (HTTPS) - Checkpoint 3 Send HTTP request Server generate HTTP response - Checkpoint 2 & 3... 2

Project 1 Overview Checkpoint 1 Socket programming I/O multiplexing with select Request parsing with Lex/Yacc Extras Design documentation Your own tests Checkpoint 2 Persistent connection Generate response for GET, HEAD, POST Final submission HTTPS CGI 3

Basic concept: Client server model 4

Basic concept: Socket Socket: Connection: endpoint <ip, port> Source endpoint <ip, port> + Destination endpoint <ip, port> 5

Establish a TCP connection (client) Create a socket via socket() Connect to an endpoint via connect() Write to socket via send() Read from socket via recv() 6

Establish a TCP connection (server) Create a socket via socket() Bind to an endpoint via bind() Listen for connections via listen() Accept connections via accept() Read from socket via recv() Write to socket via send() 7

Establish a TCP connection Review 15-213/18-213/15-513 proxy lab. Check starter code for example usage. Use man page. 8

Gotchas Endianness Matters: Network Byte Order htons() - host to network short ntohs() -network to host short Cleanup state avoid memory leaks freeaddrinfo() close() free() - check memory leak with valgrind Error Handling Tedious, but worth it (and required!) 9

Gotchas Timeouts Implement for robust networking behavior Prepare your code for random failures We introduce random faults when grading Test too - ctrl+c server and client randomly 10

Concurrency Multithreading Server gives each client its own thread Not in this class! I/O Multiplexing Watch a set of sockets (in main thread) Use select() to find sockets ready for I/O Server-side only - clients are agnostic 11

Everything is a file File descriptor (fd) a non-negative integer text file, pipe, socket etc. stdin-0, stdout-1, stderr-2 select() manage file descriptors and examine their status 12

select() #include <sys/select.h> int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); void FD_CLR(int fd, fd_set *set); // removes fd from set int FD_ISSET(int fd, fd_set *set); // is fd in set? void FD_SET(int fd, fd_set *set); // adds fd to set void FD_ZERO(fd_set *set); // clears set Useful reference for select(): Beej's Guide to Network Programming: http://beej.us/guide/bgnet/output/html/multipage/index.html man select 13

Advice from past TAs Check return value of recv() Error handle the error and clear up state If peer shutdown connection, clear up state Maintain state Maintain a read buffer Keep track of number of bytes to read May need multiple reads to get all data (Don t worry about this in checkpoint 1) Only one read per socket when select() returns 14

Advice from past TAs Check return value of send() Error handle the error and clear up state If peer shutdown connection, clear up state Maintain state Maintain a write buffer Keep track of number of bytes to write May need multiple writes to send all data (Don t worry about this in checkpoint 1) 15

Remember Code quality Clean code with appropriate comments will help you debug Robustness Handle errors Be careful with buffer overflow Connection reset by peer Efficiency Avoid extra or useless buffer copy 16

Common mistakes Make sure your executable is named correctly. tar your complete repo and submit. Autolab expects to find a.git folder within your submission Don't forget to update the tag when you make changes to your code. We run a checkout with the tag name, not your last commit. 17

Why need HTTP Parsing? Socket programming lets you read and write data. We need to interpret the data in the form of requests. GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1 Host: net.tutsplus.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729) Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Keep-Alive: 300 Connection: keep-alive Cookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120 Pragma: no-cache Cache-Control: no-cache 18

Solution: Implement rules Web Server Read bytes Apply rules Socket Lex/Yacc Response 19

Lex/Yacc Overview... definitions... %%... rules... %%... subroutines... Lex =>Lexical Analyzer YACC=>Yet Another Compiler compiler Define tokens. (Already done by us) Apply rules on tokens. You now have HTTP parser! 20

Starter Code Explanation (Rule 1) RULE for request line GET /some/example/uri/ HTTP/1.1 Snippet from parser.y: request_line: token t_sp text t_sp text t_crlf { YPRINTF("request_Line:\n%s\n%s\n%s\n",$1, $3,$5); strcpy(parsing_request->http_method, $1); strcpy(parsing_request->http_uri, $3); strcpy(parsing_request->http_version, $5); } 21

Starter Code Explanation (Rule 2) RULE for request header Host: cs.cmu.com Snippet from parser.y: request_header: token ows t_colon ows text ows t_crlf { YPRINTF("request_Header:\n%s\n%s\n",$1,$5); strcpy(parsing_request->headers[parsing_request->header_count].header_name, $1); strcpy(parsing_request->headers[parsing_request->header_count].header_value, $5); parsing_request->header_count++; }; 22

Design Document High-level overview of your code. Intuitions, design choices/trade-offs and flow-diagrams. This works as your insurance -- if your code our fails test cases. Treat this seriously as this the first thing we will look out for. 23

Don t paste your code and explain 24

Some good examples https://github.com/netsys/bess/wiki/bess-overview 25

Some good examples http://www.aosabook.org/en/bash.html 26

Questions? Good Luck and Start Early! 27