changes
parent
fa9001bb67
commit
b34514ba0d
@ -1,34 +1,93 @@
|
||||
from signal import SIGINT
|
||||
from mininet.node import Node
|
||||
from mininet.util import moveIntf
|
||||
|
||||
class LinuxRouter(Node):
|
||||
|
||||
def config(self, **params):
|
||||
def config(self, **params):
|
||||
self.cmd('sysctl net.ipv4.ip_forward=1')
|
||||
|
||||
def terminate(self):
|
||||
self.cmd('sysctl net.ipv4.ip_forward=0')
|
||||
super(LinuxRouter, self).terminate()
|
||||
|
||||
def startRTMonitor(self):
|
||||
self.popenRTMonitor = self.popen('bash routing-table-monitor.sh')
|
||||
|
||||
def stopRTMonitor(self):
|
||||
self.popenRTMonitor.send_signal(SIGINT)
|
||||
self.popenRTMonitor.wait()
|
||||
|
||||
|
||||
class OLSRRouter(LinuxRouter):
|
||||
|
||||
def config(self, **params):
|
||||
super(OLSRRouter, self).config(**params)
|
||||
self.servicePid = self.cmd('olsrd -nofork -i ' + ' '.join(self.intfNames()) + ' >/dev/null 2>&1 & echo $!')
|
||||
print(self.servicePid)
|
||||
self.popenOLSR = self.popen('olsrd', '-nofork' , '-i', *self.intfNames())
|
||||
|
||||
def terminate(self):
|
||||
self.cmd('kill ', self.servicePid)
|
||||
self.popenOLSR.send_signal(SIGINT)
|
||||
self.popenOLSR.wait()
|
||||
super(OLSRRouter, self).terminate()
|
||||
|
||||
|
||||
class BATMANRouter(LinuxRouter):
|
||||
class OLSRRouterMonitored(OLSRRouter):
|
||||
|
||||
def config(self, **params):
|
||||
self.startRTMonitor()
|
||||
super(OLSRRouterMonitored, self).config(**params)
|
||||
|
||||
def terminate(self):
|
||||
if self.popenRTMonitor:
|
||||
self.popenRTMonitor.send_signal(SIGINT)
|
||||
super(OLSRRouterMonitored, self).terminate()
|
||||
|
||||
|
||||
|
||||
class BATMANDRouter(LinuxRouter):
|
||||
|
||||
def config(self, **params):
|
||||
super(BATMANDRouter, self).config(**params)
|
||||
batman_param=[]#sum([['-a', i.IP()+'/32'] for i in self.intfList()],[])
|
||||
batman_param.extend(self.intfNames())
|
||||
self.cmd('batmand', *batman_param)
|
||||
|
||||
def terminate(self):
|
||||
# self.popenBATMAND.send_signal(SIGINT)
|
||||
# self.popenBATMAND.wait()
|
||||
super(BATMANDRouter, self).terminate()
|
||||
|
||||
|
||||
class BATMANDRouterMonitored(BATMANDRouter):
|
||||
|
||||
def config(self, **params):
|
||||
self.startRTMonitor()
|
||||
super(BATMANDRouterMonitored, self).config(**params)
|
||||
|
||||
def terminate(self):
|
||||
if self.popenRTMonitor:
|
||||
self.popenRTMonitor.send_signal(SIGINT)
|
||||
super(BATMANDRouterMonitored, self).terminate()
|
||||
|
||||
|
||||
class BATMANADVRouter(LinuxRouter):
|
||||
|
||||
def config(self, **params):
|
||||
super(BATMANRouter, self).config(**params)
|
||||
self.servicePid = self.cmd('batmand ' + ' '.join(self.intfNames()) + '& echo $!')
|
||||
print(self.servicePid)
|
||||
super(BATMANADVRouter, self).config(**params)
|
||||
if self.cmd('lsmod', '|', 'grep', '-q', 'batman') is not 0:
|
||||
self.cmd('modprobe', 'batman-adv')
|
||||
|
||||
self.batman_intf = '%s-bat0' % self.name
|
||||
self.cmd()
|
||||
|
||||
for intf in self.intfNames():
|
||||
self.cmd('batctl', '-m', self.batman_intf, 'if', 'add', intf)
|
||||
|
||||
moveIntf(self.batman_intf, self)
|
||||
id = int(self.name[1:])
|
||||
self.cmd('ip', 'address', 'add', '192.168.123.%i/24' % id, 'dev', self.batman_intf)
|
||||
self.cmd('ip', 'link', 'set', 'up', 'dev', self.batman_intf)
|
||||
|
||||
def terminate(self):
|
||||
self.cmd('kill ' + self.servicePid)
|
||||
super(BATMANRouter, self).terminate()
|
||||
self.cmd('batctl', '-m', self.batman_intf, 'if', 'destroy')
|
||||
super(BATMANADVRouter, self).terminate()
|
||||
|
Loading…
Reference in New Issue