#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
#
# test_ripng_topo1.py
# 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
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 = ""
#####################################################
-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"])
#####################################################
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 != "":
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 != "":
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 != "":
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 != "":
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 != "":
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 != "":
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 != "":
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"])