【SDN专栏】Mininet下编写python,实现自定义的网络topo结构


Mininet虚拟机是基于Linux系统的,所以编写步骤与之无异

这里插一句,mininet中有自带的一些例子,在新建python时可以使用 cp 命令

1,打开MIninet,输入:即可看见例子

cd mininet/mininet/examples
ls -a

2,使用cp命令 复制py文件,实现新建py文件的功效:

cp sshd.py doudou.py

3,使用vim 对文件进行修改:

vim doudou.py

4,进入修改页面,如出现无法修改可按“s”键即可:

5,事例:

           
from mininet.net import Mininet
from mininet.node import UserSwitch, OVSKernelSwitch
form mininet.topo import Topo
from mininet.log import lg
from mininet.util import irange
from mininet.node import RemoteController
from functools import partial
from mininet.cli import CLI
import sys
flush = sys.stdout.flush
class MyTopo(Topo):
    def __init__(self, N, **params ):

        Topo.__init__(self,**params)

        hosts = [ self.addHost('h%s' % h )
                  for h in irange( 0, N+32 ) ]
        switches = [ self.addSwitch('s%s' % s )
                     for s in irange( 0 , N) ]

    def Test(length):
        hostCount=switchCount=length
        switches={'user': UserSwitch,'kernel': OVSKernelSwitch }
        topo = MyTopo(hostCount)
        net = Mininet( topo=topo, switch=Switch, controller=partial(RemoteController,ip='10.13.112.20',port=6633))
        net.start()
        CLI(net)
if __name__ == '__main__':
    lg.setLogLevel('info')
    Test(10)

        



你可能感兴趣的:(【SDN专栏】Mininet下编写python,实现自定义的网络topo结构)