Author: bakari Date: 2012.5.23
老师上课的时候给了一张图,个人感觉非常经典,几乎将请求一个网页所要进行的流程都弄得非常详细,对宏观地理解网络有很大的帮助。所以将它翻译了以作巩固和分享:
翻译完全靠我个人的感觉,若有错误或者不妥的地方,我非常希望看到的朋友能够帮我指出,大家一起进步。
题目大致意思就是:网页请求的流程
1、前言:
本章我们主要讨论链路层,我们的网络之路从协议栈起步。
Getting Started : DHCP ,UDP, IP,and Ethernet
让我们来假设Bob启动他的笔记本然后连上以太网连接到学校的以太网交换机,这些交换机轮流连到学校的路由器,像上图显示的一样
学校的路由器连到ISP,如电信,电信为学校提供DNS服务,因此,DNS服务器存在于电信联盟的网络上而不是学校网络。
我们假设DHCP服务器运行在路由器,经常都是这样 。
当Bob第一次联网时,他不能做任何事假如没有IP地址,因此,第一次网络关联的举动就是运行DHCP来获得IP地址,也包括其他的一些信息。
2、正文:如上图所示:数字和下面的翻译对应:
1. The operating system on Bob’s laptop creates a DHCP request message and puts this message within a UDP segment with destination port 67 (DHCP server) and source port 68 (DHCP client).
The UDP segment is then placed within an IP datagram with a broadcast IP destination address (255.255.255.255) and a source IP address of 0.0.0.0, since Bob’s laptop doesn’t yet have an IP address.
Bob的笔记本电脑上的操作系统创建一个DHCP请求消息并且把这个消息放在包含目标端口67(DHCP服务器)和源端口68(DHCP客户端)UDP段内。
UDP报文封装在IP数据报内以源IP地址(0.0.0.0),全网广播出去,现在Bob的电脑依然上不了网。
2. The IP datagram containing the DHCP request message is then placed within an Ethernet frame.
The Ethernet frame has a destination MAC addresses of FF:FF:FF:FF:FF:FF so that the frame will be broadcast to all devices connected to the switch (hopefully a DHCP server); the frame’s source MAC address is that of Bob’s laptop, 00:16:D3:23:68:8A.
IP数据报包含DHCP的发送请求报文,然后封装在以太网帧中。
以太网帧的默认目的MAC地址为FF:FF:FF:FF:FF:FF,以至于以太网帧能广播到连接在交换机(准确的说应该是DHCP服务器)的全部设备上,然后帧的源MAC地址是Bob的电脑:00:16:D3:23:68:8A.
3. The broadcast Ethernet frame containing the DHCP request is the first frame sent by Bob’s laptop to the Ethernet switch.
The switch broadcasts the incoming frame on all outgoing ports, including the port connected to the router.
Bob的电脑发到以太网交换机的第一帧是包括DHCP请求报文的广播帧。
交换机广播所有来自输出端口的传入帧,包括连接到路由器的端口上的。
4. The router receives the broadcast Ethernet frame containing the DHCP request on its interface with MAC address 00:22:6B:45:1F:1B and the IP datagram is extracted from the Ethernet frame.
The datagram’s broadcast IP destination address indicates that this IP datagram should be processed by upper layer protocols at this node, so the datagram’s payload (a UDP segment) is thus demultiplexed up to UDP, and the DHCP request message is extracted from the UDP segment.
The DHCP server now has the DHCP request message.
路由器用接口MAC地址为00:22:6B:45:1F:1B接收包含DHCP请求报文的广播以太网帧,然后从以太网帧中提取IP报文。
该报文的广播的IP目的地址表明本IP数据报应该由上层协议在这个节点上进行处理,所以该数据报的有效载荷(一个UDP报文)向上分用给UDP,然后DHCP请求报文从UDP报文中提取。
此时DHCP服务器拥有了DHCP请求报文。
5. Let’s suppose that the DHCP server running within the router can allocate IP addresses in the CIDR block 68.85.2.0/24.
In this example, all IP addresses used within the school are thus within Comcast’s address block.
Let’s suppose the DHCP server allocates address 68.85.2.101 to Bob’s laptop.
The DHCP server creates a DHCP ACK message containing this IP address, as well as the IP address of the DNS server (68.87.71.226), the IP address for the default gateway router (68.85.2.1), and the subnet block (68.85.2.0/24) (equivalently, the “network mask”).
The DHCP message is put inside a UDP segment, which is put inside an IP datagram, which is put inside an Ethernet frame.
The Ethernet frame has a source MAC address of the router’s interface to the home network (00:22:6B:45:1F:1B) and a destination MAC address of Bob’s laptop (00:16:D3:23:68:8A).
我们假设在路由器上运行的DHCP服务器能用68.85.2.0/24这个地址块分配IP地址。
在这个例子中学校里面使用的IP的地址也是电线公司分配的地址块当中的地址。
我们假设DHCP服务器分配给Bob的电脑的IP是68.85.2.101。
DHCP服务器产生一个ACK报文其中包含这个IP地址,也包含DNS服务器的IP((68.87.71.226),默认网关的IP(68.85.2.1)和子网掩码68.85.2.0/24。
DHCP报文封装在UDP数据报中,UDP数据报又封装在IP报文中,IP报文封装在以太网帧中进行传输。
以太网帧有一个连接在路由器接口源MAC地址00:22:6B:45:1F:1B和Bob电脑的目的MAC地址00:16:D3:23:68:8A。
6. The Ethernet frame containing the DHCP ACK is sent (unicast) by the router to the switch.
Because the switch is self-learning and previously received an Ethernet (containing the DHCP request) from Bob’s laptop, the switch knows to forward a frame addressed to 00:16:D3:23:68:8A only to the output port leading to Bob’s laptop.
包含DHCP ACK的以太网帧从路由器发送到交换机。
因为交换机有自我学习的功能,所以在之前接收到从Bob发来的DHCP请求帧,交换机就知道转发帧从接收请求帧的那个端口发送DHCP ACK 到MAC地址为00:16:D3:23:68:8A。
7. Bob’s laptop receives the Ethernet frame containing the DHCP ACK, extracts the IP datagram from the Ethernet frame, extracts the UDP segment from the IP datagram, and extracts the DHCP ACK message from the UDP segment.
Bob’s DHCP client then records its IP address and the IP address of its DNS server.
It also installs the address of the default gateway into its IP forwarding table.
Bob’s laptop will send all datagrams with destination address outside of its subnet 68.85.2.20/24 to the default gateway.
At this point, Bob’s laptop has initialized its networking components and is ready to begin processing the web page fetch.
Note that only the last two DHCP steps of the four presented in chapter 4 are actually necessary.
When Bob types the URL for www.google.com into his web browser, he begins the long chain of events that will eventually result in Google’s home page being displayed by his web browser.
Bob’s web browser begins the process by creating a TCP socket that will be used to send the HTTP request to www.google.com.
In order to create the socket, Bob’s laptop will need to know the IP address of www.google.com.
We learned that the DNS protocol is used to provide this name-to-IP-address translation service.
Bob的电脑接收到包含DHCP ACK的帧,一层层解封装之后得到DHCP ACK报文。
然后Bob的DHCP客户端记录它的IP地址和DNS服务器的IP地址。
同时也将默认网关的地址记录在它的转发表中。
Bob的电脑开始发送带有目的地址的数据报到默认网关,他的子网是68.85.2.20/24。
此时,Bob的电脑已经开始初始化网络部件并准备开始生成并加工网页。
注意只有最后两个DHCP步骤在第四章中提出的四个步骤实际上是必要的。
当Bob使用URL用浏览器打开谷歌首页时,事件链最终将导致谷歌的主页在他的网页浏览器中显示。
Bob的浏览器开始通过创建一个被用来发送HTTP请求道谷歌首页的TCP socket进程。
为了创建套接字,Bob的电脑需要知道谷歌的IP地址。
我们学习的DNS协议就是用来提供这这种名字到IP地址翻译的服务。
8. The operating system on Bob’s laptop thus creates a DNS query message, putting the string “www.google.cn” in the question section of the DNS message.
This DNS message is then placed within a UDP segment with a destination port of 53 (DNS server).
The UDP segment is then placed within an IP datagram with an IP destination address of 68.87.71.226 (the address of the DNS server returned in the DHCP ACK in step 5) and a source IP address of 68.85.2.101.
Bob电脑的OS创建一个DNS查询消息,其中把谷歌域名放在DNS报文的请求问题部分。
DNS报文被封装在UDP数据报中,目的端口号为53.
UDP数据报被封装在目的地址为68.87.71.226的IP报文中,源IP为68.85.2.101
9. Bob’s laptop then places the datagram containing the DNS query message in an Ethernet frame.
This frame will be sent (addressed, at the link layer) to the gateway router in bob’s school’s network.
However, even though Bob’s laptop knows the IP address of the school’s gateway router (67.85.2.1) via the DHCP ACK message in step 5 above, it doesn’t know the gateway router’s MAC address
In order to obtain the MAC address of the gateway router, Bob’s laptop will need to use the ARP protocol
Bob的电脑将包含DNS请求报文的数据封装在以太网帧头中。
该数据帧将被发送到处在学校网络上的默认网关。
然而即使Bob的电脑可以通过DHCP ACK报文学习到默认网关的IP67.85.2.1,但还是无法知道其MAC地址。
为了获得默认网关的MAC地址还需要ARP协议。
10. Bob’s laptop creates an ARP query message with a target IP address of 68.85.2.1 (the default gateway), places the ARP message within an Ethernet frame with a broadcast destination address (FF:FF:FF:FF:FF:FF) and sends the Ethernet frame to the switch, which delivers the frame to all connected devices, including the gateway router.
Bob的电脑新建一个ARP查询消息到默认网关,并把ARP消息封装在以太网帧进行广播然后发送以太网帧到交换机,交换机传帧到直连的设备,包括默认网关。
11. The gateway router receives the frame containing the ARP query message on the interface to the school network, and finds that the target IP address of 68.85.2.1 in the ARP message matches the IP address of its interface.
The gateway router thus prepares an ARP reply, indicating that its MAC address of 00:22:6B:45:1F:1B corresponds to IP address 68.85.2.1.
It places the ARP reply message in an Ethernet frame, with a destination address of 00:16:D3:23:68:8A (Bob’s laptop) and sends the frame to the switch, which delivers the frame to Bob’s laptop.
网关路由器接收包含ARP查询消息的帧到连接学校网络的接口,发现在ARP查询消息中68.85.2.1的目标地址和它的接口相匹配。
网关路由器因此准备回复ARP请求,表明它的MAC地址00:22:6B:45:1F:1B和IP地址68.85.2.1相匹配。
网关路由器将ARP请求报文封装在以太网帧中,其目的地址为Bob电脑的MAC地址,并且发送帧到交换机,交换机再发送在、数据帧到Bob的电脑。
12. Bob’s laptop receives the frame containing the ARP reply message and extracts the MAC address of the gateway router (00:22:6B:45:1F:1B) from the ARP reply message.
Bob的电脑接收包含ARP请求报文的帧并从ARP请求报文中提取网关路由器的MAC地址。
13. Bob’s laptop can now (finally!) address the Ethernet frame containing the DNS query to the gateway router’s MAC address.
Note that the IP datagram in this frame has an IP destination address of 68.87.71.226 (the DNS server), while the frame has a destination address of 00:22:6B:45:1F:1B (the gateway router).
Bob’s laptop sends this frame to the switch, which delivers the frame to the gateway router.
Bob的电脑现在能发送包含DNS查询报文的以太网帧到网关路由器的MAC地址。
注意在这个帧的IP报文段中有目的IP为DNS Server的IP,目的MAC为网关路由器的MAC。
Bob的电脑发送帧到交换机,然后发送到网关路由器。
14. The gateway router receives the frame and extracts the IP datagram containing the DNS query.
The router looks up the destination address of this datagram (68.87.71.226) and determines from its forwarding table that the datagram should be sent to the leftmost router in the Comcast network in Figure 5.37.
The IP datagram is placed inside a link-layer frame appropriate for the link connecting the school’s router to the leftmost Comcast router and the frame is sent over this link.
网关路由器接收数据帧并提取包含DNS查询报文的IP报文段。
路由器查看目的IP 68.87.71.226,然后检查它的转发表,上图中最左边的路由器。
IP数据报被放置在链路层帧中通过连接到学校路由器进行发送。
15. The leftmost router in the Comcast network
- receives the frame,
- extracts the IP datagram,
- examines the datagram’s destination address (68.87.71.226) and
- determines the outgoing interface on which to forward the datagram towards the DNS server from its forwarding table, which has been filled in by Comcast’s intra-domain protocol (such as RIP, OSPF, or IS-IS) as well as the Internet’s inter-domain protocol, BGP.
最左边的路由器在电信公司的网络上
接收数据帧,提取IP报文段,检查报文的目的IP地址,检查从路由器的转发表发送数据报到DNS服务器的合适的接口,转发表通过域内网关协议和边界网关协议来进行填充。
16. Eventually the IP datagram containing the DNS query arrives at the DNS server.
The DNS server extracts the DNS query message, looks up the name www.google.com in its DNS database, and finds the DNS resource record that contains the IP address (64.233.169.105) for www.google.com. (assuming that it is currently cached in the DNS server).
Recall that this cached data originated in the authoritative DNS server for google.com.
The DNS server forms a DNS reply message containing this hostname-to-IP address mapping, and places the DNS reply message in a UDP segment, and the segment within an IP datagram addressed to Bob’s laptop (68.85.2.101).
This datagram will be forwarded back through the Comcast network to the school’s router and from there, via the Ethernet switch to Bob’s laptop.
最后包含DNS查询报文的IP数据报到达DNS服务器。
DNS服务器提取DNS查询报文,在DNS数据库中查找谷歌域名,找到包含谷歌IP地址的DNS源记录(假设该地址被放到DNS服务器的缓冲区中)
调用这些缓存数据起源于google.com认证的DNS服务器。
DNS服务器形成一个DNS回复报文,其中包含主机名到地址的映射,封装之后发到Bob的电脑上。
这个报文将被转发通过电信网络到学校路由器,然后在通过以太网交换机到Bob的电脑。
17. Bob’s laptop extracts the IP address of the server www.google.com from the DNS message.
Finally, after a lot of work, Bob’s laptop is now ready to contact the www.google.com server.
Bob的电脑从DNS回复报文中提取谷歌服务器的IP地址。
最后,经过许多工作之后,Bob的电脑准备连接谷歌服务器。
18. Now that Bob’s laptop has the IP address of www.google.com, it can create the TCP socket that will be used to send the HTTP GET message to www.google.com.
When Bob creates the TCP socket, the TCP in Bob’s laptop must first perform a three-way handshake with the TCP in www.google.com.
Bob’s laptop thus first create a TCP SYN segment with destination port 80 (for HTTP), places the datagram inside a frame with a destination MAC address of 00:22:6B:45: 1F:1B (the gateway router) and sends the frame to the switch.
现在Bob的电脑谷歌的IP,然后就能通过创建TCP套接字来发送HTTP GET消息到谷歌服务器。
当Bob创建TCP套接字,TCP连接第一次必须和谷歌服务器执行三次握手。
因此Bob的电脑第一次必须创建TCP SYN报文段到HTTP服务器,封装数据报到帧头中然后发送到目的MAC为网关路由器的接口然后发送帧到交换机。
19. The routers in the school network, Comcast’s network, and Google’s network forward the datagram containing the TCP SYN towards www.google.com, using the forwarding table in each router, as in steps 14-16 above.
Recall that the router forwarding table entries governing forwarding of packets over the inter-domain link between the Comcast and Google networks are determined by the BGP protocol.
学校网络上的路由器,电信网络和谷歌所在网络的路由器都使用各自的转发表负责转发包含TCP SYN的报文到谷歌服务器。
调用这些路由转发表的进入接口,支配数据包在域内和域外转发使用的是BGP边界网关路由协议。
20. Eventually, the datagram containing the TCP SYN arrives at www.google.com.
The TCP SYN message is extracted from the datagram and demultiplexed to the welcome socket associated with port 80.
A connection socket is created for the TCP connection between the Google HTTP server and Bob’s laptop.
A TCP SYNACK segment is generated, placed inside a datagram addressed to Bob’s laptop, and finally placed inside a link-layer frame appropriate for the link connecting www.google.com to its first-hop router.
最终,包含TCP SYN的报文段到达谷歌服务器。
TCP SYN消息被提取出来从该报文段中然后分用到和欢迎套接字绑定的80号端口。
这样,一个在googleHTTP服务器和Bob电脑上的TCP链接套接字就被创建成功了。
一个TCP SYN ACK 报文产生封装在数据报中发送到Bob的电脑,最后封装成链路层数据帧链接谷歌的第一跳路由器。
21. The datagram containing the TCP SYNACK segment is forwarded through the Google, Comcast, and school networks, eventually arriving at the Ethernet card in Bob’s laptop.
The datagram is demultiplexed within the operating system to the TCP socket created in step 18, which enters the connected state.
该包含TCP SYN ACK的报文段在通过层层转发到Bob的电脑上。
数据报被分用到OS之前创建的TCP套接字,进行匹配。
22. With the socket on Bob’s laptop now (finally) ready to send bytes to www.google.com, Bob’s browser creates the HTTP GET message containing the URL to be fetched.
The HTTP GET message is then written into the socket, with the GET message becoming the payload of a TCP segment.
The TCP segment is placed in a datagram and sent and delivered to www.google.com as in steps 18-20 above.
有了连接套接字Bob的电脑就可以准备发送字节到谷歌,Bob的浏览器创建HTTP GET消息进行访问,其中使用URL。
HTTP GET消息写进套接字,和GET消息一起变成TCP报文段的有效载荷的一部分。
TCP报文段被封装在数据报中然后发送传输到谷歌,进行的是18-20部分。
23. The HTTP server at www.google.com reads the HTTP GET message from the TCP socket, creates an HTTP response message, places the requested web page content in the body of the HTTP response message, and sends the message into the TCP socket.
谷歌的HTTP服务器从TCP套接字中读GET消息,然后创建HTTP回应报文,该报文封装在HTTP回复报文的网页主体内,然后在发送消息到TCP套接字。
24. The datagram containing the HTTP reply message is forwarded through the Google, Comcast, and school networks, and arrives at Bob’s laptop.
Bob’s web browser program reads the HTTP response from the socket, extracts the html for the web page from the body of the HTTP response, and finally (finally!) displays the web page!
这个包含有HTTP 回复消息的数据报通过层层转发到Bob的电脑。
Bob的web浏览器程序读取HTTP回复报文从套接字,然后从HTTP响应报文段的主体部分提取网页的html程序,最后显示网页。
欢迎朋友指正。