Mininet簡介


在Coursera SDN開放課程中,編程作業要用Mininet來完成。這里對Mininet做一個簡單的介紹。 

什么是Mininet

       Mininet是由一些虛擬的終端節點(end-hosts)、交換機、路由器連接而成的一個網絡仿真器,它采用輕量級的虛擬化技術使得系統可以和真實網絡相媲美。

       Mininet可以很方便地創建一個支持SDN的網絡:host就像真實的電腦一樣工作,可以使用ssh登錄,啟動應用程序,程序可以向以太網端口發送數據包,數據包會被交換機、路由器接收並處理。有了這個網絡,就可以靈活地為網絡添加新的功能並進行相關測試,然后輕松部署到真實的硬件環境中。

Mininet的特性

       可以簡單、迅速地創建一個支持用戶自定義的網絡拓撲,縮短開發測試周期

       可以運行真實的程序,在Linux上運行的程序基本上可以都可以在Mininet上運行,如Wireshark

       Mininet支持Openflow,在Mininet上運行的代碼可以輕松移植到支持OpenFlow的硬件設備上

       Mininet可以在自己的電腦,或服務器,或虛擬機,或者雲(例如Amazon EC2)上運行

       Mininet提供python API,簡單易用

       Mininet是開源項目,源代碼在這里:https://github.com/mininet

目前有三種方式使用mininet

  • Easiest "installation" - use our pre-built VM image!
  • Next-easiest option: use our Ubuntu package!
  • Native installation from source

測試

如果安裝沒有報錯,那就可以試一下mininet了

root@ubuntu:~# mn
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 
*** Adding switches:
s1 
*** Adding links:
(h1, s1) (h2, s1) 
*** Configuring hosts
h1 h2 
*** Starting controller
c0 
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> 

這是一個最簡單的拓撲,包括兩個host和一個switch

 

 然后可以互相ping一下

mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 
h2 -> h1 
*** Results: 0% dropped (2/2 received)

可以通過help命令了解其他功能

mininet> help

Documented commands (type help <topic>):
========================================
EOF    gterm  iperfudp  nodes        pingpair      py      switch
dpctl  help   link      noecho       pingpairfull  quit    time  
dump   intfs  links     pingall      ports         sh      x     
exit   iperf  net       pingallfull  px            source  xterm 

You may also send a command to a node using:
  <node> command {args}
For example:
  mininet> h1 ifconfig

The interpreter automatically substitutes IP addresses
for node names when a node is the first arg, so commands
like
  mininet> h2 ping h3
should work.

Some character-oriented interactive commands require
noecho:
  mininet> noecho h2 vi foo.py
However, starting up an xterm/gterm is generally better:
  mininet> xterm h2

這里可以看到有許多功能都集成在mininet中,可以試幾個

比如查看節點(nodes)

mininet> nodes
available nodes are: 
c0 h1 h2 s1

可以看到當前的拓撲里有四個節點,包括兩個host,一個switch,還有一個控制器c0

查看連接情況(net)

mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0

可以看到h1的port0和s1的port1連接,h2的port0和s2的port2連接

dump(這不知道怎么翻譯,好多語言里都有這個方法。。。)

mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=36658> 
<Host h2: h2-eth0:10.0.0.2 pid=36660> 
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=36665> 
<Controller c0: 127.0.0.1:6653 pid=36651> 

可以看到h1-eth0的ip是10.0.0.1 ,h2-eth0的ip是10.0.0.2 , s1的ip是127.0.0.1(本地)

還有一些集成在mininet里的工具,例如有名的網絡性能測試工具iperf

mininet> iperfudp
*** Iperf: testing UDP bandwidth between h1 and h2 
*** Results: ['10M', '2.94 Mbits/sec', '10.5 Mbits/sec'] #這里結果分別是上行帶寬和下行帶寬 
mininet> iperf
*** Iperf: testing TCP bandwidth between h1 and h2 
*** Results: ['10.1 Gbits/sec', '10.1 Gbits/sec']   #上行帶寬和下行帶寬

退出 (quit 或 exit)

mininet> exit
*** Stopping 1 controllers
c0 
*** Stopping 2 links
..
*** Stopping 1 switches
s1 
*** Stopping 2 hosts
h1 h2 
*** Done
completed in 507.131 seconds


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM