# Mininet3 Analysis Result [TOC] ## Analysis result (畫圖) ``` apt install gnuplot ``` ``` iperf -c 10.0.0.2 -t 10 ``` ``` iperf -s -i 1 | tee tcp.txt ``` ![](https://i.imgur.com/OpSVvTL.png) tee :將標準輸入複製到每個文件,也複製到標準輸出 --- 清理數據 ``` cat tcp.txt | grep Mbits | head -n 10 | tr "-" " " | awk '{print $4,$8}' ``` tr (replace) awk (show the column) ![](https://i.imgur.com/NZKDBIM.png) ### Gnuplot ``` gnuplot ``` ![](https://i.imgur.com/V6ad3Pp.png) #### plot (畫圖) gnuplot> plot "tcpClear.txt" title "tcp" with linespoints ![](https://i.imgur.com/AfhmOm1.png) ``` gnuplot> set yrange[0:5] gnuplot> set ytics 0,1,10 gnuplot> replot ``` Range 0~5 每小格 切10塊 ![](https://i.imgur.com/tMCFf7W.png) ### x y 軸 說明 跟 Title ``` gnuplot> set xlabel "Time(sec)" gnuplot> set ylabel "Throughput(Mbps)" gnuplot> set title "TCP" gnuplot> replot ``` ![](https://i.imgur.com/i1EDSc7.png) #### Save image ``` gnuplot> set terminal png gnuplot> set output "tcp.png" exit ``` ![](https://i.imgur.com/bhddYaH.png) python script Topology 1 ![](https://i.imgur.com/zUqJZhR.png) ```python #!/usr/bin/env python from mininet.cli import CLI from mininet.net import Mininet from mininet.link import Link,TCLink if '__main__' == __name__: net = Mininet(link=TCLink) h1 = net.addHost('h1') h2 = net.addHost('h2') Link(h1, h2) net.build() CLI(net) net.stop() ``` TCLink 可以設定 Bandwidth or Delay or loss Rate(比較強) Topology2 ![](https://i.imgur.com/3LCR88d.png) ``` #!/usr/bin/env python from mininet.cli import CLI from mininet.net import Mininet from mininet.link import Link,TCLink if '__main__' == __name__: net = Mininet(link=TCLink) h1 = net.addHost('h1') h2 = net.addHost('h2') r = net.addHost('r') Link(h1, r) Link(h2, r) net.build() CLI(net) net.stop() ``` H1 ``` root@ubuntu:/home/user/scriptTopology# ifconfig h1-eth0 0 root@ubuntu:/home/user/scriptTopology# ifconfig h1-eth0 192.168.1.1/24 root@ubuntu:/home/user/scriptTopology# ip route add default via 192.168.1.254 root@ubuntu:/home/user/scriptTopology# ip route show default via 192.168.1.254 dev h1-eth0 root@ubuntu:/home/user/scriptTopology# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 h1-eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 h1-eth0 ``` H2 ``` root@ubuntu:/home/user/scriptTopology# ifconfig h2-eth0 0 root@ubuntu:/home/user/scriptTopology# ifconfig h2-eth0 192.168.2.1/24 root@ubuntu:/home/user/scriptTopology# ip route add default via 192.168.2.254 root@ubuntu:/home/user/scriptTopology# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.2.254 0.0.0.0 UG 0 0 0 h2-eth0 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 h2-eth0 ``` Router ``` root@ubuntu:/home/user/scriptNet# ifconfig r-eth0 192.168.1.254/24 root@ubuntu:/home/user/scriptNet# ifconfig r-eth1 192.168.2.254/24 root@ubuntu:/home/user/scriptNet# ifconfig ``` ``` r-eth0 Link encap:Ethernet HWaddr 96:1b:78:5b:20:a4 inet addr:192.168.1.254 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::941b:78ff:fe5b:20a4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:10 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:648 (648.0 B) TX bytes:828 (828.0 B) r-eth1 Link encap:Ethernet HWaddr f2:e2:4e:0f:9b:2c inet addr:192.168.1.254 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::f0e2:4eff:fe0f:9b2c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:648 (648.0 B) TX bytes:648 (648.0 B) ``` h1 ping h2 ![](https://i.imgur.com/aOL0Zvt.png) Routing status 可以去check ``` root@ubuntu:/home/user/scriptNet# cat /proc/sys/net/ipv4/ip_forward 1 ``` 1 -> enable 如果為1 表示有router 有forward 的功能 0 -> disable ``` root@ubuntu:/home/user/scriptNet#echo 1 > /proc/sys/net/ipv4/ip_forward root@ubuntu:/home/user/scriptNet#echo 0 > /proc/sys/net/ipv4/ip_forward ``` ### CLI 寫進 python Script ``` #!/usr/bin/env python from mininet.cli import CLI from mininet.net import Mininet from mininet.link import Link,TCLink if '__main__' == __name__: net = Mininet(link=TCLink) h1 = net.addHost('h1') h2 = net.addHost('h2') r = net.addHost('r') Link(h1, r) Link(h2, r) net.build() h1.cmd("ifconfig h1-eth0 0") h1.cmd("ip addr add 192.168.1.1/24 brd + dev h1-eth0") h1.cmd("ip route add default via 192.168.1.254") h2.cmd("ifconfig h2-eth0 0") h2.cmd("ip addr add 192.168.2.1/24 brd + dev h2-eth0") h2.cmd("ip route add default via 192.168.2.254") r.cmd("ifconfig r-eth0 0") r.cmd("ifconfig r-eth1 0") r.cmd("ip addr add 192.168.1.254/24 brd + dev r-eth0") r.cmd("ip addr add 192.168.2.254/24 brd + dev r-eth1") r.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward") CLI(net) net.stop() ``` CLI(net) -> Display mininet prompt