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
18 "Add the OpenFlow13 Protocol" 20 params[
'protocols'] =
'OpenFlow13' 21 OVSSwitch.__init__(self, name, **params)
26 netstat = subprocess.check_output([
'netstat',
'-rn']).split(
'\n')
28 if line.startswith(
'0.0.0.0'):
29 gateway = re.split(
'\s+', line)[1]
32 print "gateway=", gateway
35 net = Mininet( controller=RemoteController, switch=KildaSwitch, build=
False )
37 info(
"*** Creating (Remote) controllers\n" )
38 c0 = net.addController(
'c0', ip=gateway, port=6653)
40 info(
"*** Creating switches\n" )
41 s1 = net.addSwitch(
's1' )
42 s2 = net.addSwitch(
's2' )
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 ) ]
48 info(
"*** Creating links\n" )
55 info(
"*** Starting network\n" )
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)
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()
77 print "NO CONNECTION BETWEEN ", hosts1[0].IP(),
"and", hosts1[1].IP()
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()
84 print "NO CONNECTION BETWEEN ", hosts1[0].IP(),
"and", hosts2[0].IP()
90 info(
"*** Running CLI\n" )
93 info(
"*** Stopping network\n" )
def __init__(self, name, params)