Chapter 2: Application layer - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Chapter 2: Application layer

Description:

amazon.com. DNS servers. pbs.org. DNS servers. Distributed, Hierarchical Database. Client wants ... Client queries com DNS server to get amazon.com DNS server ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 34
Provided by: JimKurosea347
Category:

less

Transcript and Presenter's Notes

Title: Chapter 2: Application layer


1
Chapter 2 Application layer
  • 2.1 Principles of network applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
  • SMTP, POP3, IMAP
  • 2.5 DNS
  • CDNs
  • 2.6 P2P file sharing
  • 2.7 Socket programming with TCP
  • 2.8 Socket programming with UDP
  • 2.9 Building a Web server

2
Distributed, Hierarchical Database
  • Client wants IP for www.amazon.com 1st approx
  • Client queries a root server to find com DNS
    server
  • Client queries com DNS server to get amazon.com
    DNS server
  • Client queries amazon.com DNS server to get IP
    address for www.amazon.com

3
Example
root DNS server
2
  • Host at lehigh.edu wants IP address for
    www.ibm.com

3
TLD DNS server
4
5
6
7
1
8
authoritative DNS server ns.watson.ibm.com
requesting host R192042.res.lehigh.edu
www.ibm.com
4
DNS caching and updating records
  • once (any) name server learns mapping, it caches
    mapping
  • cache entries timeout (disappear) after some time
  • TLD servers typically cached in local name
    servers
  • Thus root name servers not often visited
  • update/notify mechanisms under design by IETF
  • RFC 2136
  • http//www.ietf.org/html.charters/dnsind-charter.h
    tml

5
DNS records
  • DNS distributed db storing resource records (RR)
  • TypeA
  • name is hostname
  • value is IP address
  • TypeCNAME
  • name is alias name for some cannonical (the
    real) name
  • www.ibm.com is really
  • servereast.backup2.ibm.com
  • value is cannonical name
  • TypeNS
  • name is domain (e.g. foo.com)
  • value is IP address of authoritative name server
    for this domain
  • TypeMX
  • value is name of mailserver associated with name

6
DNS protocol, messages
  • DNS protocol query and reply messages, both
    with same message format
  • msg header
  • identification 16 bit for query, reply to
    query uses same
  • flags
  • query or reply
  • recursion desired
  • recursion available
  • reply is authoritative

7
DNS protocol, messages
Name, type fields for a query
RRs in reponse to query
records for authoritative servers
additional helpful info that may be used
8
Inserting records into DNS
  • Example just created startup Network Utopia
  • Register name networkuptopia.com at a registrar
    (e.g., Network Solutions)
  • Need to provide registrar with names and IP
    addresses of your authoritative name server
    (primary and secondary)
  • Registrar inserts two RRs into the com TLD
    server
  • (networkutopia.com, dns1.networkutopia.com, NS)
  • (dns1.networkutopia.com, 212.212.212.1, A)
  • Put in authoritative server Type A record for
    www.networkuptopia.com and Type MX record for
    networkutopia.com
  • How do people get the IP address of your Web
    site?

9
DNS Tools
  • dig and host
  • Show more detail
  • Not on Suns
  • common on Linux
  • Online
  • http//www.ip-plus.net/tools/ dns_config.en.html
  • nslookup
  • can find IP given name
  • can find name given IP
  • can show other RR
  • whois
  • can show information about domain and owner
  • can show information about owner of an IP
    address or network
  • online whois servers
  • http//www.arin.net/whois/index.html
  • http//network-tools.com/

10
Content distribution networks (CDNs)
origin server in North America
  • The content providers are the CDN customers.
  • Content replication
  • CDN company installs hundreds of CDN servers
    throughout Internet
  • in lower-tier ISPs, close to users
  • CDN replicates its customers content in CDN
    servers. When provider updates content, CDN
    updates servers

CDN distribution node
CDN server in S. America
CDN server in Asia
CDN server in Europe
11
CDN example
  • CDN company
  • cdn.com
  • distributes gif files
  • uses its authoritative DNS server to redirect
    requests
  • origin server
  • www.foo.com
  • distributes HTML
  • Replaces
  • http//www.foo.com/sports.ruth.gif
  • with
    http//www.cdn.com/www.foo.com/sports/ruth.gif

12
More about CDNs
  • routing requests
  • CDN creates a map, indicating distances from
    leaf ISPs and CDN nodes
  • when query arrives at authoritative DNS server
  • server determines ISP from which query originates
  • uses map to determine best CDN server
  • not just Web pages
  • streaming stored audio/video
  • streaming real-time audio/video
  • CDN nodes create application-layer overlay network

13
Chapter 2 Application layer
  • 2.1 Principles of network applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
  • SMTP, POP3, IMAP
  • 2.5 DNS
  • CDNs
  • 2.6 P2P file sharing
  • 2.7 Socket programming with TCP
  • 2.8 Socket programming with UDP
  • 2.9 Building a Web server

14
Socket programming
Goal learn how to build client/server
application that communicate using sockets
  • Socket API
  • introduced in BSD4.1 UNIX, 1981
  • explicitly created, used, released by apps
  • client/server paradigm
  • two types of transport service via socket API
  • unreliable datagram
  • reliable, byte stream-oriented

15
Socket-programming using TCP
  • Socket a door between application process and
    end-end-transport protocol (UCP or TCP)
  • TCP service reliable transfer of bytes from one
    process to another

controlled by application developer
controlled by application developer
controlled by operating system
controlled by operating system
internet
host or server
host or server
16
Socket programming with TCP
  • Client must contact server
  • server process must first be running
  • server must have created socket (door) that
    welcomes clients contact
  • Client contacts server by
  • creating client-local TCP socket
  • specifying IP address, port number of server
    process
  • When client creates socket client TCP
    establishes connection to server TCP
  • When contacted by client, server TCP creates new
    socket for server process to communicate with
    client
  • allows server to talk with multiple clients
  • source port numbers used to distinguish clients
    (more in Chap 3)

17
Stream jargon
  • A stream is a sequence of characters that flow
    into or out of a process.
  • An input stream is attached to some input source
    for the process, eg, keyboard or socket.
  • An output stream is attached to an output source,
    eg, monitor or socket.

18
Socket programming with TCP
  • 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)

Client process
client TCP socket
19
Client/server socket interaction TCP
Server (running on hostid)
Client
20
Example Java echo client (TCP)
import java.io. import java.net. class
TCPClient public static void main(String
argv) throws Exception String
sentence String modifiedSentence
BufferedReader inFromUser new
BufferedReader(new InputStreamReader(System.in))
Socket clientSocket new
Socket("hostname", 6789)
DataOutputStream outToServer new
DataOutputStream(clientSocket.getOutputStream())

Create input stream
Create client socket, connect to server
Create output stream attached to socket
21
Example Java echo client (TCP), cont.
Create input stream attached to socket
BufferedReader inFromServer
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()))
sentence inFromUser.readLine()
outToServer.writeBytes(sentence '\n')
modifiedSentence inFromServer.readLine()
System.out.println("FROM SERVER "
modifiedSentence) clientSocket.close()

Send line to server
Read line from server
22
Example Java echo server (TCP)
import java.io. import java.net. class
TCPServer 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(
)))
Create welcoming socket at port 6789
Wait, on welcoming socket for contact by client
Create input stream, attached to socket
23
Example Java echo server (TCP), cont
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
24
Example C echo client (TCP)
include ltsys/types.hgt / basic system
data types / include ltsys/socket.hgt /
basic socket definitions / include
ltnetinet/in.hgt include ltstdio.hgt include
ltunistd.hgt int main(int argc, char
argv) int sockfd struct sockaddr_in
servaddr if (argc ! 2) printf("usage
tcpcli ltIPaddressgt\n") exit(-1)
sockfd socket(AF_INET, SOCK_STREAM, 0)
Helpful includes
Define socket address structure
Create TCP socket
25
Example C echo client (TCP), cont.
bzero(servaddr, sizeof(servaddr))
servaddr.sin_family AF_INET
servaddr.sin_port htons(6789)
servaddr.sin_addr.s_addr inet_addr(argv1)
connect(sockfd, (struct sockaddr
) servaddr, sizeof(servaddr))
str_cli(stdin, sockfd) / do it
all / exit(0)
Fill in socket structure with server information
Establish connection with server
Work with the established socket
26
Example C echo client (TCP), cont.
void str_cli(FILE fp, int sockfd) char
sendlineMAXLINE, recvlineMAXLINE while
(fgets(sendline, MAXLINE, fp) ! NULL)
write(sockfd, sendline, strlen(sendline))
if (readline(sockfd, recvline, MAXLINE) 0)
printf("str_cli server terminated
prematurely\n") exit(-1)
fputs(recvline, stdout)
Get line of text from stdin
Send line to server
Get line from server
Write the line to stdout
Readline is also user defined.
27
Example C echo server (TCP)
include ltsys/types.hgt / basic system
data types / include ltsys/socket.hgt /
basic socket definitions / include
ltnetinet/in.hgt include ltstdio.hgt include
ltunistd.hgt define MAXLINE 1024 define
LISTENQ 16 / max size of queue / int
main(int argc, char argv) int
listenfd, connfd pid_t
childpid int clilen struct
sockaddr_in cliaddr, servaddr listenfd
socket(AF_INET, SOCK_STREAM, 0)
bzero(servaddr, sizeof(servaddr))
Helpful includes
Define socket address structure
Create TCP socket
28
Example C echo server (TCP), cont.
Fill in structure to accept conns from any local
interface
servaddr.sin_family AF_INET
servaddr.sin_addr.s_addr htonl(INADDR_ANY)
servaddr.sin_port htons(6789)
bind(listenfd, (struct sockaddr ) servaddr,
sizeof(servaddr)) listen(listenfd,
LISTENQ) for ( ) clilen
sizeof(cliaddr) connfd accept(listenfd,
(struct sockaddr ) cliaddr, clilen)
str_echo(connfd) / process the request /
close(connfd) / close connected
socket / / end main /
Assign structure to the socket
Convert socket to a listening socket
Wait until new conn. is established
Work with the established conn.
29
Example C echo server (TCP), cont.
void str_echo(int sockfd) ssize_t
n char lineMAXLINE for (
) if ( (n readline(sockfd, line,
MAXLINE)) 0) return /
connection closed by other end /
write(sockfd, line, n) / end str_echo /
Get line from client
Write line back to client
Readline is also user defined.
30
Chapter 2 Application layer
  • 2.1 Principles of network applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
  • SMTP, POP3, IMAP
  • 2.5 DNS
  • CDNs
  • 2.6 P2P file sharing
  • 2.7 Socket programming with TCP
  • 2.8 Socket programming with UDP
  • 2.9 Building a Web server

31
Socket programming with UDP
  • UDP no connection between client and server
  • no handshaking
  • sender explicitly attaches IP address and port of
    destination to each packet
  • server must extract IP address, port of sender
    from received packet
  • UDP transmitted data may be received out of
    order, or lost

32
Client/server socket interaction UDP
Server (running on hostid)
33
Example Java client (UDP)
Client process
Input receives packet (TCP received byte
stream)
Output sends packet (TCP sent byte stream)
client UDP socket
Write a Comment
User Comments (0)
About PowerShow.com