MCPcopy Create free account
hub / github.com/mininet/mininet / scratchNet

Function scratchNet

examples/scratchnet.py:20–63  ·  view source on GitHub ↗

Create network from scratch using Open vSwitch.

( cname='controller', cargs='-v ptcp:' )

Source from the content-addressed store, hash-verified

18
19
20def scratchNet( cname='controller', cargs='-v ptcp:' ):
21 "Create network from scratch using Open vSwitch."
22
23 info( "*** Creating nodes\n" )
24 controller = Node( 'c0', inNamespace=False )
25 switch = Node( 's0', inNamespace=False )
26 h0 = Node( 'h0' )
27 h1 = Node( 'h1' )
28
29 info( "*** Creating links\n" )
30 Link( h0, switch )
31 Link( h1, switch )
32
33 info( "*** Configuring hosts\n" )
34 h0.setIP( '192.168.123.1/24' )
35 h1.setIP( '192.168.123.2/24' )
36 info( str( h0 ) + '\n' )
37 info( str( h1 ) + '\n' )
38
39 info( "*** Starting network using Open vSwitch\n" )
40 controller.cmd( cname + ' ' + cargs + '&' )
41 switch.cmd( 'ovs-vsctl del-br dp0' )
42 switch.cmd( 'ovs-vsctl add-br dp0' )
43 for intf in switch.intfs.values():
44 switch.cmd( 'ovs-vsctl add-port dp0 %s\n' % intf )
45
46 # Note: controller and switch are in root namespace, and we
47 # can connect via loopback interface
48 switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
49
50 info( '*** Waiting for switch to connect to controller' )
51 while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
52 sleep( 1 )
53 info( '.' )
54 info( '\n' )
55
56 info( "*** Running test\n" )
57 h0.cmdPrint( 'ping -c1 ' + h1.IP() )
58
59 info( "*** Stopping network\n" )
60 controller.cmd( 'kill %' + cname )
61 switch.cmd( 'ovs-vsctl del-br dp0' )
62 switch.deleteIntfs()
63 info( '\n' )
64
65
66if __name__ == '__main__':

Callers 1

scratchnet.pyFile · 0.85

Calls 9

setIPMethod · 0.95
cmdMethod · 0.95
cmdPrintMethod · 0.95
IPMethod · 0.95
deleteIntfsMethod · 0.95
NodeClass · 0.90
LinkClass · 0.90
quietRunFunction · 0.90
valuesMethod · 0.45

Tested by

no test coverage detected