Transcript PowerPoint

Networking Overview
February 2, 2004
Assignments
• Due – Homework 0
• Due – Reading and Warmup questions
• Work on Homework 1
2/2/2004
What’s the Internet: “nuts and bolts”
view
router
server
workstation
mobile
local ISP
regional ISP
company
network
2/2/2004
What’s the Internet: “nuts and bolts”
view
router
server
• connect hosts or end
systems running
network applications
mobile
local ISP
regional ISP
company
network
2/2/2004
workstation
What’s the Internet: “nuts and bolts”
view
router
• connected via
communication links
• physical media
server
regional ISP
• bandwidth how fast
bits are transmitted
2/2/2004
mobile
local ISP
– fiber optics
– coaxial cable
– others?
– examples?
workstation
company
network
What’s the Internet: “nuts and bolts”
view
router
• routers connect links
• forward packets along
a path or route
server
mobile
local ISP
– what’s in a packet?
regional ISP
• packet switching
company
network
2/2/2004
workstation
What’s the Internet: a service view
• communication infrastructure enables
distributed applications:
– games – what else?
• communication services provided to apps:
– connection-oriented, reliable (TCP)
• example apps?
– connectionless, unreliable (UDP)
• example apps?
2/2/2004
What’s a protocol?
• human protocols
– define communication between two people
• network protocols
– protocols define format, order of msgs sent
and received among network entities, and
actions taken on msg transmission, receipt
• Why are protocols so important?
2/2/2004
What’s a protocol?
a human protocol and a computer network
protocol:
Hi
TCP connection
req
Hi
TCP connection
response
Got the
time?
Get http://www.awl.com/kurose-ross
2:00
<file>
time
2/2/2004
Protocol Example – HTTP
Request
GET /index.html HTTP/1.1
Response
HTTP/1.1 200 OK
Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 …...
Content-Length: 6821
Content-Type: text/html
data data data data data
2/2/2004
Layering
• How can we organize the structure of the
network?
– Why is this important?
2/2/2004
Organization of Air Travel
ticket (purchase)
ticket (complain)
baggage (check)
baggage (claim)
gates (load)
gates (unload)
runway takeoff
runway landing
airplane routing
airplane routing
airplane routing
2/2/2004
A Layered Approach
Counter-to-counter delivery of person+bags
baggage-claim-to-baggage-claim delivery
people transfer: loading gate to arrival gate
runway-to-runway delivery of plane
airplane routing from source to destination
2/2/2004
ticket (purchase)
ticket (complain)
baggage (check)
baggage (claim)
gates (load)
gates (unload)
runway takeoff
runway landing
airplane routing
airplane routing
intermediate air traffic sites
airplane routing
2/2/2004
airplane routing
airplane routing
Arriving airport
Departing airport
Distributed Implementation
Why Layering?
• Makes a complex system easier to deal
with
• Modularization eases maintenance,
updating of system
– change of implementation of layer’s service
transparent to rest of system
2/2/2004
Internet Protocol Stack
• Application
– supporting network
applications
• Transport
– host-host data transfer
• Network
– routing of datagrams from
source to destination
• Link
– data transfer between
neighboring network elements
• Physical
– bits “on the wire”
2/2/2004
application
transport
network
link
physical
Sockets
• Interface between app
and transport layers
• Send/receive
messages to/from
socket
• API
– choice of transport
protocol
– ability to fix a few
parameters (buffer size,
etc)
2/2/2004
host or
server
host or
server
process
controlled by
app developer
process
socket
socket
TCP with
buffers,
variables
Internet
controlled
by OS
TCP with
buffers,
variables
Sockets
Socket
Application
Transport
Network
Link
Physical
2/2/2004
Addressing
• Need ID for receiving host
– Unique 32-bit IP address
• 138.110.1.1
2/2/2004
Addressing
• Need ID for receiving host
– Unique 32-bit IP address
• 138.110.1.1
• Need to differentiate between processes
– Port number (HTTP is typically port 80)
2/2/2004
Port Number
Web Server
Mail Server
Port = 80
Port = 25
Transport
IP = 138.110.1.1
2/2/2004
Socket Programming with TCP
•
Client/Server
1. Server starts
2. Server creates a socket (specifying port
number)
3. Client starts
4. Client creates a socket (what must be
specified?) and initiates TCP connection
5. Server creates a new socket for the
connection
2/2/2004
Stream Jargon
• Stream – a sequence of characters that
flow into or out of a process.
• Input Stream – attached to some input
source for the process
– keyboard, socket, ???
• Output Stream – attached to an output
source
– monitor, socket, ???
2/2/2004
TCP Client Architecture
Client
Process
process
output
stream
client
TCP
clientSocket
socket
to network
2/2/2004
inFromServer
input
stream
monitor
inFromUser
keyboard
outToServer
Example client-server app
1. client reads line from standard
input (inFromUser stream) ,
sends to server via socket
(outToServer stream)
2. server reads line from socket
3. server converts line to
uppercase, sends back to
client
4. client reads, prints modified
line from socket (inFromServer
stream)
input
stream
TCP
socket
from network
TCP Client/Server Interaction
Server (running on hostid)
Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
TCP
wait for incoming
connection request connection
connectionSocket =
welcomeSocket.accept()
read request from
connectionSocket
write reply to
connectionSocket
close
connectionSocket
2/2/2004
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket
read reply from
clientSocket
close
clientSocket
TCPClient.java
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
Create
input stream
Create
client socket,
connect to server
Create
output stream
attached to socket
2/2/2004
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
TCPClient.java
Create
input stream
attached to socket
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
Send line
to server
outToServer.writeBytes(sentence + '\n');
Read line
from server
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
2/2/2004
TCPServer.java
import java.io.*;
import java.net.*;
class TCPServer {
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
2/2/2004
public static void main(String argv[]) throws Exception
{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
TCPServer.java
Create output
stream, attached
to socket
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
Write out line
to socket
outToClient.writeBytes(capitalizedSentence);
}
}
}
2/2/2004
End of while loop,
loop back and wait for
another client connection