Open Kilda Java Documentation
plan-d.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # Plan D builds on Plan C, removing the need to load the flow rules and/or do a ping.
5 #
6 
7 
8 from mininet.net import Mininet
9 from mininet.node import OVSSwitch, Controller, RemoteController
10 from mininet.log import setLogLevel, info
11 from mininet.cli import CLI
12 
13 import subprocess
14 import re
15 
16 
17 class KildaSwitch( OVSSwitch ):
18  "Add the OpenFlow13 Protocol"
19  def __init__(self,name,**params):
20  params['protocols'] = 'OpenFlow13'
21  OVSSwitch.__init__(self, name, **params)
22 
23 
24 setLogLevel( 'info' )
25 gateway = '127.0.0.1'
26 netstat = subprocess.check_output(['netstat', '-rn']).split('\n')
27 for line in netstat:
28  if line.startswith('0.0.0.0'):
29  gateway = re.split('\s+', line)[1]
30  break
31 
32 print "gateway=", gateway
33 
34 
35 net = Mininet( controller=RemoteController, switch=KildaSwitch, build=False )
36 
37 info( "*** Creating (Remote) controllers\n" )
38 c0 = net.addController( 'c0', ip=gateway, port=6653)
39 
40 info( "*** Creating switches\n" )
41 s1 = net.addSwitch( 's1' )
42 s2 = net.addSwitch( 's2' )
43 
44 info( "*** Creating hosts\n" )
45 hosts1 = [ net.addHost( 'h%ds1' % n ) for n in ( 1, 2 ) ]
46 hosts2 = [ net.addHost( 'h%ds2' % n ) for n in ( 1, 2 ) ]
47 
48 info( "*** Creating links\n" )
49 for h in hosts1:
50  net.addLink( h, s1 )
51 for h in hosts2:
52  net.addLink( h, s2 )
53 net.addLink( s1, s2 )
54 
55 info( "*** Starting network\n" )
56 net.configHosts()
57 
58 # c0.start()
59 # s1.start( [c0] )
60 # s2.start( [c0] )
61 
62 net.start()
63 
64 p = subprocess.Popen(["ovs-ofctl","-O","OpenFlow13","add-flow","s1",
65  "idle_timeout=0,priority=1000,in_port=1,actions=output:2"],
66  stdout=subprocess.PIPE)
67 p = subprocess.Popen(["ovs-ofctl","-O","OpenFlow13","add-flow","s1",
68  "idle_timeout=0,priority=1000,in_port=2,actions=output:1"],
69  stdout=subprocess.PIPE)
70 p.wait()
71 
72 result = hosts1[0].cmd( 'ping -c1 %s' % (hosts1[1].IP()) )
73 lines = result.split("\n")
74 if "1 packets received" in lines[3]:
75  print "CONNECTION BETWEEN ", hosts1[0].IP(), "and", hosts1[1].IP()
76 else:
77  print "NO CONNECTION BETWEEN ", hosts1[0].IP(), "and", hosts1[1].IP()
78 
79 result = hosts1[0].cmd( 'ping -c1 %s' % (hosts2[0].IP()) )
80 lines = result.split("\n")
81 if "1 packets received" in lines[3]:
82  print "CONNECTION BETWEEN ", hosts1[0].IP(), "and", hosts2[0].IP()
83 else:
84  print "NO CONNECTION BETWEEN ", hosts1[0].IP(), "and", hosts2[0].IP()
85 
86 
87 
88 #info( "loss=" + loss )
89 
90 info( "*** Running CLI\n" )
91 CLI( net )
92 
93 info( "*** Stopping network\n" )
94 net.stop()
def __init__(self, name, params)
Definition: plan-d.py:19