Lab1

實驗目的:創建一個基本的SDN網路環境和使用iperf工具測試網路頻寬

實驗環境:1台Controller,4台host,1台switch

Topology:

再按右鍵Craete New -> Blank File 新增一個新的python檔 -> 檔案命名為mymininet1.py

Step 1:開啟文件夾 -> 點選pox -> pox -> forwarding 進入到controller內部放置執行檔的位置

Step 2:新增完之後開啟mymininet1.py,再把頁面最下方的程式碼下載下來,貼上內部的程式碼然後儲存

Step 3:開啟終端機輸入chmod指令更改執行檔案屬性

Step 4:執行mymininet1.py

執行結果

程式碼:

#!/usr/bin/python

from mininet.topo import Topo

from mininet.net import Mininet

from mininet.node import CPULimitedHost

from mininet.link import TCLink

from mininet.util import dumpNodeConnections

from mininet.log import setLogLevel

class SingleSwitchTopo(Topo):定義switch內的拓墣

定義單一switch連接到2個host

def __init__(self, n=2, **opts):

Topo.__init__(self, **opts)

switch = self.addSwitch('s1') switch名稱定義為s1

for h in range(n):

每個host使用50%的CPU效率

host = self.addHost('h%s' % (h + 1), cpu=.5/n)

#10 Mbps, 5ms delay, 0% Loss, 1000 packet queue 設定Switch和host連結的參數

self.addLink(host, switch, bw=10, delay='5ms', loss=0, max_queue_size=1000, use_htb=True)

def perfTest():(定義網路測試內容)

topo = SingleSwitchTopo(n=4)

net = Mininet(topo=topo,host=CPULimitedHost, link=TCLink)

net.start()啟動網路拓墣

print "Dumping host connections"顯示出host結點連接狀況

dumpNodeConnections(net.hosts)

print "Testing network connectivity"

net.pingAll()

所有主機與其他所有主機進行ping測試

print "Testing bandwidth between h1 and h4"測試h1到h4的頻寬

h1, h4 = net.get('h1', 'h4')

net.iperf((h1, h4))使用iperf工具測試

net.stop()

if __name__=='__main__':

setLogLevel('info')

perfTest()