Skip to content

Commit

Permalink
Merge pull request #3499 from donaldsharp/topotest_inheritance
Browse files Browse the repository at this point in the history
Topotest inheritance
  • Loading branch information
rzalamena committed Dec 20, 2018
2 parents 96def26 + 4b1d6d4 commit f691341
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions tests/topotests/lib/topotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,10 @@ def addRouter(topo, name):
'/var/run/frr',
'/var/run/quagga',
'/var/log']
return topo.addNode(name, cls=Router, privateDirs=MyPrivateDirs)
if sys.platform.startswith("linux"):
return topo.addNode(name, cls=LinuxRouter, privateDirs=MyPrivateDirs)
elif sys.platform.startswith("freebsd"):
return topo.addNode(name, cls=FreeBSDRouter, privateDirs=MyPrivateDirs)

def set_sysctl(node, sysctl, value):
"Set a sysctl value and return None on success or an error string"
Expand All @@ -603,21 +606,6 @@ def assert_sysctl(node, sysctl, value):
"Set and assert that the sysctl is set with the specified value."
assert set_sysctl(node, sysctl, value) is None

class LinuxRouter(Node):
"A Node with IPv4/IPv6 forwarding enabled."

def config(self, **params):
super(LinuxRouter, self).config(**params)
# Enable forwarding on the router
assert_sysctl(self, 'net.ipv4.ip_forward', 1)
assert_sysctl(self, 'net.ipv6.conf.all.forwarding', 1)
def terminate(self):
"""
Terminate generic LinuxRouter Mininet instance
"""
set_sysctl(self, 'net.ipv4.ip_forward', 0)
set_sysctl(self, 'net.ipv6.conf.all.forwarding', 0)
super(LinuxRouter, self).terminate()

class Router(Node):
"A Node with IPv4/IPv6 forwarding enabled and Quagga as Routing Engine"
Expand Down Expand Up @@ -678,17 +666,6 @@ def config(self, **params):
if params.get('routertype') is not None:
self.routertype = self.params.get('routertype')

# Enable forwarding on the router
assert_sysctl(self, 'net.ipv4.ip_forward', 1)
assert_sysctl(self, 'net.ipv6.conf.all.forwarding', 1)
# Enable coredumps
assert_sysctl(self, 'kernel.core_uses_pid', 1)
assert_sysctl(self, 'fs.suid_dumpable', 1)
#this applies to the kernel not the namespace...
#original on ubuntu 17.x, but apport won't save as in namespace
# |/usr/share/apport/apport %p %s %c %d %P
corefile = '%e_core-sig_%s-pid_%p.dmp'
assert_sysctl(self, 'kernel.core_pattern', corefile)
self.cmd('ulimit -c unlimited')
# Set ownership of config files
self.cmd('chown {0}:{0}vty /etc/{0}'.format(self.routertype))
Expand Down Expand Up @@ -1084,6 +1061,40 @@ def report_memory_leaks(self, filename_prefix, testscript):
if leakfound:
leakfile.close()

class LinuxRouter(Router):
"A Linux Router Node with IPv4/IPv6 forwarding enabled."

def __init__(self, name, **params):
Router.__init__(self, name, **params)

def config(self, **params):
Router.config(self, **params)
# Enable forwarding on the router
assert_sysctl(self, 'net.ipv4.ip_forward', 1)
assert_sysctl(self, 'net.ipv6.conf.all.forwarding', 1)
# Enable coredumps
assert_sysctl(self, 'kernel.core_uses_pid', 1)
assert_sysctl(self, 'fs.suid_dumpable', 1)
#this applies to the kernel not the namespace...
#original on ubuntu 17.x, but apport won't save as in namespace
# |/usr/share/apport/apport %p %s %c %d %P
corefile = '%e_core-sig_%s-pid_%p.dmp'
assert_sysctl(self, 'kernel.core_pattern', corefile)

def terminate(self):
"""
Terminate generic LinuxRouter Mininet instance
"""
set_sysctl(self, 'net.ipv4.ip_forward', 0)
set_sysctl(self, 'net.ipv6.conf.all.forwarding', 0)
Router.terminate(self)

class FreeBSDRouter(Router):
"A FreeBSD Router Node with IPv4/IPv6 forwarding enabled."

def __init__(eslf, name, **params):
Router.__init__(Self, name, **params)


class LegacySwitch(OVSSwitch):
"A Legacy Switch without OpenFlow"
Expand Down

0 comments on commit f691341

Please sign in to comment.