2015-01-06 14:47:15 +00:00
|
|
|
from mininet.topo import Topo
|
2015-01-07 13:44:44 +00:00
|
|
|
from mininet.net import Mininet
|
|
|
|
from mininet.link import TCLink
|
|
|
|
from mininet.cli import CLI
|
2015-01-06 14:47:15 +00:00
|
|
|
|
|
|
|
class MpMininetBuilder(Topo):
|
|
|
|
def __init__(self):
|
|
|
|
Topo.__init__( self )
|
2015-01-07 13:44:44 +00:00
|
|
|
self.net = None
|
|
|
|
|
|
|
|
def commandTo(self, who, cmd):
|
|
|
|
who.cmd(cmd)
|
|
|
|
|
|
|
|
def startNetwork(self):
|
|
|
|
self.net = Mininet(topo=self,link=TCLink)
|
|
|
|
self.net.start()
|
|
|
|
|
|
|
|
def getCLI(self):
|
|
|
|
if self.net is None:
|
|
|
|
print("Can not get the CLI")
|
|
|
|
else:
|
|
|
|
CLI(self.net)
|
|
|
|
|
|
|
|
def getHost(self, who):
|
|
|
|
if self.net is None:
|
|
|
|
print("Network not available....")
|
|
|
|
raise Exception("Network not ready");
|
|
|
|
else:
|
|
|
|
return self.net.getNodeByName(who)
|
|
|
|
|
|
|
|
def stopNetwork(self):
|
|
|
|
if self.net is None:
|
|
|
|
print("Could not stop network... Nothing to stop)")
|
|
|
|
else:
|
|
|
|
self.net.stop()
|
|
|
|
|