Open Kilda Java Documentation
plan-b.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # Plan B shows how to interact with Mininet directly, without using the MininetRunner class.
5 # It replaces these two commands:
6 #
7 # 1) export gateway=`netstat -rn | grep "^0.0.0.0" | awk '{print $2}'`
8 # 2) mn --topo linear,k=2,n=2 --switch ovsk,protocols=OpenFlow13 --controller=remote,ip=${gateway}:6653
9 #
10 # Still need to:
11 # 3) mininet> sh ./h1s1_h2s1_rules.sh
12 # 4) mininet> h1s1 ping h2s2
13 #
14 
15 
16 from mininet.net import Mininet
17 from mininet.node import OVSSwitch, Controller, RemoteController
18 from mininet.topo import LinearTopo
19 from mininet.log import setLogLevel
20 from mininet.cli import CLI
21 
22 import subprocess
23 import re
24 
25 
26 class KildaSwitch( OVSSwitch ):
27  "Add the OpenFlow13 Protocol"
28  def __init__(self,name,**params):
29  params['protocols'] = 'OpenFlow13'
30  OVSSwitch.__init__(self, name, **params)
31 
32 
33 setLogLevel( 'info' )
34 gateway = '127.0.0.1'
35 netstat = subprocess.check_output(['netstat', '-rn']).split('\n')
36 for line in netstat:
37  if line.startswith('0.0.0.0'):
38  gateway = re.split('\s+', line)[1]
39  break
40 
41 print "gateway=", gateway
42 
43 
44 c0 = RemoteController( 'c0', ip=gateway, port=6653 )
45 topo = LinearTopo( k=2, n=2 )
46 net = Mininet( controller=c0, topo=topo, switch=KildaSwitch, build=False )
47 net.build()
48 net.start()
49 CLI( net )
50 net.stop()
def __init__(self, name, params)
Definition: plan-b.py:28