From e0bf8ece3c9c4be2078d65df99e08423d57fc007 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Sun, 23 Nov 2014 17:17:21 -0800 Subject: [PATCH] Minor code cleanup --- examples/bind.py | 2 +- examples/clusterSanity.py | 2 +- examples/clustercli.py | 2 +- examples/cpu.py | 3 +- examples/intfOptions.py | 48 -------------------- examples/linuxrouter.py | 1 - examples/mobility.py | 2 - examples/multiLink.py | 35 --------------- examples/multilink.py | 4 +- examples/numberedports.py | 2 - examples/simpleperf.py | 2 +- examples/test/test_intfOptions.py | 42 ----------------- examples/test/test_multiLink.py | 55 ----------------------- mininet/test/test_switchdpidassignment.py | 2 +- 14 files changed, 8 insertions(+), 194 deletions(-) delete mode 100755 examples/intfOptions.py delete mode 100755 examples/multiLink.py delete mode 100755 examples/test/test_intfOptions.py delete mode 100755 examples/test/test_multiLink.py diff --git a/examples/bind.py b/examples/bind.py index 4bc30a8..b5fecf3 100755 --- a/examples/bind.py +++ b/examples/bind.py @@ -38,7 +38,7 @@ from mininet.net import Mininet from mininet.node import Host from mininet.cli import CLI from mininet.topo import SingleSwitchTopo -from mininet.log import setLogLevel, info, debug +from mininet.log import setLogLevel, info from functools import partial diff --git a/examples/clusterSanity.py b/examples/clusterSanity.py index c840ea0..5383b25 100755 --- a/examples/clusterSanity.py +++ b/examples/clusterSanity.py @@ -5,7 +5,7 @@ A sanity check for cluster edition ''' from mininet.examples.cluster import MininetCluster -from mininet.log import info, setLogLevel +from mininet.log import setLogLevel from mininet.examples.clustercli import ClusterCLI as CLI from mininet.topo import SingleSwitchTopo diff --git a/examples/clustercli.py b/examples/clustercli.py index 7ff0f97..c753ccf 100644 --- a/examples/clustercli.py +++ b/examples/clustercli.py @@ -32,6 +32,7 @@ class ClusterCLI( CLI ): import networkx as nx import matplotlib.pyplot as plt import pygraphviz + assert pygraphviz # silence pyflakes except: error( 'plot requires networkx, matplotlib and pygraphviz - ' 'please install them and try again\n' ) @@ -40,7 +41,6 @@ class ClusterCLI( CLI ): g = nx.Graph() mn = self.mn servers, hosts, switches = mn.servers, mn.hosts, mn.switches - hlen, slen = len( hosts ), len( switches ) nodes = hosts + switches g.add_nodes_from( nodes ) links = [ ( link.intf1.node, link.intf2.node ) diff --git a/examples/cpu.py b/examples/cpu.py index 630fa2e..3a83661 100755 --- a/examples/cpu.py +++ b/examples/cpu.py @@ -8,9 +8,8 @@ from mininet.net import Mininet from mininet.node import CPULimitedHost from mininet.topolib import TreeTopo from mininet.util import custom, waitListening -from mininet.log import setLogLevel, output, info +from mininet.log import setLogLevel, info -from time import sleep def bwtest( cpuLimits, period_us=100000, seconds=5 ): """Example/test of link and CPU bandwidth limits diff --git a/examples/intfOptions.py b/examples/intfOptions.py deleted file mode 100755 index 89a7148..0000000 --- a/examples/intfOptions.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/python - -''' -example of using various TCIntf options. -reconfigures a single interface using intf.config() -to use different traffic control commands to test -bandwidth, loss, and delay -''' - -from mininet.net import Mininet -from mininet.log import setLogLevel, info -from mininet.link import TCLink - -def intfOptions(): - "run various traffic control commands on a single interface" - net = Mininet( autoStaticArp=True ) - net.addController( 'c0' ) - h1 = net.addHost( 'h1' ) - h2 = net.addHost( 'h2' ) - s1 = net.addSwitch( 's1' ) - link1 = net.addLink( h1, s1, cls=TCLink ) - link2 = net.addLink( h2, s1 ) - net.start() - - # flush out latency from reactive forwarding delay - net.pingAll() - - info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' ) - link1.intf1.config( bw=5 ) - info( '\n*** Running iperf to test\n' ) - net.iperf() - - info( '\n*** Configuring one intf with loss of 50%\n' ) - link1.intf1.config( loss=50 ) - info( '\n' ) - net.iperf( ( h1, h2 ), l4Type='UDP' ) - - info( '\n*** Configuring one intf with delay of 15ms\n' ) - link1.intf1.config( delay='15ms' ) - info( '\n*** Run a ping to confirm delay\n' ) - net.pingPairFull() - - info( '\n*** Done testing\n' ) - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - intfOptions() diff --git a/examples/linuxrouter.py b/examples/linuxrouter.py index 488ec3c..329538a 100755 --- a/examples/linuxrouter.py +++ b/examples/linuxrouter.py @@ -27,7 +27,6 @@ from mininet.net import Mininet from mininet.node import Node from mininet.log import setLogLevel, info from mininet.cli import CLI -from mininet.util import irange class LinuxRouter( Node ): "A Node with IP forwarding enabled." diff --git a/examples/mobility.py b/examples/mobility.py index 0e3e557..dd04451 100755 --- a/examples/mobility.py +++ b/examples/mobility.py @@ -22,11 +22,9 @@ to-do: from mininet.net import Mininet from mininet.node import OVSSwitch from mininet.topo import LinearTopo -from mininet.util import quietRun from mininet.log import output, warn from random import randint -from re import findall class MobilitySwitch( OVSSwitch ): diff --git a/examples/multiLink.py b/examples/multiLink.py deleted file mode 100755 index 28a67a8..0000000 --- a/examples/multiLink.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/python - -""" -This is a simple example that demonstrates multiple links -between nodes. -""" - -from mininet.cli import CLI -from mininet.log import lg, info -from mininet.net import Mininet -from mininet.topo import Topo - -def runMultiLink(): - - topo = simpleMultiLinkTopo( n=2 ) - net = Mininet( topo=topo ) - net.start() - CLI( net ) - net.stop() - -class simpleMultiLinkTopo( Topo ): - - def __init__( self, n, **kwargs ): - Topo.__init__( self, **kwargs ) - - h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' ) - s1 = self.addSwitch( 's1' ) - - for _ in range( n ): - self.addLink( s1, h1 ) - self.addLink( s1, h2 ) - -if __name__ == '__main__': - lg.setLogLevel( 'info' ) - runMultiLink() diff --git a/examples/multilink.py b/examples/multilink.py index 28a67a8..632ed79 100755 --- a/examples/multilink.py +++ b/examples/multilink.py @@ -6,7 +6,7 @@ between nodes. """ from mininet.cli import CLI -from mininet.log import lg, info +from mininet.log import setLogLevel from mininet.net import Mininet from mininet.topo import Topo @@ -31,5 +31,5 @@ class simpleMultiLinkTopo( Topo ): self.addLink( s1, h2 ) if __name__ == '__main__': - lg.setLogLevel( 'info' ) + setLogLevel( 'info' ) runMultiLink() diff --git a/examples/numberedports.py b/examples/numberedports.py index 8220550..5784e2e 100755 --- a/examples/numberedports.py +++ b/examples/numberedports.py @@ -9,7 +9,6 @@ and that the ovs ports match the mininet ports. from mininet.net import Mininet from mininet.node import Controller from mininet.log import setLogLevel, info, warn -from mininet.node import Node def validatePort( switch, intf ): "Validate intf's OF port number" @@ -48,7 +47,6 @@ def net(): net.addLink( h4, s1 ) net.addLink( h5, s1, port1 = 1, port2 = 9 ) # specify a different port to connect host 5 to on the switch. - root = Node( 'root', inNamespace=False ) info( '*** Starting network\n' ) net.start() diff --git a/examples/simpleperf.py b/examples/simpleperf.py index 7d16968..96725ef 100755 --- a/examples/simpleperf.py +++ b/examples/simpleperf.py @@ -40,7 +40,7 @@ def perfTest(): dumpNodeConnections(net.hosts) print "Testing bandwidth between h1 and h4" h1, h4 = net.getNodeByName('h1', 'h4') - results = net.iperf( ( h1, h4 ), l4Type='UDP' ) + net.iperf( ( h1, h4 ), l4Type='UDP' ) net.stop() if __name__ == '__main__': diff --git a/examples/test/test_intfOptions.py b/examples/test/test_intfOptions.py deleted file mode 100755 index 1493693..0000000 --- a/examples/test/test_intfOptions.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python - -""" -Test for intfOptions.py -""" - -import unittest -import pexpect -import sys - -class testIntfOptions( unittest.TestCase ): - - def testIntfOptions( self ): - "verify that intf.config is correctly limiting traffic" - p = pexpect.spawn( 'python -m mininet.examples.intfOptions ' ) - tolerance = .8 - opts = [ "Results: \['([\d\.]+) .bits/sec", - "Results: \['10M', '([\d\.]+) .bits/sec", - "h(\d+)->h(\d+): (\d)/(\d), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms", - pexpect.EOF ] - while True: - index = p.expect( opts, timeout=600 ) - if index == 0: - bw = float( p.match.group( 1 ) ) - self.assertGreaterEqual( bw, float( 5 * tolerance ) ) - self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) ) - elif index == 1: - BW = 10 - measuredBw = float( p.match.group( 1 ) ) - loss = ( measuredBw / BW ) * 100 - self.assertGreaterEqual( loss, 50 * tolerance ) - self.assertLessEqual( loss, 50 + 50 * ( 1 - tolerance ) ) - elif index == 2: - delay = float( p.match.group( 6 ) ) - self.assertGreaterEqual( delay, 15 * tolerance ) - self.assertLessEqual( delay, 15 + 15 * ( 1 - tolerance ) ) - else: - break - - -if __name__ == '__main__': - unittest.main() diff --git a/examples/test/test_multiLink.py b/examples/test/test_multiLink.py deleted file mode 100755 index 6b4bca2..0000000 --- a/examples/test/test_multiLink.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python - -''' -Test for multiple links between nodes -validates mininet interfaces against systems interfaces -''' - -import unittest -import pexpect - -class testMultiLink( unittest.TestCase ): - - prompt = 'mininet>' - - def testMultiLink(self): - p = pexpect.spawn( 'python -m mininet.examples.multiLink' ) - p.expect( self.prompt ) - p.sendline( 'intfs' ) - p.expect( 's(\d): lo' ) - intfsOutput = p.before - # parse interfaces from mininet intfs, and store them in a list - hostToIntfs = intfsOutput.split( '\r\n' )[ 1:3 ] - intfList = [] - for hostToIntf in hostToIntfs: - intfList += [ intf for intf in - hostToIntf.split()[1].split(',') ] - - # get interfaces from system by running ifconfig on every host - sysIntfList = [] - opts = [ 'h(\d)-eth(\d)', self.prompt ] - p.expect( self.prompt ) - - p.sendline( 'h1 ifconfig' ) - while True: - p.expect( opts ) - if p.after == self.prompt: - break - sysIntfList.append( p.after ) - - p.sendline( 'h2 ifconfig' ) - while True: - p.expect( opts ) - if p.after == self.prompt: - break - sysIntfList.append( p.after ) - - failMsg = ( 'The systems interfaces and mininet interfaces\n' - 'are not the same' ) - - self.assertEqual( sysIntfList, intfList, msg=failMsg ) - p.sendline( 'exit' ) - p.wait() - -if __name__ == '__main__': - unittest.main() diff --git a/mininet/test/test_switchdpidassignment.py b/mininet/test/test_switchdpidassignment.py index 29ae9e5..9db98f7 100644 --- a/mininet/test/test_switchdpidassignment.py +++ b/mininet/test/test_switchdpidassignment.py @@ -37,7 +37,7 @@ class testSwitchDpidAssignmentCommon ( object ): name of the switch does not contin a digit. Also verify the exception message.""" with self.assertRaises( Exception ) as raises_cm: - switch = Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' ) + Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' ) self.assertEqual(raises_cm.exception.message, 'Unable to derive ' 'default datapath ID - please either specify a dpid ' 'or use a canonical switch name such as s23.')