From: http://blog.chinaunix.net/u1/54663/showart_1071889.html
2.2 术语
数据:
在 Ethernet 上: Ethernet frame
在 Ethernet 和 IP 层之间: IP packet
IP , UDP 之间: UDP datagram
IP , TCP 之间: TCP segment
在 network application 中: application message
2.3 数据流
See fig2. 也与 fig1 相符
从上到下: n-to-1. 多对一
从下到上: 1-to-n
2.4 两个网络接口
则 ip 这层是 n-to-n ,无论上到下 or 下到上
“Forwarding”: sending an IP packet out onto another network.
用于 forward ippackets 的 computer 叫做 ip-router 。(看来路由器必须要有两个物理接口啊!)因转发不用接触到 tcp , udp 层,所以有的路由器不实现 tcp , udp module
2.5 IP Creates a Single Logical Network
数据在协议栈中,每往下传就加一层 header 。到目的地后,每往上传就剥一层 header
2.6 Physical Network Independence
新加个 hardware ,只要新装个 driver 即可,不影响层之间
2.7 Interoperability
就是两台机之间一定可连
3. Ethernet
An Ethernet address is 6 bytes (网卡 mac 地址)。 The computer also has a 4-byte IP address.
每个设备听是不是发给自己的,同时也听是不是广播 "FF-FF-FF-FF-FF-FF"
CSAM/CD (Carrier Sense and Multiple Access with Collision Detection) 载波侦听多路访问 / 冲突检测:每次只能一个设备 transmit ,可以一起 receive 。所以如果同一时刻两个设备发,则检测到冲突,两设备都等一个 random 时段,再次 transmit
3.1 A Human Analogy
Each person can hear the words when another is talking (Carrier
Sense ). Everyone in the room has equal capability to talk (Multiple
Access ), but none of them give lengthy speeches because they are
polite. If a person is impolite, he is asked to leave the room
(i.e., thrown off the net).
No one talks while another is speaking. But if two people start
speaking at the same instant, each of them know this because each
hears something they haven’t said (Collision Detection ).
4. ARP
要发 ip packet 出去的时候,怎么确定目的地的 Ethernet address ?可用 arp : ip address –> Ethernet address.
4.1 ARP Table for Address Translation
4.3 ARP Request/Response Pair
( 在 arp 表中找不到 Ethernet address 时的情况 )
当在表中找不到时,要广播发送 ARP request
---------------------------------------
|Sender IP Address 223.1.2.1 |
|Sender Enet Address 08-00-39-00-2F-C3|
---------------------------------------
|Target IP Address 223.1.2.2 |
|Target Enet Address <blank> |
---------------------------------------
TABLE 2. Example ARP Request
收到的结点都比较是否是自己的 ip ,若是,则单播 response ,交换了 sender 和 target
---------------------------------------
|Sender IP Address 223.1.2.2 |
|Sender Enet Address 08-00-28-00-38-A9|
---------------------------------------
|Target IP Address 223.1.2.1 |
|Target Enet Address 08-00-39-00-2F-C3|
---------------------------------------
在 arp 表中找不到 Ethernet address 时的情况:
1. An ARP request packet with a broadcast Ethernet address is sent out on the network to every computer.
2. The outgoing IP packet is queued.
3. The ARP response arrives with the IP-to-Ethernet address translation for the ARP table.
4. For the queued IP packet, the ARP table is used to translate the IP address to the Ethernet address.
5. The Ethernet frame is transmitted on the Ethernet.
如果没有那个 ip address ,也就没有 response ,这种情况就丢弃 ip packet 。上层协议分不清得不到 ip address 是因为网络坏了还是没有这个 ip 地址。
有的实现在等 ethernet address 的时候,不把 ip packet queue ,而是直接丢弃。依赖于上层的 tcp or udp 来用超时重传来恢复。
5. Internet Protocol
5.1 Direct Routing
同一个 network 之内的 routing
5.2 Indirect Routing
不同 networks 之间的 routing ,跨过了路由器,需要路由器来转发。
如图 7 , D 节点的协议栈不同之处在于:它有 3 个 arp module , 3 个 ethernet drivers , 1 个 ip module
如果 A 与 E 通信, source 的 ip 和 ethernet address 当然是 A 的, destination ip address 是 E 的,但是 destination Ethernet address 是 D 的。 因为需要 D 来转发。
----------------------------------------
|address source destination|
----------------------------------------
|IP header A E |
|Ethernet header A D |
----------------------------------------
TABLE 6. Addresses in an Ethernet frame for an IP packet from A to E (before D )
D’s IP module receives the IP packet and upon examining the destination IP address, says "This is not my IP address," and sends the IP packet directly to E.
----------------------------------------
|address source destination|
----------------------------------------
|IP header A E |
|Ethernet header D E |
----------------------------------------
TABLE 7. Addresses in an Ethernet frame for an IP packet from A to E (after D )
即 indirect routing 的 Ip 和 Ethernet address 不匹配。
5.3 IP Module Routing Rules
对于 outgoting ip packet ,从上层来: ip module 要判断,是 directly 还是 Indirectly 发送,然后查 route table ,选择 a lower network interface 。
对于 incoming ip packet ,从下层来: ip module 判断是转发还是给上层。如果转发,则看成 outgoing ip packet 。如果要转发,肯定不发回给来的那个 network interface 。
5.4 IP Address
C 类地址前三 bit 是 110 ,表示前 24-3 bit 用于网络地址,故可有 2^21 = 2,097,152 个 c 类网络地址。
5.5 Names
对于小网络:每台机的“ hosts ”文件记载了 name-to-address translation 。大网络在 server 上记载,网络上的机都可访问。
You may notice that "delta" has only one entry in this file even though it has 3 IP addresses (见 fig9 )。 Delta can be reached with any of its IP addresses; it does not matter which one is used.
5.6 IP Route Table
对于要出去的 ip packet ,可在 route table 中查找路由。 Route table 可由管理员用“ route ”命令来修改。
5.7 Direct Routing Details
--------------------------------------------------------------
|network direct/indirect flag router interface number|
--------------------------------------------------------------
|development direct <blank> 1 |
--------------------------------------------------------------
TABLE 8. Example Simple Route Table
5.8 Direct Scenario
在路由表中找到的情况:往 interface1 发数据包的时候, arp table translation is done 。
在路由表中找不到的情况:丢弃,发 error message
5.9 Indirect Routing Details
5.10 Indirect Scenario
Alpha is sending to epsilon, it’s in IP module now. Ip module 首先取出 ip 地址中 network 部分,然后在路由表中跟第一列匹配。
找到了,要经过 devnetrouter 路由器,然后 alpha 的 ip module 就在 arp 表中找 devnetrouter 的物理地址,然后把目的地的物理地址改成 devnetrouter 的,目的地的 ip 地址还是 epsilon ,并通过 interface1 发送出去。
Delta ,也就是 devnetrouter 路由器收到了,并传到了它的 ip module 了,它发现目的地的 ip 地址不是自己,所以决定转发。
Delta 的 ipmodule 取出目的地 ip 的网络部分,在路由表中找到匹配,然后发送 ip 包给 epsilon 通过 interface3. 此时的目的地的 ip 和物理地址都是 epsilon 的了。
Epsilon 收到了,它的 ip module 发现就是发给自己的,就传到上层。
5.11 Routing Summary
源节点不知道中途经过的路由是怎么样的。
5.12 Managing the Routes
ICMP (Internet Control Message Protocol) can report some routing problems 。小网络可以手动设定路由表,大网络必须自动更新和分发路由表。
如果设备移动,改了 ip 地址,则“ host ” file 也要改变,即使中型网络也很难维护,所以要用 domain name system ( DNS )来解决这个问题。
6. User Datagram Protocol
UDP 给上层的网络应用提供服务。使用 UDP 的网络应用有: Network File System (NFS) , Simple Network Management Protocol (SNMP) 。
UDP 是无连接的数据包传输服务,不保证 delivery 。
UDP 把 ip 传来的包,加上了两个值。一个是多个应用之间基于端口( port )的多路传输信息。另一个是验证码( checksum )用于验证数据完整性。
6.1 Ports
UDP preserves the message boundary defined by the application. It never joins two application messages together, or divides a single application message into parts.
6.2 Checksum
验证码为 0 :说明 sender 没有计算验证码, discard 。
验证码正确:比较是不是自己的端口号,若是,则按队列顺序读取。若队列达到了最大,则 discard 。
7. Transmission Control Protocol
TCP 提供面向连接的 byte stream ,用 timeout 和 retransmission 保证 delivery 。最典型的两个 tcp 协议的应用是 ftp 和 telnet 。其他的还有 x-window system , rcp ( remote copy ),和其他的 r 系列。 Tcp 需要更多的 cpu 和网络带宽。
两台机 tcp 通信后,它们的 tcp modules 里都有定义虚电路( virtual circuit )的状态信息。该虚电路是全双工的。可以同时向两个方向传。
TCP packetizes the byte stream at will; it does not retain the boundaries between writes.
滑动窗口,超时重传,握手。
8. Network Applications
根据需要选择使用 tcp 还是 udp ,但是 Tcp , udp 的不足,可以由应用程序来弥补。
8.1 TELNET :在 tcp 上的远程登录。
8.3 rsh : tcp 上的 remote shell
8.4 NFS : udp 上的 Network File System, 通过 mount ,使得远程文件系统可以像在本地一样使用。
8.5 SNMP : Simple Network Management Protocol (SNMP) uses UDP and is designed for use by central network management stations. 如果给出了足够的数据,管理员就可以分析网络问题。 The central station 就用 snmp 来收集网络上的数据给管理员,让其来分析解释。