Bài giảng Mạng máy tính - Chương IV: Internet

CHƢƠNG IV. INTERNET  
NỘI DUNG CỦA CHƢƠNG  
I. Giới thiệu Internet  
I.1. Giới thiệu Internet  
I.2. Họ giao thức TCP/IP  
II. Một số dịch vụ trên Internet  
II.1. Mô hình Client/ Server.  
II.2. Dịch vụ giao thức : HTTP.  
II.3. Dịch vụ truyền File : Ftp  
II.4. Dịch vụ: Electronic Mail  
II.5. Dịch vụ đặt tên mềm DNS  
III. Các dạng hoạt động của Socket  
III.1.TCPSockets.  
III.2. UDP Sockets.  
iV. Thảo Luận  
I.1. GIỚI THIỆU INTERNET  
Tháng 6/1968 cục các dự án tiên tiến của bộ Quốc phòng Mỹ  
đã xây dựng án liên kết 4 trung nghiên cứu lớn trong toàn liên  
bang là : Viện nghiên cứu Stanford, Đaị học California Los  
Angeles, Đại học California Santa Barbara và Đại học Utah  
thành một hệ thống thống nhất để trao đổi các thông tin. Đến  
giữa năm 1969, 4 trạm đầu tiên đã kết nối thành công, đánh dấu  
sự ra đời của mạng ARPANET – tiền thân của INTERNET. Giao  
thức truyền thông dùng trong ARPANET đƣợc gọi là NCP  
(Network Control Protocol). Tuy nhiên xuất phát từ nhu cầu thực  
tế, các nhà thiết kế ARPANET đã nhận thức đƣợc xây dựng một  
mạng của các mạng máy tính “Mạng của các mạng-  
INTERNET”, vì vậy giữa những năm 70, họ giao thức TCP/IP  
đƣợc Vint Cerf và Robert Kahn đề xuất và phát triển, ban đầu  
cùng tồn tại với NCP trong mạng ARPANET và đến năm 1983 thì  
hoàn toàn thay thế NCP.  
Thuật ngữ INTERNET đƣợc xuất hiện lần đầu tiên vào năm  
1974. Nh
ƣ
ng tên
gọi
ARPANET
vẫn tồn tại
cho
đầu nhữ
ng
n
ă
m  
1
 
So sánh thời gian đạt đƣợc 50 triệu ngƣời dùng trên thế  
giới:  
• Telephone sau  
74 năm  
38 năm  
16 năm  
13 năm  
4 năm  
• Radio  
• PC  
sau  
sau  
sau  
sau  
• TV  
• WWW  
• Cấu trúc mạng và kết nối Internet  
• Internet là một mạng GAN dựa trên kết nối liên mạng  
WAN, sử dụng mô hình TCP/IP. Việc kết nối và truy  
cập Internet của ngƣời dùng đƣợc cung cấp bởi các nhà  
cung cấp dịch vụ Internet ISP (Internet Service  
Provider). Các Các ISP phải thuê đƣờng và cổng của  
một IAP.  
4
2
 
5
I.2. HỌ GIAO THỨC TCP/IP  
TCP/IP là một giao thức cùng làm việc với nhau để cung cấp  
phƣơng tiện truyền thông liên mạng. So sánh với mô hình tham  
chiếu OSI ta thấy:  
So sánh các mô hình giao thức trên INTERNET  
TCP/IP Model  
TCP/IP Protocols  
OSI Ref Model  
Application  
Presentation  
Session  
Telnet  
Application FTP  
HTTP  
UDP  
Transport  
TCP  
Transport  
Network  
Internetwork  
IP  
Datalink  
Host to  
Network  
EtherPacketPoint-to-  
net Radio Point  
Physical  
3
 
1. Hoạt động của giao thức IP-Internet Protocol  
application  
transport  
•Application: Truyền thông và  
các quá trình phân tán  
network  
data link  
physical  
– Thực hiện giao dịch giữa các  
Hosts theo địa chỉ ngƣời dùng  
– Thay đổi các thông báo theo  
yêu cầu ứng dụng  
– Thực hiện các dịch vụ E-mail,  
truyền file (FTP), WWW,...  
application  
transport  
network  
data link  
physical  
application  
transport  
network  
data link  
physical  
Phân tích quá trình hoạt động của mô hình giao thức IP trên  
INTERNET ta có thấy việc giao dịch đƣợc tiến hành:  
4
 
HOST 1  
ROUTER A  
ROUTER B  
HOST 2  
Application  
TCP  
Application  
TCP  
IP  
IP  
IP  
IP  
DLa  
DLa  
DLa  
DLa  
PHYa  
PHYa  
PHYa  
PHYa  
LAN A  
WAN  
LAN B  
IP là giao thức kiểu không liên kết có nghĩa là không cần gian đoạn  
thiết lập liên kết trƣớc khi truyền dữ liệu. Đơn vị dùng trong IP  
đƣợc gọi là Datagram có khuôn dạng tổng quát giống nhƣ các  
PDU đã biết. Hoạt động của giao thức ở tầng IP đƣợc mô tả nhƣ  
sau:  
Đối với thực thể IP ở trạm nguồn:  
1. Tạo một IP Datagram để gửi đi  
2. Tính Checksum và ghép vào Header của Datagra  
3. Ra quyết định chọn đƣờng: hoặc trạm đích thuộc cùng  
một mạng hoặc khác mạng chuyển tới Router hoặc  
Gateway tiếp theo.  
4. Chuyển Datagram xuống tầng dƣới để truyền qua  
Đối với Gateway hoặc Router:  
mạng.  
1. Tính lại Checksum nếu có lỗi thì loại bỏ.  
2. Giảm giá trị tham số Time to Live. Nếu bằng 0 thì loại bỏ.  
3. Ra quyết định chọn đƣờng.  
4. Phân đoạn Datagram nếu cần.  
5. Kiến tạo lại IP Header, bao gồm giá trị mới của tham số  
Time to Live, phân đoạn và Checksum.  
6. Chuyển Datagram xuống tầng dƣới để truyền qua mạng.  
5
 
Đối với thực thể IP ở trạm  
đích:  
1. Tính Checksum nếu có lỗi thi loại bỏ  
2. Tập hợp các Datagram nếu dữ liệu bị phân đoạn.  
3. Chuyển Datagram và các tham số điều khiển lên tầng  
trên.  
2. Giao thức TCP – Transfer Control Protocol  
TCP là giao thức có liên kết, tức là cần phải thiết lập liên kết  
(logic) giữa hai thực thể trƣớc khi tiến hành trao đổi dữ liệu. Đơn  
vị dữ liệu sử dụng trong TCP gọi là Segment (đoạn dữ liệu). Khuôn  
dạng tổng quát nhƣ sau:  
Source Port  
Destination Port  
Sequence Number  
Acknowledgment Number  
Data Reser- U  
A
C
K
P R  
S S  
H T  
S
Y
N
F
I
ved  
Offset  
R
G
Window  
N
Checksum  
Option  
Urgent Pointer  
Padding  
TCP data  
Source Destination Port Số hiệu cổng.  
Optiont Khai báo các thay đổi.  
URG Con trỏ khẩn có hiệu lực. ACK Tín hiệu báo nhận. PSH  
Chức năng đẩy. RST Reset. SYN Đồng bộ hoá. FIN Không còn dữ  
liệu từ trạm nguồn.  
6
 
Một cổng kết hợp với một địa chỉ IP tạo thành một Socket duy  
nhất trong liên mạng. Dịch vụ TCP đƣợc cung cấp nhờ một liên  
kết logic giữa một cặp Socket. Một Socket có thể tham gia với  
nhiều Socket ở xa. Trƣớc khi truyền dữ liệu giữa 2 trạm cần phải  
thiết lập liên kết TCP giữa chúng và khi không còn nhu cầu truyền  
dữ liệu thì liên kết đó sẽ đƣợc giải phóng.  
3. Giao thức UDP – User Datagram Protocol  
UDP là giao thức không liên kết đƣợc sử dụng thay thế cho TCP  
theo yêu cầu của ứng dụng. Nó thƣờng đƣợc dùng cho các ứng  
dụng không đòi hỏi độ tin cậy cao trong giao vận. Đơn vị dữ liệu  
đƣợc gọi là UDP datagram. Có khuôn dạng nhƣ sau:  
Source Port  
DestinationPort  
Checksum  
Message Length  
Data  
II. MỘT SỐ DỊCH VỤ TRÊN INTERNET  
TCP/IP là một giao thức cùng làm việc với nhau để cung cấp phương  
tiện truyền thông liên mạng. So sánh với mô hình tham chiếu OSI ta  
thấy:  
1. Dịch vụ WWW  
2. Dịch vụ Telnet  
3. Dịch vụ Email  
4. Dịch vụ FTP  
5. Dịch vụ tên miền DNS  
7
 
II.1. Mô hình Client-server  
Một trao đổi điển hình giữa:  
client và server  
application  
transport  
network  
data link  
physical  
Client:  
request  
• Khëi t¹o kÕt nèi víi server  
(“speaksfirst”)  
• Yªu cÇu requests dÞch vô  
reply  
tõ server,  
application  
transport  
network  
data link  
physical  
• C¸c dÞch vô nh Web,  
client lµ c«ng cô duyÖt  
browser; nh e-mail lµ ®äc  
th  
15  
II.2. Dịch vụ: giao thức http  
http: hypertext transfer  
protocol  
Dịch vụ Web thuộc giao thức  
tầng ứng dụng  
PC running  
Explorer  
Mô hinh client/server  
. client: duyệt và tiếp nhận  
các yêu cầu, “displays”  
Web objects  
Server  
running  
Apache Web  
server  
. server: Web server  
chuyển các đối tƣợng để  
đáp ứng các yêu cầu  
http1.0: RFC 1945  
http1.1: RFC 2068  
Mac running  
Navigator  
16  
8
 
Ví dụ về http  
Giả sử ngƣời sử dụng đƣa vào địa chỉ URL sau www.  
(contains text,  
references to 10  
jpeg images)  
School.edu/Department/home.index  
1a. http client initiates TCP  
connection to http server  
(process) at www.  
School.edu. Port 80 is  
default for http server.  
1b. http server at host www.  
School.edu waiting for TCP  
connection at port 80.  
“accepts” connection,  
notifying client  
2. http client sends http  
request message  
3. http server receives request  
message, forms response  
message containing requested  
object  
(containing URL) into TCP  
connection socket  
(Department/home.index),  
sends message into socket  
time  
17  
http example (cont.)  
4. http server closes  
TCP connection.  
5. http client receives  
response message  
containing html file,  
displays html.  
Parsing html file, finds  
10 referenced jpeg  
objects  
time  
6. Steps 1-5 repeated for  
each of 10 jpeg  
objects  
18  
9
Dạng tổng quát của http request message  
19  
Khuôn dạng của http message: response  
status line  
(protocol  
status code  
status phrase)  
HTTP/1.0 200 OK  
Date: Thu, 06 Aug 1998 12:00:15 GMT  
Server: Apache/1.3.0 (Unix)  
Last-Modified: Mon, 22 Jun 1998 …...  
Content-Length: 6821  
header  
lines  
Content-Type: text/html  
data data data data data ...  
data, e.g.,  
requested  
html file  
20  
10  
User-server interaction: authentication  
Authentication goal: control  
access to server  
• stateless: client presents  
authorization in each  
request  
server  
client  
usual http request msg  
401: authorization req.  
WWW authenticate:  
• authorization: typically  
name, password  
– authorization:  
usual http request msg  
+ Authorization:line  
header line in request  
usual http response msg  
– Sends header line  
WWW authenticate:  
if unauthorized  
usual http request msg  
+ Authorization:line  
Browser caches name & password so  
that user does not have to repeatedly  
enter it.  
time  
usual http response msg  
21  
User-server interaction: cookies  
• server sends  
“cookie” to client in  
response msg  
Set-cookie: 1678453  
server  
client  
usual http request msg  
usual http response +  
• client presents  
cookie in later  
requests  
Set-cookie: #  
usual http request msg  
cookie: 1678453  
cookie-  
spectific  
action  
cookie: #  
• server matches  
presented-cookie  
with server-stored  
info  
usual http response msg  
usual http request msg  
cookie-  
spectific  
action  
cookie: #  
– authentication  
usual http response msg  
– remembering user  
preferences  
22  
11  
User-server interaction: conditional  
GET  
• Goal: don’t send  
server  
client  
object if client has up-  
to-date stored  
http request msg  
If-modified-since:  
<date>  
(cached) version  
object  
not  
modified  
• client: specify date of  
cached copy in http  
request  
http response  
HTTP/1.0  
304 Not Modified  
If-modified-since:  
<date>  
• server: response  
contains no object if  
cached copy up-to-  
date:  
http request msg  
If-modified-since:  
<date>  
object  
modified  
http response  
HTTP/1.1 200 OK  
…
HTTP/1.0 304 Not  
Modified  
<data>  
23  
Web Caches (proxy server)  
Goal: satisfy client request without involving origin server  
• user sets browser:  
Web accesses via web  
cache  
• client sends all http  
origin  
server  
Proxy  
server  
requests to web cache  
– if object at web  
cache, web cache  
immediately returns  
object in http  
client  
response  
– else requests object  
from origin server,  
then returns http  
client  
origin  
server  
response to client  
24  
12  
Why Web Caching?  
Assume: cache is  
origin  
servers  
“close” to client  
(e.g., in same  
network)  
public  
Internet  
• smaller response  
time: cache  
“closer” to client  
• decrease traffic to  
1.5 Mbps  
access link  
institutional  
network  
10 Mbps LAN  
distant servers  
– link out of  
institutional/local  
ISP network often  
bottleneck  
institutional  
cache  
25  
Mô hình phân phối nội dung  
Networks  
Browsers  
Web Server  
26  
13  
Xảy ra tắc nghẽn trên đƣờng truyền  
Networks  
Browsers  
Routers  
Web Servers  
27  
II.3. Dịch vụ truyền File ftp  
file transfer  
FTP  
user  
interface  
FTP  
client  
FTP  
server  
user  
at host  
remote file  
system  
local file  
system  
• transfer file to/from remote host  
• client/server model  
– client: side that initiates transfer  
(either to/from remote)  
– server: remote host  
• ftp: RFC 959  
• ftp server: port 21  
28  
14  
ftp: separate control, data connections  
• ftp client contacts ftp  
server at port 21,  
specifying TCP as  
transport protocol  
TCP control connection  
• two parallel TCP  
port 21  
connections opened:  
– control: exchange  
TCP data connection  
commands, responses  
between client, server.  
“out of band control”  
FTP  
client  
FTP  
server  
port 20  
– data: file data to/from  
server  
• ftp server maintains  
“state”: current directory,  
earlier authentication  
29  
ftp commands, responses  
Sample commands:  
Sample return codes  
• sent as ASCII text over  
• status code and  
control channel  
phrase (as in http)  
• USER username  
• PASS password  
• 331 Username OK,  
password required  
• 125 data  
• LISTreturns list of file  
connection  
in current directory  
already open;  
transfer starting  
• 425 Can’t open  
data connection  
• 452 Error writing  
• RETR filename  
retrieves (gets) file  
• STOR filenamestores  
(puts) file onto remote  
host  
file  
30  
15  
II.4. Dịch vụ: Electronic Mail  
outgoing  
message queue  
Three major components:  
user mailbox  
• user agents  
• mail servers  
user  
agent  
• simple mail transfer  
mail  
server  
user  
agent  
protocol: smtp  
SMTP  
mail  
server  
User Agent  
• a.k.a. “mail reader”  
• composing, editing,  
reading mail messages  
• e.g., Eudora, Outlook,  
elm, Netscape  
user  
agent  
SMTP  
SMTP  
user  
agent  
mail  
server  
user  
agent  
Messenger  
user  
agent  
• outgoing, incoming  
messages stored on  
server  
31  
Electronic Mail: mail servers  
Mail Servers  
user  
agent  
• mailbox contains  
incoming messages  
(yet to be read) for user  
mail  
server  
user  
agent  
SMTP  
• message queue of  
outgoing (to be sent)  
mail messages  
• smtp protocol between  
mail servers to send  
email messages  
mail  
server  
user  
agent  
SMTP  
SMTP  
user  
agent  
mail  
server  
– client: sending mail  
server  
– “server”: receiving  
user  
agent  
user  
agent  
mail server  
32  
16  
Mail message format  
smtp: protocol for  
exchanging email  
msgs  
header  
body  
RFC 822: standard for  
text message format:  
• header lines, e.g.,  
– To:  
blank  
line  
– From:  
– Subject:  
different from smtp  
commands!  
• body  
– the “message”, ASCII  
charactersonly  
33  
Message format: multimedia extensions  
• MIME: multimedia mail extension, RFC  
2045, 2056  
• additional lines in msg header declare  
MIME content type  
MIME version  
Subject: Picture of yummy crepe.  
MIME-Version: 1.0  
Content-Transfer-Encoding: base64  
Content-Type: image/jpeg  
method used  
to encode data  
multimedia data  
type, subtype,  
base64 encoded data .....  
.........................  
......base64 encoded data  
parameter declaration  
encoded data  
34  
17  
Mail access protocols  
SMTP  
SMTP  
POP3 or  
IMAP  
user  
agent  
user  
agent  
receiver’s mail  
server  
sender’s mail  
server  
• SMTP: delivery/storage to receiver’s server  
• Mail access protocol: retrieval from server  
– POP: Post Office Protocol [RFC 1939]  
• authorization (agent <-->server) and download  
– IMAP: Internet Mail Access Protocol [RFC 1730]  
• more features (more complex)  
• manipulation of stored msgs on server  
– HTTP: Hotmail , Yahoo! Mail, etc.  
35  
POP3 protocol  
authorization phase  
S: +OK POP3 server ready  
• client commands:  
C: user alice  
S: +OK  
C: pass hungry  
S: +OK user successfully logged on  
– user:declare  
username  
– pass:password  
• server responses  
– +OK  
C: list  
S: 1 498  
S: 2 912  
S: .  
– -ERR  
transaction phase, client:  
• list:list message  
numbers  
• retr:retrieve  
C: retr 1  
S: <message 1 contents>  
S: .  
C: dele 1  
C: retr 2  
S: <message 1 contents>  
S: .  
C: dele 2  
message by number  
C: quit  
S: +OK POP3 server signing off  
• dele:delete  
• quit  
36  
18  
II.5. Dịch vụ đặt tên mềm DNS  
root name server  
host surf.eurecom.fr  
wants IP address of  
gaia.cs.umass.edu  
2
4
1. Contacts its local DNS  
server,  
3
5
dns.eurecom.fr  
2. dns.eurecom.fr  
contacts root name  
server, if necessary  
local name server authorititive name server  
dns.eurecom.fr  
dns.umass.edu  
3. root name server  
contacts authoritative  
name server,  
1
6
dns.umass.edu,if  
necessary  
requesting host  
gaia.cs.umass.edu  
surf.eurecom.fr  
37  
III. Các dạng hoạt động của Socket.  
III.1. TCP sockets  
Socket: Là cửa kết nối giữa một quá trình ứng dụng và  
đâu cuôi giao thức tầng transport (UCP or TCP)  
TCP service: dịch vụ vận chuyển tin cậy các byte từ  
một quá trình này sang một quá trình khác  
controlled by  
controlled by  
application  
developer  
process  
process  
application  
developer  
socket  
TCP with  
buffers,  
variables  
socket  
TCP with  
buffers,  
variables  
controlled by  
operating  
system  
controlled by  
operating  
system  
internet  
host or  
server  
host or  
server  
38  
19  
TCP sockets  
• When client creates socket:  
Client must contact server  
• server process must  
client TCP establishes  
connection to server TCP  
• When contacted by client,  
server TCP creates new  
socket for server process  
to communicate with client  
first be running  
• server must have  
created socket (door)  
that welcomes client’s  
contact  
– allows server to talk with  
Client contacts server by:  
multiple clients  
• creating client-local  
TCP socket  
application viewpoint  
• specifying IP address,  
port number of server  
process  
TCP provides reliable, in-order  
transfer of bytes (“pipe”)  
between client and server  
39  
TCP Sockets  
Example client-server app:  
• client reads line from  
standard input  
Input stream: sequence  
of bytes into process  
Output stream:  
sequence of bytes  
out of process  
(inFromUserstream) ,  
sends to server via  
socket (outToServer  
stream)  
• server reads line from  
socket  
• server converts line to  
uppercase, sends back to  
client  
• client reads, prints  
modified line from socket  
(inFromServerstream)  
client socket  
40  
20  
Tải về để xem bản đầy đủ
pdf 22 trang yennguyen 20720 Free
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 IV: Internet", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pdfbai_giang_mang_may_tinh_chuong_iv_internet.pdf