---
# System prepended metadata

title: Multipath TCP Document
tags: [Handover, MPTCP, TCP]

---

###### tags: `TCP` `MPTCP` `Handover`
# Multipath TCP Document

## 實驗前
- [x] 準備若干手機，確認電量足夠 
- [ ] 確認筆電電量足夠
- [ ] 確認可以正常SSH到遠端電腦
- [ ] 手機預先安裝python, git環境
- [ ] 開啟手機可在背景執行某些APP功能
- [ ] 手機關閉螢幕自動轉向
- [ ] 手機開啟USB預設功能網路熱點
- [ ] 電腦terminal輸入"df"指令確認儲存空間足夠
- [ ] 電腦terminal輸入"ifconfig"指令確認network interface正常
- [ ] Port forwarding 有設定好，連線至router頁面設定

## redundant packet實驗

**將packet複製到多個subflows同時傳的實驗**

- [ ] 關閉tcpdump sudo權限，執行mptcp/init.sh

封包組成
* 1-8 bytes: epoch time (精確度1ms)
* 9-12 bytes: sequence number
* 13 byte: OK
* 14~ bytes redundant

### Server side

#### 實驗開始

假定同時收/傳給2個device

    Run:
        $ python3 server.py -p Port -d NumOfDevice
    ex:
        $ python3 server.py -p 3270 -d 2

* **UL Ports**: Port, Port+2, ...
* **DL Ports**: Port+1, Port+3, ...

可調整的參數
* 封包長度 單位 bytes
* bandwidth 單位 kbps
* 實驗時間長度 單位 秒
* tcpdump抓到的data儲存位置
* ss指令抓到的data儲存位置(cwnd, rto...)
* congention control(cubic bbr reno ...)
![](https://i.imgur.com/gkLZQdY.png)

* 啟用congestion algorithm https://securenetweb.wordpress.com/2017/01/24/add-tcp-congestion-control-variant-to-linux-ubuntu-comparing/

#### 實驗終止
server or client 其中一端中斷socket (ctrl + C)

--- 

### Client side

- [ ] 先確認ifconfig指令可以抓到的都是會用到的interface(含running者)
- [ ] 關閉tcpdump sudo權限，執行mptcp/init.sh
- [ ] persistent change the network interface

```
$ mv mptcpsocket/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules
```



    Run:
        $ python3 client.py -p Port -H server_ip_address
    ex:
        $ python3 client.py -p 3270 -d 140.112.20.183


* **UL Ports**: Port, Port+2, ...
* **DL Ports**: Port+1, Port+3, ...

可調整參數同Server side 

![](https://i.imgur.com/Ez0ERMj.png)



#### 實驗開始

![](https://i.imgur.com/7yGWj0y.png)
* 確認print出的network interface正常，否則手動修正
```
EX: network_interface = ['usb0', 'usb1']
```
* network interface會是依據字典排序，若是某個port掛掉了可以依照排序規則找出是哪一個network interface掛點

#### 實驗終止
server or client 其中一端中斷socket (ctrl + C)

--- 

#### 實驗分析

##### Post Processing

**STEP1** 將檔案傳送整理好至Server
- [ ] handoff_study\socket_program\file_transfer_server.py
- [ ] handoff_study\socket_program\file_transfer_client.py
```
$ python3 file_transfer_server.py
```

```
$ python3 file_transfer_client.py
```

預設傳送至電二249 server的home/wmnlab/D (2TB大行動硬碟)
server setting
port 3230
![](https://i.imgur.com/gFpX8ZC.png)

client setting

- [ ] device.txt

* 先在handoff_study\socket_program放置device.txt文件，裏頭將client side取名字
* taget_dir append想要備分之目標資料夾
![](https://i.imgur.com/CZ121qo.png)
![](https://i.imgur.com/oT61jKW.png)

**注意**: 已經傳過的檔案將不會再重新傳送(顯示PASS)，若是原本的檔案為殘缺版本，將會跳過不會傳送

**STEP2** 將pcap檔案轉換成csv檔案以利分析

- [ ] 安裝tshark
- [ ] handoff_study\post_processing\tcp_pcap_to_csv.py

* METHOD1 指定資料夾(將資料夾內全部pcap轉換)
python3 tcp_pcap_to_csv.py dir

**注意**: 有設計一個sleep time作為轉換檔案的緩衝時間，一次處理過多檔案將導致電腦當機

![](https://i.imgur.com/3aubpUC.png)


* METHOD2 指定pcap
python3 tcp_pcap_to_csv.py filename.pcap


對於有興趣的field可開啟wireshark，右鍵field，選擇copy Field Name
![](https://i.imgur.com/4IEmd6X.png)
接著插入至pcap_to_csv function，-e field name
![](https://i.imgur.com/Y5bdutR.png)
注意default separator為 **@**
![](https://i.imgur.com/OCjLsmz.png)


**STEP3** 持續整理檔案(mv)
- [ ] handoff_study\utils\auto_mv_redundant_pcapcsv.py
- [ ] pcap to csv已經跑完

將轉換好的csv放置於同一份資料夾

```
$ python3 auto_mv_redundant_pcapcsv.py tagetdir
```

* 成功後，同一梯次做的實驗將會被放置於同一份資料夾

 --- 

**STEP4** 後續分析

- [ ] handoff_study\statistic\redundant_analysis.ipynb

![](https://i.imgur.com/E7gY2M8.png)

**注意** timestamp搜尋要常常更換目前是182，即將183了

![](https://i.imgur.com/wfp51cf.png)





兩個參數設定
* targetdir, 設定分析之日期
* num_devices:N, 欲過濾出的實驗當時幾個devices



result
前N個, N個network的retransmission rate
接下來的\\(C^N_2\\)個 RTT
再接下來的\\(C^N_2\\)個 Excessive RTT Rate
都是按照port字典排序

可將結果貼至google sheet

![](https://i.imgur.com/4qiAYFJ.png)

**STEP4** heatmap 分析

- [ ] handoff_study\statistic\heatmap.ipynb

1. 首先將資料整理成矩陣

![](https://i.imgur.com/rHiwhBY.png)

2. assign給data

![](https://i.imgur.com/e6MEmwo.png)




## MPTCP 實驗
實驗準備

- [ ] 安裝mptcp kernel https://github.com/multipath-tcp/mptcp/releases
- [ ] enable grub https://askubuntu.com/questions/16042/how-to-get-to-the-grub-menu-at-boot-time
- [ ] 重新開機選擇mptcp kernel
- [ ] mptcpsocket/scripts.sh

1. 確認確實有啟用kernel

```
$ dmesg | grep MPTCP
$ sudo sysctl -a | grep mptcp
```

**net.mptcp.mptcp_enabled=1 必須是1**

2. select scheduler
```
sudo sysctl -w net.mptcp.mptcp_scheduler=redundant
sudo sysctl -w net.mptcp.mptcp_scheduler=default
sudo sysctl -w net.mptcp.mptcp_scheduler=blest
```

3. check

```
$ sudo sysctl -a | grep mptcp
```

4. CCA

```
$ echo reno > /proc/sys/net/ipv4/tcp_congestion_control
$ echo cubic > /proc/sys/net/ipv4/tcp_congestion_control
$ echo bbr > /proc/sys/net/ipv4/tcp_congestion_control
$ cat /proc/sys/net/ipv4/tcp_congestion_control
```

實驗可透過iperf3 or UD_socket進行，iperf3用C寫的速度較快，UD_socket為可自製封包的code。

#### UD_socket

- [ ] UD_socket/server.py
- [ ] UD_socket/client.py


* Server Side

```
python3 server.py
```
可調整參數同redundant
![](https://i.imgur.com/De8M2T1.png)


* Client Side
可調整參數同redundant


```
python3 client.py
```
![](https://i.imgur.com/QxNKChG.png)

#### iperf3 實驗

- [ ] iperf3/iperf_server.py
- [ ] iperf3/iperf_client.py

```
    $ python3 iperf_server.py
    $ python3 iperf_client.py
```
* 自行調參
![](https://i.imgur.com/Hw4Lxpl.png)


#### 後處理
同 redundant STEP1, STEP2

## video streaming實驗

- [ ] nginx server
- [ ] OBS
- [ ] VLC media player


### SETUP

**STEP1** enable nginx server
https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/


**STEP2** fix error
https://blog.cpming.top/p/nginx-the-http-gzip-module-requires-the


**STEP3** 確認port forwarding 有將1935轉至server


Server side
```
Streaming Service: Custom
Server: rtmp://<your server ip>/live
Play Path/Stream Key: test
```
Client side
安裝VLC media player
串流網址
```
rtmp://<other streaming service rtmp url>/<stream key>
```
### 實驗開始


#### server side

- [ ] mptcpsocket/init.sh
- [ ] mptcpsocket/video

```
$ sudo ./init.sh
```

or 

```
$ python3 server_capture.py
```




![](https://i.imgur.com/gXVO8DO.png)

#### client side
開啟VLC，將OBS設定的server以及streaming key以'/'分隔輸入
![](https://i.imgur.com/mvA3wCx.png)


```
$ python3 client_capture.py
```




## 其他可能有用的code

* handoff/auto_mvfiles.py 檔案自動分類，cellinfo, pcap, mi2logcsv
* handoff/post_processing/offline-analysis.py 自動將mi2log轉成txt
* handoff/post_processing/xml_mi.py/自動將mi2logtxt轉成csv

## Google Map Mapping

- [ ] cellinfo csv
- [ ] mi2log csv


STEP1
執行特定cell取得gps csv
![](https://i.imgur.com/Xq2fs3P.png)


STEP2
丟到google mymap
![](https://i.imgur.com/aESWRvK.png)


## tcp parameters

retransmission timeout (RTO)
何時重傳
RFC 6298
https://www.rfc-editor.org/rfc/rfc6298.html
使用ss指令觀看
RTO約為200多ms
![](https://i.imgur.com/PWozWwG.png)

kernel (transportation) layer
tcp_keep_alive時間 7200
or 每75秒重傳一次確認alive
![](https://i.imgur.com/GvB0ZwF.png)


application layer

timeout (沒有recv packetc會raise error)
default是沒有timeout
![](https://i.imgur.com/Y9kaJFP.png)


retransmission

![](https://i.imgur.com/gjrucfi.png)



https://perthcharles.github.io/2015/09/07/wiki-tcp-retries/

**tcp_retries1** - INTEGER
    This value influences the time, after which TCP decides, that
    something is wrong due to unacknowledged RTO retransmissions,
    and reports this suspicion to the network layer.
    See tcp_retries2 for more details.

RFC 1122 recommends at least 3 retransmissions, which is the
default.
    
**tcp_retries2** - INTEGER
    This value influences the timeout of an alive TCP connection,
    when RTO retransmissions remain unacknowledged.
    Given a value of N, a hypothetical TCP connection following
    exponential backoff with an initial RTO of TCP_RTO_MIN would
    retransmit N times before killing the connection at the (N+1)th RTO.

The default value of 15 yields a hypothetical timeout of 924.6
    seconds and is a lower bound for the effective timeout.
    TCP will effectively time out at the first RTO which exceeds the
    hypothetical timeout.

RFC 1122 recommends at least 100 seconds for the timeout,
    which corresponds to a value of at least 8.
