TCP/IP卷一:第一章

时间:2023-03-09 00:26:38
TCP/IP卷一:第一章

=================================================

版權聲明:如需轉載,請列明出處:HingAglaiaWong@博客園

支持原創,是對作者最好的的鼓勵。

http://www.cnblogs.com/HingAglaiaWong/

=================================================

不能再拖了,要開始認真的啃 “TCP/IP:協議”。這算是讀書報告吧,以“TCP/IP卷x” 作開頭,希望能完成這一個系列的讀書報告(半年?)。由於閱讀中譯文有理解困難症,買來的譯本看得很苦b,最後還是很賤的去找原文電子版。寫這一系列的初衷主要是要克服自己的金魚記憶,同時能為志同道合的計科人提供一個菜鳥學習的見證。當中補充資料可能會用上親切的中文。由於本人生性遲鈍,如有曲解書中的內容,還望各位大神當頭棒喝一下,我以感激的心小心翼翼的開始這趟旅程。

Chapter 1: Introduction

- overview of internet architecture

- overview of TCP/IP protocol suite

 TCP/IP and its use

TCP/IP is a protocol suite encompassing different but related protocols. Protocol architecture defines the functionality of a protocol and coordinates their interaction. TCI/IP adopts APRANET Reference Model, which supports packet switching.

TCP/IP is used to communicate different packet-switched networks by providing routers as translators between otherwise incompatible networks. (Q: translate what?) Nodes providing different services are connected together, forming a catenet (or internetwork), where members (nodes) could share and use resources and data on the network, contrary to the originally localized distribution of resources.

===============================================

1.1 Architectural principles

1.1.1. Packets, Connections and Datagrams 

1.1.2.The end-to-end argument and fate sharing 

1.1.3. Error control and flow control 

===============================================

1.1 Architectural principles

TCP/IP is a protocol suite allowing all digital devices to communicate with each other. Notably, internet IS NOT EXACTLY WWW. internet refers to the ability of allowing communications between computers. And Internet is implemented using application WWW,

Considerations of  of internet architecture designs

primary goal: allow multiplexed(data can be combined and split) utilization (data transmission: send & receive) of existing interconnected network.

Consequence: allow simultaneous running of multiple activities on the resultant, interconnected network from different ones. 

Second level goal: Internet must be able to...

i) support different types of networks, communicaiton services & distributed rsc mangagment.

ii) continue communication as long as the network not entirely destoryed

iii) rsc accountability, easy host attachment (Q: not quite understand these points...)

===============================================

1.1.1. Packets, Connections and Datagrams 

For each connection, bandwidth is allocated for data transmission. Once the connection is occupied, whether or not bandwideth is used, the connection is maintained and impossible to be redirected without breaking the connection. Data transmission usually comes with latency.

Packet switching

It divides data to be transmitted into packets, which can be multiplexed (i.e. mixed together and then split apart). Implications of multiplexing are of several folds: i) multiple signals can be transmitted simultaneously within the same channel. ii) path of packets are subject to change. Optimization of data transfer efficiency on network is realized by statistical multiplexing. Actual application includes X.25, ATM(fixed packet size), frame relay(variable packet size).

Statistical multiplexing

When packets arrived at packet switch, they are sequenced in a FIFO manner within the buffer memory. Statistical multiplexing derives the performance statistics of a particular packet ran by other applications sharing the same network. These statistics are used for intermixing packages from different sources. Then, in plain words, when there is bandwidth available, it would soon be stuffed with packets so that the entire network would be busy (or, high utilization at every bottleneck possible). During the process, packets from different sources may be combined or split to fit into the available bandwidth of channels.

Time-division multiplexing

Time and rsc (bandwidth) are reserved at each packet switch. Thus, there is a potential wastage of unused bandwidth.

X.25 protocol suite is a connection-oriented packet network.

=================

補充來源:http://blog.cwke.org/2011/01/virtual-circuit.html

概念紙
1. 串流技術(Streaming)

是指把一連串資料壓縮後,經過網路以資料流的方式分段傳送資料,讓使用者不需等待下載完成就能檢視或收聽資料。

2. 電路交換(circuit switching)
相對於封包交換的一個概念。通信兩端必須在通信前建立連接,這個連接會一直佔用通信系統所分配的資源(通道、頻寬、時隙、碼字等等)直到通信結束。

3. 分時多工(Time-Division Multiplexing, TDM)

is a digital multiplexing technique (rarely used in analog counterparts)。It allow two or more signals/ data streams to be transmitted over a common signal path (communication channel). Each TDM frame consists of a sub-channels with a time slot. Each time slot is dedicated for the transmission of one sub-channel only. Physically speaking, the channel is occupied alternatively by different TDM frams.

4. Connection-oriented communication

a mode of communication where communication session(通訊會話) are set up prior to data transfer. A stream of data is delivered in the same order as it was sent. Example includes: 傳輸控制協定(TCP)與異步傳輸模式(ATM)

5. Connectionless communication

counterpart to connection-oriented communication. Datagram mode communication used by IP protocol adopts this convention. In connectionless communication, data may be delivered out of order due to different delivery path.

6.Packet switching

a method of grouping data transmitted over a network into packets composing of headers and a payload.
Data in header is used by networking hardwares (i.e. switches or routers) to direct the packet to destination. Payload is used and extracted by application.

7.Signaling protocol

to identify signaling encapsulation (the adding of information to abstract the task). In a nutshell, signaling protocol establishes agreement on the way how two machines can communicate, as each machine may talk in its own language only...

8. Encapsulation 

During encapsulation, each layer builds a protocol data unit (PDU) by adding additional headers or tailers on the PDU from previous layers.As a result, the functions of lower layer is hidden. The more abstract layer is called the upper layer protocol, while the most specific one is called the lower layer protocol (e.g. layer 1-4 in the OSI model)

在電腦網絡中,封裝是一種通訊協定的設計方法。將網絡功能進行抽象,對高層功能隱藏底層功能的資訊。例子:OSI模型(layers)、TCP/IP

9. Datagram

Special type of packet with the source and destination information included in the packet itself, instead of inside packet switches. Thus, the packets using datagram packet switching are bigger. However, it also gets rid of per-connection state at packet switch. That's why datagram packet switching is called connectionless network, which in turns, does not need signaling protocol.

2 ways of packet switching
i) datagram packet switching(資料元): each packets are numbered and transmit indepenedely, meaning no fixed transmission path. (Packet Switch Element;PSE)  recombine all packets to recover the data and send to receiver.
ii) Virtual circuit  packet switching(虛擬電路): similar to circuit switching in a way that it establishes a specialized channel between 2 end systems. However, such channel would only partially occupy the entire bandwidth, unlike CS whose channel between 2 end systems occupy the entire bandwidth provided to the channel.

Calculation of path at switch incurs overhead and consumes time. Therefore, VC is usually preferred in huge amount of data. However, in case of node failure, datagram can alter transmission path to continue with the transfer. Yet VC cannot achieve this.

=================

More about Virtual Circuit 

Both VC and X.25 protocol requires 'state' at each packet switch, as the packets adopting these schemes only contain a tiny piece of overhead information indicating an index to state table. Take X.25 for instance, each packet only contain a 12-bit overhead information called Logical Channel Number (LCN, or LCI, I stands for identifier). At each switch, the per-flow state and LCN are considered combined to determine the next switch along the path for the packet. Noted that the path for the packet stream is still fixed, while the choices of switch along the fixed path are determined by the collective consideration mentioned.

================

延伸閱讀:網絡入門

來源:偉大的鳥哥:http://linux.vbird.org/linux_server/0110network_basic.php#tcpip_link_mac

網絡的技術發展
Ethernet使用Token-Ring技術,要求硬體的配合達成通訊。但是後來發展到軟件為主導的ARPANET和TCP/IP,讓不同網絡硬體透過相同的平台進行溝通。

補充:以太網(ethernet)和因特網(internet)分別

以太網採用IEEE802標準,只要硬體支援,就能讓機器連上互聯網。

以太網是連接不同網絡的技術,著重傳輸介質。因特網由很多小網組成,包含所有傳輸介質和技術。
以太网是一种局域网,只能连接附近的设备,因特网是广域网。

電腦網路組成元件
節點(node):以IP位址來劃分。PC、伺服器、印表機等等設備都有IP,但是hub/switch (i.e. router)就沒有。
Server & Client
Network Interface Card (網絡界面卡,NIC):提供網絡連線的卡片。因其擁有MAC位址(48位元序號),所以網絡卡屬於OSI模型的第一層。在網絡上的每一台電腦都擁有獨一無二的MAC位址。網絡卡利用以太網或是令牌環連到電腦網絡。換句話說,任何機器想要連上互聯網都必須有網絡卡。
Network interface(網絡界面):是一個軟體,提供網絡標識(IP),一張網卡至少需要配置一個網絡界面,軟硬鍵配合就能上網。
Network topology(網絡拓撲):分成物理拓撲和邏輯拓撲,規範物理主機之間的連接和資料的邏輯傳輸方式。
Route or gateway (網關或通訊閘):網關在網絡層上實現網絡互連,透過翻譯不同的通訊協議、IP位址(i.e.不同網域)、數據格式和語言,讓不同的不同協議的網絡實現互連。廣域網或是局域網均能使用。例子:一個有三個子網路的網路,在子網路1上的101電腦想要跟子網路3的345電腦進行存取,那101需要通過DNS伺服器獲得345的IP位址,再用子網路遮罩去決定是否同屬同一個網路。若是,就能直接存取。若不是,101就會把345的IP位址傳給通訊閘,讓它分析345的目標網路。由於通訊閘與多個網路連接,所以確定網路後就能把資料發到345主機上。

網關參考:http://www.ablmcc.edu.hk/~scy/CIT/network/Elearning_S2_2.htm

網絡的範圍

區域網絡(Local area network, LAN):節點之間傳輸距離近,使用昂貴的連線材料(光纖、CAT6),速度快,穩定性高。
廣域網絡(Wide area network, WAN):傳輸距離遠,使用便宜的連線材料。速度較慢,穩定性較低。由多個LAN組成。但是現今的WAN速度已經大大提升。

網絡體系結構(network architecture)
是指通訊系統的設計模式,由於網絡連接過程複雜,所以需要NA為網絡硬件、軟件、協議、存取限制和拓撲提供標準。
NA的組成包括:計算機系統和提供網絡服務界面的終端、通訊處理機(獨立計算機或網卡)、通訊線路和設備(物理層面)、操作系統(多管理局域網)、網絡協議。
常見的NA有以太网、令牌环网和快速以太网等等。

OSI的七層協定
是一個網絡體系結構(network architecture),為通訊過程中涉及不同的技術提供標準。OSI是一個概念性的通訊協定,讓開發人員能模塊化各個步驟和技術。

https://baike.baidu.com/item/OSI%E6%A8%A1%E5%9E%8B

延伸閱讀:TCP/IP的IP位址、子網路遮罩、分類網路

來源:偉大的文檔(https://support.microsoft.com/zh-tw/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics)
無所不能的維基(https://en.wikipedia.org/wiki/Classful_network)

網路位址(Network Address)
網路位址是節點(node)和網路界面(network interface)的識別碼,是一個跨網路獨一無二的識別碼。但是在自定義網絡系統中,允許本地位址或是相對位址,這樣網絡標識就未必是獨一(Q:how?)。在一個網路系統裡面,通常採用多種網路位址。

TCP/IP下的網路位址

TCP/IP 組態設定需要 IP 位址、子網路遮罩以及預設閘道。TCP/IP是一個能過連接大小不一的網絡、不同類型的系統的協定。在這個網路主要分成3個網路(classful addressing)的類別。

IP位址是一個32位元的地址,能獨一無二的識別TCP/IP網路上的主機(節點可以是電腦、列表機或路由器)(Q:不是說路由器hub不會有IP嗎?)。IP位址有兩部分組成,

而子網路遮罩亦是一個32位元的序號,把IP位址分成兩部分:一部分用來識別主機,另一部分識別主機所屬的網路。在TCP/IP中,路由器並不知道封包目標主機的確實位置。(Q:為什麼?不是有IP位址嗎?)路由器只會知道目標主機所處的網路,再利用路由表來決定發送封包到哪一個網路上。當封包抵達該網路時,自然會傳到目標主機(Q:how?)。

分類網絡(classful addressing)
將IPv4的IP位址分成五個類別,由不同的首位(leading bits)位數分類。IP位址的10進制格式為XXX.XXX.XXX.XXX。每個XXX由8位二進制表示,最大值為256;所以每個IP位址為32位序號。

class leading bits address range  subnet mask
A 0   (1.0.0.0 至 126.0.0.0) 255.0.0.0
B 10 (128.0.0.0 至 191.255.255.255) 255.255.0.0
C 110 (192.0.0.0 至 223.255.255.255) 255.255.255.0

TCP/IP卷一:第一章

以下是有關於網路位址的計算:

Let x be the size of 'network number'and y be the number of leading bits.
Number of networks at a particular class = 2^(x-y)
Number of addresses per network = 2^(32-x)
Total number of addresses in class = 2^(32-y)

網路位址、主機標識、子網路遮罩
TCP/IP中的IP位址中作為網路及主機標識的部分並非固定,所以,我們需要借助子網路遮罩來分割IP位址的網路和主機部分。以192.168.123.132 為例,假設子網路遮罩是255.255.255.0,那麼我們就能得到網路位址為192.168.123而主機為.132:

11000000.10101000.01111011.10000100 -- IP 位址 (192.168.123.132)
11111111.11111111.11111111.00000000 -- 子網路遮罩 (255.255.255.0)

就可以識別出主機標識和網路位址:

11000000.10101000.01111011.00000000 -- 網路位址 (192.168.123.0)
00000000.00000000.00000000.10000100 -- 主機標識 (000.000.000.132)

子網路遮罩的一般格式為:左邊全1(每節8位元表示255),右邊全0,不會出現梅花間竹的狀態,其他子網路遮罩例子:
  十進位           二進位
255.255.255.192 1111111.11111111.1111111.11000000
255.255.255.224 1111111.11111111.1111111.11100000

不同類別的網路使用不同的子網路遮罩(見上表),所以子網路遮罩的位元數確定了該IP位址所在的區域網的大小。子網路遮罩位元數愈多,IP中32位元裡面剩下的、可分配於主機標識的位元數就愈少,即使在該區域網路上允許的主機數愈少。從上述例子可見,子網路遮罩的最末的8位元不一定是0。

子網路
當在TCP/IP下的分類網路被進一步細分,就會成為子網路。子網路是由子網路遮罩下使用。例如,你被分配了一個C類網路192.168.123.0,那麼,可能的IP位址為:192.168.123.1至192.168.123.254。192.168.123.0和192.168.123.255都是無效的IP位址,因為他們的主機位元全0代表網路(網域位址,Domain address:用來判斷IP位址所在的網域),主機位元全1代表廣播位址(Broadcast address:發出訊息給網路上所有的主機);換句話說,主機標識全1或是全0是用來指向未指定主機的網路。假設一個擁有150不主機的廣域網,他們透過路由器分發到三個不同網路,每個網路各有50部主機。每個主機就能從192.168.123.1至192.168.123.254這個域中獲得一個IP位址。值得注意的是,主機位元不等於IP位址,因為主機位元只是IP位址的一部分。

為何要使用子網掩碼呢?首先是用來分割一個主機的IP位址的主機標識和網路標識,用作在互聯網上尋址的用途。因為在32位元的IP位址上,必須識別出網路位元,才能確認該主機在哪一個網路上。在同一個網路上的傳輸(即局域網)無需經過路由器,但是不同網路上的主機(即遠程網)則需要路由器進行存取。(路由器的作用?)

另一個劃分子網的原因是,增加整體可供採用的IP位址。由於一個網路下擁有不同數量的主機(幾台到幾百台...),如果沒有劃分子網,就會浪費很多IP位址。

若沒有劃分子網,則會出現一個IP位址下只有數台電腦,而另一個IP位址下卻又很多台電腦。以C類網路192.168.123.0為例,這個網絡能容納254部主機,ISP負責分配IP位址。在這個C類網路192.168.123.0下,可能只有數台電腦。如果沒有劃分子網(即使沒有子網掩碼),那麼這家台電腦就獲得了本來能用於254主機的位址,這樣就造成了IP位址的浪費。有了子網掩碼,ISP得知在這個網絡下有多少部電腦,那就利用掩碼,只分配幾個IP位址給主機。換句話說,不同地方、不同擁有者的主機有可能會公用一個子網路。這樣,就節省了IP位址。

怎樣判斷子網路

繼續閱讀:https://baike.baidu.com/item/%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81/100207?fr=aladdin#4

來源:R.F.@電腦王
https://www.techbang.com/posts/15861-3-ip-introduction-to-network-architecture-concept-classification-and-the-subnet-mask?page=3
子網路切割
上文提到,由於在IP位址中,網路位元和主機位元的位元數不受限制,我們就能透過子網路遮罩隨意分割網路區段。例如把192.168.0.0∼192.168.0.255的位址區段劃分為一個網路,那麼子網路遮罩必須為255.255.255.0 (IP裡面頭24位元為網路位址)。如果我們要把192.168.0.0∼192.168.0.255的位址區段劃分為兩個網路,那麼子網路遮罩必須為255.255.255.128(IP裡面頭25位元為網路位址)。(Q:為何劃分為兩個網絡要用多1個位元?A:因為一個位元代表2,若子網路遮罩為128,遮罩後就等於把網絡一分為二,因為在網路標識裡面多了一個位元,等於主機標識少了一個位元,就等於該網路所允許的主機數將會一分為二,實現了子網路切割)。
子網路遮罩1的部分的長度,決定IP位址上網路位址的位元長度。因為將IP位址和子網路遮罩進行布林AND操作後,子網路遮罩1的部分會完整保留IP位址上的1和0,但是子網路遮罩0部分就會讓IP位址的下部分變成全0。運算結果就會會是IP位址上的網路位址。
原文例子如下:
“以192.168.0.1位址和子網路遮罩255.255.255.0做為例子,轉換為2進位後便是11000000 10101000 00000000 00000001和11111111 11111111 11111111 00000000,將兩者進行布林運算AND之後,會得到11000000 10101000 00000000 00000000,轉換回十進位為192.168.0.0,所以192.168.0.0就是192.168.0.1的網路位置。”

A類IP位址、內部網絡上的私有IP
有四個網域不能使用:0.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8。
0.0.0.0:代表所有在這台機器上的IP位址。
10.0.0.0:作為內部私有IP用。如要與網際網路上的其他電腦通訊,就必須透過網路位址轉換機制(Network Address Translation, NAT)把私有IP轉換成網址網路IP。所以,在不同的局域網上,私有IP能被重複使用而不必是唯一。
127.0.0.0:網路迴路回測(loopback testing),所有發送到這個IP的封包都會原封不動的發回發送主機上,通常是用來測試某一主機上的TCP/IP設置是否正確。
100.64.0.0/10:歷史性過渡問題。

而在B類和C類裡面都有保留供內部網路使用的私有IP。如在B類就是172.16.0.0/12,C類就是192.168.0.0/16,等等。

DNS 伺服器
由於每部電腦至少有一個IP,是用來讓在同一網路上的其他節點(主機)跟自己溝通。DNS其實只是把IP位址文字化。由於架站的時候需要用到主機的IP位址,所以在網址欄輸入IP位址就能連上網站。例如:http://192.***.161.79/。但是,在互聯網上會使用網域名稱(Domain name)來管理電腦的位址。
所以,整個流程是,在輸入了網址後,網址會被傳到DNS(domain name server)去解析放置該網站的主機的IP,這個過程稱為“網路名稱解析”。為何我們要知道網站放到那個主機上呢?因為我們要從那個主機上進行存取。

怎樣判斷主機是否在同一個子網路上
假設主機IP位址為210.73.140.5,那麼210二進制就是11010010,所以屬於C類網路,預設子網路遮罩為255.255.255.0。所以主機標識就是00000101。
假設另一台主機的IP位址為210.73.60.252,同屬C類網路,所以主機標識就是11111100,由於兩個主機的主機標識的頭三位都不同,說明這兩部主機都在不同的網路區域中,所以在交換訊息時必須通過路由器。(Q: 為什麼不同的網路需要路由器?他們有什麼不同?)。

例子:判斷3個主機是否在同一個子網路上。
三個主機的IP位址:192.168.0.1、192.168.0.254、192.168.0.4
分析:他們同屬C類網路,子網掩碼為255.255.255.0。將IP位址和子網掩碼進行二進制AND運算,均得到了192.168.0.0。由於結果一樣,他們同屬相同的子網。

兩種子網掩碼的表示方法
1. 255.255.255.0 (適用於C類網路)
2. 192.168.1.1/24,意即網路標識為24位元,即是佔三個字節(意同255.255.255.0),剩下1個字節的主機標識,最多能容納126台電腦(主機全1或是全0都是不可被主機佔用)。

計算子網路下能有多少台主機

若網路為192.168.128.0,這個網域就能夠容納主機IP由192.168.128.0到192.168.128.255。但是我們知道192.168.128.0和192.168.128.255並不能用來代表主機,所以,有效主機IP為192.168.128.1到192.168.128.254。
但是,萬一子網路掩碼不是255.255.255.0,而是255.255.128.0,那怎樣計算主機標識的範圍和可容納主機數呢?首先,255.255.128.0等於11111111.11111111.10000000.00000000,即是網路標識為頭17位元,後15位元為主機標識位元。所以,使用此子網路遮罩的網域能容納總共2^15-2=32766台主機。值得注意的是,從這裡我們不能知道網域是屬於那類的網,因為並沒有提供網路IP。

 =============延伸閱讀暫告一段落,回歸本文=====================

1.1.1. Packets, Connections and Datagrams(Continued)

Message boundaries

When applications write to network, it usually writes in packets of various sizes. Depending on whether the protocol preserves message boundaries or not, the packets received by the application at the other end would perceive the chunk sizes either of the original pattern or at an altered manner. In other words, message boundaries determine how many bits are there in a packet to be read. In case the protocol failed to preserve message boundaries, the application that needs it has to provide its own. Most datagram protocol provides MB, but not for VC protocol. The boundary information is perceived by the receiver side.

TCP/IP卷一:第一章

1.1.2.The end-to-end argument and fate sharing