MPTCP 源碼分析(三) 子路徑選擇

來源:互聯網
上載者:User

標籤:

簡述:     支援MPTCP的鏈路中存在多條子路徑,因此在發送資料的時候需要選擇最優路徑來進行操作。MPTCP利用核心通知鏈對MPTCP中各子路徑進行增加路徑、刪除路徑、修改路徑優先順序的操作。MPTCP根據相應的策略進行直接選取。  直接選取的代碼實現     直接選取的關鍵在於從多個子路徑中選擇其中一個進行資料的發送。此過程通過下面的函數實現:
"net/mptcp/mptcp_sched.c" line 114 of 496114 static struct sock *get_available_subflow(struct sock *meta_sk,115                       struct sk_buff *skb,116                       bool zero_wnd_test)117 {118     struct mptcp_cb *mpcb = tcp_sk(meta_sk)->mpcb;   //MPTCP核心實現的三個組成部分之一:Multi-path control bock(mpcb) 119     struct sock *sk, *bestsk = NULL, *lowpriosk = NULL, *backupsk = NULL;120     u32 min_time_to_peer = 0xffffffff, lowprio_min_time_to_peer = 0xffffffff;121     int cnt_backups = 0;122123     /* if there is only one subflow, bypass the scheduling function */    124     if (mpcb->cnt_subflows == 1) {125         bestsk = (struct sock *)mpcb->connection_list;126         if (!mptcp_is_available(bestsk, skb, zero_wnd_test))127             bestsk = NULL;128         return bestsk;129     }130131     /* Answer data_fin on same subflow!!! */132     if (meta_sk->sk_shutdown & RCV_SHUTDOWN &&133         skb && mptcp_is_data_fin(skb)) {134         mptcp_for_each_sk(mpcb, sk) {135             if (tcp_sk(sk)->mptcp->path_index == mpcb->dfin_path_index &&136                 mptcp_is_available(sk, skb, zero_wnd_test))137                 return sk;138         }139     }
View Code第124行的代碼是處理只有一個子路徑的特殊情況。第132行是對關閉操作進行了處理,在收包過程中對接收關閉包的子路徑進行記錄,然後回包的時候使用相同的子路徑。
"net/mptcp/mptcp_input.c" line 876 of 2293875     /* Record it, because we want to send our data_fin on the same path */876     if (tp->mptcp->map_data_fin) {877         mpcb->dfin_path_index = tp->mptcp->path_index;878         mpcb->dfin_combined = !!(sk->sk_shutdown & RCV_SHUTDOWN);879     }
第876行是對子路徑關閉的處理,關於data_fin可以參考https://tools.ietf.org/html/rfc6824#section-3.3.3。 下面的代碼遍曆mpcb下管理的sk,選擇最合適的sk。
"net/mptcp/mptcp_sched.c" line 142 of 496141     /* First, find the best subflow */142     mptcp_for_each_sk(mpcb, sk) {143         struct tcp_sock *tp = tcp_sk(sk);144145         if (tp->mptcp->rcv_low_prio || tp->mptcp->low_prio)146             cnt_backups++;147148         if ((tp->mptcp->rcv_low_prio || tp->mptcp->low_prio) &&149             tp->srtt < lowprio_min_time_to_peer) {150             if (!mptcp_is_available(sk, skb, zero_wnd_test))151                 continue;152153             if (mptcp_dont_reinject_skb(tp, skb)) {154                 backupsk = sk;155                 continue;156             }157158             lowprio_min_time_to_peer = tp->srtt;159             lowpriosk = sk;160         } else if (!(tp->mptcp->rcv_low_prio || tp->mptcp->low_prio) &&161                tp->srtt < min_time_to_peer) {162             if (!mptcp_is_available(sk, skb, zero_wnd_test))163                 continue;164165             if (mptcp_dont_reinject_skb(tp, skb)) {166                 backupsk = sk;167                 continue;168             }169170             min_time_to_peer = tp->srtt;171             bestsk = sk;172         }173     }
View Code從上面的代碼可以看出,選擇sk的依據有4條:1. “tp->mptcp->rcv_low_prio ” which stands for priority level in the remote machine.2.  "tp->mptcp->low_prio" which stands for priority level in the local machine.3.   whether the skb has already been enqueued into this subsocket4.   "tp->srtt" stands for smoothed round trip time. 
"net/mptcp/mptcp_sched.c" line 175 of 496175     if (mpcb->cnt_established == cnt_backups && lowpriosk) {176         sk = lowpriosk;  177     } else if (bestsk) {178         sk = bestsk;179     } else if (backupsk) {180         /* It has been sent on all subflows once - let‘s give it a181          * chance again by restarting its pathmask.182          */183         if (skb)184             TCP_SKB_CB(skb)->path_mask = 0;185         sk = backupsk;186     }187188     return sk;189 }
View Code第176行的情況說明所有的子路徑都處於backup狀態。而第178行則是存在bestsk。 總結:1.控制直接選取的因素有下面四個:此路徑在對端機器的優先順序此路徑在本地的優先順序此次發送的skb是否已經使用此路徑發送過,不能在同一路徑重複發送。tp->srtt 2.調整 low_prio 和 rcv_low_prio 可以通過下面命令: ip link set dev eth0 multipath backup當通訊雙方的一端被設定為backup後,可以通過MP_PRIO通知對端。具體內容可以參考:https://tools.ietf.org/html/rfc6824#section-3.3.8 3.srtt的調整通過函數 tcp_ack_update_rtt 實現。

MPTCP 源碼分析(三) 子路徑選擇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.