Bài giảng Mạng máy tính - Chương 2 (Tiếp): Giao thức tầng ứng dụng (Application Layer) - Trần Quang Hải Bằng

pdf 22 trang ngocly 2580
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Mạng máy tính - Chương 2 (Tiếp): Giao thức tầng ứng dụng (Application Layer) - Trần Quang Hải Bằng", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • pdfbai_giang_mang_may_tinh_chuong_2_tiep_giao_thuc_tang_ung_dun.pdf

Nội dung text: Bài giảng Mạng máy tính - Chương 2 (Tiếp): Giao thức tầng ứng dụng (Application Layer) - Trần Quang Hải Bằng

  1. Ch ươ ng 2 (ti p). Giao th c tng ng dng (application layer) Tr n Quang H i B ng Computer Networking and Internet (course of 2009) Faculty of Information Technology University of Communication and Transport (Unit 2) Office location: Administration building, Block D3, Room 6 Office phone: 38962018 Cell phone: N/A Email: bangtqh@hotmail.com Discussion Web programming with ASP. Visual Basic programming. § Object oriented programming. § Event driven programming. § Component driven programming. TCP Socket programming. § Simple web server. 24/8-25/10/2009 Chapter 2. The Application Layer 2
  2. Winsock 24/8-25/10/2009 Chapter 2. The Application Layer 3 HTTP example Gi s ng ưi dùng truy cp URL: www.uct2.edu.vn/index.htm (trang web có text và 10 hình nh jpeg) 0. http server ti máy ph c v 1a . http client thi t lp liên kt www.uct2.edu.vn ch yêu cu TCP vi http server (process) kt ni TCP ti cng 80. ti đa ch www.uct2.edu.vn, cng 80 (ng m đnh vi http server). 1b. http server ch p nh n k t n i ri thông báo vi client. 2. http client gi http request message (bao gm c URL) ti TCP connection socket 3. http server nh n request message, to ra http response đ time message có ch a các i tưng đưc yêu cu ri gi vào socket. 24/8-25/10/2009 Chapter 2. The Application Layer 4
  3. 4. http server ng t liên kt. 5. http client nh n response message có ch a html file, hi n th html. Sau đó, phân tích html file, tìm URL ca 10 hình nh time jpeg trong tài li u. 6. Bưc 1-5 đưc lp li vi tng hình nh. 24/8-25/10/2009 Chapter 2. The Application Layer 5 Ch2. The Application Layer 2.1. Mt s khái ni m và nguyên tc. 2.2. Web & Hyper Text Transfer Protocol. 2.3. Web design and HTTP, Web programming. 2.4. File Transfer Protocol. 2.5. Electronic Mail Protocols. 2.6. Domain Name System. 24/8-25/10/2009 Chapter 2. The Application Layer 6
  4. 2.4. FTP - File Transfer Protocol FTP file transfer FTP FTP user client server interface user at host local file remote file system system n Truy n/t i tp (to/from remote host). n Client/server model ¤ Client: đưa ra yêu cu truy n ti. ¤ Server = remote host. n FTP: RFC 959 24/8-25/10/2009 Chapter 2. The Application Layer 7 FTP: control & data connections TCP control connection port 21 TCP data connection FTP port 20 FTP n FTP s dng TCP. client server n FTP s dng đng th i 2 liên kt TCP ti 2 cng: ¤ TCP control connection, port 21: trao đi các thông đ i p đ i u khi n (commands, responses ). ¤ TCP data connection, port 20: truy n ti tp. n FTP lưu gi tr ng thái client trong phiên làm vi c (state vs. HTTP is stateless). 24/8-25/10/2009 Chapter 2. The Application Layer 8
  5. FTP: Quá trình trao đi/truy n ti TCP control connection port 21 TCP data connection FTP server nghe ti cng 21. client port 20 server FTP client yêu cu kt ni vi FTP server qua TCP ti cng 21. Gi user & password đ đă ng nh p. FTP server ch p nh n, liên kt đ i u khi n (control connection) đưc thi t lp. Quá trình trao đi có th bt đu. Khi server nh n đưc lnh truy n tp, nó m liên kt d li u (data connection) ti client, tp đưc truy n qua liên kt này. Sau khi truy n xong mt tp, server ng t liên kt d li u (mi liên kt ch s dng đ truy n mt tp). 24/8-25/10/2009 Chapter 2. The Application Layer 9 FTP commands, responses Lnh (commands), phúc đáp (responses) đưc truy n dng ASCII Sample commands: Sample return codes n sent as ASCII text over control n status code and phrase (as in channel HTTP) n USER username n 331 Username OK, n PASS password password required n 125 data connection n LIST return list of file in already open; current directory transfer starting n RETR filename retrieves n 425 Can’t open data (gets) file connection n STOR filename stores n 452 Error writing (puts) file onto remote host file 24/8-25/10/2009 Chapter 2. The Application Layer 10
  6. FTP clients & servers FTP file transfer FTP FTP user client server interface user at host local file remote file system system n Command-based client: n Microsoft FTP Service ¤ Windows FTP command. n ¤ Linux FTP command. n GUI clients ¤ Windows Commander. ¤ CuteFTP, WS_FTP 24/8-25/10/2009 Chapter 2. The Application Layer 11 Ch2. The Application Layer 2.1. Mt s khái ni m và nguyên tc. 2.2. Web & Hyper Text Transfer Protocol. 2.3. Web design and HTTP, Web programming. 2.4. File Transfer Protocol. 2.5. Electronic Mail Protocols. 2.6. Domain Name System. 24/8-25/10/2009 Chapter 2. The Application Layer 12
  7. 2.5. Electronic Mail Ba thành ph n chính: user agent n User agents (mail clients) mail user ¤ đ server So n, c th ư (messages). agent ¤ Vd: Outlook, Eudora, Netscape SMTP Messenger mail server user n Mail servers SMTP agent ¤ Lưu tr , x lý th ư. ¤ Vd: Exchange, MDeamon SMTP mail user n Protocols server agent ¤ Simple Mail Transfer Protocol (SMTP). user ¤ Post Office Protocol (POP). agent outgoing ¤ Internet Mail Access Protocol (IMAP). user agent message queue ¤ HTTP. user mailbox 24/8-25/10/2009 Chapter 2. The Application Layer 13 Alice Bob 1) Alice s dng UA so n th ư, đ/c gi 4) Mail server ca Alice gi ti “to”: bob@yahoo.com. th ư qua liên kt TCP. 2) Alice’s UA gi th ư đn mail server 5) Mail server ca Bob ct th ư ca Alice, bc th ư đưc xp vào nh n đưc vào hòm th ư ca hàng đi (message queue). Bob. 3) Mail server ca Alice m liên kt 6) Bob dùng UA đ ly th ư t TCP ti mail server ca Bob. server v ri đc th ư. 1 mail mail user user server server agent agent 2 3 4 6 Outlook 5 Yahoo! Mail uct2.edu.vn yahoo.com 24/8-25/10/2009 Chapter 2. The Application Layer 14
  8. SMTP (Simple Mail Transfer Protocol) n S dng liên kt TCP (port 25) đ gi mails: ¤ T sender’s mail client ti sender’s mail server. ¤ T sender’s mail server ti receiver’s mail server. n Ba pha (three ways handshake): ¤ Bt tay (handshaking/greeting). ¤ Trao đi messages. ¤ Kt thúc. n Command/response: ¤ commands: ASCII. ¤ responses: status code & phrase. 24/8-25/10/2009 Chapter 2. The Application Layer 15 SMTP: sample interaction (C: client; S: server) S: 220 yahoo.com C: HELO uct2.edu.vn S: 250 Hello uct2.edu.vn, pleased to meet you C: MAIL FROM: S: 250 alice@uct2.edu.vn Sender ok C: RCPT TO: S: 250 bob@yahoo.com Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Hi Bob! C: Would you like to play tennis this evening? C: . S: 250 Message accepted for delivery C: QUIT S: 221 yahoo.com closing connection 24/8-25/10/2009 Chapter 2. The Application Layer 16
  9. SMTP: more n SMTP s dng persistent connection: mt liên kt, nhi u thông đ i p. n Thông đ i p (k c ni dung th ư) ph i đưc mã hoá dng ASCII 7 bit (US-ASCII). n Đánh du kt thúc msg bi CRLF.CRLF n Mt s d li u nh phân (vd: picture) có th ch a CRLF.CRLF cn mã hoá đ đm bo không có d li u nào trùng vi ký hi u kt thúc message (vd: base64). n So sánh vi HTTP: ¤ HTTP: pull protocol SMTP: cho phép nhi u obj (text, picture ) trong mt msg (multipart msg). 24/8-25/10/2009 Chapter 2. The Application Layer 17 Mail message format SMTP : giao th c trao đi email msg (exchange msgs). header RFC 822 : standard for text message blank format: line n Header lines, vd: ¤ To: ¤ From: body ¤ Subject: Khác với smtp commands ( MAIL FROM, RCPT TO, )! n Body ¤ The “message”. ¤ ASCII 24/8-25/10/2009 Chapter 2. The Application Layer 18
  10. MIME (Multipurpose Internet Mail Extension) n RFC 822: text msg, gp khó kh ă n vi multimedia. n MIME: RFC 2045, RFC 2056. n So vi RFC 822, MIME thêm vào các header lines đ mô t ni dung ca email msg. From: alice@uct2.edu.vn MIME version To: bob@yahoo.com Subject: Picture of yummy crepe. method used MIME-Version: 1.0 to encode data Content-Transfer-Encoding: base64 Content-Type: image/jpeg multimedia data type, subtype, base64 encoded data parameter declaration base64 encoded data encoded data 24/8-25/10/2009 Chapter 2. The Application Layer 19 MIME: Content types Content-type: type/subtype; parameters 24/8-25/10/2009 Chapter 2. The Application Layer 20
  11. MIME: Encoding types Content-Transfer-Encoding: Encoding type 24/8-25/10/2009 Chapter 2. The Application Layer 21 MIME: Multiple objects mail message From: alice@uct2.edu.vn To: bob@yahoo.com Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=StartOfNextPart StartOfNextPart Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Dear Bob, Please find a picture of a crepe. StartOfNextPart Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data base64 encoded data StartOfNextPart 24/8-25/10/2009 Chapter 2. The Application Layer 22
  12. The received mail message n Server thêm vào dòng header mi khi nh n th ư: ¤ Received: ¤ Return-path: n Mail có th đưc chuy n qua nhi u server khác nhau (forward). Received: from hamburger.edu by sushi.jp; 12 Oct 98 15:30:01 GMT Received: from crepes.fr by hamburger.edu; 12 Oct 98 15:27:39 GMT From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data base64 encoded data 24/8-25/10/2009 Chapter 2. The Application Layer 23 Hi n th full headers vi Y! Mail 2.General Preference 1.Mail Options 3.Messages: Show all 24/8-25/10/2009 Chapter 2. The Application Layer 24
  13. Mail access protocol SMTP SMTP access user user agent agent protocol sender’s mail receiver’s mail server server n SMTP: giao th c gi mail ti server. n Mail access protocol: giao th c nh n mail t server. ¤ POP (Post Office Protocol): RFC 1939. TCP Port 110. ¤ IMAP (Internet Mail Access Protocol): RFC 1730. TCP port 143. ¤ HTTP: Hotmail, Yahoo! 24/8-25/10/2009 Chapter 2. The Application Layer 25 POP3 protocol [1] Authorization phase S: +OK POP3 server ready n client commands: C: user bob ¤ user: declare username [1] S: +OK ¤ pass: password C: pass hungry n server responses S: +OK user successfully logged on ¤ +OK C: list ¤ -ERR S: 1 498 S: 2 912 S: . [2] Transaction phase, client: C: retr 1 n list: list message numbers [2] S: n retr: retrieve message by number S: . n dele: delete C: dele 1 C: retr 2 [3] Update phase: S: n Quit S: . n nh ng thay đi (dele) đưc cp nh t C: dele 2 C: quit [3] S: +OK POP3 server signing off 24/8-25/10/2009 Chapter 2. The Application Layer 26
  14. POP3 (more) and IMAP More about POP3 IMAP4 n Ch đ “download and delete” n Lưu tr toàn b msg ti (xem vd tr ưc): server. ¤ Msg b xoá khi thoát. n Cho phép ng ưi dùng t ch c ¤ Không th nh n msg ln na. lưu tr trên server (to th ư n “Download-and-keep”: mc, di chuy n msg ) ¤ Msg đưc gi li server. n Lưu tr ng thái gi a các phiên ¤ Có th nh n msg nhi u ln t (state): nhi u client. ¤ Th ư mc t to. n Không lưu tr ng thái gi a các ¤ Các msgs đã di chuy n. phiên làm vi c (stateless). 24/8-25/10/2009 Chapter 2. The Application Layer 27 Ch2. The Application Layer 2.1. Mt s khái ni m và nguyên tc. 2.2. Web & Hyper Text Transfer Protocol. 2.3. Web design and HTTP, Web programming. 2.4. File Transfer Protocol. 2.5. Electronic Mail Protocols. 2.6. Domain Name System. 24/8-25/10/2009 Chapter 2. The Application Layer 28
  15. 2.6. DNS (Domain Name System) Mr Toan HTTP (Internet Explorer) www.uct2.edu.vn From: N.V.Toan www.uct2.edu.vn => 210.245.22.125 To: Phòng ðT Phòng ðT 210.245.22.125 => D3 DNS client DNS servers Ms Phuong n Đa ch IP (32 bit) đưc s dng đ xác đnh mt nút trong mng TCP/IP: 210.245.22.125 khó nh ! S dng tên (host name) song song vi IP address. n DNS (RFC 1034, RFC 1035, RFC 2136): ¤ Chuy n host name IP address. 24/8-25/10/2009 Chapter 2. The Application Layer 29 DNS services DNS không tươ ng tác tr c ti p vi users mà cung cp các dch v cho các ch ươ ng trình khác (HTTP, FTP ) thu c tng ng dng: n Host name IP (hostname to IP resolve). n Host aliasing. ¤ Mt máy tính có tên chính th c và có th có bí danh (alias). n Mail server aliasing. ¤ @uct2.edu.vn mail server address = ? n Load distribution (phân tán ti) ¤ Mt dch v web (cnn.com, yahoo.com ) có th đưc cung cp ti nhi u server có IP khác nhau đ phân tán ti do lưng ng ưi s dng cao. 24/8-25/10/2009 Chapter 2. The Application Layer 30
  16. Internet domain name space vn n Domain name (tên mi n): n Host name: www.uct2.edu.vn ; ¤ Mi n = tp hp các nút mng có cùng mail.uct2.edu.vn mt nút cha trong sơ đ trên. ¤ vn: Vietnam. ¤ Vd: ¤ edu: education. ¤ uct2.edu.vn; yahoo.com; yale.edu. ¤ uct2: University of Commnication & ¤ Sub-domain: cs.yale.edu; Transport – unit 2. ¤ www: máy ch world wide web. ¤ mail: máy ch mail. 24/8-25/10/2009 Chapter 2. The Application Layer 31 Domain name servers Root DNS Servers com DNS servers org DNS servers edu DNS servers poly.edu umass.edu yahoo.com pbs.org amazon.com DNS servers DNS servers DNS servers DNS servers DNS servers Vd: client mu n bi t IP ca www.amazon.com thì: n Tìm đa ch ca com DNS servers hi Root DNS servers. n amazon.com com DNS servers . n www.amazon.com amazon.com DNS servers . 24/8-25/10/2009 Chapter 2. The Application Layer 32
  17. DNS: Root name servers a Verisign, Dulles, VA c Cogent, Herndon, VA (also Los k RIPE London (also Amsterdam, Angeles) Frankfurt) d U Maryland College Park, MD g US DoD Vienna, VA i Autonomica, Stockholm (plus 3 h ARL Aberdeen, MD other locations) j Verisign, ( 11 locations) m WIDE Tokyo e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 17 other locations) 13 root name servers b USC-ISI Marina del Rey, CA worldwide l ICANN Los Angeles, CA n Khi local name server không th chuy n host name IP, gi yêu cu ti root srv. n root name server: ¤ Liên lc vi authoritative name server nu ch ưa th ánh x đ/c ngay. ¤ Ly kt qu ánh x gi v t authoritative name server. ¤ Tr kt qu v cho local name server . 24/8-25/10/2009 Chapter 2. The Application Layer 33 TLD and Authoritative Servers n Top-level domain (TLD) servers: ch u trách nhi m v các mi n com, org, net, edu và uk, fr, ca, jp ¤ Network Solutions: qu n lý com TLD servers. ¤ Educause: qu n lý edu TLD servers. n Authoritative DNS servers: ¤ Mi host trong mng mu n đưc bi t đn ph i đưc khai báo vi mt authoritiative DNS server. ¤ DNS servers ca các t ch c ánh x hostname IP cho các hosts ca t ch c đó (vd: web, mail ). ¤ Có th đưc qu n lý bi các t ch c hay nhà cung cp dch v. 24/8-25/10/2009 Chapter 2. The Application Layer 34
  18. Local name server n Thu c qu n lý ca ISP (ISP, company, university ). n Khi mt host mu n bi t IP ca mt host nào đó, tr ưc tiên, nó “hi” local name server. n Không nh t thi t ph i nm trong ki n trúc DNS servers (đc lp). n “Gn” máy tính ca ng ưi s dng nh t nên th ưng đưc “hi th ă m” đu tiên mi khi có truy vn DNS. n Xem Windows Local DNS: ipconfig 24/8-25/10/2009 Chapter 2. The Application Layer 35 DNS example 1 Tình hu ống : root name server host surf.eurecom.fr cần đ/c IP của gaia.cs.umass.edu 2 4 3 1. Liên lc vi local DNS 5 server: dns.eurecom.fr 2. dns.eurecom.fr liên lc vi local name server Authorititive root name server (nu cn) dns.eurecom.fr name server dns.umass.edu 3. root name server liên lc vi 1 6 authoritative name server : dns.umass.edu (nu cn) requesting host gaia.cs.umass.edu surf.eurecom.fr 24/8-25/10/2009 Chapter 2. The Application Layer 36
  19. DNS example 2 Root name server có th : root name server n Không bi t authoritative 2 6 7 3 name server (ans). n Bi t intermediate name server (ins) local name server intermediate name server ¤ T ins có th tìm ra ans dns.eurecom.fr dns.umass.edu 4 5 1 8 authoritative name server dns.cs.umass.edu requesting host surf.eurecom.fr gaia.cs.umass.edu 24/8-25/10/2009 Chapter 2. The Application Layer 37 DNS example 3 recursive query: root name server n A hi B, B hi C, C hi 2 iterated query D, ri tr li ng ưc li. 3 4 n Server đưc hi ch u ti nng gp đ ôi? 7 local name server intermediate name server dns.eurecom.fr dns.umass.edu iterative query: 5 6 1 8 n DNS server đưc hi gi ý hi mt server khác. authoritative name server dns.cs.umass.edu n requesting host “I don’t know this name, surf.eurecom.fr but ask this server” gaia.cs.umass.edu 24/8-25/10/2009 Chapter 2. The Application Layer 38
  20. DNS: caching & updating n Mi khi DNS server nh n đưc yêu cu tra cu IP, IP mà nó tìm đưc s đưc lưu li ph c v cho nh ng ln tra cu ti p theo. ¤ Timeout: th i gian ht hn (sau mt kho ng th i gian, bn ghi cache tươ ng ng b xoá). ¤ TLD servers th ưng đưc cache ti local name servers. n Cơ ch cp nh t/thông báo đưc đưa ra bi IETF: ¤ RFC 2136 ¤ 24/8-25/10/2009 Chapter 2. The Application Layer 39 DNS records DNS : distributed db storing resource records (RR) RR format: (name, value, type, ttl) n Type=A n Type=CNAME ¤ name = hostname ¤ name = “bí danh” (alias). ¤ value = IP address www.ibm.com ¤ n Type=NS value = tên th t. ¤ name = domain name servereast.backup2.ibm.com ¤ value = IP address ca n Type=MX authoritative name ¤ name = domain name server cho domain này ¤ value = tên ca mail server 24/8-25/10/2009 Chapter 2. The Application Layer 40
  21. DNS protocol, messages DNS Protocol: Query/reply messages có cùng format. n Msg header (12 bytes) n Identification: s 16 bit reply msg s dng cùng id vi req msg. n Flags: nhi u bit, mi bit có mt ý ngh ĩa: ¤ Query (0) hay reply (1) ¤ Authoritative DNS. ¤ recursion desired: client mong mu n DNS server tra cu đ quy. ¤ recursion available: server h tr tra cu đ quy. 24/8-25/10/2009 Chapter 2. The Application Layer 41 DNS messages Name, type fields for a query RRs in reponse to query records for authoritative servers additional “helpful” info that may be used 24/8-25/10/2009 Chapter 2. The Application Layer 42
  22. Summary √ √ √ √ Telnet! RTSP? Terminal Emulation ? Web programming ? TCP Socket Programming 24/8-25/10/2009 Chapter 2. The Application Layer 43 Bài tp t làm và th o lu n n Tìm hi u các câu lnh cơ bn ca FTP, SMTP, POP3. (Np báo cáo sau 1 tu n) n Vi t mail client đơn gi n (không b t bu c). 24/8-25/10/2009 Chapter 2. The Application Layer 44