From 87b6021428f7251209358b3102a528fd987e77ea Mon Sep 17 00:00:00 2001 From: Cody <cody@onlab.us> Date: Thu, 29 May 2014 17:26:40 -0700 Subject: [PATCH] restructured code and added a test for the numberedports.py example --- examples/README.md | 5 +++ examples/test/test_numberedports.py | 51 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 examples/test/test_numberedports.py diff --git a/examples/README.md b/examples/README.md index 4be55642..96e30d75 100644 --- a/examples/README.md +++ b/examples/README.md @@ -117,3 +117,8 @@ memory and `sysctl` configuration (see `INSTALL`.) This example creates a 64-host tree network, and attempts to check full connectivity using `ping`, for different switch/datapath types. + +#### numberedports.py + +This example verifies the mininet ofport numbers match up to the ovs port numbers. +It also verifies that the port numbers match up to the interface numbers diff --git a/examples/test/test_numberedports.py b/examples/test/test_numberedports.py new file mode 100755 index 00000000..f92e482b --- /dev/null +++ b/examples/test/test_numberedports.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +Test for numberedports.py +""" + +import unittest +import pexpect +from collections import defaultdict + + +class testNumberedports( unittest.TestCase ): + + def testConsistency( self ): + """verify consistency between mininet and ovs ports""" + p = pexpect.spawn( 'python -m mininet.examples.numberedports' ) + opts = [ 'Validating that s1-eth\d is actually on port \d ... Validated.', + 'Validating that s1-eth\d is actually on port \d ... WARNING', + pexpect.EOF ] + correct_ports = True + count = 0 + while True: + index = p.expect( opts ) + if index == 0: + count += 1 + elif index == 1: + correct_ports = False + elif index == 2: + self.assertNotEqual( 0, count ) + break + self.assertTrue( correct_ports ) + + def testNumbering( self ): + """verify that all of the port numbers are printed correctly and consistent with their interface""" + p = pexpect.spawn( 'python -m mininet.examples.numberedports' ) + opts = [ 's1-eth(\d+) : (\d+)', + pexpect.EOF ] + count_intfs = 0 + while True: + index = p.expect( opts ) + if index == 0: + count_intfs += 1 + intfport = p.match.group( 1 ) + ofport = p.match.group( 2 ) + self.assertEqual( intfport, ofport ) + elif index == 1: + self.assertNotEqual( 0, count_intfs ) + break + +if __name__ == '__main__': + unittest.main() -- GitLab