【SDN專欄】Mininet下編寫python,實現自定義的網路topo結構
阿新 • • 發佈:2019-02-08
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)