# 20210308 Iperf

## 課堂資料

{% file src="/files/-MVFVeChfwVPPcc2SiF7" %}

{% embed url="<https://websiteforstudents.com/how-to-install-python-3-8-on-ubuntu-18-04-16-04/>" %}

{% file src="/files/-MVFheUD96rlw7rF23ro" %}

{% embed url="<https://m1016c.pixnet.net/blog/post/145780230>" %}

{% embed url="<https://linuxhint.com/iperf_command_usage/>" %}

{% embed url="<https://github.com/p4lang/behavioral-model>" %}

## 課堂練習

### 安裝 pip

> #### 安裝 ppa

```
add-apt-repository ppa:deadsnakes/ppa
```

![](/files/-MVmV1adf37tSZgrmnCo)

> #### Update packeges

```
apt-get update
```

```
apt-get upgrade
```

![](/files/-MVmPIR39Xq_tRe__on4)

> #### 升級 python 2.x 到 python 3.x

```
apt-get install python3.6
```

```
apt-get install python3.6-gdbm
```

![](/files/-MVmWiK-YVX1xqaFwhBO)

![](/files/-MVmvdzltqqI7NZu1ijX)

```
apt-get install python3.7
```

```
apt-get install python3.7-gdbm
```

![](/files/-MVmX7g4ZJKHRjkyxoqR)

![](/files/-MVmw2_kEsJUUICDLSpx)

```
apt install ansible
```

![](/files/-MVmwaQYsHy87uZARWGP)

```
python -V
```

```
python3 -V
```

> #### 安裝 pip

```
apt-get install python3-pip
```

```
pip3 install --upgrade pip
```

![](/files/-MVmbrVoOqnWkCWd_2PA)

> #### 設定優先順序

```
update-alternatives --install / usr / bin / python3 python3 /usr/bin/python3.6 1
```

```
update-alternatives --install / usr / bin / python3 python3 /usr/bin/python3.7 2
```

![](/files/-MVmY340zvhcT40g4UST)

> #### 到 pip document 官方網站建議的載點下載 pip 安裝檔

```
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
```

> #### 啟動剛剛下載好的 get-pip.py 檔案

```
python3 get-pip.py
```

![](/files/-MVmcSC6UZaVv_HNKYER)

> #### 查看 pip 目前版本

```
python3 -m pip -V
```

![](/files/-MVmcfDpIo3SUnYmTsDc)

### 額外補充

<div align="left"><img src="/files/-MVmzeyoqCNMo5bXy-r0" alt=""></div>

{% tabs %}
{% tab title="R1" %}

> ### Part 01.

```
en
```

```
conf t
```

```
ho R1
```

```
do writ
```

```
int e0/2
```

```
ip add dhcp
```

```
no shut
```

![](/files/-MVmj2Xaklyz4Ps2YSih)

```
do sh ip int brief
```

![](/files/-MVmjIVJ01Tf_L7AX-Q1)

> ### Part 03.

```
exit
```

```
username cisco privile 15 password cisco
```

```
ip domain-name test.com
```

```
crypto key generate rsa
```

```
ip ssh ver 2
```

```
line vty 0 4
```

```
login local
```

```
transport input ssh
```

![](/files/-MVmlmPWkLCQ7YQw5AjW)
{% endtab %}

{% tab title="ubuntu" %}

> ### Part 02.

```
ping 192.168.8.140
```

![](/files/-MVmjnn2W5RUK0ZOZx8z)

> ### Part 04.

```
ssh cisco@192.168.8.140
```

![](/files/-MVmmLFzEkzEICprXFEL)

```
conf t
```

```
int e0/0
```

```
ip add 192.168.1.254 255.255.255.0
```

```
no shut
```

```
int e0/1
```

```
ip add 192.168.2.254 255.255.255.0
```

```
no shut
```

```
do sh ip int bri
```

```
exit
```

```
exit
```

```
exit
```

![](/files/-MVmzI-wn4wYPtL4zc6V)

```
python3 -m  pip install paramiko
```

```
python3 -m  pip install --upgrade pip
```

```
python3
```

```
import paramiko
```

![](/files/-MVmoZxne3h9hcKjmXmr)

```
exit
```

```
mkdir cisco
```

```
cd cisco
```

```
gedit hosts config_cisco.yml
```

{% hint style="info" %}

> #### hosts

```
[cisco]
192.168.8.140 ansible_connection=local
```

> #### config\_cisco.yml

```
- hosts: 192.168.8.140
  gather_facts: yes
  vars:
    - cisco_host_ip: 192.168.8.140
      ssh_username: cisco
      ssh_password: cisco
      enable_open: yes
      enable_password: cisco
  roles:
     - config_cisco
```

{% endhint %}

![](/files/-MVmrFjLNleroF578qXA)

```
mkdir config_cisco
```

```
cd config_cisco
```

```
mkdir tasks
```

```
cd tasks
```

```
gedit main.yml
```

{% hint style="info" %}

> #### main.yml

```
- name: cisco_description_ssh_certification
  set_fact:
    cisco_verification:
      host: "{{cisco_host_ip}}"
      username: "{{ssh_username}}"
      password: "{{ssh_password}}"
      authorize: "{{enable_open}}"
      auth_pass: "{{enable_password}}"

- name: config e0/0
  ios_config:
      provider: "{{cisco_verification}}"
      parents:  interface Ethernet 0/0     
      lines:
        - ip addr 192.168.1.254 255.255.255.0
        - no shut

- name: config e0/1
  ios_config:
      provider: "{{cisco_verification}}"
      parents:  interface Ethernet 0/1     
      lines:
        - ip addr 192.168.2.254 255.255.255.0
        - no shut

- name: show ip interface
  ios_command:
      provider: "{{cisco_verification}}"
      commands: show ip interface brief
  register: show_ip_log

- name: show_ip_log
  debug:
    var: show_ip_log.stdout_lines
  with_items: show_ip_log.results
```

{% endhint %}

![](/files/-MVmqzsdCo4O_jzLemLU)

```
cd ..
```

```
cd ..
```

```
apt install tree
```

```
tree
```

![](/files/-MVmt3H6EQcx9QIQlSNH)

```
ansible-playbook config_cisco.yml -i hosts
```

```
ansible-playbook plyabook.yml -i hosts
```

{% endtab %}
{% endtabs %}

```
cd ..
```

```
cd mininet
```

### Iperf

```
mn
```

```
net
```

```
xterm h1 h2
```

```
pingall
```

![](/files/-MVoy1w8cZ2mDtDUulH6)

{% tabs %}
{% tab title="h2 - 1" %}

```
iperf -s -i 1
```

![](/files/-MWNgHQcnZ4jaXBRQPXX)

```
iperf -s -i 1 -u
```

![](/files/-MWNiPXZI3l9ANqsqJEs)

```
iperf -s -i 1 -u -p 6666
```

* `-p`：port

![](/files/-MWNlNgg-KXGGC5CKbcX)
{% endtab %}

{% tab title="h1 - 1" %}

```
iperf -c 10.0.0.2 -t 20
```

* `-c`：Client
* `-t`：Time

![](/files/-MWNg8exQg9ZzjGelEsv)

```
iperf -c 10.0.0.2 -t 10 -u -b 100M
```

![](/files/-MWNiW61J9EnKU6AuGG2)

```
iperf -c 10.0.0.2 -t 10 -u -b 100M -p 6666
```

![](/files/-MWNlHSFrtKOf6rVcAP1)
{% endtab %}
{% endtabs %}

```
xterm h1 h2 s1
```

{% tabs %}
{% tab title="h2 - 2" %}

```
iperf -s -i 1 -u -p 5555
```

![](/files/-MWNl5uvbNiLOXrvVBmJ)
{% endtab %}

{% tab title="h1 - 2" %}

```
iperf -c 10.0.0.2 -t 10 -u -b 100M -p 5555
```

![](/files/-MWNlCAbdohK4w9as19Y)
{% endtab %}
{% endtabs %}

```
exit
```

```
xterm h1 h2
```

{% tabs %}
{% tab title="h2 - 3" %}

```
iperf -s -i 1 -u -p 5555 > udp5555
```

```
^C
```

```
cat udp5555
```

![](/files/-MWnGVmZwrklN4ZhI8Gq)

```
cat udp5555 | grep sec
```

![](/files/-MWnH6b69q6tOqBkFZjI)

```
cat udp5555 | grep sec | grep -y 0.0-15  
```

![](/files/-MWnHqB8IfbXrMz8nMVr)

```
cat udp5555 | grep sec | head -n 14 > result.txt
```

![](/files/-MXsLsB2yS4p0QqMsNPg)
{% endtab %}

{% tab title="h1 - 3" %}

```
iperf -c 10.0.0.2 -t 15 -u -b 100M -p 5555
```

![](/files/-MWnGcMuw8TopnZVh4dw)
{% endtab %}
{% endtabs %}

![Mininet 指令](/files/-Mcj4EA0Pqv4RFRut-ln)

```
cd mininet
```

```
mn
```

```
xterm h1 h2
```

```
xterm s1
```

![](/files/-MWtsu0U_0dpelU37jCb)

```
h1 ifconfig
```

![](/files/-MWtt8L_gt9LBXo8erRW)

```
h1 ping 10.0.0.2 -c 3
```

![](/files/-MWttfSlaOm1CUfZSfj4)

{% tabs %}
{% tab title="h2" %}

```
ping 10.0.0.2
```

```
python -m SimpleHTTPServer 80
```

![](/files/-MWtuNoKYrym8mNoN4pu)

![](/files/-MWtvHygCv4Lrh8U9zPy)
{% endtab %}

{% tab title="h1" %}

```
su - user
```

```
firefox
```

![](/files/-MWtue9gVGBlf5_SwFY1)

```
ping 10.0.0.1
```

![](/files/-MWtveFnQmmVzh6esiaE)
{% endtab %}

{% tab title="firefox" %}

```
10.0.0.2:80
```

![](/files/-MWtv8n5d5jY-DPHqwvZ)
{% endtab %}
{% endtabs %}

```
sh ls /tmp
```

```
pingall
```

![](/files/-MWtwgCtfoIQFtZrHQ5m)

### Gnuplot

```
apt install gnuplot
```

![](/files/-MWnAxWhY0A_8dPTC1ab)

```
exit
```

```
gnuplot
```

```
plot "result.txt"
```

```
set yrange [0:110]
```

```
set ytics 0,10,110
```

```
replot
```

```
set xrange [0:15]
```

```
set xtics 0,5,15
```

```
plot "result.txt" with linespoints
```

```
set xtics 0,1,15
```

```
replot
```

```
set xlabel "tine (sec)"
```

```
set ylabel "throughput (Mbis/sec)"
```

```
replot
```

```
set title "udp throughput"
```

```
replot
```

```
set terminal "gif"
```

```
type set to 'gif'
```

```
set output "result.gif"
```

```
replot
```

```
exit
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anida-huang.gitbook.io/notes-network-simulation-and-analysis/qi-zhong/20210301-mininet-jian-jie-yu-ji-ben-cao-zuo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
