Tải bản đầy đủ (.pdf) (22 trang)

Bài giảng Chương 4: Internet

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (939.75 KB, 22 trang )

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.TCP Sockets.
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ạngINTERNET”, 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ì


hồn tồn thay thế NCP.
2
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
80, đến 11/1986 đã có

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
Radio
sau
38 năm
PC
sau
16 năm
TV
sau
13 năm
WWW
sau

4 năm

3

• 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
ta thấy:
SoOSI
sánh
các mơ hình giao thức trên INTERNET

TCP/IP Model


Application
Transport

TCP/IP Protocols

FTP Telnet HTTP
TCP

UDP

Internetwork

IP

Host to
Network

EtherPacketPoint-tonet Radio Point

OSI Ref Model

Application
Presentation
Session
Transport
Network
Datalink
Physical
6


3


1. Hoạt động của giao thức IP-Internet Protocol

•Application: Truyền thơng và
các quá trình phân tán
– 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

application
transport
network
data link

physical

7

Phân tích q 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:

8

4


HOST 1

ROUTER A

ROUTER B

HOST 2

Application

Application

TCP

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ó khn 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ƣ
9
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.
10

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.thức TCP – Transfer Control Protocol
2. Giao
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:

11

Source Port

Destination Port
Sequence Number

Acknowledgment Number
Data
Offset

Reser- U
ved R
G

A
C
K

P R S F
S S Y I

H T N N

Window

Checksum

Urgent Pointer

Option

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ộ hố. FIN Khơng cịn dữ
liệu từ trạm nguồn.
12

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ó khn dạng nhƣ sau:
Source Port

Destination Port

Message Length

Checksum

Data
13

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

14

7



II.1. Mơ hình Client-server
Một trao đổi điển hình giữa:
client và server

Client:
ã Khởi tạo kết nối với server
(speaks first)
ã Yêu cầu requests dịch vụ
từ server,
ã Các dịch vụ nh- Web,
client là công cụ duyệt
browser; nh- e-mail là đọc
th-

application
transport
network
data link
physical

request

reply
application
transport
network
data link
physical


15

II.2. Dch vụ: giao thức http
http: hypertext transfer
protocol
 Dịch vụ Web thuộc giao thức
tầng ứng dụng
 Mô hinh client/server
 client: duyệt và tiếp nhận
các yêu cầu, “displays”
Web objects
 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

PC running
Explorer

Server
running
Apache Web
server
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,
School.edu/Department/home.index
references to 10
jpeg images)

1a. http client initiates TCP
connection to http server
(process) at www.
School.edu. Port 80 is
default for http server.
2. http client sends http
request message
(containing URL) into TCP
connection socket

time

1b. http server at host www.
School.edu waiting for TCP
connection at port 80.
“accepts” connection,
notifying client
3. http server receives request
message, forms response
message containing requested
object

(Department/home.index),
sends message into socket
17

http example (cont.)
5. http client receives

time

response message
containing html file,
displays html.
Parsing html file, finds
10 referenced jpeg
objects

4. http server closes
TCP connection.

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)
header
lines

data, e.g.,
requested
html file

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
Content-Type: text/html
data data data data data ...

20

10


User-server interaction: authentication
Authentication goal: control
access to server

server
client
• stateless: client presents
usual http request msg
authorization in each
401: authorization req.
request
WWW authenticate:
• authorization: typically
name, password
usual http request msg
– authorization:
+ Authorization:line
header line in request
usual http response msg
– Sends header line
WWW authenticate:
usual http request msg
+ Authorization:line
if unauthorized

Browser caches name & password so
that user does not have to repeatedly
enter it.

usual http response msg

time
21


User-server interaction: cookies
• server sends
“cookie” to client in
response msg
Set-cookie: 1678453

• client presents
cookie in later
requests
cookie: 1678453

• server matches
presented-cookie
with server-stored
info
– authentication
– remembering user
preferences

server

client
usual http request msg

usual http response +

Set-cookie: #
usual http request msg

cookie: #

usual http response msg

usual http request msg

cookie: #
usual http response msg

cookiespectific
action
cookiespectific
action
22

11


User-server interaction: conditional
GET

• Goal: don’t send
object if client has up- client
to-date stored
http request msg
(cached) version
If-modified-since:
<date>
• client: specify date of
cached copy in http
http response
HTTP/1.0

request
If-modified-since:
<date>

server
object
not
modified

304 Not Modified

• server: response
contains no object if
cached copy up-todate:

If-modified-since:
<date>

HTTP/1.0 304 Not
Modified

HTTP/1.1 200 OK


http request msg

http response

<data>


object
modified

23

Web Caches (proxy server)
Goal: satisfy client request without involving origin server
• user sets browser:
Web accesses via web
origin
cache
server
• client sends all http
Proxy
requests to web cache
server
– if object at web
client
cache, web cache
immediately returns
object in http
response
– else requests object
client
from origin server,
origin
then returns http
server
response to client
24


12


Why Web Caching?
Assume: cache is
“close” to client
(e.g., in same
network)
• smaller response
time: cache
“closer” to client
• decrease traffic to
distant servers

origin
servers
public
Internet

institutional
network

1.5 Mbps
access link

– link out of
institutional/local
ISP network often
bottleneck


10 Mbps LAN

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

user

at host

FTP
FTP
user
client
interface
local file
system

file transfer

FTP
server
remote 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
• two parallel TCP
connections opened:
– control: exchange
commands, responses
between client, server.
“out of band control”
– data: file data to/from
server
• ftp server maintains
“state”: current directory,
earlier authentication

TCP control connection
port 21

FTP
client

TCP data connection
port 20

FTP
server

29


ftp commands, responses
Sample commands:
• sent as ASCII text over
control channel
• USER username
• PASS password
• LIST returns list of file
in current directory
• RETR filename
retrieves (gets) file
• STOR filename stores
(puts) file onto remote
host

Sample return codes
• status code and
phrase (as in http)
• 331 Username OK,
password required
• 125 data
connection
already open;
transfer starting
• 425 Can’t open
data connection
• 452 Error writing
file
30

15



II.4. Dịch vụ: Electronic Mail
Three major components:
• user agents
• mail servers
• simple mail transfer
protocol: smtp

outgoing
message queue
user mailbox

user
agent
mail
server

User Agent
• a.k.a. “mail reader”
SMTP
• composing, editing,
reading mail messages
mail
• e.g., Eudora, Outlook,
server
elm, Netscape
Messenger
user
• outgoing, incoming

agent
messages stored on
server

SMTP

user
agent
mail
server

SMTP

user
agent

user
agent

user
agent

31

Electronic Mail: mail servers
Mail Servers
• mailbox contains
incoming messages
(yet to be read) for user
• message queue of

outgoing (to be sent)
mail messages
• smtp protocol between
mail servers to send
email messages
– client: sending mail
server
– “server”: receiving
mail server

user
agent
mail
server

SMTP
SMTP
mail
server

user
agent

SMTP

user
agent
mail
server


user
agent

user
agent

user
agent

32

16


Mail message format
smtp: protocol for
exchanging email
msgs
RFC 822: standard for
text message format:
• header lines, e.g.,
– To:
– From:
– Subject:
different from smtp
commands!

header

blank

line

body

• body
– the “message”, ASCII
characters only

33

Message format: multimedia extensions
• MIME: multimedia mail extension, RFC
2045, 2056
• additional lines in msg header declare
MIME content type
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data

From:
To:
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....

.........................
......base64 encoded data

34

17


Mail access protocols
user
agent

SMTP

SMTP

sender’s mail
server

POP3 or
IMAP

user
agent

receiver’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
• client commands:
– user: declare
username
– pass: password
• server responses
– +OK
– -ERR
transaction phase, client:
• list: list message
numbers
• retr: retrieve
message by number
• dele: delete
• quit

S:
C:
S:
C:

S:

+OK POP3 server ready
user alice
+OK
pass hungry
+OK user successfully logged

C:
S:
S:
S:
C:
S:
S:
C:
C:
S:
S:
C:
C:
S:

list
1 498
2 912
.
retr 1
<message 1 contents>
.

dele 1
retr 2
<message 1 contents>
.
dele 2
quit
+OK POP3 server signing off

on

36

18


II.5. Dịch vụ đặt tên mềm DNS
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


root name server

2

4
3

5

local name server
dns.eurecom.fr

1

authorititive name server
dns.umass.edu

6

requesting host
surf.eurecom.fr

gaia.cs.umass.edu

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
application
developer
controlled by
operating
system

process

process
socket
TCP with
buffers,
variables

host or
server

internet

socket
TCP with
buffers,
variables


controlled by
application
developer
controlled by
operating
system

host or
server
38

19


TCP sockets
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
application viewpoint

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
(inFromUser stream) ,
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

(inFromServer stream)

Input stream: sequence
of bytes into process
Output stream:
sequence of bytes
out of process

client socket
40

20


Tƣơng tác Client/server socket: TCP

Server

Client

(running on hostid)

create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()

TCP


wait for incoming
connection request connection
connectionSocket =
welcomeSocket.accept()
read request from
connectionSocket
write reply to
connectionSocket
close
connectionSocket

setup

create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket

read reply from
clientSocket
close
clientSocket
41

III.2. UDP Sockets

UDP: no “connection”
between client and

server
• no handshaking
• sender explicitly
attaches IP address
and port of
destination
• server must extract IP
address, port of
sender from received
datagram

application viewpoint

UDP provides unreliable transfer
of groups of bytes (“datagrams”)
between client and server

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

21


Client/server socket interaction: UDP
Server

(running on hostid)


create socket,
port=x, for
incoming request:
serverSocket =
DatagramSocket()

read request from
serverSocket
write reply to
serverSocket
specifying client
host address,
port umber

Client
create socket,
clientSocket =
DatagramSocket()

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

read reply from
clientSocket
close
clientSocket

43


22



×