You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
from signal import SIGINT
|
|
from mininet.node import Node
|
|
from mininet.util import moveIntf
|
|
|
|
class LinuxRouter(Node):
|
|
|
|
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.popenOLSR = self.popen('olsrd', '-nofork' , '-i', *self.intfNames())
|
|
|
|
def terminate(self):
|
|
self.popenOLSR.send_signal(SIGINT)
|
|
self.popenOLSR.wait()
|
|
super(OLSRRouter, self).terminate()
|
|
|
|
|
|
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(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('batctl', '-m', self.batman_intf, 'if', 'destroy')
|
|
super(BATMANADVRouter, self).terminate()
|