• No results found

Computer Networks EE357

N/A
N/A
Protected

Academic year: 2021

Share "Computer Networks EE357"

Copied!
41
0
0

Loading.... (view fulltext now)

Full text

(1)

Computer Networks

EE357

Application Layer-Part 2

Haiming Jin

The slides are adapted from those provided by Prof. Romit Roy Choudhury.

(2)

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTP

r 2.3 FTP

r 2.4 Electronic Mail

v SMTP, POP3, IMAP r 2.5 DNS

r 2.7 Socket programming with TCP

r 2.8 Socket programming with UDP

(3)

DNS: Domain Name System

r Imagine a world without DNS

r You would have to remember the IP addresses of

v Every website you want to visit

v Your bookmarks will be a list of IP addresses

v You will speak like

“I went to 167.33.24.10, and there was an awesome link to 153.11.35.81… “

(4)

DNS: Domain Name System

People: many identifiers:

v SSN, name, passport #

Internet hosts, routers:

v IP address (32 bit) - used for addressing datagrams

v “name”, e.g.,

www.yahoo.com - used by humans

Q: map between IP addresses and name ?

Domain Name System:

r distributed database implemented in hierarchy of many name servers

r application-layer protocol host, name servers to communicate to resolve names (address/name translation)

v note: core Internet function,

implemented as application-layer protocol

v complexity at network’s “edge”

(5)

DNS

Why not centralize DNS?

r single point of failure

r traffic volume

r distant centralized database doesn’t scale!

DNS services

r Hostname to IP address translation

r Host aliasing

v Canonical and alias names

r Load distribution

v Replicated Web servers: set of IP addresses for one

canonical name

(6)

Root DNS Servers

com DNS servers org DNS servers edu DNS servers poly.edu

DNS servers

umass.edu DNS servers yahoo.com

DNS servers amazon.com DNS servers

pbs.org

DNS servers

Distributed, Hierarchical Database

Client wants IP for www.amazon.com; 1st approx:

r Client queries a root server to find .com DNS server

r Client queries com DNS server to get amazon.com DNS server

r Client queries amazon.com DNS server to get IP address for www.amazon.com

(7)

DNS: Root name servers

r contacted by local name server that can not resolve name

r root name server:

v contacts authoritative name server if name mapping not known

v gets mapping

v returns mapping to local name server

b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA e NASA Mt View, CA

f Internet Software C. PaloAlto, CA (and 17 other locations)

i Autonomica, Stockholm (plus 3 other locations) k RIPE London (also Amsterdam, Frankfurt)

m WIDE Tokyo a Verisign, Dulles, VA

c Cogent, Herndon, VA (also Los Angeles) d U Maryland College Park, MD

g US DoD Vienna, VA h ARL Aberdeen, MD j Verisign, ( 11 locations)

(8)

TLD and Authoritative Servers

r

Top-level domain (TLD) servers:

v responsible for com, org, net, edu, etc.

v all top-level country domains uk, fr, ca, jp.

v Educause for edu TLD

r

Authoritative DNS servers:

v An organization’s DNS servers,

• providing authoritative hostname to IP mappings for organization’s servers (e.g., Web and mail).

v Can be maintained by organization or service provider

(9)

Local Name Server

r

Does not strictly belong to hierarchy

r

Each ISP (residential, company, univ) has one.

v Also called “default name server”

r

When a host makes a DNS query

v query is sent to its local DNS server

v Acts as a proxy, forwards query into hierarchy.

(10)

requesting host

cis.poly.edu

gaia.cs.umass.edu

root DNS server

local DNS server

dns.poly.edu

1

2 3

4 5

6

authoritative DNS server dns.cs.umass.edu

8 7

TLD DNS server

Example

r Iterative Querying Host at cis.poly.edu wants IP address for gaia.cs.umass.edu

(11)

requesting host

cis.poly.edu

gaia.cs.umass.edu

root DNS server

local DNS server

dns.poly.edu

1

2

5 4 6

authoritative DNS server dns.cs.umass.edu

7

8

TLD DNS server 3

Recursive queries

recursive query:

r puts burden of name resolution on contacted name server

r heavy load?

iterated query:

r contacted server replies with name of server to contact

r “I don’t know this name, but ask this server”

Which is a better design choice?

(12)

DNS: caching

r Once (any) name server learns mapping, it caches mapping

v cache entries timeout (disappear) after some time

v TLD servers typically cached in local name servers

• Thus root name servers not often visited

(13)

DNS records

DNS: distributed db storing resource records (RR)

r Type=NS

v name is domain (e.g.

foo.com)

v value is hostname of

authoritative name server for this domain

RR format: (name, value, type, ttl) r Type=A

v name is hostname

v value is IP address

r Type=CNAME

v name is alias name for some

“canonical” (the real) name www.ibm.com is really

servereast.backup2.ibm.com

v value is canonical name r Type=MX

v value is name of mailserver associated with name

(14)

DNS protocol, messages

DNS protocol : query and reply messages, both with same message format

msg header

r identification: 16 bit # for query, reply to query uses same #

r flags:

v query or reply

v recursion desired

v recursion available

v reply is authoritative

(15)

DNS protocol, messages

Name, type fields for a query RRs in response

to query records for authoritative servers additional “helpful”

info that may be used

(16)

Inserting records into DNS

r Example: just created startup “Network Utopia”

r Register name networkuptopia.com at a registrar (e.g., Network Solutions)

v Need to provide registrar with names and IP addresses of your authoritative name server (primary and secondary)

v Registrar inserts two RRs into the com TLD server:

(networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212.212.212.1, A)

r Put in authoritative server Type A record for

www.networkuptopia.com and Type MX record for networkutopia.com

(17)

Questions ?

(18)

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTP

r 2.3 FTP

r 2.4 Electronic Mail

v SMTP, POP3, IMAP r 2.5 DNS

r 2.7 Socket programming with TCP

r 2.8 Socket programming with UDP

(19)

Socket programming

Socket API

r introduced in BSD4.1 UNIX, 1981

r explicitly created, used, released by apps

r client/server paradigm

r two types of transport service via socket API:

v unreliable datagram

v reliable, byte stream-oriented

a host-local,

application-created, OS-controlled interface

(a “door”) into which application process can

both send and

receive messages to/from another application

process

socket

Goal: learn how to build client/server application that communicate using sockets

(20)

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

process TCP with

buffers, variables

socket

controlled by application developer controlled by operating system

host or server

process TCP with

buffers, variables

socket

controlled by application developer controlled by operating system

host or server internet

(21)

Socket programming with TCP

Client must contact server

r server process must first be running

r server must have created socket (door) that welcomes client’s contact

Client contacts server by:

r creating client-local TCP socket

r specifying IP address, port number of server process

r When client creates socket:

client TCP establishes connection to server TCP

r When contacted by client, server TCP creates new socket for

server process to communicate with client

v allows server to talk with multiple clients

v source port numbers used to distinguish clients (more in Chap 3)

TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

(22)

Stream jargon

r A stream is a sequence of

characters that flow into or out of a process.

r An input stream is attached to some input source for the

process, e.g., keyboard or socket.

r An output stream is attached to an output source, e.g., monitor or socket.

(23)

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

(24)

Client/server socket interaction: TCP

wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket,

port=x, for

incoming request:

welcomeSocket = ServerSocket()

create socket,

connect to hostid, port=x clientSocket =

Socket()

close

read reply from clientSocket

Server (running on hostid) Client

send request using clientSocket

read request from connectionSocket

write reply to connectionSocket

connection setupTCP

(25)

Client/server socket interaction: TCP

(26)

Example: Java 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

(27)

Example: Java client (TCP), cont.

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();

} } Create input stream attached to socket

Send line to server Read line from server

(28)

Example: Java 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

(29)

Example: Java server (TCP), cont

DataOutputStream outToClient =

new DataOutputStream(connectionSocket.getOutputStream());

clientSentence = inFromClient.readLine();

capitalizedSentence = clientSentence.toUpperCase() + '\n';

outToClient.writeBytes(capitalizedSentence);

} } } Read in line from socket Create output stream, attached

to socket

Write out line to socket

End of while loop,

loop back and wait for another client connection

(30)

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTP

r 2.3 FTP

r 2.4 Electronic Mail

v SMTP, POP3, IMAP r 2.5 DNS

r 2.7 Socket programming with TCP

r 2.8 Socket programming with UDP

(31)

Socket programming with UDP

UDP: no “connection” between client and server

r no handshaking

r sender explicitly attaches IP address and port of destination to each packet

r server must extract IP address, port of sender from received packet

UDP: transmitted data may be received out of order, or lost

application viewpoint

UDP provides unreliable transfer of groups of bytes (“datagrams”)

between client and server

(32)

Client/server socket interaction: UDP

close

clientSocket

Server (running on hostid)

read reply from clientSocket create socket, clientSocket = DatagramSocket()

Client

Create, address (hostid, port=x, send datagram request

using clientSocket create socket,

port=x, for

incoming request:

serverSocket = DatagramSocket()

read request from serverSocket

write reply to serverSocket specifying client host address, port number

(33)

Example: Java client (UDP)

Output: sends packet (recall that TCP sent

“byte stream”)

Input: receives packet (recall thatTCP received

“byte stream”) Client

process

client UDP socket

(34)

Example: Java 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 byte[1024];

byte[] receiveData = new byte[1024];

String sentence = inFromUser.readLine();

Create input stream Create client socket Translate hostname to IP address using DNS

(35)

Example: Java client (UDP), cont.

DatagramPacket sendPacket =

new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

clientSocket.send(sendPacket);

DatagramPacket receivePacket =

new DatagramPacket(receiveData, receiveData.length);

clientSocket.receive(receivePacket);

String modifiedSentence =

new String(receivePacket.getData());

System.out.println("FROM SERVER:" + modifiedSentence);

clientSocket.close();

} }

Create datagram with data-to-send, length, IP addr, port Send datagram

to server

Read datagram from server

(36)

Example: Java 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 byte[1024];

byte[] sendData = new byte[1024];

while(true) {

DatagramPacket receivePacket =

new DatagramPacket(receiveData, receiveData.length);

serverSocket.receive(receivePacket);

Create datagram socket at port 9876

Create space for received datagram Receive

(37)

Example: Java server (UDP), cont

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(sendPacket);

} } }

Get IP addr port #, of sender

Write out datagram to socket

End of while loop,

loop back and wait for Create datagram

to send to client

Which address is this?

(38)

Sockets and Ports

What is the difference between sockets and ports?

Sockets are physical telephones Ports are extension numbers IP address is the phone number

(39)

Chapter 2: Summary

r Application architectures

v client-server

v P2P

v hybrid

r application service requirements:

v reliability, bandwidth, delay r Internet transport service

model

v connection-oriented, reliable:

TCP

v unreliable, datagrams: UDP

Our study of network apps now complete!

r specific protocols:

v HTTP

v FTP

v SMTP, POP, IMAP

v DNS

r socket programming

(40)

Chapter 2: Summary

r typical request/reply message exchange:

v client requests info or service

v server responds with data, status code

r message formats:

v headers: fields giving info about data

v data: info being communicated

Most importantly: learned about protocols

r control vs. data msgs

v in-band, out-of-band

r centralized vs. decentralized

r stateless vs. stateful

r reliable vs. unreliable msg transfer

r “complexity at network edge”

(41)

Questions?

References

Related documents

The predicted aircraft count in the peak sector was lower using algorithm-generated airspace designs than the manually generated ones in the larger test airspace (i.e., 7-sector)

[r]

Moon Sky Noble Six Harms Solitary Piercing Rope Heavenly Officer Charm Death God Great Assembly Sky Charm Hook Spirit Fortune Virtue Prosperity Star Heavenly Virture Grand

We refer to the Markov chain X as nearly uncoupled (with respect to some pos- itive ) if its associated state space contains two or more disjoint almost invariant aggregates..

EchoClient reads input from the user, sends it to the Echo server, gets a response from Page 2 sur 3 Reading from and Writing to a Socket.

Create input stream Create client socket, connect to server Create output stream attached to socket.. Network

Viewed from the server side, the input stream is read to get commands from the client and the output stream is used to write results back to the client.. Viewed from the client

 When origin server is sending a stream through client, and stream passes through a proxy, proxy can use TCP to obtain the stream; but proxy still sends RTSP control messages to