ospf6-topo1: Code cleanup

This commit is contained in:
Martin Winter 2016-11-24 03:56:05 -08:00 committed by Donald Sharp
parent 50bd94cd20
commit 68a655673f

View File

@ -1,23 +1,23 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# ospf6-test1.py # test_ospf6_topo1.py
# Part of NetDEF Topology Tests # Part of NetDEF Topology Tests
# #
# Copyright (c) 2016 by # Copyright (c) 2016 by
# Network Device Education Foundation, Inc. ("NetDEF") # Network Device Education Foundation, Inc. ("NetDEF")
# #
# Permission to use, copy, modify, and/or distribute this software # Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided # for any purpose with or without fee is hereby granted, provided
# that the above copyright notice and this permission notice appear # that the above copyright notice and this permission notice appear
# in all copies. # in all copies.
# #
# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE. # OF THIS SOFTWARE.
# #
@ -72,9 +72,9 @@ test_ospf6_topo1.py:
import os import os
import re import re
import StringIO
import sys import sys
import difflib import difflib
import StringIO
from mininet.topo import Topo from mininet.topo import Topo
from mininet.net import Mininet from mininet.net import Mininet
@ -98,6 +98,7 @@ def int2dpid(dpid):
raise Exception('Unable to derive default datapath ID - ' raise Exception('Unable to derive default datapath ID - '
'please either specify a dpid or use a ' 'please either specify a dpid or use a '
'canonical switch name such as s23.') 'canonical switch name such as s23.')
class LinuxRouter(Node): class LinuxRouter(Node):
"A Node with IPv4/IPv6 forwarding enabled." "A Node with IPv4/IPv6 forwarding enabled."
@ -121,7 +122,7 @@ class QuaggaRouter(Node):
super(QuaggaRouter, self).config(**params) super(QuaggaRouter, self).config(**params)
# Enable forwarding on the router # Enable forwarding on the router
self.cmd('sysctl net.ipv4.ip_forward=1') self.cmd('sysctl net.ipv4.ip_forward=1')
self.cmd('sysctl net.ipv6.conf.all.forwarding=1') self.cmd('sysctl net.ipv6.conf.all.forwarding=1')
self.cmd('chown quagga:quaggavty /etc/quagga') self.cmd('chown quagga:quaggavty /etc/quagga')
self.daemons = {'zebra': 0, 'ripd': 0, 'ripngd': 0, 'ospfd': 0, self.daemons = {'zebra': 0, 'ripd': 0, 'ripngd': 0, 'ospfd': 0,
'ospf6d': 0, 'isisd': 0, 'bgpd': 0, 'pimd': 0} 'ospf6d': 0, 'isisd': 0, 'bgpd': 0, 'pimd': 0}
@ -244,9 +245,12 @@ class NetworkTopo(Topo):
def setup_module(module): def setup_module(module):
global topo, net global topo, net
print ("\n\n** %s: Setup Topology" % module.__name__) print("\n\n** %s: Setup Topology" % module.__name__)
print("******************************************\n") print("******************************************\n")
print("Cleanup old Mininet runs")
os.system('sudo mn -c > /dev/null 2>&1')
thisDir = os.path.dirname(os.path.realpath(__file__)) thisDir = os.path.dirname(os.path.realpath(__file__))
topo = NetworkTopo() topo = NetworkTopo()
@ -269,7 +273,7 @@ def setup_module(module):
def teardown_module(module): def teardown_module(module):
global net global net
print ("\n\n** %s: Shutdown Topology" % module.__name__) print("\n\n** %s: Shutdown Topology" % module.__name__)
print("******************************************\n") print("******************************************\n")
# End - Shutdown network # End - Shutdown network
@ -279,7 +283,7 @@ def teardown_module(module):
def test_quagga_running(): def test_quagga_running():
global net global net
print ("\n\n** Check if Quagga is running on each Router node") print("\n\n** Check if Quagga is running on each Router node")
print("******************************************\n") print("******************************************\n")
sleep(5) sleep(5)
@ -352,8 +356,7 @@ def test_ospf6_routingTable():
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
# Generate Diff # Generate Diff
diff=difflib.unified_diff(actual, expected) diff = ''.join(difflib.unified_diff(actual, expected))
diff=''.join(diff)
# Empty string if it matches, otherwise diff contains unified diff # Empty string if it matches, otherwise diff contains unified diff
if diff: if diff: