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-14 14:19:39 +00:00
|
|
|
from subprocess import Popen, PIPE
|
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
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def commandTo(self, who, cmd):
|
2015-02-10 10:03:21 +00:00
|
|
|
return who.cmd(cmd)
|
2015-01-14 14:19:39 +00:00
|
|
|
|
|
|
|
def notNSCommand(self, cmd):
|
|
|
|
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
if stderr:
|
|
|
|
return "Error"
|
|
|
|
return stdout
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def startNetwork(self):
|
2016-05-04 07:23:12 +00:00
|
|
|
self.net = Mininet(topo=self,link=TCLink,autoStaticArp=True)
|
2015-01-07 13:44:44 +00:00
|
|
|
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)
|
2015-02-26 16:43:45 +00:00
|
|
|
|
2015-01-07 13:44:44 +00:00
|
|
|
def stopNetwork(self):
|
|
|
|
if self.net is None:
|
|
|
|
print("Could not stop network... Nothing to stop)")
|
|
|
|
else:
|
|
|
|
self.net.stop()
|