Open Kilda Java Documentation
plan-c.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # Plan C builds on Plan B, swapping out the topology mechanism for a hand built one.
5 #
6 # Still need to:
7 # 1) mininet> sh ./h1s1_h2s1_rules.sh
8 # 2) mininet> h1s1 ping h2s1
9 #
10 
11 from mininet.net import Mininet
12 from mininet.node import OVSSwitch, Controller, RemoteController
13 from mininet.log import setLogLevel, info
14 from mininet.cli import CLI
15 
16 import subprocess
17 import re
18 
19 
20 class KildaSwitch( OVSSwitch ):
21  "Add the OpenFlow13 Protocol"
22  def __init__(self,name,**params):
23  params['protocols'] = 'OpenFlow13'
24  OVSSwitch.__init__(self, name, **params)
25 
26 
27 setLogLevel( 'info' )
28 gateway = '127.0.0.1'
29 netstat = subprocess.check_output(['netstat', '-rn']).split('\n')
30 for line in netstat:
31  if line.startswith('0.0.0.0'):
32  gateway = re.split('\s+', line)[1]
33  break
34 
35 print "gateway=", gateway
36 
37 
38 net = Mininet( controller=RemoteController, switch=KildaSwitch, build=False )
39 
40 info( "*** Creating (Remote) controllers\n" )
41 c0 = net.addController( 'c0', ip=gateway, port=6653)
42 
43 info( "*** Creating switches\n" )
44 s1 = net.addSwitch( 's1' )
45 s2 = net.addSwitch( 's2' )
46 
47 info( "*** Creating hosts\n" )
48 hosts1 = [ net.addHost( 'h%ds1' % n ) for n in ( 1, 2 ) ]
49 hosts2 = [ net.addHost( 'h%ds2' % n ) for n in ( 1, 2 ) ]
50 
51 info( "*** Creating links\n" )
52 for h in hosts1:
53  net.addLink( h, s1 )
54 for h in hosts2:
55  net.addLink( h, s2 )
56 net.addLink( s1, s2 )
57 
58 info( "*** Starting network\n" )
59 net.configHosts()
60 
61 # c0.start()
62 # s1.start( [c0] )
63 # s2.start( [c0] )
64 
65 net.start()
66 
67 info( "*** Running CLI\n" )
68 CLI( net )
69 
70 info( "*** Stopping network\n" )
71 net.stop()
def __init__(self, name, params)
Definition: plan-c.py:22