前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mininet+floodlight使用(一)

mininet+floodlight使用(一)

作者头像
Enterprise_
发布2019-03-21 15:54:39
1.1K0
发布2019-03-21 15:54:39
举报
文章被收录于专栏:小L的魔法馆小L的魔法馆

一 .安装Floodlight

1.下载源和相关工具

代码语言:javascript
复制
git clone git://github.com/floodlight/floodlight.git
#tools
sudo apt-get install build-essential ant python-dev

2.安装(注意,需要java1.8,否则报错)

代码语言:javascript
复制
cd floodlight
ant

输出如下

在这里插入图片描述
在这里插入图片描述

3.尝试游览器访问管理界面

启动floodlight

代码语言:javascript
复制
java -jar target/floodlight.jar 

游览器访问

代码语言:javascript
复制
http://localhost:8080/ui/index.html 

如果报错

在这里插入图片描述
在这里插入图片描述

此时shell可能都是

代码语言:javascript
复制
Sending LLDP packets out of all the enabled ports

4.修复查看不了floodlight

代码语言:javascript
复制
git pull origin master
git submodule init
git submodule update
ant
在这里插入图片描述
在这里插入图片描述

编译完成后重启floodlight

代码语言:javascript
复制
java -jar target/floodlight.jar 

再游览器访问

在这里插入图片描述
在这里插入图片描述

如果路径错误(如下图,就把target下floodlight.jar复制到flootlight根目录下再尝试)

在这里插入图片描述
在这里插入图片描述

二.Mininet自定义拓扑图(需要先把刚才的floodlight关闭)

fattree.pyip指的是自己的主机ip

代码语言:javascript
复制
#!/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占用需要换一个,类似下面

代码语言:javascript
复制
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')
代码语言:javascript
复制
#运行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://blog.csdn.net/Enterprise_/article/details/88046726#t3),把参数写到里面,就不用手写了,ip指的是自己的主机ip

代码语言:javascript
复制
#!/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查看

代码语言:javascript
复制
java -jar floodlight.jar
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

和想的一样,OK

PS

记得net.stop()

Shell控制命令:

代码语言:javascript
复制
command& #让进程在后台运行
jobs #查看后台运行的进程
fg %pid #让后台运行(stopped的)的进程n到前台来,只是暂停了一个命令,可以直接使用fg来继续执行
bg %pid #让进程n到后台去;  
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年03月01日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一 .安装Floodlight
    • 1.下载源和相关工具
      • 2.安装(注意,需要java1.8,否则报错)
        • 3.尝试游览器访问管理界面
          • 4.修复查看不了floodlight
          • 二.Mininet自定义拓扑图(需要先把刚才的floodlight关闭)
          • 三.Sample
            • PS
            相关产品与服务
            轻量应用服务器
            轻量应用服务器(TencentCloud Lighthouse)是新一代开箱即用、面向轻量应用场景的云服务器产品,助力中小企业和开发者便捷高效的在云端构建网站、Web应用、小程序/小游戏、游戏服、电商应用、云盘/图床和开发测试环境,相比普通云服务器更加简单易用且更贴近应用,以套餐形式整体售卖云资源并提供高带宽流量包,将热门开源软件打包实现一键构建应用,提供极简上云体验。
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档