Title: CS472 Computer Networks
1CS472Computer Networks
- Professor Mike Kain
- Class 3 Slides
- Spring 2008-2009
2Tonights Topics
- Review last weeks class
- Tonights topics
- Finish application layer
- HTTP, DNS, SMTP, FTP, BitTorrent, P2P
- Start Transport Layer
- Reliable Data Transfer
- TCP, UDP.
3How Processes Actually Communicate
- Interface between Processes and Computer Networks
- Sockets Application Programming interfaces
internet
host or server
host or server
4Port Usage
- Port is represented by a positive (16-bit)
integer value - Some ports have been reserved to support
common/well known services - ftp 21/tcp
- telnet 23/tcp
- smtp 25/tcp
- User level process/services generally use port
number value gt 1024
5Internet Endpoints Connections
- How do we uniquely identify a process on a host?
- INTERNET ENDPOINT
- (IP, port , TCP/UDP)
- How do we uniquely identify a connection?
- INTERNET CONNECTION (socketpair)
- (src IP, src port, dst IP, dst port, TCP/UDP)
- Netstat -a
6HTTP
- RFC 1945 and 2616
- Client Server Architecture
- Communication using HTTP messages
- HTTP defines how Web Clients request Web Pages
and how Servers transfer Web Pages back - Web Page composed of objects ,
- HTML is the data
- Objects addressable by URLs
7HTTP
- Stateless (Important)
- Versions
- 1.0 - Non- Persistent
- 1.1 Persistent
From http//commons.wikimedia.org/wiki/ImageHTTP_
persistent_connection.svg
8HTTP Request Message
9HTTP Response Message
10Cookies
11The Conditional GET
- GET /sample.html HTTP/1.1Host www.example.com
- HTTP/1.1 200 OKDate Tue, 27 Dec 2005 052511
GMTContent-Type text/html charsetiso-8859-1Se
rver Apache/1.3.33 (Unix) PHP/4.3.10Last-Modifie
d Thur, 10 Apr 2008 132452 GMT - GET /sample.html HTTP/1.1Host
www.example.comIf-Modified-Since Thur, 10 Apr
2008 132452 GMT - HTTP/1.1 304 Not ModifiedDate Tue, 27 Dec 2005
052519 GMTServer Apache/1.3.33 (Unix)
PHP/4.3.10
12URL Resolution
- http//www.cs.drexel.edu/mkain/cs472/index.html
- The browsers operation
- Takes first part (hostname) and resolves through
DNS (if it doesnt already know). - Takes method (http) and looks up port (unless
overwritten by after hostname. - Connects to that host and port number.
- Sends GET with the rest (/mkain/cs472/index.htm)
to server and waits for answer. - Then it looks through what it gets back and sends
requests for any objects contained.
13Socket Programming - TCP
- Sockets are a protocol independent method of
creating a connection between processes. Sockets
can be either - connection based or connectionless
- packet based or streams based
- reliable or unreliable
- The TCP and UDP protocols use ports to map
incoming data to a particular process running on
a computer.
14Client/Server Implementation TCP
Server (running on hostid)
Client
15TCP Client (JAVA)
- Socket clientSocket new Socket( hostname, port
) - DataOutputStream outToServer new
DataOutputStream( clientSocket.getOutputStream() - BufferedReader inFromServer new BufferedReader(
clientSocket.getInputStream() - While (protocol)
- ltconstruct PDUgt
- outToServer.writeBytes( PDU, buflen )
- inFromServer.readLine( PDU )
- ltparse response PDUgt
-
- clientSocket.close()
16TCP Client (C)
- int mysocket
-
- mysocket socket( AF_INET, SOCK_STREAM, 0)
- if ( mysocket lt 0 )
- perror(socket() called failed.\n)
- exit(-1)
-
- struct sockaddr_in you
- sockaddr.s_family AF_INET
- sockaddr.s_port ntohs(port)
- sockaddr.s_addr ltfill in with IP addressgt
- if ( connect( mysocket, you, sizeof(sockaddr_in)
) lt 0 ) - perror(connect failed.\n)
- close(mysocket)
- exit(-1)
-
17TCP Client (C), continued
- while (protocol)
- ltconstruct PDUgt
- send( mysocket, buffer, buflen )
- rcvlen recv( mysocket, buffer, maxbuflen )
- ltparse response PDUgt
-
- close( mysocket )
- exit(0)
18Example Java Server
import java.io. import java.net. class
TCPServer public static void main(String
argv) throws Exception String
clientSentence String capitalizedSentence
ServerSocket listeningSocket new
ServerSocket(6789) while(true)
Socket connectionSocket
listeningSocket.accept()
BufferedReader inFromClient new
BufferedReader(new
InputStreamReader(connectionSocket.getInputStream(
)))
Create Listening socket at port 6789
Wait, on listening socket for contact by client
Create input stream, attached to socket
19 DataOutputStream outToClient
new DataOutputStream(connectionSocket.get
OutputStream()) clientSentence
inFromClient.readLine()
capitalizedSentence clientSentence.toUpperCase()
'\n' outToClient.writeBytes(capit
alizedSentence)
Create output stream, attached to socket
Read in line from socket
Write out line to socket
End of while loop, loop back and wait for another
client connection
20TCP Server (JAVA)
- ServerSocket groupSocket new ServerSocket(6789)
- While (true)
- Socket connectedSocket groupSocket.accept()
- ltconstruct reader and writer from
connectedSocket just like clientgt - ltrun protocolgt
21Example in C
22TCP Server (C)
- Groupsocket Socket( ltsame parameters as
clientgt) - Bind() using specific port , and addr
IPADDR_ANY - Listen( groupsocket, 5 )
- While (TRUE)
- Newsocket accept( groupsocket )
- Do protocol with newsocket
- Close newsocket
23- while (protocol)
- send( mysocket, buffer, buflen )
- rcvlen recv( mysocket, buffer, maxbuflen )
-
- close( mysocket )
- exit(0)
24Server types
- Iterative handles one client at a time
- Concurrent handles multiple clients
simultaneously - Two methods
- Process/thread server executes one
process/thread for each client for 1-1
communication/protocol - select model server maintains list of active
sockets and polls for activity through select()
call. - Affects models after accept and before
execution of protocol.
25UDP Clients
- Similar to TCP clients, but no connection to
worry about. - C gt no connect, just sendto() and recvfrom()
- JAVA gt use DatagramSocket and DatagramPacket to
send and recv.
26UDP Servers
- UDP servers have the same algorithm as the UDP
client, but the send recv are in the other
order (usually servers wait for the next message
to be read and then send a response)
27UDP
Server (running on hostid)
28JAVA CLIENT -UDP
import java.io. import java.net. class
UDPClient public static void main(String
args) throws Exception
BufferedReader inFromUser new
BufferedReader(new InputStreamReader(System.in))
DatagramSocket clientSocket new
DatagramSocket() InetAddress IPAddress
InetAddress.getByName("hostname")
byte sendData new byte1024 byte
receiveData new byte1024 String
sentence inFromUser.readLine() sendData
sentence.getBytes()
Create input stream
Create client socket
Translate hostname to IP address using DNS
29Create datagram with data-to-send, length, IP
addr, port
DatagramPacket sendPacket new
DatagramPacket(sendData, sendData.length,
IPAddress, 9876) clientSocket.send(send
Packet) DatagramPacket receivePacket
new DatagramPacket(receiveData,
receiveData.length) clientSocket.receiv
e(receivePacket) String
modifiedSentence new
String(receivePacket.getData())
System.out.println("FROM SERVER"
modifiedSentence) clientSocket.close()
Send datagram to server
Read datagram from server
30JAVA SERVER -UDP
import java.io. import java.net. class
UDPServer public static void main(String
args) throws Exception
DatagramSocket serverSocket new
DatagramSocket(9876) byte
receiveData new byte1024 byte
sendData new byte1024 while(true)
DatagramPacket
receivePacket new
DatagramPacket(receiveData, receiveData.length)
serverSocket.receive(receivePacket)
Create datagram socket at port 9876
Create space for received datagram
Receive datagram
31 String sentence new
String(receivePacket.getData())
InetAddress IPAddress receivePacket.getAddress()
int port receivePacket.getPort()
String
capitalizedSentence sentence.toUpperCase()
sendData capitalizedSentence.getBytes()
DatagramPacket sendPacket
new DatagramPacket(sendData,
sendData.length, IPAddress,
port) serverSocket.send(s
endPacket)
Get IP addr port , of sender
Create datagram to send to client
Write out datagram to socket
End of while loop, loop back and wait for another
client connection
32Example C
33FTP
file transfer
user or host
Remote file system
- transfer file to/from remote host
- client/server architecture
- ftp RFC 959
- ftp server port 21
34FTP
- Data and control connection
- ftp/21
- ftp-data/20 (either direction)
- 4 character commands
- GET, PUT, MDIR, AUTH, ADAT
- Implicit vs Explicit SSL model
- 990 vs 21
35DNS (Domain Name System)
- Takes names and translates to IP addresses
- www.cs.drexel.edu gt 129.25.6.158 or IPv6 address
(FEC042F4800BFFFE3A211C) - Can do other things
- Host aliasing mailserver.drexel.edu and
webserver.drexel.edu might be the same machine - bob_at_drexel.edu bob_at_mailrelay.irt.drexel.edu
- www.drexel.edu may be more than one IP address
- Problems with 3?
36DNS Record Types
- A IPv4 address record
- AAAA IPv6 address record
- CNAME Canonical Name (alias, processing
continues) - MX Mail server record
- PTR Name record (processing stops)
- LOC geographic location
- RFC 1035, 3596 (Ipv6)
37SMTP
- Push protocol used to deliver mail
- RFC 2821 (used to be RFC 821)
- MIME extensions (822, 2405, 2406)
- Content-type image/jpeg, text/ascii, etc.
- Content-Transfer-Encoding base64
- 4 character ASCII commands
- HELO, EHLO, etc.
38SMTP errors
- 1yz Positive Preliminary reply
- 2yz Positive Completion reply
- 3yz Positive Intermediate reply
- 4yz Transient Negative Completion
- 5yz Permanent Negative Completion
- X0z Syntax
- X1z Information
- X2z Connection
- X5z mail system
39Peer-to-Peer protocols
- Perform both client and server functionality at
the same time - BitTorrent
- Web Proxy services (ICP, etc.)
- Content distribution
40Transport Layer
- What the network provides to the user
- Hides any network characteristics
- Make believe that the applications are directly
connected (logically), NOT HOSTS - Uniquely identify each process on each host
- TCP/IP gives us at least two
- TCP and UDP
41UDP
- RFC 768 (1980)
- Connectionless, message-oriented transport
- Adds
- Checksum for segment
- Port numbers for source and destination
- Up to 64KB data
- Used by protocols which cant or dont want
reliability or delay - DNS, SNMP, RTP, TFTP, real-time
42Reliable Data Transfer
- Concept that is used by many layers (data link
above) to guarantee quality of service - Uses a SLIDING WINDOW PROTOCOL (SWP) or AUTOMATIC
REPEAT REQUEST PROTOCOL (ARQ) different names
for the same thing
43SWP/ARQ basics
- Assume one direction (for now)
- Each PDU (or some addressable part of the
message) has a sequence number that increases - Have ACKs and NAKs
- Have timeouts
- Have errors (each PDU has checksum)
44Stop-And-Wait
- Send PDU. Wait for ACK. If ACK received, send
next PDU. - How does this protocol deal with lost duplicate
frames?
45Add sequence numbers
- Send PDU 0. Wait for ACK. If ACK then send next
sequence numbered PDU. - What does ACK have in it?
- What happens if frame corrupted?
46Add NAK retransmission
- Send PDU 0. Wait for ACK. If ACK 0 received,
then send PDU 1. - If NAK received, then resend PDU 0.
- What happens if frame is lost?
47Add timeout
- Send PDU 0. Wait for ACK or timeout
(preconfigured). - If ACK received before timeout, then send PDU 1.
- If timeout or NAK, then retransmit PDU 0.
- How does receiver deal if he sees two or more PDU
0?
48Restrict sequence numbers
- Solution is to make sure that a sequence number
can only be valid for a period of time. - Sequence numbers are really a field of the PDU
which is a certain size (3 bits, 32 bits, etc.) - Restrict reuse of sequence numbers within timeout
interval.
49So, what do we have?
- One-directional reliable protocol
- Send PDU 0. Wait for ACK or timeout.
- If ACK received, send PDU 1.
- If NAK received, or timeout, then resend PDU 0
and wait again. - Receiver throws away any subsequent copies of PDU
0 once successfully received. - sender and receiver have agreed on what numbers
to start
50More sequence numbers
- More than one PDU outstanding
- ACK/NAK has for PDU.
- Window of what PDUs are outstanding at any
time. - Pipelining having more than one PDU outstanding
at any time.
51Pipelined ACKs
- Can ACK last PDU and that implies ACKs of all
outstanding PDU cumulative ACK. - Really next to receive how is this better?
- SENDING WINDOW
- RECEIVING WINDOW
52Two way transfer
- But, we really have bidirectional transfer. Each
end has a SENDING and RECEIVING WINDOW. - Each PDU has reserved spot for both PDU sequence
number and ACK number (piggybacking)
53So, what does it look like?
54Retransmission
- With multiple PDUs outstanding, what happens when
one (or more) get lost? - Go Back N
- Selective Repeat
- Some protocols do a combination of both
- Fast retransmission
55Other types of SWP
- Does the protocol have to be reliable?
- Do we really care about timeout?
56The Big Picture
- Technology doesnt really drive network design,
new protocols, etc. - Social / Society / networking
- Business
- Legal / Criminal
- Others?
57Next two weeks
- NO SCHOOL NEXT WEEK (10/13), but homework 2a
DUE! (if not before) - Homework 2b due 10/20 (posted)
- Finish reliable data transfer
- TCP
- Connection Management
- Congestion Control (Reno/Tahoe/Vegas)
- RTT/RTO problems (sockstress)
- Flow Control
- Other types SCTP, DCCP
- 1st midterm examination in 3 weeks (October 27th)