Bài giảng Mạng máy tính - Chương 2b: Giao thức tầng ứng dụng (Application Layer) - Đoàn Thị Thu Hà
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 2b: Giao thức tầng ứng dụng (Application Layer) - Đoàn Thị Thu Hà", để 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:
bai_giang_mang_may_tinh_chuong_2b_giao_thuc_tang_ung_dung_ap.ppt
Nội dung text: Bài giảng Mạng máy tính - Chương 2b: Giao thức tầng ứng dụng (Application Layer) - Đoàn Thị Thu Hà
- Chương 2 (tiếp). Giao thức tầng ứng dụng (application layer) Đoàn Thị Thu Hà
- Discussion ➢ Web programming with ASP. ➢ Visual Basic programming. ▪ Object oriented programming. ▪ Event driven programming. ▪ Component driven programming. ➢ TCP Socket programming. ▪ Simple web server. 1-6/2005 Chapter 2. The Application Layer 2
- Ch2. The Application Layer 2.1. Một số khái niệm và nguyên tắc. 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. 1-6/2005 Chapter 2. The Application Layer 3
- 2.4. FTP - File Transfer Protocol FTP file transfer FTP FTP user client server interface user at host local file remote file system system ◼ Truyền/tải tệp (to/from remote host). ◼ Client/server model Client: đưa ra yêu cầu truyền tải. Server = remote host. ◼ FTP: RFC 959 1-6/2005 Chapter 2. The Application Layer 4
- FTP: control & data connections TCP control connection port 21 TCP data connection FTP port 20 FTP ◼ FTP sử dụng TCP. client server ◼ FTP sử dụng đồng thời 2 liên kết TCP tại 2 cổng: 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 tải tệp. ◼ FTP lưu giữ trạng thái client trong phiên làm việc (state vs. HTTP is stateless). 1-6/2005 Chapter 2. The Application Layer 5
- FTP: Quá trình trao đổi/truyền tải TCP control connection port 21 TCP data connection ➢ FTP server nghe tại cổng 21. client port 20 server ➢ FTP client yêu cầu kết nối với FTP server qua TCP tại cổng 21. Gửi user & password để đăng nhập. ➢ FTP server chấp nhận, liên kết điều khiển (control connection) được thiết lập. Quá trình trao đổi có thể bắt đầu. ➢ Khi server nhận được lệnh truyền tệp, nó mở liên kết dữ liệu (data connection) tới client, tệp được truyền qua liên kết này. ➢ Sau khi truyền xong một tệp, server ngắt liên kết dữ liệu (mỗi liên kết chỉ sử dụng để truyền một tệp). 1-6/2005 Chapter 2. The Application Layer 6
- FTP commands, responses Lệnh (commands), phúc đáp (responses) được truyền dạng ASCII Sample commands: Sample return codes ◼ sent as ASCII text over control ◼ status code and phrase (as in channel HTTP) ◼ USER username ◼ 331 Username OK, ◼ PASS password password required ◼ 125 data connection ◼ LIST return list of file in already open; current directory transfer starting ◼ RETR filename retrieves ◼ 425 Can’t open data (gets) file connection ◼ STOR filename stores ◼ 452 Error writing (puts) file onto remote host file 1-6/2005 Chapter 2. The Application Layer 7
- FTP clients & servers FTP file transfer FTP FTP user client server interface user at host local file remote file system system ◼ Command-based client: ◼ Microsoft FTP Service Windows FTP command. ◼ Linux FTP command. ◼ GUI clients Windows Commander. CuteFTP, WS_FTP 1-6/2005 Chapter 2. The Application Layer 8
- CuteFTP 1-6/2005 Chapter 2. The Application Layer 9
- Ch2. The Application Layer 2.1. Một số khái niệm và nguyên tắc. 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. 1-6/2005 Chapter 2. The Application Layer 10
- 2.5. Electronic Mail Ba thành phần chính: user agent ◼ User agents (mail clients) mail user server Soạn, đọc thư (messages). agent Vd: Outlook, Eudora, Netscape SMTP Messenger mail server user ◼ Mail servers SMTP agent Lưu trữ, xử lý thư. SMTP Vd: Exchange, MDeamon mail user agent ◼ Protocols server Simple Mail Transfer Protocol (SMTP). user Post Office Protocol (POP). agent user outgoing Internet Mail Access Protocol (IMAP). agent message queue HTTP. user mailbox 1-6/2005 Chapter 2. The Application Layer 11
- Alice → Bob 1) Alice sử dụng UA soạn thư, đ/c gửi 4) Mail server của Alice gửi tới “to”: bob@yahoo.com. thư qua liên kết TCP. 2) Alice’s UA gửi thư đến mail server 5) Mail server của Bob cất thư của Alice, bức thư được xếp vào nhận được vào hòm thư của hàng đợi (message queue). Bob. 3) Mail server của Alice mở liên kết 6) Bob dùng UA để lấy thư từ TCP tới mail server của Bob. server về rồi đọc thư. 1 mail mail user user server server agent agent 2 3 4 6 Outlook 5 Yahoo! Mail hua.edu.vn yahoo.com 1-6/2005 Chapter 2. The Application Layer 12
- SMTP (Simple Mail Transfer Protocol) ◼ Sử dụng liên kết TCP (port 25) để gửi mails: Từ sender’s mail client tới sender’s mail server. Từ sender’s mail server tới receiver’s mail server. ◼ Ba pha: Bắt tay (handshaking/greeting). Trao đổi messages. Kết thúc. ◼ Command/response: commands: ASCII. responses: status code & phrase. 1-6/2005 Chapter 2. The Application Layer 13
- SMTP: sample interaction (C: client; S: server) S: 220 yahoo.com C: HELO hau.edu.vn S: 250 Hello hau.edu.vn, pleased to meet you C: MAIL FROM: S: 250 alice@hau.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 1-6/2005 Chapter 2. The Application Layer 14
- SMTP: more ◼ SMTP sử dụng persistent connection: một liên kết, nhiều thông điệp. ◼ Thông điệp (kể cả nội dung thư) phải được mã hoá dạng ASCII 7 bit (US-ASCII). ◼ Đánh dấu kết thúc msg bởi CRLF.CRLF ◼ Một số dữ liệu nhị phân (vd: picture) có thể chứa CRLF.CRLF → cần mã hoá để đảm bảo không có dữ liệu nào trùng với ký hiệu kết thúc message (vd: base64). ◼ So sánh với HTTP: HTTP: pull protocol SMTP: cho phép nhiều obj (text, picture ) trong một msg (multipart msg). 1-6/2005 Chapter 2. The Application Layer 15
- Mail message format SMTP: giao thức trao đổi email msg (exchange msgs). header RFC 822: standard for text message blank format: line ◼ Header lines, vd: To: body From: Subject: Khác với smtp commands (MAIL FROM, RCPT TO, )! ◼ Body The “message”. ASCII 1-6/2005 Chapter 2. The Application Layer 16
- MIME (Multipurpose Internet Mail Extension) ◼ RFC 822: text msg, gặp khó khăn với multimedia. ◼ MIME: RFC 2045, RFC 2056. ◼ So với RFC 822, MIME thêm vào các header lines để mô tả nội dung của email msg. From: alice@hau1.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 1-6/2005 Chapter 2. The Application Layer 17
- MIME: Content types Content-type: type/subtype; parameters 1-6/2005 Chapter 2. The Application Layer 18
- MIME: Encoding types Content-Transfer-Encoding: Encoding type 1-6/2005 Chapter 2. The Application Layer 19
- MIME: Multiple objects mail message From: alice@hau.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 1-6/2005 Chapter 2. The Application Layer 20
- The received mail message ◼ Server thêm vào dòng header mỗi khi nhận thư: Received: Return-path: ◼ 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 1-6/2005 Chapter 2. The Application Layer 21
- Hiển thị full headers với Y! Mail 2.General Preference 1.Mail Options 3.Messages: Show all 1-6/2005 Chapter 2. The Application Layer 22
- Mail access protocol SMTP SMTP access user user agent agent protocol sender’s mail receiver’s mail server server ◼ SMTP: giao thức gửi mail tới server. ◼ 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! 1-6/2005 Chapter 2. The Application Layer 23
- POP3 protocol [1] Authorization phase S: +OK POP3 server ready ◼ client commands: C: user bob user: declare username [1] S: +OK pass: password C: pass hungry ◼ server responses S: +OK user successfully logged on +OK C: list -ERR S: 1 498 S: 2 912 [2] Transaction phase, client: S: . C: retr 1 ◼ list: list message numbers [2] S: ◼ retr: retrieve message by number S: . ◼ dele: delete C: dele 1 C: retr 2 [3] Update phase: S: ◼ Quit S: . ◼ những thay đổi (dele) được cập nhật C: dele 2 C: quit [3] S: +OK POP3 server signing off 1-6/2005 Chapter 2. The Application Layer 24
- POP3 (more) and IMAP More about POP3 IMAP4 ◼ Chế độ “download and delete” ◼ Lưu trữ toàn bộ msg tại (xem vd trước): server. Msg bị xoá khi thoát. ◼ Cho phép người dùng tổ chức Không thể nhận msg lần nữa. lưu trữ trên server (tạo thư ◼ “Download-and-keep”: mục, di chuyển msg ) Msg được giữ lại server. ◼ Lưu trạng thái giữa các phiên Có thể nhận msg nhiều lần từ (state): nhiều client. Thư mục tự tạo. ◼ 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). 1-6/2005 Chapter 2. The Application Layer 25
- Ch2. The Application Layer 2.1. Một số khái niệm và nguyên tắc. 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. 1-6/2005 Chapter 2. The Application Layer 26
- 2.6. DNS (Domain Name System) Mr Binh HTTP (Internet Explorer) From: Đ.V.Bình www.hau.edu.vn www.hau.edu.vn To: Phòng ĐT => 203.162.8.82 Phòng 203.162.8.82 ĐT => H.101 DNS client DNS servers Ms Nam ◼ Địa chỉ IP (32 bit) được sử dụng để xác định một nút trong mạng TCP/IP: 203.162.8.82 → khó nhớ! → Sử dụng tên (host name) song song với IP address. ◼ DNS (RFC 1034, RFC 1035, RFC 2136): Chuyển host name → IP address. 1-6/2005 Chapter 2. The Application Layer 27
- 2.6. DNS (Domain Name System) 1-6/2005 Chapter 2. The Application Layer 28
- DNS services DNS không tương tác trực tiếp với users mà cung cấp các dịch vụ cho các chương trình khác (HTTP, FTP ) thuộc tầng ứng dụng: ◼ Host name → IP (hostname to IP resolve). ◼ Host aliasing. Một máy tính có tên chính thức và có thể có bí danh (alias). ◼ Mail server aliasing. @hau1.edu.vn → mail server address = ? ◼ Load distribution (phân tán tải) Một dịch vụ web (cnn.com, yahoo.com ) có thể được cung cấp tại nhiều server có IP khác nhau để phân tán tải do lượng người sử dụng cao. 1-6/2005 Chapter 2. The Application Layer 29
- Domain name servers Root DNS Servers com DNS servers org DNS servers edu DNS servers pbs.org poly.edu umass.edu yahoo.com amazon.com DNS servers DNS servers DNS servers DNS servers DNS servers Vd: client muốn biết IP của www.amazon.com thì: ◼ Tìm địa chỉ của com DNS servers hỏi Root DNS servers. ◼ amazon.com com DNS servers. ◼ www.amazon.com amazon.com DNS servers. 1-6/2005 Chapter 2. The Application Layer 30
- Internet domain name space vn ◼ Domain name (tên miền): ◼ Host name: www.hau1.edu.vn; mail.hau1.edu.vn Miền = tập hợp các nút mạng có cùng một nút cha trong sơ đồ trên. vn: Vietnam. Vd: edu: education. hau1.edu.vn; yahoo.com; yale.edu. hau: Hanoi Agricultural University. Sub-domain: cs.yale.edu; www: máy chủ world wide web. mail: máy chủ mail. 1-6/2005 Chapter 2. The Application Layer 31
- Internet domain name space 1-6/2005 Chapter 2. The Application Layer 32
- Internet domain name space 1-6/2005 Chapter 2. The Application Layer 33
- Internet domain name space ◼ 1-6/2005 Chapter 2. The Application Layer 34
- Internet domain name space 1-6/2005 Chapter 2. The Application Layer 35
- 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 ◼ Khi local name server không thể chuyển host name → IP, gửi yêu cầu tới root srv. ◼ root name server: Liên lạc với authoritative name server nếu chưa thể ánh xạ đ/c ngay. Lấy kết quả ánh xạ gửi về từ authoritative name server. Trả kết quả về cho local name server. 1-6/2005 Chapter 2. The Application Layer 36
- TLD and Authoritative Servers ◼ 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. ◼ Authoritative DNS servers: Mỗi host trong mạng muốn được biết đến phải được khai báo với một authoritiative DNS server. DNS servers của các tổ chức ánh xạ hostname → IP cho các hosts của tổ chức đó (vd: web, mail ). Có thể được quản lý bởi các tổ chức hay nhà cung cấp dịch vụ. 1-6/2005 Chapter 2. The Application Layer 37
- Local name server ◼ Thuộc quản lý của ISP (ISP, company, university ). ◼ Khi một host muốn biết IP của một host nào đó, trước tiên, nó “hỏi” local name server. ◼ Không nhất thiết phải nằm trong kiến trúc DNS servers (độc lập). ◼ “Gần” máy tính của người sử dụng nhất nên thường được “hỏi thăm” đầu tiên mỗi khi có truy vấn DNS. ◼ Xem Windows Local DNS: ipconfig 1-6/2005 Chapter 2. The Application Layer 38
- DNS example 1-6/2005 Chapter 2. The Application Layer 39
- 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 1. Liên lạc với local DNS 5 3 server: dns.eurecom.fr 2. dns.eurecom.fr liên lạc với local name server Authorititive root name server (nếu cần) dns.eurecom.fr name server dns.umass.edu 3. root name server liên lạc với 1 6 authoritative name server: dns.umass.edu (nếu cần) requesting host gaia.cs.umass.edu surf.eurecom.fr 1-6/2005 Chapter 2. The Application Layer 40
- DNS example 2 Root name server có thể: root name server ◼ Không biết authoritative 2 6 3 name server (ans). 7 ◼ 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 1-6/2005 Chapter 2. The Application Layer 41
- DNS example 3 recursive query: root name server iterated query ◼ A hỏi B, B hỏi C, C hỏi 2 D, rồi trả lời ngược lại. 3 4 ◼ Server được hỏi chịu tải nặng gấp đôi? 7 local name server intermediate name server dns.eurecom.fr dns.umass.edu iterative query: 5 6 1 8 ◼ DNS server được hỏi gợi ý hỏi một server khác. authoritative name server dns.cs.umass.edu ◼ “I don’t know this name, requesting host but ask this server” surf.eurecom.fr gaia.cs.umass.edu 1-6/2005 Chapter 2. The Application Layer 42
- DNS: caching & updating ◼ Mỗi khi DNS server nhận được yêu cầu tra cứu IP, IP mà nó tìm được sẽ được lưu lại phục vụ cho những lần tra cứu tiếp theo. Timeout: thời gian hết hạn (sau một khoảng thời gian, bản ghi cache tương ứng bị xoá). TLD servers thường được cache tại local name servers. ◼ Cơ chế cập nhật/thông báo được đưa ra bởi IETF: RFC 2136 1-6/2005 Chapter 2. The Application Layer 43
- DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type, ttl) ◼ Type=A ◼ Type=CNAME name = hostname name = “bí danh” (alias). value = IP address www.ibm.com value = tên thật. ◼ Type=NS servereast.backup2.ibm.com name = domain name value = IP address của ◼ Type=MX authoritative name name = domain name server cho domain này value = tên của mail server 1-6/2005 Chapter 2. The Application Layer 44
- DNS protocol, messages DNS Protocol: Query/reply messages có cùng format. ◼ Msg header (12 bytes) ◼ Identification: số 16 bit reply msg sử dụng cùng id với req msg. ◼ Flags: nhiều bit, mỗi bit có một ý nghĩa: Query (0) hay reply (1) Authoritative DNS. recursion desired: client mong muốn DNS server tra cứu đệ quy. recursion available: server hỗ trợ tra cứu đệ quy. 1-6/2005 Chapter 2. The Application Layer 45
- DNS messages Name, type fields for a query RRs in reponse to query records for authoritative servers additional “helpful” info that may be used 1-6/2005 Chapter 2. The Application Layer 46