]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/ripng_topo1/test_ripng_topo1.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / ripng_topo1 / test_ripng_topo1.py
index 4a5a59cd75a233a28a7d7c7df62d4b285edb94d3..ce2f5986d1ea43e005a8b94e7f8f2dd4caee8b15 100644 (file)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# SPDX-License-Identifier: ISC
 
 #
 # test_ripng_topo1.py
@@ -7,20 +8,6 @@
 # Copyright (c) 2017 by
 # Network Device Education Foundation, Inc. ("NetDEF")
 #
-# Permission to use, copy, modify, and/or distribute this software
-# for any purpose with or without fee is hereby granted, provided
-# that the above copyright notice and this permission notice appear
-# in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
-# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
-# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-# OF THIS SOFTWARE.
-#
 
 """
 test_ripng_topo1.py: Test of RIPng Topology
@@ -31,20 +18,12 @@ import os
 import re
 import sys
 import pytest
-import unicodedata
 from time import sleep
 
-from mininet.topo import Topo
-from mininet.net import Mininet
-from mininet.node import Node, OVSSwitch, Host
-from mininet.log import setLogLevel, info
-from mininet.cli import CLI
-from mininet.link import Intf
-
-from functools import partial
 
 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from lib import topotest
+from lib.topogen import Topogen, get_topogen
 
 fatal_error = ""
 
@@ -57,46 +36,34 @@ pytestmark = [pytest.mark.ripd]
 #####################################################
 
 
-class NetworkTopo(Topo):
-    "RIPng Topology 1"
-
-    def build(self, **_opts):
-
-        # Setup Routers
-        router = {}
-        #
-        # Setup Main Router
-        router[1] = topotest.addRouter(self, "r1")
-        #
-        # Setup RIPng Routers
-        for i in range(2, 4):
-            router[i] = topotest.addRouter(self, "r%s" % i)
-
-        # Setup Switches
-        switch = {}
-        #
-        # On main router
-        # First switch is for a dummy interface (for local network)
-        switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch)
-        self.addLink(switch[1], router[1], intfName2="r1-eth0")
-        #
-        # Switches for RIPng
-        # switch 2 switch is for connection to RIP router
-        switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch)
-        self.addLink(switch[2], router[1], intfName2="r1-eth1")
-        self.addLink(switch[2], router[2], intfName2="r2-eth0")
-        # switch 3 is between RIP routers
-        switch[3] = self.addSwitch("sw3", cls=topotest.LegacySwitch)
-        self.addLink(switch[3], router[2], intfName2="r2-eth1")
-        self.addLink(switch[3], router[3], intfName2="r3-eth1")
-        # switch 4 is stub on remote RIP router
-        switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch)
-        self.addLink(switch[4], router[3], intfName2="r3-eth0")
-
-        switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch)
-        self.addLink(switch[5], router[1], intfName2="r1-eth2")
-        switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch)
-        self.addLink(switch[6], router[1], intfName2="r1-eth3")
+def build_topo(tgen):
+    # Setup RIPng Routers
+    for i in range(1, 4):
+        tgen.add_router("r%s" % i)
+
+    #
+    # On main router
+    # First switch is for a dummy interface (for local network)
+    switch = tgen.add_switch("sw1")
+    switch.add_link(tgen.gears["r1"])
+    #
+    # Switches for RIPng
+    # switch 2 switch is for connection to RIP router
+    switch = tgen.add_switch("sw2")
+    switch.add_link(tgen.gears["r1"])
+    switch.add_link(tgen.gears["r2"])
+    # switch 3 is between RIP routers
+    switch = tgen.add_switch("sw3")
+    switch.add_link(tgen.gears["r2"])
+    switch.add_link(tgen.gears["r3"], nodeif="r3-eth1")
+    # switch 4 is stub on remote RIP router
+    switch = tgen.add_switch("sw4")
+    switch.add_link(tgen.gears["r3"], nodeif="r3-eth0")
+
+    switch = tgen.add_switch("sw5")
+    switch.add_link(tgen.gears["r1"])
+    switch = tgen.add_switch("sw6")
+    switch.add_link(tgen.gears["r1"])
 
 
 #####################################################
@@ -107,44 +74,36 @@ class NetworkTopo(Topo):
 
 
 def setup_module(module):
-    global topo, net
-
     print("\n\n** %s: Setup Topology" % module.__name__)
     print("******************************************\n")
 
-    print("Cleanup old Mininet runs")
-    os.system("sudo mn -c > /dev/null 2>&1")
-
     thisDir = os.path.dirname(os.path.realpath(__file__))
-    topo = NetworkTopo()
+    tgen = Topogen(build_topo, module.__name__)
+    tgen.start_topology()
 
-    net = Mininet(controller=None, topo=topo)
-    net.start()
+    net = tgen.net
 
     # Starting Routers
     #
     for i in range(1, 4):
         net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i))
         net["r%s" % i].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir, i))
-        net["r%s" % i].startRouter()
+        tgen.gears["r%s" % i].start()
 
     # For debugging after starting FRR daemons, uncomment the next line
-    # CLI(net)
+    # tgen.mininet_cli()
 
 
 def teardown_module(module):
-    global net
-
     print("\n\n** %s: Shutdown Topology" % module.__name__)
     print("******************************************\n")
-
-    # End - Shutdown network
-    net.stop()
+    tgen = get_topogen()
+    tgen.stop_topology()
 
 
 def test_router_running():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -158,13 +117,10 @@ def test_router_running():
         fatal_error = net["r%s" % i].checkRouterRunning()
         assert fatal_error == "", fatal_error
 
-    # For debugging after starting FRR daemons, uncomment the next line
-    # CLI(net)
-
 
 def test_converge_protocols():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -183,13 +139,10 @@ def test_converge_protocols():
         fatal_error = net["r%s" % i].checkRouterRunning()
         assert fatal_error == "", fatal_error
 
-    # For debugging after starting FRR daemons, uncomment the next line
-    # CLI(net)
-
 
 def test_ripng_status():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -251,13 +204,10 @@ def test_ripng_status():
         fatal_error = net["r%s" % i].checkRouterRunning()
         assert fatal_error == "", fatal_error
 
-    # For debugging after starting FRR daemons, uncomment the next line
-    # CLI(net)
-
 
 def test_ripng_routes():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -318,13 +268,10 @@ def test_ripng_routes():
         fatal_error = net["r%s" % i].checkRouterRunning()
         assert fatal_error == "", fatal_error
 
-    # For debugging after starting FRR daemons, uncomment the next line
-    # CLI(net)
-
 
 def test_zebra_ipv6_routingTable():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -386,13 +333,10 @@ def test_zebra_ipv6_routingTable():
         fatal_error = net["r%s" % i].checkRouterRunning()
         assert fatal_error == "", fatal_error
 
-    # For debugging after starting FRR daemons, uncomment the next line
-    # CLI(net)
-
 
 def test_shutdown_check_stderr():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -421,7 +365,7 @@ def test_shutdown_check_stderr():
 
 def test_shutdown_check_memleak():
     global fatal_error
-    global net
+    net = get_topogen().net
 
     # Skip if previous fatal error condition is raised
     if fatal_error != "":
@@ -443,7 +387,6 @@ def test_shutdown_check_memleak():
 
 if __name__ == "__main__":
 
-    setLogLevel("info")
     # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
     # retval = pytest.main(["-s", "--tb=no"])
     retval = pytest.main(["-s"])