迷你网络拓扑

时间:2018-10-25 20:08:34

标签: mininet

由于某种原因,我在运行mininet时遇到了麻烦,该mininet会生成转发规则。

无论如何,这是我的代码:

from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.topolib import TreeTopo
from mininet.log import setLogLevel
from mininet.cli import CLI

import time

class TwoLayerTreeTopo(object):
 def __init__(self, controller_ip, controller_port):
        self.controller_ip = controller_ip
        self.controller_port = controller_port
        self.tree = TreeTopo(depth=2, fanout=2)


        self.net = Mininet(topo=self.tree,
                           controller=None,
                           autoSetMacs=True,
                           listenPort=6634)
        self.net.addController('floodlight',
                               controller=RemoteController,
                               ip=self.controller_ip,
                               port=self.controller_port)
        self.sw = self.net.switches

    def kick_start(self):
        """ Fire up mininet with customized topology and settings
        """
        self.net.start()
        self.net.waitConnected()

    def build_table(self):
        """ Construct switches' flow table
        """
       sudo dpctl add-flow unix:/tmp/s2 "idle_timeout=0,hard_timeout=0,in_port=1,ip,nw_src=10.0.0.1,nw_dst=10.0.0.3,actions=output:3"
sudo dpctl add-flow unix:/tmp/s1 "idle_timeout=0,hard_timeout=0,in_port=1,ip,nw_src=10.0.0.1,nw_dst=10.0.0.3,actions=output:2"
sudo dpctl add-flow unix:/tmp/s3 "idle_timeout=0,hard_timeout=0,in_port=3,ip,nw_src=10.0.0.1,nw_dst=10.0.0.3,actions=output:1"

sudo dpctl add-flow unix:/tmp/s2 "idle_timeout=0,hard_timeout=0,in_port=1,arp,nw_src=10.0.0.1,nw_dst=10.0.0.3,actions=output:3"
sudo dpctl add-flow unix:/tmp/s1 "idle_timeout=0,hard_timeout=0,in_port=1,arp,nw_src=10.0.0.1,nw_dst=10.0.0.3,actions=output:2"
sudo dpctl add-flow unix:/tmp/s3 "idle_timeout=0,hard_timeout=0,in_port=3,arp,nw_src=10.0.0.1,nw_dst=10.0.0.3,actions=output:1"

sudo dpctl add-flow unix:/tmp/s3 "idle_timeout=0,hard_timeout=0,in_port=1,ip,nw_src=10.0.0.3,nw_dst=10.0.0.1,actions=output:3"
sudo dpctl add-flow unix:/tmp/s1 "idle_timeout=0,hard_timeout=0,in_port=2,ip,nw_src=10.0.0.3,nw_dst=10.0.0.1,actions=output:1"
sudo dpctl add-flow unix:/tmp/s2 "idle_timeout=0,hard_timeout=0,in_port=3,ip,nw_src=10.0.0.3,nw_dst=10.0.0.1,actions=output:1"

sudo dpctl add-flow unix:/tmp/s3 "idle_timeout=0,hard_timeout=0,in_port=1,arp,nw_src=10.0.0.3,nw_dst=10.0.0.1,actions=output:3"
sudo dpctl add-flow unix:/tmp/s1 "idle_timeout=0,hard_timeout=0,in_port=2,arp,nw_src=10.0.0.3,nw_dst=10.0.0.1,actions=output:1"
sudo dpctl add-flow unix:/tmp/s2 "idle_timeout=0,hard_timeout=0,in_port=3,arp,nw_src=10.0.0.3,nw_dst=10.0.0.1,actions=output:1"

 def show_table(self):
        """ Dump the switch flow table
        """
        print 'FLOW TABLES'
        for i in self.sw:
            print '*** switch %x ***' % int(i.dpid, 16)
            print i.dpctl('dump-flows')

    def ping_test(self):
        """ Ping all for connectivity test
        """
        self.net.pingAll()

    def __del__(self):
        self.net.stop()

def main():
    """ Main procedure
    Assume the Floodlight controller without forwarding module is listening at
    loopback interface and port 6633, which is the default port.
    """
    topo = TwoLayerTreeTopo('127.0.0.1', 6633)
    topo.kick_start()
    topo.build_table()
    topo.show_table()
    topo.ping_test()

if __name__ == '__main__':
    setLogLevel('info')
    main()

基本上,我建立了mininet,它将深度和扇出参数作为输入,并生成转发规则(采用dpctl格式),该规则允许Mininet中的所有主机之间的通信都具有该深度和扇出的拓扑。换句话说,安装转发规则后,pingall应该在Mininet中成功。

但是我不知道我的方向是否正确?

0 个答案:

没有答案