8000 Migrate to iproute2 by SPYFF · Pull Request #1226 · mininet/mininet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate to iproute2 #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/hwintf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def checkIntf( intf ):
"Make sure intf exists and is not configured."
config = quietRun( 'ifconfig %s 2>/dev/null' % intf, shell=True )
config = quietRun( 'ip addr show dev %s 2>/dev/null' % intf, shell=True )
if not config:
error( 'Error:', intf, 'does not exist!\n' )
exit( 1 )
Expand Down
2 changes: 1 addition & 1 deletion examples/linuxrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run():
waitConnected=True ) # controller is used by s1-s3
net.start()
info( '*** Routing Table on Router:\n' )
info( net[ 'r0' ].cmd( 'route' ) )
info( net[ 'r0' ].cmd( 'ip route' ) )
CLI( net )
net.stop()

Expand Down
34 changes: 18 additions & 16 deletions examples/miniedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def start( self, controllers ):
# Set Switch IP address
if self.switchIP is not None:
if not self.inNamespace:
self.cmd( 'ifconfig', self, self.switchIP )
self.cmd( 'ip addr add', self.switchIP, 'dev', self)
else:
self.cmd( 'ifconfig lo', self.switchIP )
self.cmd( 'ip addr add', self.switchIP, 'dev lo' )

class LegacyRouter( Node ):
"Simple IP router"
Expand All @@ -139,9 +139,8 @@ def __init__( self, name, inNamespace=True, **params ):

# pylint: disable=arguments-differ
def config( self, **_params ):
if self.intfs:
self.setParam( _params, 'setIP', ip='0.0.0.0' )
r = Node.config( self, **_params )
par = {'ip':'0.0.0.0'} if self.intfs else _params
r = Node.config( self, **par )
self.cmd('sysctl -w net.ipv4.ip_forward=1')
return r

Expand Down Expand Up @@ -172,7 +171,7 @@ def start( self, controllers ):
OVSSwitch.start( self, controllers )
# Set Switch IP address
if self.switchIP is not None:
self.cmd( 'ifconfig', self, self.switchIP )
self.cmd( 'ip addr add', self.switchIP, 'dev', self)

class PrefsDialog(tkSimpleDialog.Dialog):
"Preferences dialog"
Expand Down Expand Up @@ -1930,27 +1929,27 @@ def exportScript( self ):
if self.appPrefs['switchType'] == 'user':
if 'switchIP' in opts:
if len(opts['switchIP']) > 0:
f.write(" "+name+".cmd('ifconfig "+name+" "+opts['switchIP']+"')\n")
f.write(" "+name+".cmd('ip addr add "+opts['switchIP']+" dev "+name+"')\n")
elif self.appPrefs['switchType'] == 'userns':
if 'switchIP' in opts:
if len(opts['switchIP']) > 0:
f.write(" "+name+".cmd('ifconfig lo "+opts['switchIP']+"')\n")
f.write(" "+name+".cmd('ip addr add "+opts['switchIP']+" dev lo')\n")
elif self.appPrefs['switchType'] == 'ovs':
if 'switchIP' in opts:
if len(opts['switchIP']) > 0:
f.write(" "+name+".cmd('ifconfig "+name+" "+opts['switchIP']+"')\n")
f.write(" "+name+".cmd('ip addr add "+opts['switchIP']+" dev "+name+"')\n")
elif opts['switchType'] == 'user':
if 'switchIP' in opts:
if len(opts['switchIP']) > 0:
f.write(" "+name+".cmd('ifconfig "+name+" "+opts['switchIP']+"')\n")
f.write(" "+name+".cmd('ip addr add "+opts['switchIP']+" dev "+name+"')\n")
elif opts['switchType'] == 'userns':
if 'switchIP' in opts:
if len(opts['switchIP']) > 0:
f.write(" "+name+".cmd('ifconfig lo "+opts['switchIP']+"')\n")
f.write(" "+name+".cmd('ip addr add "+opts['switchIP']+" dev lo')\n")
elif opts['switchType'] == 'ovs':
if 'switchIP' in opts:
if len(opts['switchIP']) > 0:
f.write(" "+name+".cmd('ifconfig "+name+" "+opts['switchIP']+"')\n")
f.write(" "+name+".cmd('ip addr add "+opts['switchIP']+" dev "+name+"')\n")
for widget, item in self.widgetToItem.items():
name = widget[ 'text' ]
tags = self.canvas.gettags( item )
Expand All @@ -1959,8 +1958,9 @@ def exportScript( self ):
# Attach vlan interfaces
if 'vlanInterfaces' in opts:
for vlanInterface in opts['vlanInterfaces']:
f.write(" "+name+".cmd('vconfig add "+name+"-eth0 "+vlanInterface[1]+"')\n")
f.write(" "+name+".cmd('ifconfig "+name+"-eth0."+vlanInterface[1]+" "+vlanInterface[0]+"')\n")
f.write(" "+name+".cmd('ip link add link "+name+"-eth0 name %s-eth0.%s" % (name,vlanInterface[1])+" type vlan id "+vlanInterface[1]+"')\n")
f.write(" "+name+".cmd('ip addr add "+vlanInterface[0]+" dev "+name+"-eth0."+vlanInterface[1]+"')\n")
f.write(" "+name+".cmd('ip link set dev "+name+"-eth0."+vlanInterface[1]+" up')\n")
# Run User Defined Start Command
if 'startCommand' in opts:
f.write(" "+name+".cmdPrint('"+opts['startCommand']+"')\n")
Expand Down Expand Up @@ -2458,7 +2458,7 @@ def checkIntf( intf ):
showerror(title="Error",
message='External interface ' +intf + ' does not exist! Skipping.')
return False
ips = re.findall( r'\d+\.\d+\.\d+\.\d+', quietRun( 'ifconfig ' + intf ) )
ips = re.findall( r'\d+\.\d+\.\d+\.\d+', quietRun( 'ip addr show ' + intf ) )
if ips:
showerror(title="Error",
message= intf + ' has an IP address and is probably in use! Skipping.' )
Expand Down Expand Up @@ -2940,7 +2940,9 @@ def postStartSetup( self ):
if 'vlanInterfaces' in opts:
for vlanInterface in opts['vlanInterfaces']:
info( 'adding vlan interface '+vlanInterface[1], '\n' )
newHost.cmdPrint('ifconfig '+name+'-eth0.'+vlanInterface[1]+' '+vlanInterface[0])
newHost.cmdPrint('ip link add link '+name+'-eth0 name %s-eth0.%s' % (name,vlanInterface[1])+' type vlan id '+vlanInterface[1])
newHost.cmdPrint('ip addr add '+vlanInterface[0]+' dev '+name+'-eth0.'+vlanInterface[1])
newHost.cmdPrint('ip link set dev '+name+'-eth0.'+vlanInterface[1]+' up')
# Run User Defined Start Command
if 'startCommand' in opts:
newHost.cmdPrint(opts['startCommand'])
Expand Down
4 changes: 2 additions & 2 deletions examples/mobility.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def validatePort( self, intf ):

def renameIntf( self, intf, newname='' ):
"Rename an interface (to its canonical name)"
intf.ifconfig( 'down' )
intf.cmd( 'ip link set', intf, 'down' )
if not newname:
newname = '%s-eth%d' % ( self.name, self.ports[ intf ] )
intf.cmd( 'ip link set', intf, 'name', newname )
del self.nameToIntf[ intf.name ]
intf.name = newname
self.nameToIntf[ intf.name ] = intf
intf.ifconfig( 'up' )
intf.cmd( 'ip link set', intf, 'up' )

def moveIntf( self, intf, switch, port=None, rename=True ):
"Move one of our interfaces to another switch"
Expand Down
10 changes: 5 additions & 5 deletions examples/multitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from mininet.node import OVSKernelSwitch
from mininet.topolib import TreeTopo

def ifconfigTest( net ):
"Run ifconfig on all hosts in net."
def ip_linkTest( net ):
"Run ip link on all hosts in net."
hosts = net.hosts
for host in hosts:
info( host.cmd( 'ifconfig' ) )
info( host.cmd( 'ip link' ) )


if __name__ == '__main__':
Expand All @@ -29,8 +29,8 @@ def ifconfigTest( net ):
network.start()
info( "*** Running ping test\n" )
network.pingAll()
info( "*** Running ifconfig test\n" )
ifconfigTest( network )
info( "*** Running ip link test\n" )
ip_linkTest( network )
info( "*** Starting CLI (type 'exit' to exit)\n" )
CLI( network )
info( "*** Stopping network\n" )
Expand Down
2 changes: 1 addition & 1 deletion examples/scratchnetuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):

info( '*** Starting controller and user datapath\n' )
controller.cmd( cname + ' ' + cargs + '&' )
switch.cmd( 'ifconfig lo 127.0.0.1' )
switch.cmd( 'ip link set lo up' )
intfs = str( sintf1 ), str( sintf2 )
switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
Expand Down
2 changes: 1 addition & 1 deletion examples/sshd.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def connectToRootNS( network, switch, ip, routes ):
network.start()
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
root.cmd( 'ip route add ' + route + ' dev ' + str( intf ) )

# pylint: disable=too-many-arguments
def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
Expand Down
22 changes: 22 additions & 0 deletions examples/test/new_test_for_iproute2/forTests/net.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
from mininet.net import Mininet
from mininet.log import setLogLevel, info
from mininet.cli import CLI


def net():

net = Mininet()
c0 = net.addController()
s1 = net.addSwitch( 's1' )
h1 = net.addHost( 'h1', ip='0.0.0.0/0' )
h2 = net.addHost( 'h2', ip='0.0.0.0/0' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
net.start()
CLI( net )
net.stop()

if __name__ == '__main__':
setLogLevel( 'info' )
net()
42 changes: 42 additions & 0 deletions examples/test/new_test_for_iproute2/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

"""
Run all mininet.examples tests
-v : verbose output
-quick : skip tests that take more than ~30 seconds
"""

import unittest
import os
import sys
from mininet.util import ensureRoot
from mininet.clean import cleanup

class MininetTestResult( unittest.TextTestResult ):
def addFailure( self, test, err ):
super( MininetTestResult, self ).addFailure( test, err )
cleanup()
def addError( self,test, err ):
super( MininetTestResult, self ).addError( test, err )
cleanup()

class MininetTestRunner( unittest.TextTestRunner ):
def _makeResult( self ):
return MininetTestResult( self.stream, self.descriptions, self.verbosity )

def runTests( testDir, verbosity=1 ):
"discover and run all tests in testDir"
# ensure root and cleanup before starting tests
ensureRoot()
cleanup()
# discover all tests in testDir
testSuite = unittest.defaultTestLoader.discover( testDir )
# run tests
success = MininetTestRunner( verbosity=verbosity ).run( testSuite ).wasSuccessful()
sys.exit( 0 if success else 1 )

if __name__ == '__main__':
# get the directory containing example tests
testDir = os.path.dirname( os.path.realpath( __file__ ) )
verbosity = 2 if '-v' in sys.argv else 1
runTests( testDir, verbosity )
94 changes: 94 additions & 0 deletions examples/test/new_test_for_iproute2/test_LinuxBridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python
import re
import unittest
from mininet.net import Mininet
from mininet.nodelib import LinuxBridge
from mininet.topo import Topo
from functools import partial
from mininet.util import irange

class RingTopo( Topo ):

def build( self, switchNum=3, hosts=1 ):
if switchNum < 3:
raise Exception( 'The minimal number of switches to form a ring is 3.')
first = self.addSwitch( 's1' )
for hostnum in irange( 1, hosts ):
host = self.addHost( 'h%s' % hostnum )
self.addLink( first, host )
last = first
for number in irange( 2, switchNum ):
next = self.addSwitch( 's%s' % number )
for hostnum in irange( ((number-1)*hosts)+1, ((number-1)*hosts)+hosts ):
host = self.addHost( 'h%s' % hostnum )
self.addLink( next, host )
self.addLink( last, next )
last = next
self.addLink( last, first )


def NodesConnectedToSwitch( switch ):
result = []
for intf in switch.intfList():
if intf.link:
intfs = [ intf.link.intf1, intf.link.intf2 ]
intfs.remove( intf )
node = intfs[ 0 ].node
name = node.name
if name[0:1]=='h':
result.append(node)
return result

class lxbrTest(unittest.TestCase):

def setUp( self ):
self.regex = '(\d+) received'
topo = RingTopo(hosts=2)
switch = partial( LinuxBridge, stp=True )
self.net = Mininet( topo=topo, switch=switch, waitConnected=True )
self.net.start()
self.hosts = [ self.net.getNodeByName( h ) for h in topo.hosts() ]
self.switches = [ self.net.getNodeByName( s ) for s in topo.switches() ]
self.swichToStop = self.switches[ -1 ]
self.nodeToPing = NodesConnectedToSwitch(self.swichToStop)[-1]
self.pingingNode = [h for h in self.hosts if h != self.nodeToPing][0]

def testHostsAndSwitchesNum( self ):
self.assertFalse(len(self.switches) < 3)
self.assertFalse(len(self.hosts) < 2)

def testAfterSetup( self ):
isForwarding = 'forwarding' in self.swichToStop.cmd('bridge link show | grep \'%s state\'' % self.swichToStop.name )
self.assertTrue(isForwarding)
ping = self.pingingNode.cmd('ping -c 1 %s | grep packets' % self.nodeToPing.IP())
pingReceived = re.search(self.regex,ping)
received = pingReceived.group(1)
self.assertEqual(int(received),1)

def testAfterStopLinuxBridge( self ):
self.swichToStop.stop(deleteIntfs=False)
stoppedSwitchState = self.swichToStop.cmd('bridge link show | grep \'%s state\'' % self.swichToStop.name )
self.assertEqual(stoppedSwitchState,'')
ping = self.pingingNode.cmd('ping -c 1 %s | grep packets' % self.nodeToPing.IP())
pingReceived = re.search(self.regex,ping)
received = pingReceived.group(1)
self.assertEqual(int(received),0)

def testAfterStartLinuxBridge( self ):
self.swichToStop.start([])
isListening = 'listening' in self.swichToStop.cmd('bridge link show | grep \'%s state\'' % self.swichToStop.name )
self.assertTrue(isListening)
self.net.waitConnected()
isForwarding = 'forwarding' in self.swichToStop.cmd('bridge link show | grep \'%s state\'' % self.swichToStop.name )
self.assertTrue(isForwarding)
ping = self.pingingNode.cmd('ping -c 1 %s | grep packets' % self.nodeToPing.IP())
pingReceived = re.search(self.regex,ping)
received = pingReceived.group(1)
self.assertEqual(int(received),1)


def tearDown( self ):
self.net.stop()

if __name__ == '__main__':
unittest.main()
Loading
0