blob: 5305b64e1379b4ecb56c20e42e8064bd0f37c246 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
輸出檔案與原始檔的關係,以及各檔案的功能:
1. liblbs.a
這是個與此次作業沒有直接相關的函式庫,部份程式碼取自上次作業以及之前寫
其他科目作業時留下來的程式。
xwrap.[ch] 提供一些標準函式的 wrapper。
l4logger.[ch] 透過環境變數決定輸出紀錄檔方式的功能。
2. libump.a
這是這次作業主要的程式。
ump-common.h 提供一些轉型用的 macro 和定義 getter / setter 的 macro。
ump-pkt.[ch] 定義封包外層的 header 格式,以及填入與檢查 checksum 的功能。
ump-app.[ch] 定義封包內層的 header 格式,用以存放無法放在外層的資料。
ump-gai.[ch] 一個 getaddrinfo(3) 的 wrapper,用於產生 host 和 port 參數。
ump-sched.[ch] 提供類似 connect、list、accept、read、write 的界面供 sender
和 receiver 使用。各種作業要求的功能,像是 multipath、congestion control、
reliable transmission 也都實作在這個檔案裡。多數作業要求的輸出訊息也是這
裡產生的。
3. ump-agent (statically linked 到 libump.a 和 liblbs.a)
這是這次作業的 agent,僅有一個原始檔 agent-main.c。
4. ump-trans (statically linked 到 libump.a 和 liblbs.a)
這是這次作業的 file transmitter,並用 command line arguments 數量來決定
身份是 sender 或 receiver。
trans-main.c 解析 command line arguments。
trans-loop.[ch] sender 與 receiver 讀寫檔案與傳送資料的地方。
5. 其他 build system 相關檔案
configure 由 configure.ac 產生,用於設定參數、檢查 C 編譯器的功能、開啟
C 編譯器的 C99 支援、根據作業系統類型定義不同的 feature test macros。
Makefile 由 configure 根據 Makefile.in 產生,而 Makefile.in 由 Makefile.am
產生。目的是節省花在編寫 Makefile 的時間。
實作的方法與功能:
1. sender 要向 receiver 建立連線時,會隨機選一個數字當作 sequence number,
並送出 SYN packet (ump_sched_connect)。若在 5 次的 time out 時間內有收到
receiver 的 ACK,則表示成功建立連線。之後 sender 會開始傳送 data packet
(ump_sched_send),並可能同時向多個 agent 傳送多個 packet。sender 會等到
這個 window 的所有 data packet 對應的 ACK 都收到以後,根據傳輸狀況更改
window size 和 threshold,再進入下一個 window。結束連線時會送出 FIN packet
(ump_sched_shutdown),並最多等待 5 次的 time out 時間。與建立連線時不同的
是,若 5 次 time out 時間內都沒有收到 ACK,仍視為成功結束連線。time out
的功能是用 SIGALRM 和 setitimer(2) 實作的。
2. sender 會記錄每個封包送出時使用的 agent,以藉此對 agent 傳送的可靠程度
評分。當封包成功收到時,對應的 agent 會被加分;當封包 time out 時,對應的
agent 會被扣分。sender 會選擇當時 (agent 分數 - 已要求 agent 送出的封包數)
數值最大的 agent 送出這個 window 的資料,若數值相同則以 command line 上排
在較前面位置的 agent 優先。發生 time out 而需要重傳時,sender 會重新評估
分數,選擇新的 agent。事實上不論 agent 是否有 drop packets,都會因為
receiver buffer 滿了而發生 time out,使得各 agent 的分數相當接近,而
sender 也藉此不斷變換使用的 agent,達成 multipath 的要求。當檔案夠大時,
可看出 sender 會將較多的封包送給 loss rate 較低的 agent。
3. receiver 首先會先 bind 到使用者指定的位址上 (ump_sched_listen),接著等候
sender 的 SYN packet (ump_sched_accept)。隨後開始接收 data packet,並在
收到 FIN packet 時 (ump_sched_receive) 回復最初狀態等待下一個連線
(ump_sched_accept)。receiver 會在收到每個 packet 後,告知 sender 目前已
經連續收到的 sequence number。receiver 用接收到的 packet 的來源位址當作
送回 ACK 時的目的地,因此 receiver 並不需要知道 sender 使用了哪些 agent。
4. agent 僅是重複 recvfrom 接收 packet,檢查 checksum 並隨機決定是否要幫忙轉
送封包。如果決定願意轉送封包,則 agent 會在內層 header 填入來源 IP address
與在外層 header 填入來源 port,並重新計算 checksum 後用 sendto 送出
packet。agent 並不知道封包是 sender 或 receiver 傳送的,也不知道有哪些
sender 和 receiver。
|