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到后台去;  
原文地址:https://www.cnblogs.com/FlyerBird/p/10458579.html