1. 程式人生 > >mininet實現自定義拓撲結構--基於兩個資料中心的網路拓撲--fattree.py

mininet實現自定義拓撲結構--基於兩個資料中心的網路拓撲--fattree.py

前言

基於兩個資料中心的網路拓撲是最常見的、也是最基本的一種網路拓撲結構,這裡先拿這個作為練習。
其網路拓撲結構圖如下:
這裡寫圖片描述

一、首先編寫生成拓撲結構的python程式碼fattree.py檔案

#建立網路拓撲,程式碼可以直接使用
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections

class MyTopo( Topo ):
    "Simple topology example."
    def __init__( self ):
        "Create custom topo."
        # Initialize topology
        Topo.__init__( self )
        L1 = 2
        L2 = L1 * 2 
        L3 = L2
        c = []
        a = []
        e = []  

        # add core ovs  
        for i in range( L1 ):
                sw = self.addSwitch( 'c{}'.format( i + 1 ) )
                c.append( sw )

        # add aggregation ovs
        for i in range( L2 ):
                sw = self.addSwitch( 'a{}'.format( L1 +i + 1 ) )
                a.append( sw )

        # add edge ovs
        for i in range( L3 ):
                sw = self.addSwitch( 'e{}'.format( L1 +L2 + i + 1 ) )
                e.append( sw )

        # add links between core and aggregation ovs
        for i in range( L1 ):
                sw1 = c[i]
                for sw2 in a[i/2::L1/2]:                    
                        self.addLink( sw2, sw1 )

        # add links between aggregation and edge ovs
        for i in range( 0, L2, 2 ):
                for sw1 in a[i:i+2]:
                    for sw2 in e[i:i+2]:
                        self.addLink( sw2, sw1 )

        #add hosts and its links with edge ovs
        count = 1
        for sw1 in e:
                for i in range(2):
                    host = self.addHost( 'h{}'.format( count ) )
                    self.addLink( sw1, host )
                    count += 1
    topos = { 'mytopo': ( lambda: MyTopo() ) }

在home目錄建立fattree.py檔案之後,寫入上述程式碼儲存。

二、啟動floodlight

java -jar target/floodlight.jar
* 注:當然前提是floodlight編譯並配置成功,可以參考我前面的部落格。
啟動好之後floodlight會自動輸出debug資訊,不要關閉,另開啟一個終端,輸入mininet命令。
注:具體mininet+floodlight的環境搭建,可以參考我前面的一篇部落格: mininet+floodlight 配置,連結:http://blog.csdn.net/xueer767/article/details/72910643

三、啟動mininet

sudo mn --custom ~/fattree3.py --topo mytopo --controller=remote,ip=10.0.0.2 --switch ovsk,protocols=OpenFlow13

具體引數含義可以執行 sudo mn -help 檢視,下面只簡單列舉這裡使用到的幾個引數。
–custom自定義拓撲的phyton檔案
–topo指定載入拓撲的名字
–controller=remote,ip=遠端控制器IP地址
–switch of交換機 protocols=OpenFlow協議版本(10或13)

啟動之後,會看到
這裡寫圖片描述

然後進入瀏覽器,開啟http://10.10.14.3:8080/ui/index.html


就可以看到相應的交換機和主機資訊。
如下:
首頁顯示(switch和host資訊):
首頁

首頁2
交換機資訊
switch
拓撲結構
topo