Title: Course Introduction
1Course Introduction
- OSI reference model
- services
- interfaces
- protocols
- TCP/IP reference model
- Example protocols
2Where do the layers reside?
- Which layers are implemented by OS?
- The interfaces between OS and applications
- Socket API
3What is the course about?
- Application designs
- Client designs
- Server designs
- Application implementations
- Socket APIs
- Interaction of applications and TCP/IP stack
- Application protocols
- RTP, RTSP, SIP
4Standard Application Protocols
- Standard applications well documented,
standardized and adopted as official TCP/IP suite - Examples
- email
- telnet
- ftp
- More?
- Let us look more closely at telnet
- (multiple choice) telnet application can be used
to - A. Remotely access terminals
- B. Remotely access services
- C. Send an email
- D. Fetch a web page
5Fetching a web page using telnet
- 1. Telnet to your favorite Web server
Opens TCP connection to port 80 (default http
server port) at cis.poly.edu. Anything typed in
sent to port 80 at cis.poly.edu
telnet cis.poly.edu 80
- 2. Type in a GET http request
By typing this in (hit carriage return twice),
you send this minimal (but complete) GET request
to http server
GET /ross/ HTTP/1.0
3. Look at response message sent by http server!
6Scenario Alice sends message to Bob
- 4) MTA (Message Transfer Agent) in mail server
sends Alices message over the TCP connection - 5) Bobs mail server places the message in Bobs
mailbox - 6) Bob invokes his user agent to read message
- 1) Alice uses MUA to compose message and to
bob_at_someschool.edu - 2) Alices MUA sends message to her mail server
message placed in message queue - 3) Client side of SMTP opens TCP connection with
Bobs mail server
1
2
6
3
4
5
7Sample smtp interaction
S 220 hamburger.edu C HELO crepes.fr
S 250 Hello crepes.fr, pleased to meet
you C MAIL FROM ltalice_at_crepes.frgt
S 250 alice_at_crepes.fr... Sender ok C RCPT
TO ltbob_at_hamburger.edugt S 250
bob_at_hamburger.edu ... Recipient ok C DATA
S 354 Enter mail, end with "." on a line
by itself C Do you like ketchup? C
How about pickles? C . S 250
Message accepted for delivery C QUIT
S 221 hamburger.edu closing connection
More messages?
8Sending an email using telnet
- telnet servername 25
- HELO your own domain name
- MAIL FROM ltyour own email addressgt
- RCPT TO ltrecipient addressgt
- DATA
- QUIT
9What can we learn here?
- telnet goes beyond standard terminal access and
provides basic interactive communication facility - telnet protocol provides maximal flexibility
because it only defines interactive communication
but not the details of the service accessed - Users at many sites may want to access the same
service at the same time. It is important yet
challenging to provide concurrent services
10Client-server model
- Typical network app has two pieces client and
server
- Client
- initiates contact with server (speaks first)
- typically requests service from server,
- for Web, client is implemented in browser for
e-mail, in mail reader - Server
- provides requested service to client
- e.g., Web server sends requested Web page, mail
server delivers e-mail
11More on Client Server Model
- Clients initiate requests
- Servers wait for incoming requests and provide
services - Servers always up and running
- Operating systems normally start servers
automatically when they start - More differences
- Servers access system resources gt special
privileges - Servers sometimes handle security issues
12Connectionless vs. Connection-Oriented Protocols
- Connectionless protocols
- UDP
- Fast
- Unreliable
- Connection-oriented protocols
- TCP
- Slower
- Reliable
- Examples
13Stateless vs. Stateful Protocols
- Stateful protocols
- Keeping states in the servers
- Reducing the size and number of messages
- Applications sometimes need session information
- Stateless protocols
- Simple
- Protocol reliability
- example
- Stateless file server
- Stateful file server
14How to keep track of clients?
- Two ways
- End points (IP address, port number)
- What is wrong?
- Handles
- A short identifier allocated by the server,
stored in servers database and sent to the
client
15Keeping track of clients handles
- user accounts
- shopping carts
- Web portals
- Advertising
- Secretly collecting users browsing habits
- What to do?
16More on Stateful Protocols
- Keeping correct states is challenging
- What happens when clients crash and reboot?
- What happens when messages arrive out of order,
get duplicated or get lost? - Keeping states sometimes poses security risks
- Tracking browsing patterns
- Loss of confidential information (e.g. credit
card number, ssn)
17Concurrent Processing
- Concurrent Processing
- Why is it needed?
- Achieving concurrent processing
- Time sharing
- multiprocessing
- Concurrency in clients
- no special efforts by client programmers
- Concurrency in servers
- Special efforts needed by server programmers
- Multiple processes
- Multiple threads
18Processes and Threads
- Processes
- Fundamental unit of computation
- An address space and at least one thread of
execution (instruction pointer) - Thread
- Light-weight process
- Program vs process
- Static concept
19Sharing of Variables
- Local Variable Rule - When multiple processes or
threads execute a piece of code concurrently,
each creates its own independent copy of the
variables associated with the code (local
variables) - Global Variable Rule - Each process creates a
copy of global variables, but multiple threads
within a single process share the processs
global variables
- int x
- for (i1 ilt10 i)
- printf (d\n, ix)
20Procedure Calls
- Procedure Call Rule - When multiple threads
execute a piece of code concurrently, each has
its own stack of procedure activation records - Example - Putting the rules together!
21Example of Concurrent Process Creation
- Example 1
- Sequential processing
- Example 2
- Concurrent version
- Computationally light
- Computationally intensive
- Both processes do the same job!
22Sequential C Example
/ seq.c - A conventional C program that sums
integers from 1 to 5 / include
ltstdlib.hgt include ltstdio.hgt int sum
/ global variable / main() int i
/ local variable / sum 0 for
(i1 ilt5 i) / iterate from 1 to 5 /
printf(The value of i is d\n, i)
fflush (stdout) / flush buffer /
sum i printf (The sum is d\n,
sum) exit (0)
23Concurrent C Example
/ concurr.c - A concurrent C program that sums
integers from 1 to 5 / include
ltstdlib.hgt include ltstdio.hgt int sum
/ global variable / main() int i
/ local variable / sum 0
fork() for (i1 ilt5 i) / iterate
from 1 to 5 / printf(The value of i is
d\n, i) fflush (stdout) / flush
buffer / sum i printf
(The sum is d\n, sum) exit (0)
24Concurrent Processes (II)
- Processes perform different tasks
- Distinguished by the return value of fork()
- fork and execve allow newly created processes to
execute an independent, separately-compiled
program
/ sum.c - A concurrent C program that performs
different tasks for two processes / include
ltstdlib.hgt include ltstdio.hgt main() int
pid / local variable /
pidfork() if (pid ! 0) / original
process / printf(The original process
prints this.\n) else /
newly created process / printf (The new
process prints this.\n) exit(0)
25Concurrency in I/O
- Let us take a browser as an example
- It needs to respond to input from users
- Mouse clicks
- Keyboard input
- It needs to respond to input from the network
- Downloaded web pages, images,
- It needs to send request to the network
- Send a HTTP request
- How to handle this scenario?
- Asynchronous I/O (aka non-blocking I/O)
- Concurrency in I/O
- select system call
26Lab Exercises
- Use telnet to send an email to yourself
- Concurrent processing
- Modify concurr.c so that the messages printed
from parent and child processes are different - Observe how the messages from parent and child
are interleaved in the output - Write and compile the summation procedure as a
separate program and use execv() to call it in
the child process