1 / 44

Homework

Collect Homework 1 Assign Homework 2 Problems Ch 2#1,4,6,7 (two graded) Due Wednesday, 10 September. Homework. 2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS. 2.6 Socket programming with TCP 2.7 Socket programming with UDP

Download Presentation

Homework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Collect Homework 1 Assign Homework 2 Problems Ch 2#1,4,6,7 (two graded) Due Wednesday, 10 September Homework 2: Application Layer

  2. 2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Socket programming with TCP 2.7 Socket programming with UDP 2.8 Building a Web server 2.9 Content distribution Network Web caching Content distribution networks P2P file sharing Chapter 2 outline 2: Application Layer

  3. People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing datagrams “name”, e.g., gaia.cs.umass.edu - used by humans Domain Name System: distributed database implemented in hierarchy of many name servers application-layer protocol host, routers, name servers to communicate to resolvenames (address/name translation) note: core Internet function, implemented as application-layer protocol complexity at network’s “edge” DNS: Domain Name System 2: Application Layer

  4. no server has all name-to-IP address mappings local name servers: each ISP, company has local (default) name server host DNS query first goes to local name server authoritative name server: for a host: stores that host’s IP address, name can perform name/address translation for that host’s name Why not centralize DNS? single point of failure traffic volume distant centralized database maintenance doesn’t scale! DNS name servers 2: Application Layer

  5. contacted by local name server that can not resolve name root name server: contacts authoritative name server if name mapping not known gets mapping returns mapping to local name server a NSI Herndon, VA c PSInet Herndon, VA d U Maryland College Park, MD g DISA Vienna, VA h ARL Aberdeen, MD j NSI (TBD) Herndon, VA k RIPE London i NORDUnet Stockholm m WIDE Tokyo e NASA Mt View, CA f Internet Software C. Palo Alto, CA b USC-ISI Marina del Rey, CA l ICANN Marina del Rey, CA DNS: Root name servers 13 root name servers worldwide 2: Application Layer

  6. host surf.eurecom.fr wants IP address of gaia.cs.umass.edu 1. contacts its local DNS server, dns.eurecom.fr 2.dns.eurecom.fr contacts root name server, if necessary 3. root name server contacts authoritative name server, dns.umass.edu, if necessary local name server dns.eurecom.fr Simple DNS example root name server 2 4 3 5 authorititive name server dns.umass.edu 1 6 requesting host surf.eurecom.fr gaia.cs.umass.edu 2: Application Layer

  7. Root name server: may not know authoritative name server may know intermediate name server: who to contact to find authoritative name server local name server dns.eurecom.fr intermediate name server dns.umass.edu DNS example root name server 6 2 3 7 5 4 1 8 authoritative name server dns.cs.umass.edu requesting host surf.eurecom.fr gaia.cs.umass.edu 2: Application Layer

  8. recursive query: puts burden of name resolution on contacted name server heavy load? iterated query: contacted server replies with name of server to contact “I don’t know this name, but ask this server” local name server dns.eurecom.fr intermediate name server dns.umass.edu DNS: iterated queries root name server iterated query 2 3 4 7 5 6 1 8 authoritative name server dns.cs.umass.edu requesting host surf.eurecom.fr gaia.cs.umass.edu 2: Application Layer

  9. once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time update/notify mechanisms under design by IETF RFC 2136 http://www.ietf.org/html.charters/dnsext-charter.html DNS: caching and updating records 2: Application Layer

  10. DNS: distributed db storing resource records (RR) Type=NS name is domain (e.g. foo.com) value is IP address of authoritative name server for this domain RR format: (name, value, type, ttl) DNS records • Type=A • name is hostname • value is IP address • Type=CNAME • name is alias name for some “canonical” (the real) name www.ibm.com is really servereast.backup2.ibm.com • value is canonical name • Type=MX • value is name of mailserver associated with name 2: Application Layer

  11. DNS protocol :queryand reply messages, both with same message format DNS protocol, messages msg header • identification: 16 bit # for query, reply to query uses same # • flags: • query or reply • recursion desired • recursion available • reply is authoritative 2: Application Layer

  12. 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 2: Application Layer

  13. DNS Tools dig and host: • Show more detail • Not on Suns • common on Linux • Online: • http://www.dnsstuff.com/ • 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/ 2: Application Layer

  14. Email SPAM Problem: • I get over 100 messages per day. • Perhaps 30% are SPAM. • How can I stop it? • NEVER respond to SPAM: • From address is often bogus. • When valid, it just verifies that your address works. • SPAM is a violation of most ISP’s AUPs. • Complain to the ISP, and get the spammer disconnected. • Use tools and knowledge • Examine mail headers • Use traceroute • Use whois 2: Application Layer

  15. Sample SPAM Return-Path: <560424@spray.no> Received: from mx02.mrf.mail.rcn.net (mx02.mrf.mail.rcn.net [207.172.4.51]) by briansbooks.com (8.9.3/8.8.7) with ESMTP id PAA22178 for <brian@davison.net>; Tue, 22 Jan 2002 15:22:59 -0500 From: 560424@spray.no Received: from [211.251.72.130] (helo=spray.no) by mx02.mrf.mail.rcn.net with smtp (Exim 3.34 #5) id 16T7U6-0004iN-00; Tue, 22 Jan 2002 15:25:35 -0500 Reply-To: <560424@spray.no> Message-ID: <006b42c45cbe$5652b6c4$0ee32ab0@uihupb> To: Syble@briansbooks.com Subject: Support Follow up. (2141@4) MiME-Version: 1.0 Content-Type: text/html; charset="iso-8859-1" X-Mailer: MIME-tools 5.503 (Entity 5.501) Importance: Normal Date: Tue, 22 Jan 2002 15:25:35 -0500 <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=iso-8859-1"> <HTML> […] 2: Application Layer

  16. 2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Socket programming with TCP 2.7 Socket programming with UDP 2.8 Building a Web server 2.9 Content distribution Network Web caching Content distribution networks P2P file sharing Chapter 2 outline 2: Application Layer

  17. 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 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 2: Application Layer

  18. process process TCP with buffers, variables TCP with buffers, variables socket socket Socket-programming using TCP Socket: a door between application process and end-end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytesfrom 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 2: Application Layer

  19. Client must contact server server process must first be running server must have created socket (door) that welcomes client’s 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) TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint Socket programming with TCP 2: Application Layer

  20. 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. Stream jargon 2: Application Layer

  21. 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) Socket programming with TCP Client process client TCP socket 2: Application Layer

  22. create socket, connect to hostid, port=x create socket, port=x, for incoming request: clientSocket = Socket() welcomeSocket = ServerSocket() TCP connection setup wait for incoming connection request connectionSocket = welcomeSocket.accept() send request using clientSocket read request from connectionSocket write reply to connectionSocket read reply from clientSocket close connectionSocket close clientSocket Client/server socket interaction: TCP Server (running on hostid) Client 2: Application Layer

  23. 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 2: Application Layer

  24. Example: Java echo client (TCP), cont. BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); while (sentence != null) { outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); sentence = inFromUser.readLine(); } clientSocket.close(); } } Create input stream attached to socket Send line to server Read line from server 2: Application Layer

  25. 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 2: Application Layer

  26. Example: Java echo server (TCP), cont DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); while(clientSentence != null) { capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); clientSentence = inFromClient.readLine(); } connectionSocket.close(); } } } 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 2: Application Layer

  27. Example: C echo client (TCP) #include <sys/types.h> /* basic system data types */ #include <sys/socket.h> /* basic socket definitions */ #include <netinet/in.h> #include <stdio.h> #include <unistd.h> int main(int argc, char **argv) { int sockfd; struct sockaddr_in servaddr; if (argc != 2) { printf("usage: tcpcli <IPaddress>\n"); exit(-1); } sockfd = socket(AF_INET, SOCK_STREAM, 0); Helpful includes Define socket address structure Create TCP socket 2: Application Layer

  28. 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(argv[1]); 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 2: Application Layer

  29. Example: C echo client (TCP), cont. void str_cli(FILE *fp, int sockfd) { char sendline[MAXLINE], recvline[MAXLINE]; 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. 2: Application Layer

  30. Example: C echo server (TCP) #include <sys/types.h> /* basic system data types */ #include <sys/socket.h> /* basic socket definitions */ #include <netinet/in.h> #include <stdio.h> #include <unistd.h> #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 2: Application Layer

  31. 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. 2: Application Layer

  32. Example: C echo server (TCP), cont. void str_echo(int sockfd) { ssize_t n; char line[MAXLINE]; 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. 2: Application Layer

  33. 2.1 Principles of app layer protocols clients and servers app requirements 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Socket programming with TCP 2.7 Socket programming with UDP 2.8 Building a Web server 2.9 Content distribution Network Web caching Content distribution networks P2P file sharing Chapter 2 outline 2: Application Layer

  34. 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 UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server application viewpoint Socket programming with UDP 2: Application Layer

  35. Client create socket, port=x, for incoming request: serverSocket = DatagramSocket() create socket, clientSocket = DatagramSocket() Create, address (hostid, port=x, send datagram request using clientSocket read request from serverSocket write reply to serverSocket specifying client host address, port number read reply from clientSocket close clientSocket Client/server socket interaction: UDP Server (running on hostid) 2: Application Layer

  36. Example: Java client (UDP) Client process Input: receives packet (TCP received “byte stream”) Output: sends packet (TCP sent “byte stream”) client UDP socket 2: Application Layer

  37. Example: Java echo 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]; String sentence = inFromUser.readLine(); while (sentence != null) { byte[] receiveData = new byte[1024]; sendData = sentence.getBytes(); Create input stream Create client socket Translate hostname to IP address using DNS Get line from STDIN Convert to byte array 2: Application Layer

  38. Example: Java echo client (UDP), cont. Create datagram with data-to-send, length, IP addr, port DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 6789); 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); String sentence = inFromUser.readLine(); } clientSocket.close(); } } Send datagram to server Read datagram from server Convert to String Send to STDOUT Look for more input 2: Application Layer

  39. Example: Java echo server (UDP) import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(6789); byte[] sendData = new byte[1024]; while(true) { byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create datagram socket at port 6789 Create space for received datagram Receive datagram 2: Application Layer

  40. Example: Java echo 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 Convert to caps, convert to bytes Create datagram to send to client Write out datagram to socket End of while loop, loop back and wait for another datagram 2: Application Layer

  41. Example: C echo client (UDP) […headers…] int main(int argc, char **argv) { int sockfd; struct sockaddr_in servaddr; if (argc != 2) { printf("usage: udpcli <IPaddress>"); exit(-1); } bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(6789); servaddr.sin_addr.s_addr = inet_addr(argv[1]); sockfd = socket(AF_INET, SOCK_DGRAM, 0); dg_cli(stdin, sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); exit(0); } Set up socket parameters Create UDP socket Work with the established socket 2: Application Layer

  42. Example: C echo client (UDP) cont. void dg_cli(FILE *fp, int sockfd, const struct sockaddr *pservaddr, int servlen) { int n; char sendline[MAXLINE], recvline[MAXLINE + 1]; while (fgets(sendline, MAXLINE, fp) != NULL) { sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); recvline[n] = 0; /* null terminate */ fputs(recvline, stdout); } } Get line from STDIN Write out datagram to socket Receive datagram From socket Send line to STDOUT 2: Application Layer

  43. Example: C echo server (UDP) #include <sys/types.h> /* basic system data types */ #include <sys/socket.h> /* basic socket definitions */ #include <netinet/in.h> #include <stdio.h> #include <unistd.h> #define MAXLINE 1024 int main(int argc, char **argv) { int sockfd; struct sockaddr_in servaddr, cliaddr; sockfd = socket(AF_INET, SOCK_DGRAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(6789); bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); dg_echo(sockfd, (struct sockaddr *) &cliaddr, sizeof(cliaddr)); } Create UDP socket Bind socket to specified address Work with the established socket 2: Application Layer

  44. Example: C echo server (UDP) cont. void dg_echo(int sockfd, struct sockaddr *pcliaddr, int clilen) { int n; int len; char mesg[MAXLINE]; for ( ; ; ) { len = clilen; n = recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len); sendto(sockfd, mesg, n, 0, pcliaddr, len); } } Read next datagram Send datagram back to client 2: Application Layer

More Related