I have two SDN network topologies and I would like to change my network topology from topology 1 to topology 2. Both topologies are created inside a python script and I would like to allow the user to enter topology number (1 or 2) which should run the correspondent topology. I am using Mininet to run the python scripts and here is my Topo.py
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import Link, TCLink, Intf
from subprocess import call
from mininet.util import irange,dumpNodeConnections
class VLANHost( Host ):
def config( net, vlan=100, **params ):
r = super( Host, net ).config( **params )
intf = net.defaultIntf()
# remove IP from default, physical interface
net.cmd( 'ifconfig %s inet 0' % intf )
# create VLAN interface
net.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
# assign the host's IP to the VLAN interface
net.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
# update the intf name and host's intf map
newName = '%s.%d' % ( intf, vlan )
# update the (Mininet) interface to refer to VLAN interface name
intf.name = newName
# add VLAN interface to host's name to intf map
net.nameToIntf[ newName ] = intf
return r
def topology1():
net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
c0 = net.addController( 'c0', ip='127.0.0.1', port=6633 )
sw1=net.addSwitch('sw1')
sw2=net.addSwitch('sw2')
host1=net.addHost('host1', cls=VLANHost, vlan=1)
host2=net.addHost('host2', cls=VLANHost, vlan=2)
host3=net.addHost('host3', cls=VLANHost, vlan=3)
host4=net.addHost('host4', cls=VLANHost, vlan=3)
host5=net.addHost('host5', cls=VLANHost, vlan=2)
host6=net.addHost('host6', cls=VLANHost, vlan=1)
net.addLink(sw1,sw2)
net.addLink(sw1,host1)
net.addLink(sw1,host2)
net.addLink(sw1,host3)
net.addLink(sw2,host4)
net.addLink(sw2,host5)
net.addLink(sw2,host6)
net.build()
c0.start()
sw1.start( [c0] )
sw2.start( [c0] )
CLI( net )
net.stop()
def topology2():
net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
c0 = net.addController( 'c0', ip='127.0.0.1', port=6633 )
sw1=net.addSwitch('sw1')
sw2=net.addSwitch('sw2')
host1=net.addHost('host1', cls=VLANHost, vlan=3)
host2=net.addHost('host2', cls=VLANHost, vlan=2)
host3=net.addHost('host3', cls=VLANHost, vlan=1)
host4=net.addHost('host4', cls=VLANHost, vlan=1)
host5=net.addHost('host5', cls=VLANHost, vlan=3)
host6=net.addHost('host6', cls=VLANHost, vlan=2)
net.addLink(sw1,sw2)
net.addLink(sw1,host1)
net.addLink(sw1,host2)
net.addLink(sw1,host3)
net.addLink(sw2,host4)
net.addLink(sw2,host5)
net.addLink(sw2,host6)
net.build()
c0.start()
sw1.start( [c0] )
sw2.start( [c0] )
CLI( net )
net.stop()
if __name__ == '__main__':
setLogLevel('info')
topology1()
topology2()
The python script that is used to allow user to choose which topology to run is:
import Topos
if __name__ == '__main__':
choice = raw_input('choose Topology by typing 1 or 2: ')
if choice == '1':
Topos.topology1()
elif choice == '2':
Topos.topology2()
When I run the second script, I get this error:
"ImportError: cannot import name Cmd"
Note: Both files are in the same directory