Ubuntu安裝Mininet
一滑臊、安裝
apt-get update
apt-get upgrade
apt-get update --fix-missing
apt-get install git
#下載mininet
git clone https://github.com/mininet/mininet.git
cd mininet
#選擇版本
git tag
git checkout 2.2.0
#執(zhí)行安裝腳本
util/install.sh
#驗證安裝
sudo mn
#檢查安裝是否成功
sudo mn --test pingall
#如果出現(xiàn)報錯
apt-get update
apt-get upgrade
apt-get install net-tools
#查看幫助
mininet/util/install.sh -h
-a: (default) install (A)ll packages - good luck!
#測試控制器性能工具
-b: install controller (B)enchmark (oflops)
-c: (C)lean up after kernel install
-d: (D)elete some sensitive files from a VM image
-e: install Mininet d(E)veloper dependencies
-f: install Open(F)low
-h: print this (H)elp message
-i: install (I)ndigo Virtual Switch
-k: install new (K)ernel
-m: install Open vSwitch kernel (M)odule from source dir
#安裝mininet核心
-n: install Mini(N)et dependencies + core files
-p: install (P)OX OpenFlow Controller
-r: remove existing Open vSwitch packages
-s <dir>: place dependency (S)ource/build trees in <dir>
-t: complete o(T)her Mininet VM setup tasks
#安裝默認版本
-v: install Open (V)switch
#安裝指定版本
-V <version>: install a particular version of Open (V)switch on Ubuntu
-w: install OpenFlow (W)ireshark dissector
-y: install R(y)u Controller
-x: install NO(X) Classic OpenFlow controller
-0: (default) -0[fx] installs OpenFlow 1.0 versions
-3: -3[fx] installs OpenFlow 1.3 versions
#安裝比較久
二、命令
#網絡構建啟動參數(shù)
--topo
--custom
--switch
--controller
--max
#內部交互命令
dump
net
nodes
links
dpctl
iperf
#外部運行參數(shù)
-c #清除配置信息
-h #幫助
1. 網絡構建啟動參數(shù)
– –topo
-
單一拓撲(single)
整個網絡拓撲中交換機有且只有一個懊烤,他可以下掛一個或者多個主機
sudo mn --topo=single,3 #一個交換機下掛3個主機 (h1,s1)(h2,s1)(h3,s1)
-
線形拓撲(linear)
交換機連接呈現(xiàn)線形排列爷光,且每個交換機所連接主機數(shù)目只有一個(交換機和主機數(shù)目是相同的)
sudo mn --topo=linear,4
#4個交換機,4個主機
(h1,s1)(h2,s2)(h3,s3)(h4,s4)
-
樹形拓撲(tree)
交換機連接成樹形排列缓屠,且每個交換機所連接主機一般有多個
sudo mn --topo=tree,depth=2,fanout=2 #depth:交換機有兩層 #fanout:交換機有兩個 #主機不包含在depth中 (s1,s2)(s1,s3)(h1,s2)(h2,s2)(h3,s3)(h4,s3)
-
自定義拓撲(custom)
Python編寫文件file.py,執(zhí)行此腳本即可創(chuàng)建定義的拓撲护侮,– –custom與– –topo聯(lián)用
sudo mn --custom file.py --topo mytopo (s1,s2)(s1,s3)(h1,s2)(h2,s2)(h3,s3)
– – switch
定義mininet要使用的交換機(默認使用OVSK,即OpenVSwitch交換機)
– – controller
定義要使用的控制其敌完,如果沒有指定則使用mininet中默認的控制器
連接遠程控制器,可以指定存在于本機或者與值相連通設備上的控制器羊初,指定遠程控制器方法:
#remote:遠程滨溉,port可以使用默認的不寫
sudo mn --controller=remote,--ip=[controller IP],--port=[port]
– – mac
自動設置設備的MAC地址
讓MAC地址易讀,即設置交換機的MAC长赞、主機MAC及IP地址從小到大排序且設置簡單唯一晦攒,不僅讓機器容易獲取,也容易讓肉眼容易識別其ID得哆,使用方法:
sudo mn --topo=tree,depth=2,fanout-2,--mac
2.內部交互命令
使用mn默認創(chuàng)建網絡脯颜,使用一系列命令查看并驗證網絡系統(tǒng)的鏈路健壯性
root@qiu-base:/home/qiu/mininet# sudo mn
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 #兩個主機h1,h2
*** Adding switches:
s1 #添加了一個s1交換機
*** Adding links:
(h1, s1) (h2, s1) #添加了交換機和主機的鏈路
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
# net
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 #
c0
# nodes
mininet> nodes
available nodes are:
c0 h1 h2 s1
# links
mininet> links
h1-eth0<->s1-eth1 (OK OK)
h2-eth0<->s1-eth2 (OK OK)
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2
h2 -> h1
*** Results: 0% dropped (2/2 received) #丟包率
#常用內部交互命令
help #顯示命令幫助信息
dump #各個節(jié)點的信息
intfs #網絡接口信息
nodes #查看節(jié)點
net #顯示鏈接信息
links #鏈路健壯性信息
pingpair #只驗證前兩個host連通性
pingall #驗證所有主機間通信
mininet> py net.addHost('h3')
<Host h3: pid=13522>
mininet> py net.addLink(s1,net.get('h3'))
<mininet.link.Link object at 0x7f8cedd4dbd0>
#attach:添加
mininet> py s1.attach('s1-eth3')
mininet> py net.get('h3').cmd('ifconfig h3-eth0 10.3')
mininet> intfs
h1: h1-eth0
h2: h2-eth0
h3: h3-eth0
s1: lo,s1-eth1,s1-eth2,s1-eth3
c0:
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=13389>
<Host h2: h2-eth0:10.0.0.2 pid=13391>
<Host h3: h3-eth0:None pid=13522> #None,那么我們用ping驗證一下
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=13396>
<Controller c0: 127.0.0.1:6653 pid=13382>
#
mininet> h1 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=40.5 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.203 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=4 ttl=64 time=0.038 ms
64 bytes from 10.0.0.3: icmp_seq=5 ttl=64 time=0.040 ms
64 bytes from 10.0.0.3: icmp_seq=6 ttl=64 time=0.038 ms
64 bytes from 10.0.0.3: icmp_seq=7 ttl=64 time=0.038 ms
64 bytes from 10.0.0.3: icmp_seq=8 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=9 ttl=64 time=0.050 ms
64 bytes from 10.0.0.3: icmp_seq=10 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=11 ttl=64 time=0.069 ms
64 bytes from 10.0.0.3: icmp_seq=12 ttl=64 time=0.040 ms
64 bytes from 10.0.0.3: icmp_seq=13 ttl=64 time=0.107 ms
^C
--- 10.0.0.3 ping statistics ---
13 packets transmitted, 13 received, 0% packet loss, time 12263ms
rtt min/avg/max/mdev = 0.038/3.168/40.450/10.762 ms
mininet> h2 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=39.0 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.180 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=4 ttl=64 time=0.039 ms
^C
--- 10.0.0.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3049ms
rtt min/avg/max/mdev = 0.039/9.805/38.965/16.835 ms
#再次使用dump查看
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=13389>
<Host h2: h2-eth0:10.0.0.2 pid=13391>
<Host h3: h3-eth0:10.0.0.3 pid=13522>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=13396>
<Controller c0: 127.0.0.1:6653 pid=13382>
三贩据、可視化
MiniEdit(不會python也無所謂)
直接在界面上編輯任意拓撲伐脖,生成python自定義拓撲腳本,簡單方便
Mininet 2.2.0+(內置miniedit)
/mininet/examples 目錄下
root@qiu-base:/home/qiu/mininet# ls
bin custom doc LICENSE mininet.egg-info mnexec.1 setup.py
build debian examples Makefile mn.1 mnexec.c util
CONTRIBUTORS dist INSTALL mininet mnexec README.md
root@qiu-base:/home/qiu/mininet# cd examples/
root@qiu-base:/home/qiu/mininet/examples# ls
baresshd.py controlnet.py mobility.py README.md
bind.py cpu.py multilink.py scratchnet.py
clustercli.py emptynet.py multiping.py scratchnetuser.py
clusterdemo.py hwintf.py multipoll.py simpleperf.py
clusterperf.py __init__.py multitest.py sshd.py
cluster.py intfoptions.py natnet.py test
clusterSanity.py limit.py nat.py tree1024.py
consoles.py linearbandwidth.py numberedports.py treeping64.py
controllers2.py linuxrouter.py popenpoll.py vlanhost.py
controllers.py miniedit.py popen.py
#執(zhí)行miniedit腳本乐设,出現(xiàn)可視化界面,在執(zhí)行前绎巨,最好測試python環(huán)境變量是否正確
root@qiu-base:/home/qiu/mininet/examples# python3 miniedit.py
000000000000001
000000000000002
保存文件近尚,run,然后進入命令行场勤,輸出命令查看結果
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=14890>
<Host h2: h2-eth0:10.0.0.2 pid=14892>
<Host h3: h3-eth0:10.0.0.3 pid=14894>
<customOvs s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=14884>
<customOvs s2: lo:127.0.0.1,s2-eth1:None pid=14887>
<RemoteController c0: 127.0.0.1:6633 pid=14880>
mininet> links
s1-eth1<->h1-eth0 (OK OK)
s1-eth2<->h2-eth0 (OK OK)
s2-eth1<->h3-eth0 (OK OK)
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s2-eth1
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
s2 lo: s2-eth1:h3-eth0
c0
mininet> nodes
available nodes are:
c0 h1 h2 h3 s1 s2
mininet>
#再啟動一個控制器可以查看更多信息