在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安裝
使用VirtualBox安裝Mininet虛擬機:http://mininet.org/download/
使用Mininet創建一個網絡
以Coursera SDN Week3 programming assignment為例,創建一個及其簡單的數據中心網絡。
Data center networks typically have a tree-like topology. End-hosts connect to top-of-rack switches, which form the leaves (edges) of the tree; one or more core switches form the root; and one or more layers of aggregation switches form the middle of the tree. In a basic tree topology, each switch (except the core switch) has a single parent switch. Additional switches and links may be added to construct more complex tree topologies (e.g., fat tree) in an effort to improve fault tolerance or increase inter-rack bandwidth.
In this assignment, your task is to create a simple tree topology. You will assume each level i.e., core, aggregation, edge and host to be composed of a single layer of switches/hosts with a configurable fanout value (k) looks like:
代碼:
# CustomTopo.py ''' Coursera: - Software Defined Networking (SDN) course -- Module 3 Programming Assignment Professor: Nick Feamster Teaching Assistant: Muhammad Shahbaz ''' from mininet.topo import Topo from mininet.net import Mininet from mininet.node import CPULimitedHost from mininet.link import TCLink from mininet.util import irange,dumpNodeConnections from mininet.log import setLogLevel class CustomTopo(Topo): "Simple Data Center Topology" "linkopts - (1:c1, 2:aggregation, 3: edge) parameters" "fanout - number of child switch per parent switch" def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts): # Initialize topology and default options Topo.__init__(self, **opts) # Add your logic here ... self.fanout = fanout core = self.addSwitch('c1') for i in irange(1, fanout): aggregation = self.addSwitch('a%s' %i) self.addLink(core, aggregation, **linkopts1) for j in irange(1, fanout): edge = self.addSwitch('e%s' %(fanout*(i-1)+j)) self.addLink(aggregation, edge, **linkopts2) for k in irange(1, fanout): host = self.addHost('h%s' %((fanout*(fanout*(i-1)+j-1))+k)) self.addLink(edge, host, **linkopts3) topos = { 'custom': ( lambda: CustomTopo() ) } def simpleTest(): "Create and test a simple network" linkopts1 = dict(bw=10, delay='3ms', use_htb=True) linkopts2 = dict(bw=8, delay='4ms', loss=1, max_queue_size=900, ) linkopts3 = dict(bw=6, delay='5ms', loss=1, max_queue_size=800) topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=2) net = Mininet(topo, host=CPULimitedHost, link=TCLink) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" net.pingAll() net.stop() if __name__ == '__main__': # Tell mininet to print useful information setLogLevel('info') simpleTest()
在mininet虛擬機上執行下面操作即可創建自定義的網絡拓撲。函數simpleTest()創建網絡並進行了簡單的ping測試,從屏幕輸出可以看到創建的過程。
mininet@mininet-vm:~/mininet$ sudo python CustomTopo.py
更多資料
1. Mininet: http://mininet.org/
2. Mininet wiki: https://github.com/mininet/mininet/wiki