mininet+floodlight使用(一)


一 .安裝Floodlight

1.下載源和相關工具

#tools
sudo apt-get install build-essential ant python-dev
git clone git://github.com/floodlight/floodlight.git

2.安裝(注意,需要java1.8,否則報錯)

cd floodlight
ant
sudo mkdir /var/lib/floodlight
sudo chmod 777 /var/lib/floodlight

輸出如下

3.嘗試游覽器訪問管理界面

啟動floodlight

java -jar target/floodlight.jar 

游覽器訪問

http://localhost:8080/ui/index.html 

如果報錯

此時shell可能都是

Sending LLDP packets out of all the enabled ports

4.修復查看不了floodlight

git pull origin master
git submodule init
git submodule update
ant

編譯完成后重啟floodlight

java -jar target/floodlight.jar 

再游覽器訪問

如果路徑錯誤(如下圖,就把target下floodlight.jar復制到flootlight根目錄下再嘗試)

二.Mininet自定義拓撲圖(需要先把剛才的floodlight關閉)

fattree.py(ip指的是自己的主機ip

#!/usr/bin/python
#創建網絡拓撲
"""Custom topology example
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""

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, bw=10, delay='5ms', loss=10, max_queue_size=1000, use_htb=True)
			            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() ) }

運行floodlight出現port占用需要換一個,類似下面

Exception in thread "debugserver-main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "__pyclasspath__/debugserver.py", line 69, in run_server
  File "/home/lzh/Downloads/floodlight/floodlight.jar/Lib/SocketServer.py", line 331, in __init__
  File "/home/lzh/Downloads/floodlight/floodlight.jar/Lib/SocketServer.py", line 350, in server_activate
  File "<string>", line 1, in listen
  File "/home/lzh/Downloads/floodlight/floodlight.jar/Lib/socket.py", line 934, in listen
socket.error: (98, 'Address already in use')
#運行fattree.py
sudo mn --custom /home/lzh/Downloads/mininet/fattree.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6653 --switch ovsk,protocols=OpenFlow10

--mac指定虛擬主機的mac地址順序編號,若不帶此參數則隨機編號
--controller指定of交換機的控制器
--switch指定虛擬交換機的類型,ovsk表示虛擬交換機為ovs Kernel mode
--custom指定自定義拓撲文件
--topo指定加載拓撲的名字

打開floodlight管理界面,成功

查看拓撲圖

三.Sample

改寫昨天寫的一個例子(https://www.cnblogs.com/FlyerBird/p/10453772.html#x02-sample),把參數寫到里面,就不用手寫了,ip指的是自己的主機ip

#!/usr/bin/python

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import irange,dumpNodeConnections
from mininet.log import setLogLevel
from mininet.node import RemoteController
from mininet.cli import CLI
class LinearTopo(Topo):
    ""
    """Linear topology of k switches, with n hosts per switch."""
    ""
    def __init__(self, k=2, n=5,**opts):

        """k:number of switches (and hosts)"""
        """hconf: host configuration options"""
        """lconf: ling configuration options"""
        super(LinearTopo, self).__init__(**opts)
        self.n = n
        self.k = k
        """creates 2 switchs"""
        switch1 = self.addSwitch('s1')
        switch2 = self.addSwitch('s2')

        """creates h1~h5 and addLink switch1"""

        for i in irange(1,n):
            host = self.addHost('h%s' %i)
            self.addLink(host,switch1)

        """creates h6~h10 and addLink switch2"""

        for i in irange(n+1,n+5):
            host =self.addHost('h%s' %i)
            self.addLink(host,switch2)

        """addLink switch1 and switch2"""

        self.addLink(switch1,switch2)


if __name__== '__main__':
    # Tell mininet to print useful information
    setLogLevel('info')
    topo = LinearTopo(k=2,n=5)
    net = Mininet( topo=topo, controller=None)
    # add a proxy for a controlle which may be running on the control network
    net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6653,autoSetMac = True)
    #start the network
    net.start()
    CLI(net)
    net.stop()

運行floodlight查看

java -jar floodlight.jar

和想的一樣,OK

PS

記得net.stop()

Shell控制命令:

command& #讓進程在后台運行
jobs #查看后台運行的進程
fg %pid #讓后台運行(stopped的)的進程n到前台來,只是暫停了一個命令,可以直接使用fg來繼續執行
bg %pid #讓進程n到后台去;  


免責聲明!

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



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